engine

package
v1.22.41 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package engine houses the three consensus engines: chain, dag, and pq.

Each engine orchestrates a specific transaction topology: - chain: Linear consensus for sequential blocks - dag: DAG-based consensus for parallel, causally-ordered vertices - pq: Post-quantum hardened consensus with quantum-safe certificates

All engines share the same algorithmic pipeline but differ in their data structures and finality mechanisms.

Package engine provides consensus engine implementations.

Index

Constants

View Source
const (
	PendingTxs    = vm.PendingTxs
	StateSyncDone = vm.StateSyncDone
	Unknown       = vm.Unknown
	Starting      = vm.Starting
	Syncing       = vm.Syncing
	Bootstrapping = vm.Bootstrapping
	Ready         = vm.Ready
	Degraded      = vm.Degraded
	Stopping      = vm.Stopping
	Stopped       = vm.Stopped
)

Re-export constants from vm package

Variables

This section is empty.

Functions

func CgoAvailable added in v1.22.26

func CgoAvailable() bool

CgoAvailable returns true when CGO is enabled (but ZMQ is not required)

func DefaultConfig added in v1.22.0

func DefaultConfig() types.Config

DefaultConfig returns the default chain configuration

Types

type Block added in v1.22.26

type Block interface {
	ID() ids.ID
	ParentID() ids.ID
	Height() uint64
	Timestamp() int64
	Bytes() []byte
	Verify(context.Context) error
	Accept(context.Context) error
	Reject(context.Context) error
}

Block interface for consensus

type BlockStatus added in v1.22.26

type BlockStatus uint8

BlockStatus represents block status

const (
	StatusUnknown BlockStatus = iota
	StatusProcessing
	StatusAccepted
	StatusRejected
)

type CGOConsensus added in v1.22.26

type CGOConsensus struct {
	// contains filtered or unexported fields
}

CGOConsensus is a CGO-based implementation of consensus For now, it's the same as the pure Go implementation

func NewCGOConsensus added in v1.22.26

func NewCGOConsensus(params ConsensusParams) (*CGOConsensus, error)

NewCGOConsensus creates a new CGO consensus engine

func (*CGOConsensus) Add added in v1.22.26

func (c *CGOConsensus) Add(block Block) error

Add adds a block to consensus

func (*CGOConsensus) Finalized added in v1.22.26

func (c *CGOConsensus) Finalized() bool

Finalized checks if consensus is finalized

func (*CGOConsensus) GetPreference added in v1.22.26

func (c *CGOConsensus) GetPreference() ids.ID

GetPreference returns the current preference

func (*CGOConsensus) HealthCheck added in v1.22.26

func (c *CGOConsensus) HealthCheck() error

HealthCheck performs a health check

func (*CGOConsensus) IsAccepted added in v1.22.26

func (c *CGOConsensus) IsAccepted(blockID ids.ID) bool

IsAccepted checks if a block is accepted

func (*CGOConsensus) Parameters added in v1.22.26

func (c *CGOConsensus) Parameters() ConsensusParams

Parameters returns consensus parameters

func (*CGOConsensus) RecordPoll added in v1.22.26

func (c *CGOConsensus) RecordPoll(blockID ids.ID, accept bool) error

RecordPoll records a poll result

type Chain added in v1.22.0

type Chain struct {
	// contains filtered or unexported fields
}

Chain represents a linear blockchain consensus engine

func NewChain added in v1.22.0

func NewChain(config types.Config) *Chain

NewChain creates a new chain consensus engine

func (*Chain) Add added in v1.22.0

func (c *Chain) Add(ctx context.Context, block *types.Block) error

Add adds a new block to the chain

func (*Chain) GetStatus added in v1.22.0

func (c *Chain) GetStatus(id types.ID) types.Status

GetStatus returns the status of a block

func (*Chain) IsAccepted added in v1.22.0

func (c *Chain) IsAccepted(id types.ID) bool

IsAccepted returns whether a block has been accepted

func (*Chain) RecordVote added in v1.22.0

func (c *Chain) RecordVote(ctx context.Context, vote *types.Vote) error

RecordVote records a vote for a block

func (*Chain) Start added in v1.22.0

func (c *Chain) Start(ctx context.Context) error

Start starts the consensus engine

func (*Chain) Stop added in v1.22.0

func (c *Chain) Stop() error

Stop stops the consensus engine

type Consensus added in v1.22.26

type Consensus interface {
	Add(Block) error
	RecordPoll(ids.ID, bool) error
	IsAccepted(ids.ID) bool
	GetPreference() ids.ID
	Finalized() bool
	Parameters() ConsensusParams
	HealthCheck() error
}

Consensus interface

type ConsensusFactory added in v1.22.26

type ConsensusFactory struct{}

ConsensusFactory creates the appropriate consensus implementation This is the CGO version when CGO is enabled

func NewConsensusFactory added in v1.22.26

func NewConsensusFactory() *ConsensusFactory

NewConsensusFactory creates a new consensus factory

func (*ConsensusFactory) CreateConsensus added in v1.22.26

func (f *ConsensusFactory) CreateConsensus(params ConsensusParams) (Consensus, error)

CreateConsensus creates a consensus engine instance

type ConsensusParams added in v1.22.26

type ConsensusParams struct {
	K                     int
	AlphaPreference       int
	AlphaConfidence       int
	Beta                  int
	ConcurrentPolls       int
	OptimalProcessing     int
	MaxOutstandingItems   int
	MaxItemProcessingTime time.Duration
}

ConsensusParams defines consensus parameters

type Engine added in v1.22.0

type Engine interface {
	// Add a new block to the consensus
	Add(ctx context.Context, block *types.Block) error

	// RecordVote records a vote for a block
	RecordVote(ctx context.Context, vote *types.Vote) error

	// IsAccepted returns whether a block has been accepted
	IsAccepted(id types.ID) bool

	// GetStatus returns the status of a block
	GetStatus(id types.ID) types.Status

	// Start the consensus engine
	Start(ctx context.Context) error

	// Stop the consensus engine
	Stop() error
}

Engine is the main consensus engine interface

type Fx added in v1.22.26

type Fx = vm.Fx

Type aliases imported from vm package for consensus internal use

type FxLifecycle added in v1.22.30

type FxLifecycle = vm.FxLifecycle

Type aliases imported from vm package for consensus internal use

type LuxConsensus

type LuxConsensus struct {
	// contains filtered or unexported fields
}

LuxConsensus implements Lux's consensus protocol using Photon → Wave → Focus → Prism → Quasar

func NewLuxConsensus

func NewLuxConsensus(k int, alpha int, beta int) *LuxConsensus

NewLuxConsensus creates a new Lux consensus instance

func (*LuxConsensus) Decided

func (lc *LuxConsensus) Decided() bool

Decided returns whether consensus has been reached

func (*LuxConsensus) Decision

func (lc *LuxConsensus) Decision(item ids.ID) (types.Decision, bool)

Decision returns the decision for an item

func (*LuxConsensus) Parameters

func (lc *LuxConsensus) Parameters() config.Parameters

Parameters returns the consensus parameters

func (*LuxConsensus) Poll

func (lc *LuxConsensus) Poll(responses map[ids.ID]int) bool

Poll conducts a consensus poll using Lux protocols

func (*LuxConsensus) Preference

func (lc *LuxConsensus) Preference() ids.ID

Preference returns the current preferred item

func (*LuxConsensus) RecordVote

func (lc *LuxConsensus) RecordVote(item ids.ID)

RecordVote records a vote for an item

type Message added in v1.22.26

type Message = vm.Message

Type aliases imported from vm package for consensus internal use

type MessageType added in v1.22.26

type MessageType = vm.MessageType

Type aliases imported from vm package for consensus internal use

type SimpleCut

type SimpleCut struct {
	// contains filtered or unexported fields
}

SimpleCut implements a basic Cut for sampling

func (*SimpleCut) Luminance

func (c *SimpleCut) Luminance() prism.Luminance

Luminance implements Cut interface

func (*SimpleCut) Sample

func (c *SimpleCut) Sample(k int) []types.NodeID

type SimpleTransport

type SimpleTransport struct {
	// contains filtered or unexported fields
}

SimpleTransport implements basic transport for voting

func (*SimpleTransport) MakeLocalPhoton

func (t *SimpleTransport) MakeLocalPhoton(item ids.ID, prefer bool) wave.Photon[ids.ID]

func (*SimpleTransport) RequestVotes

func (t *SimpleTransport) RequestVotes(ctx context.Context, peers []types.NodeID, item ids.ID) <-chan wave.Photon[ids.ID]

type State added in v1.22.30

type State = vm.State

Type aliases imported from vm package for consensus internal use

type Stats added in v1.22.26

type Stats struct {
	BlocksAccepted        uint64
	BlocksRejected        uint64
	VotesProcessed        uint64
	PollsCompleted        uint64
	AverageDecisionTimeMs float64
}

Stats represents consensus statistics

Directories

Path Synopsis
Package chain implements linear consensus protocol.
Package chain implements linear consensus protocol.
block/blockmock
Package blockmock is a generated GoMock package.
Package blockmock is a generated GoMock package.
block/blocktest
Package blocktest provides test utilities for blocks
Package blocktest provides test utilities for blocks
chainmock
Package chainmock provides mock implementations for testing
Package chainmock provides mock implementations for testing
chaintest
Package chaintest provides test utilities for chains
Package chaintest provides test utilities for chains
syncer
Package syncer provides state synchronization for blockchain engines
Package syncer provides state synchronization for blockchain engines
dag
Package dag provides DAG consensus functionality
Package dag provides DAG consensus functionality
Package coremock provides mock implementations for core consensus
Package coremock provides mock implementations for core consensus
Package enginetest provides test utilities for consensus engines
Package enginetest provides test utilities for consensus engines
coretest
Package coretest provides test utilities for consensus engine core
Package coretest provides test utilities for consensus engine core
Package interfaces provides consensus engine interfaces.
Package interfaces provides consensus engine interfaces.
Package pq implements the post-quantum consensus engine that combines classical and quantum-resistant consensus mechanisms.
Package pq implements the post-quantum consensus engine that combines classical and quantum-resistant consensus mechanisms.

Jump to

Keyboard shortcuts

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