Documentation ¶
Index ¶
- type Block
- type BlockWrapper
- func (bw *BlockWrapper) Accept(ctx context.Context) error
- func (bw *BlockWrapper) Reject(ctx context.Context) error
- func (bw *BlockWrapper) ShouldVerifyWithContext(ctx context.Context) (bool, error)
- func (bw *BlockWrapper) Verify(ctx context.Context) error
- func (bw *BlockWrapper) VerifyWithContext(ctx context.Context, blockCtx *block.Context) error
- type Config
- type State
- func (s *State) BatchedParseBlock(ctx context.Context, blksBytes [][]byte) ([]snowman.Block, error)
- func (s *State) BuildBlock(ctx context.Context) (snowman.Block, error)
- func (s *State) BuildBlockWithContext(ctx context.Context, blockCtx *block.Context) (snowman.Block, error)
- func (s *State) Flush()
- func (s *State) GetBlock(ctx context.Context, blkID ids.ID) (snowman.Block, error)
- func (s *State) GetBlockInternal(ctx context.Context, blkID ids.ID) (snowman.Block, error)
- func (s *State) IsProcessing(blkID ids.ID) bool
- func (s *State) LastAccepted(context.Context) (ids.ID, error)
- func (s *State) LastAcceptedBlock() *BlockWrapper
- func (s *State) LastAcceptedBlockInternal() snowman.Block
- func (s *State) ParseBlock(ctx context.Context, b []byte) (snowman.Block, error)
- func (s *State) SetLastAcceptedBlock(lastAcceptedBlock snowman.Block) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
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 ¶
BlockWrapper wraps a snowman Block while adding a smart caching layer to improve VM performance.
func (*BlockWrapper) Accept ¶
func (bw *BlockWrapper) Accept(ctx context.Context) 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(ctx context.Context) error
Reject rejects the underlying block, removes it from processing blocks, and caches it as a decided block.
func (*BlockWrapper) ShouldVerifyWithContext ¶ added in v1.9.5
func (bw *BlockWrapper) ShouldVerifyWithContext(ctx context.Context) (bool, error)
ShouldVerifyWithContext checks if the underlying block should be verified with a block context. If the underlying block does not implement the block.WithVerifyContext interface, returns false without an error. Does not touch any block cache.
func (*BlockWrapper) Verify ¶
func (bw *BlockWrapper) Verify(ctx context.Context) 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].
func (*BlockWrapper) VerifyWithContext ¶ added in v1.9.5
VerifyWithContext verifies the underlying block with the given block context, 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].
Note: If the underlying block does not implement the block.WithVerifyContext interface, an error is always returned because ShouldVerifyWithContext will always return false in this case and VerifyWithContext should never be called.
type Config ¶
type Config struct {
// Cache configuration:
DecidedCacheSize, MissingCacheSize, UnverifiedCacheSize, BytesToIDCacheSize int
LastAcceptedBlock snowman.Block
GetBlock func(context.Context, ids.ID) (snowman.Block, error)
UnmarshalBlock func(context.Context, []byte) (snowman.Block, error)
BatchedUnmarshalBlock func(context.Context, [][]byte) ([]snowman.Block, error)
BuildBlock func(context.Context) (snowman.Block, error)
BuildBlockWithContext func(context.Context, *block.Context) (snowman.Block, error)
GetBlockIDAtHeight func(context.Context, 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, config *Config, ) (*State, error)
func (*State) BatchedParseBlock ¶ added in v1.9.5
BatchedParseBlock implements part of the block.BatchedChainVM interface. In addition to performing all the caching as the ParseBlock function, it performs at most one call to the underlying VM if [batchedUnmarshalBlock] was provided.
func (*State) BuildBlock ¶
BuildBlock attempts to build a new internal Block, wraps it, and adds it to the appropriate caching layer if successful.
func (*State) BuildBlockWithContext ¶ added in v1.9.4
func (s *State) BuildBlockWithContext(ctx context.Context, blockCtx *block.Context) (snowman.Block, error)
BuildBlockWithContext attempts to build a new internal Block, wraps it, and adds it to the appropriate caching layer if successful. If [s.buildBlockWithContext] is nil, returns [BuildBlock].
func (*State) GetBlock ¶
GetBlock returns the BlockWrapper as snowman.Block corresponding to [blkID]
func (*State) GetBlockInternal ¶
GetBlockInternal returns the internal representation of [blkID]
func (*State) IsProcessing ¶ added in v1.9.9
IsProcessing returns whether [blkID] is processing in consensus
func (*State) LastAcceptedBlock ¶
func (s *State) LastAcceptedBlock() *BlockWrapper
LastAcceptedBlock returns the last accepted wrapped block
func (*State) LastAcceptedBlockInternal ¶
LastAcceptedBlockInternal returns the internal snowman.Block that was last accepted
func (*State) ParseBlock ¶
ParseBlock attempts to parse [b] into an internal Block and adds it to the appropriate caching layer if successful.
func (*State) SetLastAcceptedBlock ¶ added in v1.7.7
SetLastAcceptedBlock sets the last accepted block to [lastAcceptedBlock]. This should be called with an internal block - not a wrapped block returned from state.
This also flushes [lastAcceptedBlock] from missingBlocks and unverifiedBlocks to ensure that their contents stay valid.