mirror of https://github.com/poanetwork/gecko.git
58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package snowman
|
|
|
|
import (
|
|
"github.com/ava-labs/gecko/ids"
|
|
"github.com/ava-labs/gecko/snow/consensus/snowman"
|
|
"github.com/ava-labs/gecko/snow/engine/common"
|
|
)
|
|
|
|
// 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 ChainVM interface {
|
|
common.VM
|
|
|
|
// 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() (snowman.Block, error)
|
|
|
|
// Attempt to create a block from a stream of bytes.
|
|
//
|
|
// The block should be represented by the full byte array, without extra
|
|
// bytes.
|
|
ParseBlock([]byte) (snowman.Block, error)
|
|
|
|
// Attempt to load a block.
|
|
//
|
|
// If the block does not exist, then an error should be returned.
|
|
GetBlock(ids.ID) (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(ids.ID)
|
|
|
|
// 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() ids.ID
|
|
}
|