chain

package
v1.22.46 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: BSD-3-Clause Imports: 6 Imported by: 2

Documentation

Overview

Package chain implements linear consensus protocol.

Chain handles sequential blocks in a linear topology, where each block extends exactly one parent. The consensus pipeline flows: photon → wave → focus → nova, terminating in single-threaded finality. This is the classical blockchain model: one block, one parent, one chain.

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type Block added in v1.21.3

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

Block represents a block in the chain

type BlockBuilder added in v1.22.3

type BlockBuilder interface {
	// BuildBlock builds a new block
	BuildBlock(context.Context) (interface{}, error)
}

BlockBuilder is the interface for VMs that can build blocks

type ChainConsensus added in v1.21.3

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

ChainConsensus implements real Lux consensus for linear chains using Photon → Wave → Focus

func NewChainConsensus added in v1.21.3

func NewChainConsensus(k, alpha, beta int) *ChainConsensus

NewChainConsensus creates a real consensus engine

func (*ChainConsensus) AddBlock added in v1.21.3

func (c *ChainConsensus) AddBlock(ctx context.Context, block *Block) error

AddBlock adds a block to consensus

func (*ChainConsensus) GetBlock added in v1.21.3

func (c *ChainConsensus) GetBlock(blockID ids.ID) (*Block, bool)

GetBlock returns a block by ID

func (*ChainConsensus) IsAccepted added in v1.21.3

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

IsAccepted checks if a block is accepted

func (*ChainConsensus) IsRejected added in v1.21.3

func (c *ChainConsensus) IsRejected(blockID ids.ID) bool

IsRejected checks if a block is rejected

func (*ChainConsensus) Poll added in v1.21.3

func (c *ChainConsensus) Poll(ctx context.Context, responses map[ids.ID]int) error

Poll conducts a consensus poll

func (*ChainConsensus) Preference added in v1.21.3

func (c *ChainConsensus) Preference() ids.ID

Preference returns current preferred block

func (*ChainConsensus) ProcessVote added in v1.21.3

func (c *ChainConsensus) ProcessVote(ctx context.Context, blockID ids.ID, accept bool) error

ProcessVote processes a vote for a block

func (*ChainConsensus) Stats added in v1.21.3

func (c *ChainConsensus) Stats() map[string]interface{}

Stats returns consensus statistics

type Engine

type Engine interface {
	// Start starts the engine
	Start(context.Context, bool) error

	// StopWithError stops the engine with an error
	StopWithError(context.Context, error) error

	// Context returns the engine's context
	Context() context.Context

	// HealthCheck performs a health check
	HealthCheck(context.Context) (interface{}, error)

	// IsBootstrapped returns whether the chain is bootstrapped
	IsBootstrapped() bool
}

Engine defines the chain consensus engine

type Message added in v1.22.23

type Message = engine.Message

Re-export message types for convenience

type MessageType added in v1.22.3

type MessageType = engine.MessageType

Re-export message types for convenience

type Transitive

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

Transitive implements real transitive chain consensus using Lux protocols (Photon → Wave → Focus)

func New

func New() *Transitive

New creates a new chain consensus engine with real Lux consensus

func NewWithParams added in v1.21.3

func NewWithParams(params config.Parameters) *Transitive

NewWithParams creates an engine with specific parameters

func (*Transitive) AddBlock added in v1.21.3

func (t *Transitive) AddBlock(ctx context.Context, block *Block) error

AddBlock adds a block to consensus

func (*Transitive) Context added in v1.22.35

func (t *Transitive) Context() context.Context

Context returns the engine's context

func (*Transitive) GetBlock

func (t *Transitive) GetBlock(ctx context.Context, nodeID ids.NodeID, requestID uint32, blockID ids.ID) error

GetBlock gets a block by ID

func (*Transitive) HealthCheck

func (t *Transitive) HealthCheck(ctx context.Context) (interface{}, error)

HealthCheck performs a health check

func (*Transitive) IsAccepted added in v1.21.3

func (t *Transitive) IsAccepted(blockID ids.ID) bool

IsAccepted checks if a block is accepted

func (*Transitive) IsBootstrapped

func (t *Transitive) IsBootstrapped() bool

IsBootstrapped returns whether the chain is bootstrapped

func (*Transitive) Notify added in v1.22.3

func (t *Transitive) Notify(ctx context.Context, msg Message) error

Notify handles VM notifications (e.g., pending transactions)

func (*Transitive) PendingBuildBlocks added in v1.22.3

func (t *Transitive) PendingBuildBlocks() int

PendingBuildBlocks returns the number of pending block builds

func (*Transitive) Poll added in v1.21.3

func (t *Transitive) Poll(ctx context.Context, responses map[ids.ID]int) error

Poll conducts a consensus poll

func (*Transitive) Preference added in v1.21.3

func (t *Transitive) Preference() ids.ID

Preference returns the current preferred block

func (*Transitive) ProcessVote added in v1.21.3

func (t *Transitive) ProcessVote(ctx context.Context, blockID ids.ID, accept bool) error

ProcessVote processes a vote for a block

func (*Transitive) SetVM added in v1.22.3

func (t *Transitive) SetVM(vm BlockBuilder)

SetVM sets the block builder (VM) for the engine

func (*Transitive) Start

func (t *Transitive) Start(ctx context.Context, startReqID bool) error

Start starts the engine (implements both bool and uint32 signatures for compatibility)

func (*Transitive) StartWithID added in v1.22.35

func (t *Transitive) StartWithID(ctx context.Context, requestID uint32) error

StartWithID starts the engine with a specific request ID

func (*Transitive) Stop

func (t *Transitive) Stop(ctx context.Context) error

Stop stops the engine

func (*Transitive) StopWithError added in v1.22.35

func (t *Transitive) StopWithError(ctx context.Context, err error) error

StopWithError stops the engine with an error (for graceful shutdown on errors)

type Transport

type Transport[ID comparable] interface {
	// Send sends a message
	Send(ctx context.Context, to string, msg interface{}) error

	// Receive receives messages
	Receive(ctx context.Context) (interface{}, error)
}

Transport handles message transport for consensus

Directories

Path Synopsis
blockmock
Package blockmock is a generated GoMock package.
Package blockmock is a generated GoMock package.
blocktest
Package blocktest provides test utilities for blocks
Package blocktest provides test utilities for blocks
Package chainmock provides mock implementations for testing
Package chainmock provides mock implementations for testing
Package chaintest provides test utilities for chains
Package chaintest provides test utilities for chains
Package syncer provides state synchronization for blockchain engines
Package syncer provides state synchronization for blockchain engines

Jump to

Keyboard shortcuts

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