Version: v1.5.3 Latest Latest

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

Go to latest
Published: Sep 9, 2021 License: BSD-3-Clause Imports: 8 Imported by: 2




This section is empty.


This section is empty.


This section is empty.


type Block

type Block interface {


Block is an interface wrapping the normal snowman.Block interface to be used in association with passing in a non-nil function to GetBlockIDAtHeight

type BlockWrapper

type BlockWrapper struct {
	// contains filtered or unexported fields

BlockWrapper wraps a snowman Block while adding a smart caching layer to improve VM performance.

func (*BlockWrapper) Accept

func (bw *BlockWrapper) Accept() error

Accept accepts the underlying block, removes it from verifiedBlocks, caches it as a decided block, and updates the last accepted block.

func (*BlockWrapper) Reject

func (bw *BlockWrapper) Reject() error

Reject rejects the underlying block, removes it from processing blocks, and caches it as a decided block.

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 [cache.verifiedBlocks]. Note: it is guaranteed that if a block passes verification it will be added to consensus and eventually be decided ie. either Accept/Reject will be called on [bw] removing it from [verifiedBlocks].

type Config

type Config struct {
	// Cache configuration:
	DecidedCacheSize, MissingCacheSize, UnverifiedCacheSize, BytesToIDCacheSize int

	LastAcceptedBlock  snowman.Block
	GetBlock           func(ids.ID) (snowman.Block, error)
	UnmarshalBlock     func([]byte) (snowman.Block, error)
	BuildBlock         func() (snowman.Block, error)
	GetBlockIDAtHeight func(uint64) (ids.ID, error)

Config defines all of the parameters necessary to initialize State

type State

type State struct {
	// contains filtered or unexported fields

State implements an efficient caching layer used to wrap a VM implementation.

func NewMeteredState

func NewMeteredState(
	registerer prometheus.Registerer,
	namespace string,
	config *Config,
) (*State, error)

func NewState

func NewState(config *Config) *State

func (*State) BuildBlock

func (s *State) 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 (*State) Flush

func (s *State) Flush()

Flush each block cache

func (*State) GetBlock

func (s *State) GetBlock(blkID ids.ID) (snowman.Block, error)

GetBlock returns the BlockWrapper as snowman.Block corresponding to [blkID]

func (*State) GetBlockInternal

func (s *State) GetBlockInternal(blkID ids.ID) (snowman.Block, error)

GetBlockInternal returns the internal representation of [blkID]

func (*State) LastAccepted

func (s *State) LastAccepted() (ids.ID, error)

func (*State) LastAcceptedBlock

func (s *State) LastAcceptedBlock() *BlockWrapper

LastAcceptedBlock returns the last accepted wrapped block

func (*State) LastAcceptedBlockInternal

func (s *State) LastAcceptedBlockInternal() snowman.Block

LastAcceptedBlockInternal returns the internal snowman.Block that was last accepted

func (*State) ParseBlock

func (s *State) 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.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL