monitor

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SvcProcessEvents Uses the current state to process more events
	SvcWatchEthereum = "SvcWatchEthereum"

	// SvcEndpointInSync Checks if the Ethereum endpoint is ready for use
	SvcEndpointInSync = "SvcEndpointInSync"

	// SvcGetEvents Checks known contracts for recently emitted events
	SvcGetEvents = "SvcGetEvents"

	// SvcGetValidators Calls contract to get current list of validators
	SvcGetValidators = "SvcGetValidators"

	// SvcGetSnapShot Calls contract to get snapshots
	SvcGetSnapShot = "SvcGetSnapShot"
)

These are pseudo-constants for registering services on bus

View Source
var (
	// ErrUnknownRequest a service was invoked but couldn't figure out which
	ErrUnknownRequest = errors.New("unknown request")

	// ErrUnknownResponse only used when response to a service is not of the expected type
	ErrUnknownResponse = errors.New("response isn't in expected form")
)
View Source
var ErrCanNotContinue = errors.New("can not continue distributed key generation")

ErrCanNotContinue standard error if we must drop out of ETHDKG

Functions

func AbortETHDKG

func AbortETHDKG(ethdkg *EthDKGState)

AbortETHDKG does the required cleanup to stop a round of ETHDKG

func ETHDKGInProgress

func ETHDKGInProgress(ethdkg *EthDKGState, currentBlock uint64) bool

ETHDKGInProgress indicates if ETHDKG is currently running

func RetrieveParticipants

func RetrieveParticipants(eth blockchain.Ethereum, callOpts *bind.CallOpts) (dkg.ParticipantList, int, error)

RetrieveParticipants retrieves participant details from ETHDKG contract

Types

type Bus

type Bus interface {
	StartLoop() (chan<- bool, error)
	StopLoop() error
	Register(serviceName string, capacity uint16) (<-chan rbus.Request, error)
	Request(serviceName string, timeOut time.Duration, request interface{}) (rbus.Response, error)
}

Bus basic functionality required for monitor system

func NewBus

func NewBus(rb rbus.Rbus, svcs *Services) (Bus, error)

NewBus setups an rbus for monitoring services

type Database

type Database interface {
	FindState() (*State, error)
	UpdateState(state *State) error
}

Database describes required functionality for monitor persistence

func NewDatabase

func NewDatabase(ctx context.Context, directoryName string, inMemory bool) Database

NewDatabase initializes a new monitor database

func NewDatabaseFromExisting

func NewDatabaseFromExisting(db *badger.DB) Database

type EthDKGPhase

type EthDKGPhase int

EthDKGPhase is used to indicate what phase we are currently in

const (
	Registration EthDKGPhase = iota
	ShareDistribution
	Dispute
	KeyShareSubmission
	MPKSubmission
	GPKJSubmission
	GPKJGroupAccusation
)

These are the valid phases of ETHDKG

type EthDKGSchedule

type EthDKGSchedule struct {
	RegistrationStart        uint64
	RegistrationEnd          uint64
	ShareDistributionStart   uint64
	ShareDistributionEnd     uint64
	DisputeStart             uint64
	DisputeEnd               uint64
	KeyShareSubmissionStart  uint64
	KeyShareSubmissionEnd    uint64
	MPKSubmissionStart       uint64
	MPKSubmissionEnd         uint64
	GPKJSubmissionStart      uint64
	GPKJSubmissionEnd        uint64
	GPKJGroupAccusationStart uint64
	GPKJGroupAccusationEnd   uint64
	CompleteStart            uint64
	CompleteEnd              uint64
}

EthDKGSchedule RegistrationOpen event publishes phase schedule, so we record that here

type EthDKGState

type EthDKGState struct {

	// Local validator info
	Address             common.Address
	Index               int
	GroupPrivateKey     *big.Int
	GroupPublicKey      [4]*big.Int
	MasterPublicKey     [4]*big.Int
	NumberOfValidators  int
	PrivateCoefficients []*big.Int
	Schedule            *EthDKGSchedule
	SecretValue         *big.Int
	ValidatorThreshold  int
	TransportPrivateKey *big.Int
	TransportPublicKey  [2]*big.Int

	// Remote validator info
	Commitments                 map[common.Address][][2]*big.Int // ShareDistribution Event
	EncryptedShares             map[common.Address][]*big.Int    // "
	KeyShareG1s                 map[common.Address][2]*big.Int   // KeyShare Event
	KeyShareG1CorrectnessProofs map[common.Address][2]*big.Int   // "
	KeyShareG2s                 map[common.Address][4]*big.Int   // "
	Participants                dkg.ParticipantList              // Index, Address & PublicKey

	// Handlers
	RegistrationTH        tasks.TaskHandler
	ShareDistributionTH   tasks.TaskHandler
	DisputeTH             tasks.TaskHandler
	KeyShareSubmissionTH  tasks.TaskHandler
	MPKSubmissionTH       tasks.TaskHandler
	GPKJSubmissionTH      tasks.TaskHandler
	GPKJGroupAccusationTH tasks.TaskHandler
	CompleteTH            tasks.TaskHandler
}

EthDKGState is used to track the state of the ETHDKG

func NewEthDKGState

func NewEthDKGState() *EthDKGState

NewEthDKGState creates a new EthDKGState with maps initialized

type Monitor

type Monitor interface {
	StartEventLoop() (chan<- bool, error)
	GetStatus() <-chan string
}

Monitor describes required functionality to monitor Ethereum

func NewMonitor

func NewMonitor(db Database, bus Bus, tickInterval time.Duration, timeout time.Duration) (Monitor, error)

NewMonitor creates a new Monitor

type Services

type Services struct {
	// contains filtered or unexported fields
}

Services just a bundle of requirements common for monitoring functionality

func NewServices

func NewServices(eth blockchain.Ethereum, db *db.Database, dph *deposit.Handler, ah *admin.Handlers, batchSize int, chainID uint32) *Services

NewServices creates a new Services struct

func (*Services) DoDistributeShares

func (svcs *Services) DoDistributeShares(state *State, block uint64) error

DoDistributeShares this should happen when it's time to distribute shares

func (*Services) DoGroupAccusationGPKj

func (svcs *Services) DoGroupAccusationGPKj(state *State, block uint64) error

DoGroupAccusationGPKj does something

func (*Services) DoSubmitDispute

func (svcs *Services) DoSubmitDispute(state *State, block uint64) error

DoSubmitDispute submits a dispute if any of the shares we've seen are bad

func (*Services) DoSubmitGPKj

func (svcs *Services) DoSubmitGPKj(state *State, block uint64) error

DoSubmitGPKj does something

func (*Services) DoSubmitKeyShare

func (svcs *Services) DoSubmitKeyShare(state *State, block uint64) error

DoSubmitKeyShare does something

func (*Services) DoSubmitMasterPublicKey

func (svcs *Services) DoSubmitMasterPublicKey(state *State, block uint64) error

DoSubmitMasterPublicKey does something

func (*Services) DoSuccessfulCompletion

func (svcs *Services) DoSuccessfulCompletion(state *State, block uint64) error

DoSuccessfulCompletion does something

func (*Services) EndpointInSync

func (svcs *Services) EndpointInSync(ctx context.Context, state *State) error

EndpointInSync Checks if our endpoint is good to use -- This function is different. Because we need to be aware of errors, state is always updated

func (*Services) PersistSnapshot

func (svcs *Services) PersistSnapshot(blockHeader *objs.BlockHeader) error

PersistSnapshot records the given block header on Ethereum and increments epoch TODO Returning an error kills the main loop, retry forever instead

func (*Services) ProcessDepositReceived

func (svcs *Services) ProcessDepositReceived(state *State, log types.Log) error

ProcessDepositReceived handles logic around receiving a deposit event

func (*Services) ProcessKeyShareSubmission

func (svcs *Services) ProcessKeyShareSubmission(state *State, log types.Log) error

ProcessKeyShareSubmission ETHDKG

func (*Services) ProcessRegistrationOpen

func (svcs *Services) ProcessRegistrationOpen(state *State, log types.Log) error

ProcessRegistrationOpen when we see ETHDKG has initialized we need to start

func (*Services) ProcessShareDistribution

func (svcs *Services) ProcessShareDistribution(state *State, log types.Log) error

ProcessShareDistribution accumulates everyones shares ETHDKG

func (*Services) ProcessSnapshotTaken

func (svcs *Services) ProcessSnapshotTaken(state *State, log types.Log) error

ProcessSnapshotTaken handles receiving snapshots

func (*Services) ProcessValidatorMember

func (svcs *Services) ProcessValidatorMember(state *State, log types.Log) error

ProcessValidatorMember handles receiving keys for a specific validator

func (*Services) ProcessValidatorSet

func (svcs *Services) ProcessValidatorSet(state *State, log types.Log) error

ProcessValidatorSet handles receiving validatorSet changes

func (*Services) RegisterEvent

func (svcs *Services) RegisterEvent(selector string, name string, fn func(*State, types.Log) error) error

RegisterEvent registers a handler for when an interesting event shows up

func (*Services) SetBN256PrivateKey

func (svcs *Services) SetBN256PrivateKey(pk []byte) error

SetBN256PrivateKey informs the admin bus of the BN256 private key

func (*Services) SetSECP256K1PrivateKey

func (svcs *Services) SetSECP256K1PrivateKey(pk []byte) error

SetSECP256K1PrivateKey informs the admin bus of the SECP256K1 private key

func (*Services) UpdateProgress

func (svcs *Services) UpdateProgress(state *State) error

UpdateProgress updates what we know of Ethereum chain height

func (*Services) WatchEthereum

func (svcs *Services) WatchEthereum(state *State) error

WatchEthereum checks for state of Ethereum and processes interesting conditions

type Share

type Share struct {
	Issuer          common.Address
	Commitments     [][2]*big.Int
	EncryptedShares []*big.Int
}

Share is temporary storage of shares coming from validators

type State

type State struct {
	// TODO decide if a mutex is required
	Version                uint8
	CommunicationFailures  uint32
	EthereumInSync         bool
	HighestBlockProcessed  uint64
	HighestBlockFinalized  uint64
	HighestEpochProcessed  uint32
	HighestEpochSeen       uint32
	InSync                 bool
	LatestDepositProcessed uint32
	LatestDepositSeen      uint32
	PeerCount              uint32
	ValidatorSets          map[uint32]ValidatorSet
	Validators             map[uint32][]Validator
	// contains filtered or unexported fields
}

State contains info required to monitor Ethereum

func (*State) Clone

func (s *State) Clone() *State

Clone builds a deep copy of a state

func (*State) Diff

func (s *State) Diff(o *State) string

Diff builds a textual description between states

func (State) String

func (s State) String() string

type Validator

type Validator struct {
	Account   common.Address
	Index     uint8
	SharedKey [4]big.Int
}

Validator contains information about a Validator

type ValidatorSet

type ValidatorSet struct {
	ValidatorCount        uint8
	GroupKey              [4]big.Int
	NotBeforeMadNetHeight uint32
}

ValidatorSet is summary information about a ValidatorSet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL