Documentation ¶
Index ¶
- func InitializeState(c *config.Config, initialValidators []InitialValidatorEntry, ...) (*primitives.State, error)
- type BlockFilter
- type BlockIndex
- func (bi *BlockIndex) AddBlockNodeToIndex(block *primitives.Block, blockHash chainhash.Hash, stateRoot chainhash.Hash) (*BlockNode, error)
- func (bi *BlockIndex) GetBlockNodeByHash(hash chainhash.Hash) *BlockNode
- func (bi *BlockIndex) Has(h chainhash.Hash) bool
- func (bi *BlockIndex) LoadBlockNode(blockNodeDisk *db.BlockNodeDisk) (*BlockNode, error)
- type BlockNode
- type Blockchain
- func (b *Blockchain) AddBlockToStateMap(block *primitives.Block, verifySignature bool) ([]primitives.Receipt, *primitives.State, error)
- func (b *Blockchain) GenesisHash() chainhash.Hash
- func (b *Blockchain) GetBlockByHash(h chainhash.Hash) (*primitives.Block, error)
- func (b *Blockchain) GetConfig() *config.Config
- func (b *Blockchain) GetCurrentSlot() uint64
- func (b *Blockchain) GetEpochBoundaryHash(slot uint64) (chainhash.Hash, error)
- func (b *Blockchain) GetNextSlotTime() time.Time
- func (b *Blockchain) GetState() primitives.State
- func (b *Blockchain) GetSubView(tip chainhash.Hash) (ChainView, error)
- func (b *Blockchain) GetUpdatedState(upTo uint64) (*primitives.State, error)
- func (b *Blockchain) Height() uint64
- func (b *Blockchain) ProcessBlock(block *primitives.Block, checkTime bool, verifySignature bool) ([]primitives.Receipt, *primitives.State, error)
- func (b *Blockchain) RegisterNotifee(n BlockchainNotifee)
- func (b *Blockchain) StoreBlock(block *primitives.Block) error
- func (b *Blockchain) UpdateChainHead() error
- type BlockchainNotifee
- type BlockchainView
- func (bv *BlockchainView) GetFinalizedHead() (*BlockNode, primitives.State)
- func (bv *BlockchainView) GetJustifiedHead() (*BlockNode, primitives.State)
- func (bv *BlockchainView) SetFinalizedHead(finalizedHash chainhash.Hash, finalizedState primitives.State)
- func (bv *BlockchainView) SetJustifiedHead(justifiedHash chainhash.Hash, justifiedState primitives.State)
- type Chain
- func (c *Chain) Contains(node *BlockNode) bool
- func (c *Chain) Genesis() *BlockNode
- func (c *Chain) GetBlockByHeight(height int) *BlockNode
- func (c *Chain) GetBlockBySlot(slot uint64) (*BlockNode, error)
- func (c *Chain) GetChainLocator() [][]byte
- func (c *Chain) Height() int64
- func (c *Chain) Next(node *BlockNode) *BlockNode
- func (c *Chain) SetTip(node *BlockNode)
- func (c *Chain) Tip() *BlockNode
- type ChainView
- type InitialValidatorEntry
- type InitialValidatorEntryAndPrivateKey
- type Mempool
- func (m *Mempool) ConnectBlock(b *primitives.Block)
- func (m *Mempool) GetAttestationsToInclude(slot uint64, c *config.Config) ([]primitives.Attestation, error)
- func (m *Mempool) ProcessNewAttestation(att primitives.Attestation) error
- func (m *Mempool) RemoveAttestationsFromBitfield(slot uint64, shard uint64, bitfield []uint8)
- type StateManager
- func (sm *StateManager) AddBlockToStateMap(block *primitives.Block, verifySignature bool) ([]primitives.Receipt, *primitives.State, error)
- func (sm *StateManager) DeleteStateBeforeFinalizedSlot(finalizedSlot uint64) error
- func (sm *StateManager) GetGenesisTime() uint64
- func (sm *StateManager) GetStateForHash(blockHash chainhash.Hash) (*primitives.State, bool)
- func (sm *StateManager) GetStateForHashAtSlot(blockHash chainhash.Hash, slot uint64, view primitives.BlockView, ...) (*primitives.State, error)
- func (sm *StateManager) SetBlockState(blockHash chainhash.Hash, state *primitives.State) error
- type SyncManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitializeState ¶
func InitializeState(c *config.Config, initialValidators []InitialValidatorEntry, genesisTime uint64, skipValidation bool) (*primitives.State, error)
InitializeState initializes state to the genesis state according to the config.
Types ¶
type BlockFilter ¶ added in v0.2.4
BlockFilter is a filter for block hashes that returns whether the block hash is in the filter or not.
type BlockIndex ¶
type BlockIndex struct {
// contains filtered or unexported fields
}
BlockIndex is an index from Hash to block node.
func (*BlockIndex) AddBlockNodeToIndex ¶
func (bi *BlockIndex) AddBlockNodeToIndex(block *primitives.Block, blockHash chainhash.Hash, stateRoot chainhash.Hash) (*BlockNode, error)
AddBlockNodeToIndex adds a new block ot the blockchain.
func (*BlockIndex) GetBlockNodeByHash ¶
func (bi *BlockIndex) GetBlockNodeByHash(hash chainhash.Hash) *BlockNode
GetBlockNodeByHash gets a block node by hash.
func (*BlockIndex) Has ¶
func (bi *BlockIndex) Has(h chainhash.Hash) bool
Has returns true if the block index has the specified block.
func (*BlockIndex) LoadBlockNode ¶
func (bi *BlockIndex) LoadBlockNode(blockNodeDisk *db.BlockNodeDisk) (*BlockNode, error)
LoadBlockNode loads a block node from disk. The parent must have already been added.
type BlockNode ¶
type BlockNode struct { Hash chainhash.Hash Height uint64 Slot uint64 Parent *BlockNode StateRoot chainhash.Hash Children []*BlockNode }
BlockNode is an in-memory representation of a block.
func (*BlockNode) GetAncestorAtHeight ¶
GetAncestorAtHeight gets the ancestor of a block at a certain height.
func (*BlockNode) GetAncestorAtSlot ¶
GetAncestorAtSlot gets the ancestor of a block at a certain slot.
type Blockchain ¶
type Blockchain struct { View *BlockchainView DB db.Database Notifees []BlockchainNotifee // contains filtered or unexported fields }
Blockchain represents a chain of blocks.
func NewBlockchainWithInitialValidators ¶
func NewBlockchainWithInitialValidators(db db.Database, config *config.Config, validators []InitialValidatorEntry, skipValidation bool, genesisTime uint64) (*Blockchain, error)
NewBlockchainWithInitialValidators creates a new blockchain with the specified initial validators.
func (*Blockchain) AddBlockToStateMap ¶
func (b *Blockchain) AddBlockToStateMap(block *primitives.Block, verifySignature bool) ([]primitives.Receipt, *primitives.State, error)
AddBlockToStateMap calculates the state after applying block and adds it to the state map.
func (*Blockchain) GenesisHash ¶ added in v0.2.4
func (b *Blockchain) GenesisHash() chainhash.Hash
GenesisHash gets the genesis hash for the chain.
func (*Blockchain) GetBlockByHash ¶
func (b *Blockchain) GetBlockByHash(h chainhash.Hash) (*primitives.Block, error)
GetBlockByHash gets a block by Hash.
func (*Blockchain) GetConfig ¶
func (b *Blockchain) GetConfig() *config.Config
GetConfig returns the config used by this blockchain
func (*Blockchain) GetCurrentSlot ¶
func (b *Blockchain) GetCurrentSlot() uint64
GetCurrentSlot gets the current slot according to the time.
func (*Blockchain) GetEpochBoundaryHash ¶
func (b *Blockchain) GetEpochBoundaryHash(slot uint64) (chainhash.Hash, error)
GetEpochBoundaryHash gets the Hash of the parent block at the epoch boundary.
func (*Blockchain) GetNextSlotTime ¶
func (b *Blockchain) GetNextSlotTime() time.Time
GetNextSlotTime returns the timestamp of the next slot.
func (*Blockchain) GetState ¶
func (b *Blockchain) GetState() primitives.State
GetState gets a copy of the current state of the blockchain.
func (*Blockchain) GetSubView ¶
func (b *Blockchain) GetSubView(tip chainhash.Hash) (ChainView, error)
GetSubView gets a view of the blockchain at a certain tip.
func (*Blockchain) GetUpdatedState ¶
func (b *Blockchain) GetUpdatedState(upTo uint64) (*primitives.State, error)
GetUpdatedState gets the tip, but with processed slots/epochs as appropriate.
func (*Blockchain) Height ¶
func (b *Blockchain) Height() uint64
Height returns the height of the chain.
func (*Blockchain) ProcessBlock ¶
func (b *Blockchain) ProcessBlock(block *primitives.Block, checkTime bool, verifySignature bool) ([]primitives.Receipt, *primitives.State, error)
ProcessBlock is called when a block is received from a peer.
func (*Blockchain) RegisterNotifee ¶ added in v0.2.4
func (b *Blockchain) RegisterNotifee(n BlockchainNotifee)
RegisterNotifee registers a notifee for blockchain
func (*Blockchain) StoreBlock ¶
func (b *Blockchain) StoreBlock(block *primitives.Block) error
StoreBlock adds a block header to the current chain. The block should already have been validated by this point.
func (*Blockchain) UpdateChainHead ¶
func (b *Blockchain) UpdateChainHead() error
UpdateChainHead updates the blockchain head if needed
type BlockchainNotifee ¶ added in v0.2.4
type BlockchainNotifee interface {
ConnectBlock(*primitives.Block)
}
BlockchainNotifee is a blockchain notifee.
type BlockchainView ¶
type BlockchainView struct { Chain *Chain Index *BlockIndex // contains filtered or unexported fields }
BlockchainView is the state of GHOST-LMD
func NewBlockchainView ¶
func NewBlockchainView() *BlockchainView
NewBlockchainView creates a new blockchain view.
func (*BlockchainView) GetFinalizedHead ¶
func (bv *BlockchainView) GetFinalizedHead() (*BlockNode, primitives.State)
GetFinalizedHead gets the finalized head of the blockchain.
func (*BlockchainView) GetJustifiedHead ¶
func (bv *BlockchainView) GetJustifiedHead() (*BlockNode, primitives.State)
GetJustifiedHead gets the justified head of the blockchain.
func (*BlockchainView) SetFinalizedHead ¶
func (bv *BlockchainView) SetFinalizedHead(finalizedHash chainhash.Hash, finalizedState primitives.State)
SetFinalizedHead sets the finalized head of the blockchain.
func (*BlockchainView) SetJustifiedHead ¶
func (bv *BlockchainView) SetJustifiedHead(justifiedHash chainhash.Hash, justifiedState primitives.State)
SetJustifiedHead sets the justified head of the blockchain.
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain is a representation of the current main chain.
func (*Chain) GetBlockByHeight ¶
GetBlockByHeight gets a block at a certain height or if it doesn't exist, returns nil.
func (*Chain) GetBlockBySlot ¶ added in v0.2.4
GetBlockBySlot gets the block node at a certain slot.
func (*Chain) GetChainLocator ¶
GetChainLocator gets a chain locator by requesting blocks at certain heights. This code is basically copied from the Bitcoin code.
type ChainView ¶
type ChainView struct {
// contains filtered or unexported fields
}
ChainView is a view of a certain chain in the block tree so that block processing can access valid blocks.
func NewChainView ¶
NewChainView creates a new chain view with a certain tip
func (*ChainView) GetHashBySlot ¶
GetHashBySlot gets a hash of a block in a certain slot.
func (*ChainView) GetLastStateRoot ¶ added in v0.2.4
GetLastStateRoot gets the state root of the tip.
func (*ChainView) SetTipSlot ¶
SetTipSlot sets the effective tip slot (which may be updated due to slot transitions)
type InitialValidatorEntry ¶
type InitialValidatorEntry struct { PubKey [96]byte ProofOfPossession [48]byte WithdrawalShard uint32 WithdrawalCredentials chainhash.Hash DepositSize uint64 }
InitialValidatorEntry is the validator entry to be added at the beginning of a blockchain.
type InitialValidatorEntryAndPrivateKey ¶
type InitialValidatorEntryAndPrivateKey struct { Entry InitialValidatorEntry PrivateKey [32]byte }
InitialValidatorEntryAndPrivateKey is an initial validator entry and private key.
type Mempool ¶
type Mempool struct { AttestationMempool *attestationMempool // contains filtered or unexported fields }
Mempool keeps track of actions (attestations, deposits, exits, slashings) to include in blocks.
func NewMempool ¶
func NewMempool(blockchain *Blockchain) *Mempool
NewMempool creates a new mempool.
func (*Mempool) ConnectBlock ¶ added in v0.2.4
func (m *Mempool) ConnectBlock(b *primitives.Block)
ConnectBlock is part of the blockchain notifee.
func (*Mempool) GetAttestationsToInclude ¶
func (m *Mempool) GetAttestationsToInclude(slot uint64, c *config.Config) ([]primitives.Attestation, error)
GetAttestationsToInclude gets attestations to include in a block.
func (*Mempool) ProcessNewAttestation ¶
func (m *Mempool) ProcessNewAttestation(att primitives.Attestation) error
ProcessNewAttestation processes a new attestation to be included in a block.
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
StateManager handles all state transitions, storing of states for different forks, and time-based state updates.
func NewStateManager ¶
func NewStateManager(c *config.Config, genesisTime uint64, blockchain *Blockchain, db db.Database) (*StateManager, error)
NewStateManager creates a new state manager.
func (*StateManager) AddBlockToStateMap ¶
func (sm *StateManager) AddBlockToStateMap(block *primitives.Block, verifySignature bool) ([]primitives.Receipt, *primitives.State, error)
AddBlockToStateMap processes the block and adds it to the state map.
func (*StateManager) DeleteStateBeforeFinalizedSlot ¶
func (sm *StateManager) DeleteStateBeforeFinalizedSlot(finalizedSlot uint64) error
DeleteStateBeforeFinalizedSlot deletes any states before the current finalized slot.
func (*StateManager) GetGenesisTime ¶
func (sm *StateManager) GetGenesisTime() uint64
GetGenesisTime gets the time of the genesis slot.
func (*StateManager) GetStateForHash ¶
func (sm *StateManager) GetStateForHash(blockHash chainhash.Hash) (*primitives.State, bool)
GetStateForHash gets the state for a certain block Hash.
func (*StateManager) GetStateForHashAtSlot ¶ added in v0.2.4
func (sm *StateManager) GetStateForHashAtSlot(blockHash chainhash.Hash, slot uint64, view primitives.BlockView, c *config.Config) (*primitives.State, error)
GetStateForHashAtSlot gets the state derived from a certain block Hash at a given slot.
func (*StateManager) SetBlockState ¶
func (sm *StateManager) SetBlockState(blockHash chainhash.Hash, state *primitives.State) error
SetBlockState sets the state for a certain block. This SHOULD ONLY BE USED FOR THE GENESIS BLOCK!
type SyncManager ¶
type SyncManager struct {
// contains filtered or unexported fields
}
SyncManager is responsible for requesting blocks from clients and determining whether the client should be considered in sync (for attached validators).
The basic algorithm for syncing is as follows: func onReceive(newBlock):
if haveBlock(newBlock): processBlock(newBlock) else: locator = generateLocator(chain) - locator starts from tip and goes back exponentially including the genesis block askForBlocks(locator)
func NewSyncManager ¶
func NewSyncManager(hostNode *p2p.HostNode, blockchain *Blockchain) SyncManager
NewSyncManager creates a new sync manager
func (SyncManager) Connected ¶
func (s SyncManager) Connected() bool
Connected returns whether the client should be considered connected to the network.
func (SyncManager) ListenForBlocks ¶
func (s SyncManager) ListenForBlocks() error
ListenForBlocks listens for new blocks over the pub-sub network being broadcast as a result of finding them.
func (*SyncManager) RegisterPostProcessHook ¶ added in v0.1.2
func (s *SyncManager) RegisterPostProcessHook(hook func(*primitives.Block, *primitives.State, []primitives.Receipt))
RegisterPostProcessHook registers a hook called after a block has been processed.
func (SyncManager) Start ¶
func (s SyncManager) Start()
Start starts the sync manager by registering message handlers
func (SyncManager) TryInitialSync ¶
func (s SyncManager) TryInitialSync()
TryInitialSync tries to select a peer to sync with and start downloading blocks.