observe

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package observe contains the MainChain and Shutter structs, which the keyper uses to fetch the necessary information from the ethereum node and the shuttermint node. The SyncToHead methods can be used to fetch the latest information. All other public methods do not modify the stored data. Do not mutate any of the data stored in these structs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SyncMain

func SyncMain(
	ctx context.Context,
	caller *contract.Caller,
	mainChain *MainChain,
	mainChains chan<- *MainChain,
) error

SyncMain subscribes to new blocks on the main chain and syncs the main chain object with the head block in a loop. It writes newly synced main chain objects to the mainChains channel, as well as errors to the syncErrors channel.

func SyncShutter

func SyncShutter(ctx context.Context, shmcl client.Client, shutter *Shutter, shutters chan<- *Shutter, filter <-chan ShutterFilter) error

SyncShutter subscribes to new blocks and syncs the shutter object with the head block in a loop. It writes newly synced shutter objects to the shutters channel, as well as errors to the syncErrors channel.

Types

type Accusation

type Accusation struct {
	Executor    common.Address
	Accuser     common.Address
	Appealed    bool
	HalfStep    uint64
	BlockNumber uint64
}

Accusation represents an accusation against a keyper in the keyper slasher.

type Batch

type Batch struct {
	BatchIndex            uint64
	EncryptedBatchHash    common.Hash
	EncryptedTransactions [][]byte
	PlainTransactions     [][]byte
	PlainBatchHash        common.Hash
}

Batch stores the encrypted and plain transactions submitted to the batching contract for a particular index.

func (*Batch) DecryptTransactions

func (batch *Batch) DecryptTransactions(key *shcrypto.EpochSecretKey) [][]byte

DecryptTransactions decrypts and shuffles the encrypted transactions. It will log an error message for transactions that cannot be decrypted and skip over them.

type BatchData

type BatchData struct {
	BatchIndex           uint64
	DecryptionSignatures []shutterevents.DecryptionSignature
}

type Deposit

type Deposit struct {
	Account                  common.Address
	Slashed                  bool
	Amount                   *big.Int
	WithdrawalDelayBlocks    uint64
	WithdrawalRequestedBlock uint64
}

Deposit represents a deposit in the deposit contract.

type EncryptionPublicKey

type EncryptionPublicKey ecies.PublicKey

EncryptionPublicKey is a gob serializable version of ecies.PublicKey.

func (*EncryptionPublicKey) Encrypt

func (epk *EncryptionPublicKey) Encrypt(rand io.Reader, m []byte) ([]byte, error)

Encrypt the given message m.

func (*EncryptionPublicKey) GobDecode

func (epk *EncryptionPublicKey) GobDecode(data []byte) error

func (*EncryptionPublicKey) GobEncode

func (epk *EncryptionPublicKey) GobEncode() ([]byte, error)

type Eon

type Eon struct {
	Eon                  uint64
	StartHeight          int64
	StartEvent           shutterevents.EonStarted
	Commitments          []shutterevents.PolyCommitment
	PolyEvals            []shutterevents.PolyEval
	Accusations          []shutterevents.Accusation
	Apologies            []shutterevents.Apology
	EpochSecretKeyShares []shutterevents.EpochSecretKeyShare
}

func (*Eon) ApplyFilter

func (eon *Eon) ApplyFilter(syncHeight int64) *Eon

func (*Eon) GetAccusations

func (eon *Eon) GetAccusations(syncHeight int64) []shutterevents.Accusation

func (*Eon) GetApologies

func (eon *Eon) GetApologies(syncHeight int64) []shutterevents.Apology

func (*Eon) GetEpochSecretKeyShares

func (eon *Eon) GetEpochSecretKeyShares(syncHeight int64) []shutterevents.EpochSecretKeyShare

func (*Eon) GetPolyCommitments

func (eon *Eon) GetPolyCommitments(syncHeight int64) []shutterevents.PolyCommitment

func (*Eon) GetPolyEvals

func (eon *Eon) GetPolyEvals(syncHeight int64) []shutterevents.PolyEval

type MainChain

type MainChain struct {
	FollowDistance          uint64
	CurrentBlock            uint64
	NodeSyncProgress        *ethereum.SyncProgress
	BatchConfigs            []contract.BatchConfig
	Batches                 map[uint64]*Batch
	NumExecutionHalfSteps   uint64
	CipherExecutionReceipts map[uint64]*contract.CipherExecutionReceipt
	Deposits                map[common.Address]*Deposit
	Accusations             map[uint64]*Accusation
}

MainChain let's a keyper fetch all necessary information from an ethereum node to do it's work. The only source for the data stored in this struct should be the ethereum node. The SyncToHead method can be used to update the data. All other accesses should be read-only.

func NewMainChain

func NewMainChain(followDistance uint64) *MainChain

NewMainChain creates an empty MainChain struct.

func (*MainChain) ActiveConfig

func (mainchain *MainChain) ActiveConfig(blocknum uint64) contract.BatchConfig

ActiveConfig returns the config that is active for the given block number.

func (*MainChain) ActiveConfigIndex

func (mainchain *MainChain) ActiveConfigIndex(blocknum uint64) int

ActiveConfigIndex returns the index of the config that is active for the given block number.

func (*MainChain) ActiveConfigs

func (mainchain *MainChain) ActiveConfigs() []contract.BatchConfig

ActiveConfigs returns a slice of the active configs.

func (*MainChain) Clone

func (mainchain *MainChain) Clone() *MainChain

func (*MainChain) ConfigForBatchIndex

func (mainchain *MainChain) ConfigForBatchIndex(batchIndex uint64) (contract.BatchConfig, bool)

ConfigForBatchIndex returns the config responsible for the given batch if it is active. Note that this config might change if the batch is too far into the future.

func (*MainChain) ConfigIndexForBatchIndex

func (mainchain *MainChain) ConfigIndexForBatchIndex(batchIndex uint64) (int, bool)

ConfigIndexForBatchIndex returns the index of the config responsible for the given batch if it is active. Note that this config might change if the batch is too far into the future.

func (*MainChain) CurrentConfig

func (mainchain *MainChain) CurrentConfig() contract.BatchConfig

CurrentConfig returns the batch config active at the current block number.

func (*MainChain) GetDeposit

func (mainchain *MainChain) GetDeposit(account common.Address) *Deposit

GetDeposit returns the deposit of the given account or an empty one if it doesn't exist.

func (*MainChain) IsActiveKeyper

func (mainchain *MainChain) IsActiveKeyper(addr common.Address) bool

IsActiveKeyper checks if the given address is registered as a keyper in one of the active batch configs.

func (*MainChain) IsSynced

func (mainchain *MainChain) IsSynced() bool

IsSynced checks if the node we are connected to is synced to the network. Prior to the first call to SyncToHead, this returns true.

func (*MainChain) SyncToHead

func (mainchain *MainChain) SyncToHead(
	ctx context.Context,
	cc *contract.Caller,
) (*MainChain, error)

SyncToHead fetches the latest state from the ethereum node. It returns a new object with the latest state.

type Shutter

type Shutter struct {
	CurrentBlock         int64
	LastCommittedHeight  int64
	NodeStatus           *rpctypes.ResultStatus
	KeyperEncryptionKeys map[common.Address]*EncryptionPublicKey
	BatchConfigs         []shutterevents.BatchConfig
	Batches              map[uint64]*BatchData
	Eons                 []Eon
	Filter               ShutterFilter
}

Shutter let's a keyper fetch all necessary information from a shuttermint node. The only source for the data stored in this struct should be the shutter node. The SyncToHead method can be used to update the data. All other accesses should be read-only.

func NewShutter

func NewShutter() *Shutter

NewShutter creates an empty Shutter struct.

func (*Shutter) ApplyFilter

func (shutter *Shutter) ApplyFilter(newFilter ShutterFilter) *Shutter

ApplyFilter applies the given filter and returns a new shutter object with the filter applied.

func (*Shutter) Clone

func (shutter *Shutter) Clone() *Shutter

func (*Shutter) FindBatchConfigByBatchIndex

func (shutter *Shutter) FindBatchConfigByBatchIndex(batchIndex uint64) shutterevents.BatchConfig

func (*Shutter) FindBatchConfigByConfigIndex

func (shutter *Shutter) FindBatchConfigByConfigIndex(configIndex uint64) (shutterevents.BatchConfig, error)

func (*Shutter) FindEon

func (shutter *Shutter) FindEon(eon uint64) (*Eon, error)

func (*Shutter) FindEonByBatchIndex

func (shutter *Shutter) FindEonByBatchIndex(batchIndex uint64) (*Eon, error)

func (*Shutter) GetLastCommittedHeight

func (shutter *Shutter) GetLastCommittedHeight(ctx context.Context, shmcl client.Client) (int64, error)

func (*Shutter) IsCheckedIn

func (shutter *Shutter) IsCheckedIn(addr common.Address) bool

IsCheckedIn checks if the given address sent it's check-in message.

func (*Shutter) IsKeyper

func (shutter *Shutter) IsKeyper(addr common.Address) bool

IsKeyper checks if the given address is a keyper in any of the given configs.

func (*Shutter) IsSynced

func (shutter *Shutter) IsSynced() bool

IsSynced checks if the shuttermint node is synced with the network.

func (*Shutter) ShallowClone

func (shutter *Shutter) ShallowClone() *Shutter

func (*Shutter) SyncToHead

func (shutter *Shutter) SyncToHead(ctx context.Context, shmcl client.Client) (*Shutter, error)

SyncToHead syncs the state with the remote state. It fetches events from new blocks since the last sync and updates the state by calling applyEvent for each event. This method does not mutate the object in place, it rather returns a new object.

func (*Shutter) SyncToHeight

func (shutter *Shutter) SyncToHeight(ctx context.Context, shmcl client.Client, height int64) (*Shutter, error)

SyncToHeight syncs the state with the remote state until the given height.

type ShutterFilter

type ShutterFilter struct {
	SyncHeight int64
	BatchIndex uint64
}

ShutterFilter is used to filter the shutter state we do build. Filtering is done in Shutter.ApplyFilter.

func (ShutterFilter) NeedsUpdate

func (filter ShutterFilter) NeedsUpdate(newFilter ShutterFilter) bool

type World

type World struct {
	Shutter   *Shutter
	MainChain *MainChain
}

World describes the observable outside world, i.e. the shutter and main chain instance.

Jump to

Keyboard shortcuts

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