evm

package
v0.3.27-rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBlockNotFound indicates that the VM was not able to retrieve a block. If this error is returned
	// from getBlock then the miss will be considered cacheable. Any other error will not be considered a
	// cacheable miss.
	ErrBlockNotFound = errors.New("block not found")
)

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 keep their status up to date.
	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) Accept

func (bw *BlockWrapper) Accept() error

Accept accepts the underlying block, removes it from processingBlocks, caches it as a decided block, sets the last accepted block, and commits the underlying database atomically after block acceptance has been performed.

func (*BlockWrapper) Parent

func (bw *BlockWrapper) Parent() snowman.Block

Parent returns the parent of [bw] Ensures that a BlockWrapper is returned instead of the internal block type by using state to retrieve the block.

func (*BlockWrapper) Reject

func (bw *BlockWrapper) Reject() error

Reject rejects the underlying block, removes it from processing blocks, caches it as a decided block, sets the last accepted block, and commits the underlying database atomically after the block has been rejected.

func (*BlockWrapper) Verify

func (bw *BlockWrapper) Verify() error

Verify verifies the underlying block, evicts from the unverified block cache and if the block passes verification, adds it to [state] processingBlocks. Note: it is guaranteed that if a block passes verification it will be added to consensus and have either Accept or Reject called on it.

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 returns a new uninitialized ChainState

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 Any operations that occur on the returned database during Accept/Reject of blocks will be automatically batched by ChainState.

func (*ChainState) FlushCaches

func (c *ChainState) FlushCaches()

FlushCaches flushes each block cache completely.

func (*ChainState) GetBlock

func (c *ChainState) GetBlock(blkID ids.ID) (snowman.Block, error)

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(config *Config)

Initialize sets the last accepted block, and the internal functions for retrieving/parsing/building blocks from the VM layer.

func (*ChainState) LastAccepted

func (c *ChainState) LastAccepted() (ids.ID, error)

LastAccepted ...

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.

type Config

type Config struct {
	LastAcceptedBlock  Block
	GetBlockIDAtHeight func(uint64) (ids.ID, error)
	GetBlock           func(ids.ID) (Block, error)
	UnmarshalBlock     func([]byte) (Block, error)
	BuildBlock         func() (Block, error)
}

Config defines all of the parameters necessary to initialize ChainState

Jump to

Keyboard shortcuts

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