Help us shape the future of Go! Take the 2026 Go Developer Survey

chain

package
v1.36.184 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: BSD-3-Clause Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockWrapper

type BlockWrapper struct {
	consensuschain.Block
	// contains filtered or unexported fields
}

BlockWrapper wraps a linear 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) ShouldVerifyWithRuntime added in v1.22.87

func (bw *BlockWrapper) ShouldVerifyWithRuntime(ctx context.Context) (bool, error)

ShouldVerifyWithRuntime checks if the underlying block should be verified with a block context. If the underlying block does not implement the block.WithVerifyRuntime 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) VerifyWithRuntime added in v1.22.87

func (bw *BlockWrapper) VerifyWithRuntime(ctx context.Context, blockCtx *runtime.Runtime) error

VerifyWithRuntime verifies the underlying block with runtime

type Config

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

	LastAcceptedBlock     consensuschain.Block
	GetBlock              func(context.Context, ids.ID) (consensuschain.Block, error)
	UnmarshalBlock        func(context.Context, []byte) (consensuschain.Block, error)
	BatchedUnmarshalBlock func(context.Context, [][]byte) ([]consensuschain.Block, error)
	BuildBlock            func(context.Context) (consensuschain.Block, error)
	BuildBlockWithRuntime func(context.Context, *runtime.Runtime) (consensuschain.Block, error)
}

Config defines all of the parameters necessary to initialize State

type OracleBlock added in v1.16.16

type OracleBlock interface {
	consensuschain.Block

	// Options returns the block options that may be chosen by the oracle.
	Options(context.Context) ([2]consensuschain.Block, error)
}

OracleBlock is a block that can have multiple valid children, and one needs to be chosen by an oracle.

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 metric.Registerer,
	config *Config,
) (*State, error)

func NewState

func NewState(config *Config) *State

func (*State) BatchedParseBlock

func (s *State) BatchedParseBlock(ctx context.Context, blksBytes [][]byte) ([]consensuschain.Block, error)

BatchedParseBlock implements part of the consensuschain.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

func (s *State) BuildBlock(ctx context.Context) (consensuschain.Block, error)

BuildBlock attempts to build a new internal Block, wraps it, and adds it to the appropriate caching layer if successful.

func (*State) BuildBlockWithRuntime added in v1.22.87

func (s *State) BuildBlockWithRuntime(ctx context.Context, blockCtx *runtime.Runtime) (consensuschain.Block, error)

BuildBlockWithRuntime attempts to build a new internal Block, wraps it, and adds it to the appropriate caching layer if successful. If [s.buildBlockWithRuntime] is nil, returns [BuildBlock].

func (*State) Flush

func (s *State) Flush()

Flush each block cache

func (*State) GetBlock

func (s *State) GetBlock(ctx context.Context, blkID ids.ID) (consensuschain.Block, error)

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

func (*State) GetBlockInternal

func (s *State) GetBlockInternal(ctx context.Context, blkID ids.ID) (consensuschain.Block, error)

GetBlockInternal returns the internal representation of [blkID]

func (*State) IsProcessing

func (s *State) IsProcessing(blkID ids.ID) bool

IsProcessing returns whether [blkID] is processing in consensus

func (*State) LastAccepted

func (s *State) LastAccepted(context.Context) (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() consensuschain.Block

LastAcceptedBlockInternal returns the internal consensuschain.Block that was last accepted

func (*State) ParseBlock

func (s *State) ParseBlock(ctx context.Context, b []byte) (consensuschain.Block, error)

ParseBlock attempts to parse [b] into an internal Block and adds it to the appropriate caching layer if successful.

func (*State) SetLastAcceptedBlock

func (s *State) SetLastAcceptedBlock(lastAcceptedBlock consensuschain.Block) error

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.

type Status added in v1.11.14

type Status uint8

Status represents the status of a block

const (
	Unknown Status = iota
	Processing
	Rejected
	Accepted
)

type TestBlock added in v1.11.14

type TestBlock struct {
	IDV           ids.ID
	HeightV       uint64
	TimestampV    time.Time
	ParentV       ids.ID
	BytesV        []byte
	StatusV       Status
	ErrV          error
	ShouldVerifyV bool
}

TestBlock is a test implementation of Block

func (*TestBlock) Accept added in v1.11.14

func (b *TestBlock) Accept(context.Context) error

func (*TestBlock) Bytes added in v1.11.14

func (b *TestBlock) Bytes() []byte

func (*TestBlock) Height added in v1.11.14

func (b *TestBlock) Height() uint64

func (*TestBlock) ID added in v1.11.14

func (b *TestBlock) ID() ids.ID

func (*TestBlock) Parent added in v1.11.14

func (b *TestBlock) Parent() ids.ID

func (*TestBlock) ParentID added in v1.16.16

func (b *TestBlock) ParentID() ids.ID

func (*TestBlock) Reject added in v1.11.14

func (b *TestBlock) Reject(context.Context) error

func (*TestBlock) State added in v1.11.14

func (b *TestBlock) State() state.ReadOnlyChain

func (*TestBlock) Status added in v1.11.14

func (b *TestBlock) Status() uint8

func (*TestBlock) Timestamp added in v1.11.14

func (b *TestBlock) Timestamp() time.Time

func (*TestBlock) Verify added in v1.11.14

func (b *TestBlock) Verify(context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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