Documentation
¶
Index ¶
- Variables
- type Block
- type BlockWrapper
- type BuildBlockType
- type ChainState
- func (c *ChainState) BuildBlock() (snowman.Block, error)
- func (c *ChainState) ExternalDB() database.Database
- func (c *ChainState) FlushCaches()
- func (c *ChainState) GetBlock(blkID ids.ID) (snowman.Block, error)
- func (c *ChainState) GetBlockInternal(blkID ids.ID) (Block, error)
- func (c *ChainState) Initialize(genesisBlock Block, getBlock GetBlockType, unmarshalBlock UnmarshalType, ...) error
- func (c *ChainState) LastAccepted() ids.ID
- func (c *ChainState) LastAcceptedBlock() *BlockWrapper
- func (c *ChainState) LastAcceptedBlockInternal() snowman.Block
- func (c *ChainState) ParseBlock(b []byte) (snowman.Block, error)
- type GetBlockType
- type UnmarshalType
Constants ¶
This section is empty.
Variables ¶
var ( BlockByHeightPrefix = []byte("blockByHeight") LastAcceptedKey = []byte("lastAccepted") )
Define db prefixes and keys
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block interface {
snowman.Block
// SetStatus sets the internal status of an existing block. This is used by ChainState
// to allow internal blocks to maintain the most up to date status.
SetStatus(choices.Status)
}
Block is the internal representation of a Block to be wrapped by BlockWrapper
type BlockWrapper ¶
type BlockWrapper struct {
Block
// contains filtered or unexported fields
}
BlockWrapper wraps a snowman Block and adds a smart caching layer
func (*BlockWrapper) Verify ¶
func (bw *BlockWrapper) Verify() error
type ChainState ¶
type ChainState struct {
// contains filtered or unexported fields
}
ChainState defines the canonical state of the chain it tracks the accepted blocks and wraps a VM's implementation of snowman.Block in order to take care of writing blocks to the database and adding a caching layer for both the blocks and their statuses.
func NewChainState ¶
func NewChainState(db database.Database, cacheSize int) *ChainState
NewChainState ...
func (*ChainState) BuildBlock ¶
func (c *ChainState) BuildBlock() (snowman.Block, error)
BuildBlock attempts to build a new internal Block, wraps it, and adds it to the appropriate caching layer if successful.
func (*ChainState) ExternalDB ¶
func (c *ChainState) ExternalDB() database.Database
ExternalDB returns a database to be used external to ChainState The returned database must handle batching and atomicity by itself except for any operations that take place during block decisions. Any database operations that occur during block decisions (Accept/Reject) will be automatically batched.
func (*ChainState) FlushCaches ¶
func (c *ChainState) FlushCaches()
FlushCaches flushes each block cache completely.
func (*ChainState) GetBlock ¶
GetBlock returns the BlockWrapper as snowman.Block corresponding to [blkID]
func (*ChainState) GetBlockInternal ¶
func (c *ChainState) GetBlockInternal(blkID ids.ID) (Block, error)
GetBlockInternal returns the internal representation of [blkID]
func (*ChainState) Initialize ¶
func (c *ChainState) Initialize(genesisBlock Block, getBlock GetBlockType, unmarshalBlock UnmarshalType, buildBlock BuildBlockType) error
Initialize sets the genesis block, last accepted block, and the functions for retrieving blocks from the VM layer.
func (*ChainState) LastAcceptedBlock ¶
func (c *ChainState) LastAcceptedBlock() *BlockWrapper
LastAcceptedBlock returns the last accepted wrapped block
func (*ChainState) LastAcceptedBlockInternal ¶
func (c *ChainState) LastAcceptedBlockInternal() snowman.Block
LastAcceptedBlockInternal returns the internal snowman.Block that was last last accepted
func (*ChainState) ParseBlock ¶
func (c *ChainState) ParseBlock(b []byte) (snowman.Block, error)
ParseBlock attempts to parse [b] into an internal Block and adds it to the appropriate caching layer if successful.