github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/avalanche/vertex/vm.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package vertex
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/MetalBlockchain/metalgo/ids"
    10  	"github.com/MetalBlockchain/metalgo/snow/consensus/snowstorm"
    11  	"github.com/MetalBlockchain/metalgo/snow/engine/common"
    12  	"github.com/MetalBlockchain/metalgo/snow/engine/snowman/block"
    13  )
    14  
    15  type LinearizableVMWithEngine interface {
    16  	DAGVM
    17  
    18  	// Linearize is called after [Initialize] and after the DAG has been
    19  	// finalized. After Linearize is called:
    20  	//
    21  	// - PendingTxs will never be called again
    22  	// - GetTx will never be called again
    23  	// - ParseTx may still be called
    24  	// - All the block based functions of the [block.ChainVM] must work as
    25  	//   expected.
    26  	//
    27  	// Linearize is part of the VM initialization, and will be called at most
    28  	// once per VM instantiation. This means that Linearize should be called
    29  	// every time the chain restarts after the DAG has finalized.
    30  	Linearize(
    31  		ctx context.Context,
    32  		stopVertexID ids.ID,
    33  		toEngine chan<- common.Message,
    34  	) error
    35  }
    36  
    37  type LinearizableVM interface {
    38  	DAGVM
    39  
    40  	// Linearize is called after [Initialize] and after the DAG has been
    41  	// finalized. After Linearize is called:
    42  	//
    43  	// - PendingTxs will never be called again
    44  	// - GetTx will never be called again
    45  	// - ParseTx may still be called
    46  	// - All the block based functions of the [block.ChainVM] must work as
    47  	//   expected.
    48  	//
    49  	// Linearize is part of the VM initialization, and will be called at most
    50  	// once per VM instantiation. This means that Linearize should be called
    51  	// every time the chain restarts after the DAG has finalized.
    52  	Linearize(ctx context.Context, stopVertexID ids.ID) error
    53  }
    54  
    55  // DAGVM defines the minimum functionality that an avalanche VM must
    56  // implement
    57  type DAGVM interface {
    58  	block.ChainVM
    59  
    60  	// Convert a stream of bytes to a transaction or return an error
    61  	ParseTx(ctx context.Context, txBytes []byte) (snowstorm.Tx, error)
    62  }