Documentation ¶
Overview ¶
Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.
Index ¶
- Variables
- func BatchedParseBlock(ctx context.Context, vm Parser, blks [][]byte) ([]snowman.Block, error)
- func GetAncestors(ctx context.Context, vm Getter, blkID ids.ID, maxBlocksNum int, ...) ([][]byte, error)
- type BatchedChainVM
- type BuildBlockWithContextChainVM
- type ChainVM
- type Context
- type Getter
- type HeightIndexedChainVM
- type Parser
- type StateSummary
- type StateSyncMode
- type StateSyncableVM
- type TestBatchedVM
- type TestHeightIndexedVM
- type TestStateSummary
- type TestStateSyncableVM
- func (vm *TestStateSyncableVM) GetLastStateSummary(ctx context.Context) (StateSummary, error)
- func (vm *TestStateSyncableVM) GetOngoingSyncStateSummary(ctx context.Context) (StateSummary, error)
- func (vm *TestStateSyncableVM) GetStateSummary(ctx context.Context, summaryHeight uint64) (StateSummary, error)
- func (vm *TestStateSyncableVM) ParseStateSummary(ctx context.Context, summaryBytes []byte) (StateSummary, error)
- func (vm *TestStateSyncableVM) StateSyncEnabled(ctx context.Context) (bool, error)
- type TestVM
- func (vm *TestVM) BuildBlock(ctx context.Context) (snowman.Block, error)
- func (vm *TestVM) Default(cant bool)
- func (vm *TestVM) GetBlock(ctx context.Context, id ids.ID) (snowman.Block, error)
- func (vm *TestVM) LastAccepted(ctx context.Context) (ids.ID, error)
- func (vm *TestVM) ParseBlock(ctx context.Context, b []byte) (snowman.Block, error)
- func (vm *TestVM) SetPreference(ctx context.Context, id ids.ID) error
- type WithVerifyContext
Constants ¶
This section is empty.
Variables ¶
var ( ErrHeightIndexedVMNotImplemented = errors.New("vm does not implement HeightIndexedChainVM interface") ErrIndexIncomplete = errors.New("query failed because height index is incomplete") )
var ErrRemoteVMNotImplemented = errors.New("vm does not implement RemoteVM interface")
var ErrStateSyncableVMNotImplemented = errors.New("vm does not implement StateSyncableVM interface")
Functions ¶
func BatchedParseBlock ¶
Types ¶
type BatchedChainVM ¶
type BatchedChainVM interface { GetAncestors( ctx context.Context, blkID ids.ID, maxBlocksNum int, maxBlocksSize int, maxBlocksRetrivalTime time.Duration, ) ([][]byte, error) BatchedParseBlock(ctx context.Context, blks [][]byte) ([]snowman.Block, error) }
BatchedChainVM extends the minimal functionalities exposed by ChainVM for VMs communicating over network (gRPC in our case). This allows more efficient operations since calls over network can be duly batched
type BuildBlockWithContextChainVM ¶
type BuildBlockWithContextChainVM interface { // Attempt to build a new block given that the P-Chain height is // [blockCtx.PChainHeight]. // // This method will be called if and only if the proposervm is activated. // Otherwise [BuildBlock] will be called. BuildBlockWithContext(ctx context.Context, blockCtx *Context) (snowman.Block, error) }
BuildBlockWithContextChainVM defines the interface a ChainVM can optionally implement to consider the P-Chain height when building blocks.
type ChainVM ¶
type ChainVM interface { common.VM Getter Parser // Attempt to create a new block from data contained in the VM. // // If the VM doesn't want to issue a new block, an error should be // returned. BuildBlock(context.Context) (snowman.Block, error) // Notify the VM of the currently preferred block. // // This should always be a block that has no children known to consensus. SetPreference(ctx context.Context, blkID ids.ID) error // LastAccepted returns the ID of the last accepted block. // // If no blocks have been accepted by consensus yet, it is assumed there is // a definitionally accepted block, the Genesis block, that will be // returned. LastAccepted(context.Context) (ids.ID, error) }
ChainVM defines the required functionality of a Snowman VM.
A Snowman VM is responsible for defining the representation of state, the representation of operations on that state, the application of operations on that state, and the creation of the operations. Consensus will decide on if the operation is executed and the order operations are executed in.
For example, suppose we have a VM that tracks an increasing number that is agreed upon by the network. The state is a single number. The operation is setting the number to a new, larger value. Applying the operation will save to the database the new value. The VM can attempt to issue a new number, of larger value, at any time. Consensus will ensure the network agrees on the number at every block height.
type Context ¶
type Context struct { // PChainHeight is the height that this block will use to verify it's state. // In the proposervm, blocks verify the proposer based on the P-chain height // recorded in the parent block. The P-chain height provided here is also // the parent's P-chain height, not this block's P-chain height. // // Because PreForkBlocks and PostForkOptions do not verify their execution // against the P-chain's state, this context is undefined for those blocks. PChainHeight uint64 }
Context defines the block context that will be optionally provided by the proposervm to an underlying vm.
type Getter ¶
type Getter interface { // Attempt to load a block. // // If the block does not exist, database.ErrNotFound should be returned. // // It is expected that blocks that have been successfully verified should be // returned correctly. It is also expected that blocks that have been // accepted by the consensus engine should be able to be fetched. It is not // required for blocks that have been rejected by the consensus engine to be // able to be fetched. GetBlock(ctx context.Context, blkID ids.ID) (snowman.Block, error) }
Getter defines the functionality for fetching a block by its ID.
type HeightIndexedChainVM ¶
type HeightIndexedChainVM interface { // VerifyHeightIndex should return: // - nil if the height index is available. // - ErrHeightIndexedVMNotImplemented if the height index is not supported. // - ErrIndexIncomplete if the height index is not currently available. // - Any other non-standard error that may have occurred when verifying the // index. VerifyHeightIndex(context.Context) error // GetBlockIDAtHeight returns: // - The ID of the block that was accepted with [height]. // - database.ErrNotFound if the [height] index is unknown. // // Note: A returned value of [database.ErrNotFound] typically means that the // underlying VM was state synced and does not have access to the // blockID at [height]. GetBlockIDAtHeight(ctx context.Context, height uint64) (ids.ID, error) }
HeightIndexedChainVM extends ChainVM to allow querying block IDs by height.
type Parser ¶
type Parser interface { // Attempt to create a block from a stream of bytes. // // The block should be represented by the full byte array, without extra // bytes. // // It is expected for all historical blocks to be parseable. ParseBlock(ctx context.Context, blockBytes []byte) (snowman.Block, error) }
Parser defines the functionality for fetching a block by its bytes.
type StateSummary ¶
type StateSummary interface { // ID uniquely identifies this state summary, regardless of the chain state. ID() ids.ID // Height uniquely identifies this an accepted state summary. Height() uint64 // Bytes returns a byte slice than can be used to reconstruct this summary. Bytes() []byte // Accept triggers the VM to start state syncing to this summary. // // It returns the state sync mode selected by the VM. Accept(context.Context) (StateSyncMode, error) }
StateSummary represents all the information needed to download, verify, and rebuild its state.
type StateSyncMode ¶
type StateSyncMode uint8
StateSyncMode is returned by the StateSyncableVM when a state summary is passed to it. It indicates which type of state sync the VM is performing.
const ( // StateSyncSkipped indicates that state sync won't be run by the VM. This // may happen if the VM decides that the state sync is too recent and it // would be faster to bootstrap the missing blocks. StateSyncSkipped StateSyncMode = iota + 1 // StateSyncStatic indicates that engine should stop and wait for the VM to // complete state syncing before moving ahead with bootstrapping. StateSyncStatic // StateSyncDynamic indicates that engine should immediately transition // into bootstrapping and then normal consensus. State sync will proceed // asynchronously in the VM. // // Invariant: If this is returned it is assumed that the VM should be able // to handle requests from the engine as if the VM is fully synced. // Specifically, it is required that the invariants specified by // LastAccepted, GetBlock, ParseBlock, and Block.Verify are maintained. This // means that when StateSummary.Accept returns, the block that would become // the last accepted block must be immediately fetchable by the engine. StateSyncDynamic )
func (StateSyncMode) String ¶
func (s StateSyncMode) String() string
type StateSyncableVM ¶
type StateSyncableVM interface { // StateSyncEnabled indicates whether the state sync is enabled for this VM. // If StateSyncableVM is not implemented, as it may happen with a wrapper // VM, StateSyncEnabled should return false, nil StateSyncEnabled(context.Context) (bool, error) // GetOngoingSyncStateSummary returns an in-progress state summary if it // exists. // // The engine can then ask the network if the ongoing summary is still // supported, thus helping the VM decide whether to continue an in-progress // sync or start over. // // Returns database.ErrNotFound if there is no in-progress sync. GetOngoingSyncStateSummary(context.Context) (StateSummary, error) // GetLastStateSummary returns the latest state summary. // // Returns database.ErrNotFound if no summary is available. GetLastStateSummary(context.Context) (StateSummary, error) // ParseStateSummary parses a state summary out of [summaryBytes]. ParseStateSummary(ctx context.Context, summaryBytes []byte) (StateSummary, error) // GetStateSummary retrieves the state summary that was generated at height // [summaryHeight]. // // Returns database.ErrNotFound if no summary is available at // [summaryHeight]. GetStateSummary(ctx context.Context, summaryHeight uint64) (StateSummary, error) }
StateSyncableVM contains the functionality to allow VMs to sync to a given state, rather then boostrapping from genesis.
type TestBatchedVM ¶
type TestBatchedVM struct { T *testing.T CantGetAncestors bool CantBatchParseBlock bool GetAncestorsF func( ctx context.Context, blkID ids.ID, maxBlocksNum int, maxBlocksSize int, maxBlocksRetrivalTime time.Duration, ) ([][]byte, error) BatchedParseBlockF func( ctx context.Context, blks [][]byte, ) ([]snowman.Block, error) }
TestBatchedVM is a BatchedVM that is useful for testing.
func (*TestBatchedVM) BatchedParseBlock ¶
func (*TestBatchedVM) Default ¶
func (vm *TestBatchedVM) Default(cant bool)
type TestHeightIndexedVM ¶
type TestHeightIndexedVM struct { T *testing.T CantVerifyHeightIndex bool CantGetBlockIDAtHeight bool VerifyHeightIndexF func(context.Context) error GetBlockIDAtHeightF func(ctx context.Context, height uint64) (ids.ID, error) }
TestBatchedVM is a BatchedVM that is useful for testing.
func (*TestHeightIndexedVM) GetBlockIDAtHeight ¶
func (*TestHeightIndexedVM) VerifyHeightIndex ¶
func (vm *TestHeightIndexedVM) VerifyHeightIndex(ctx context.Context) error
type TestStateSummary ¶
type TestStateSummary struct { IDV ids.ID HeightV uint64 BytesV []byte T *testing.T CantAccept bool AcceptF func(context.Context) (StateSyncMode, error) }
func (*TestStateSummary) Accept ¶
func (s *TestStateSummary) Accept(ctx context.Context) (StateSyncMode, error)
func (*TestStateSummary) Bytes ¶
func (s *TestStateSummary) Bytes() []byte
func (*TestStateSummary) Height ¶
func (s *TestStateSummary) Height() uint64
func (*TestStateSummary) ID ¶
func (s *TestStateSummary) ID() ids.ID
type TestStateSyncableVM ¶
type TestStateSyncableVM struct { T *testing.T CantStateSyncEnabled, CantStateSyncGetOngoingSummary, CantGetLastStateSummary, CantParseStateSummary, CantGetStateSummary bool StateSyncEnabledF func(context.Context) (bool, error) GetOngoingSyncStateSummaryF func(context.Context) (StateSummary, error) GetLastStateSummaryF func(context.Context) (StateSummary, error) ParseStateSummaryF func(ctx context.Context, summaryBytes []byte) (StateSummary, error) GetStateSummaryF func(ctx context.Context, summaryHeight uint64) (StateSummary, error) }
func (*TestStateSyncableVM) GetLastStateSummary ¶
func (vm *TestStateSyncableVM) GetLastStateSummary(ctx context.Context) (StateSummary, error)
func (*TestStateSyncableVM) GetOngoingSyncStateSummary ¶
func (vm *TestStateSyncableVM) GetOngoingSyncStateSummary(ctx context.Context) (StateSummary, error)
func (*TestStateSyncableVM) GetStateSummary ¶
func (vm *TestStateSyncableVM) GetStateSummary(ctx context.Context, summaryHeight uint64) (StateSummary, error)
func (*TestStateSyncableVM) ParseStateSummary ¶
func (vm *TestStateSyncableVM) ParseStateSummary(ctx context.Context, summaryBytes []byte) (StateSummary, error)
func (*TestStateSyncableVM) StateSyncEnabled ¶
func (vm *TestStateSyncableVM) StateSyncEnabled(ctx context.Context) (bool, error)
type TestVM ¶
type TestVM struct { common.TestVM CantBuildBlock, CantParseBlock, CantGetBlock, CantSetPreference, CantLastAccepted bool BuildBlockF func(context.Context) (snowman.Block, error) ParseBlockF func(context.Context, []byte) (snowman.Block, error) GetBlockF func(context.Context, ids.ID) (snowman.Block, error) SetPreferenceF func(context.Context, ids.ID) error LastAcceptedF func(context.Context) (ids.ID, error) }
TestVM is a ChainVM that is useful for testing.
func (*TestVM) BuildBlock ¶
func (*TestVM) ParseBlock ¶
type WithVerifyContext ¶
type WithVerifyContext interface { // Returns true if [VerifyWithContext] should be called. // Returns false if [Verify] should be called. // // This method will be called if and only if the proposervm is activated. // Otherwise [Verify] will be called. ShouldVerifyWithContext(context.Context) (bool, error) // Verify that the state transition this block would make if accepted is // valid. If the state transition is invalid, a non-nil error should be // returned. // // It is guaranteed that the Parent has been successfully verified. // // This method may be called again with a different context. VerifyWithContext(context.Context, *Context) error }