block

package
v1.22.25 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: BSD-3-Clause Imports: 7 Imported by: 28

Documentation

Index

Constants

View Source
const (
	PendingTxs    = core.PendingTxs
	StateSyncDone = core.StateSyncDone
)

Message type constants re-exported from core

Variables

View Source
var (
	// ErrRemoteVMNotImplemented is returned when the remote VM is not implemented
	ErrRemoteVMNotImplemented = errors.New("remote VM not implemented")
	// ErrStateSyncableVMNotImplemented is returned when state syncable VM is not implemented
	ErrStateSyncableVMNotImplemented = errors.New("state syncable VM not implemented")
)

Functions

func GetAncestors added in v1.19.12

func GetAncestors(
	ctx context.Context,
	vm ChainVM,
	blkID ids.ID,
	maxBlocks int,
	maxBlocksSize int,
	maxBlocksRetrievalTime time.Duration,
) ([][]byte, error)

GetAncestors retrieves ancestors of a block up to a maximum count

Types

type BatchedChainVM

type BatchedChainVM interface {
	ChainVM
	GetAncestors(
		ctx context.Context,
		blkID ids.ID,
		maxBlocksNum int,
		maxBlocksSize int,
		maxBlocksRetrievalTime time.Duration,
	) ([][]byte, error)
	BatchedParseBlock(ctx context.Context, blks [][]byte) ([]Block, error)
}

BatchedChainVM extends ChainVM with batch operations

type Block

type Block interface {
	ID() ids.ID
	Parent() ids.ID // Alias for ParentID for compatibility
	ParentID() ids.ID
	Height() uint64
	Timestamp() time.Time
	Status() uint8
	Verify(context.Context) error
	Accept(context.Context) error
	Reject(context.Context) error
	Bytes() []byte
}

Block is a block in the chain

type BuildBlockWithContextChainVM

type BuildBlockWithContextChainVM interface {
	ChainVM
	BuildBlockWithContext(ctx context.Context, blockCtx *Context) (Block, error)
}

BuildBlockWithContextChainVM extends ChainVM with context-aware block building

type BuildBlockWithContextVM

type BuildBlockWithContextVM interface {
	ChainVM
	BuildBlockWithContext(context.Context, *Context) (Block, error)
}

BuildBlockWithContextVM extends ChainVM with context support

type ChainContext

type ChainContext struct {
	*consensuscontext.Context
}

ChainContext provides chain context

type ChainVM

type ChainVM interface {
	// Initialize initializes the VM
	Initialize(
		ctx context.Context,
		chainCtx interface{},
		db interface{},
		genesisBytes []byte,
		upgradeBytes []byte,
		configBytes []byte,
		msgChan interface{},
		fxs []interface{},
		appSender interface{},
	) error

	// BuildBlock builds a new block
	BuildBlock(context.Context) (Block, error)

	// ParseBlock parses a block from bytes
	ParseBlock(context.Context, []byte) (Block, error)

	// GetBlock gets a block by ID
	GetBlock(context.Context, ids.ID) (Block, error)

	// Shutdown shuts down the VM
	Shutdown(context.Context) error

	// NewHTTPHandler returns a new HTTP handler for the VM
	NewHTTPHandler(context.Context) (interface{}, error)

	// SetState sets the VM state
	SetState(context.Context, uint32) error

	// Version returns the VM version
	Version(context.Context) (string, error)

	// Network callbacks - optional
	Connected(context.Context, ids.NodeID, interface{}) error
	Disconnected(context.Context, ids.NodeID) error
	HealthCheck(context.Context) (interface{}, error)

	// GetBlockIDAtHeight gets block ID at a specific height
	GetBlockIDAtHeight(context.Context, uint64) (ids.ID, error)

	// SetPreference sets the preferred block
	SetPreference(context.Context, ids.ID) error

	// LastAccepted returns the last accepted block
	LastAccepted(context.Context) (ids.ID, error)

	// WaitForEvent blocks until an event occurs that should trigger block building
	WaitForEvent(context.Context) (interface{}, error)
}

ChainVM defines the interface for a blockchain VM

type ChainVMWithHealth added in v1.19.12

type ChainVMWithHealth interface {
	ChainVM
	HealthCheck(ctx context.Context) (interface{}, error)
}

HealthCheck interface

type ChainVMWithNetwork added in v1.19.12

type ChainVMWithNetwork interface {
	ChainVM
	Connected(ctx context.Context, nodeID ids.NodeID, version interface{}) error
	Disconnected(ctx context.Context, nodeID ids.NodeID) error
}

Network callbacks

type Context

type Context struct {
	PChainHeight uint64
}

Context provides context for building blocks

type DBManager

type DBManager = manager.Manager

DBManager manages databases

type Epoch added in v1.19.12

type Epoch struct {
	PChainHeight uint64 `serialize:"true" json:"pChainHeight"`
	Number       uint64 `serialize:"true" json:"number"`
	StartTime    int64  `serialize:"true" json:"startTime"`
}

Epoch represents a P-Chain epoch for validator set coordination

type Fx

type Fx = core.Fx

Re-export core types for backwards compatibility

type Message

type Message = core.Message

Re-export core types for backwards compatibility

type MessageType added in v1.22.19

type MessageType = core.MessageType

Re-export core types for backwards compatibility

type SignedBlock added in v1.19.12

type SignedBlock interface {
	Block

	// PChainHeight returns the P-Chain height when this block was proposed
	PChainHeight() uint64

	// PChainEpoch returns the P-Chain epoch information
	PChainEpoch() Epoch

	// Timestamp returns the block timestamp
	Timestamp() time.Time

	// Proposer returns the ID of the node that proposed this block.
	// If no node signed this block, ids.EmptyNodeID will be returned.
	Proposer() ids.NodeID
}

SignedBlock extends Block with proposer and epoch information

type StateSummary

type StateSummary interface {
	ID() ids.ID
	Height() uint64
	Bytes() []byte
	Accept(context.Context) (StateSyncMode, error)
}

StateSummary represents a state summary

type StateSyncMode

type StateSyncMode uint8

StateSyncMode defines state sync modes

const (
	StateSyncSkipped StateSyncMode = iota
	StateSyncStatic
	StateSyncDynamic
)

type StateSyncableVM

type StateSyncableVM interface {
	ChainVM

	// StateSyncEnabled returns whether state sync is enabled
	StateSyncEnabled(context.Context) (bool, error)

	// GetOngoingSyncStateSummary returns the ongoing sync state summary
	GetOngoingSyncStateSummary(context.Context) (StateSummary, error)

	// GetLastStateSummary returns the last state summary
	GetLastStateSummary(context.Context) (StateSummary, error)

	// ParseStateSummary parses a state summary
	ParseStateSummary(context.Context, []byte) (StateSummary, error)

	// GetStateSummary gets a state summary by height
	GetStateSummary(context.Context, uint64) (StateSummary, error)
}

StateSyncableVM defines a VM that supports state sync

type WithVerifyContext

type WithVerifyContext interface {
	// VerifyWithContext verifies with context
	VerifyWithContext(context.Context, *Context) error

	// ShouldVerifyWithContext returns whether to verify with context
	ShouldVerifyWithContext(context.Context) (bool, error)
}

WithVerifyContext provides verify context support

Directories

Path Synopsis
Package blockmock is a generated GoMock package.
Package blockmock is a generated GoMock package.
Package blocktest provides test utilities for blocks
Package blocktest provides test utilities for blocks

Jump to

Keyboard shortcuts

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