chain

package
v1.13.5-lux Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownBlock     = errors.New("unknown block")
	ErrBlockNotVerified = errors.New("block not verified")
	ErrNotOracle        = errors.New("block is not an oracle block")
)

Functions

This section is empty.

Types

type Block

type Block interface {
	choices.Decidable

	// Parent returns the parent block ID.
	Parent() ids.ID

	// Height returns the height of the block.
	Height() uint64

	// Time returns the time the block was created.
	Time() uint64

	// Verify that the block is valid.
	Verify(context.Context) error

	// Bytes returns the byte representation of the block.
	Bytes() []byte

	// Accept accepts the block (overrides choices.Decidable)
	Accept() error
}

Block is a block that can be decided.

type Consensus

type Consensus interface {
	// Initialize the consensus with the given parameters.
	Initialize(ctx context.Context, params Parameters, lastAcceptedID string, lastAcceptedHeight uint64, lastAcceptedTime uint64) error

	// Parameters returns the parameters of this consensus instance.
	Parameters() Parameters

	// Add a block to consensus consideration.
	Add(ctx context.Context, block Block) error

	// Issued returns true if the block has been issued into consensus.
	Issued(blk Block) bool

	// Processing returns true if the block is currently processing.
	Processing(blkID ids.ID) bool

	// Decided returns true if the block has been decided.
	Decided(blk Block) bool

	// IsPreferred returns true if the block is on the preferred chain.
	IsPreferred(blk Block) bool

	// Preference returns the current preferred block.
	Preference() ids.ID

	// RecordPoll records the results of a network poll.
	RecordPoll(ctx context.Context, votes []ids.ID) error

	// Finalized returns true if consensus has finalized.
	Finalized() bool

	// HealthCheck returns the health status of consensus.
	HealthCheck(ctx context.Context) (interface{}, error)

	// NumProcessing returns the number of currently processing blocks.
	NumProcessing() int
}

Consensus represents a linear consensus instance.

type Factory

type Factory interface {
	New() Consensus
	Default() Parameters
}

Factory returns new instances of Consensus

type OracleBlock

type OracleBlock interface {
	Block

	// Options returns the oracle block options
	Options(context.Context) ([2]Block, error)
}

OracleBlock is an oracle block interface

type Parameters

type Parameters struct {
	// K is the number of nodes to poll.
	K int

	// AlphaPreference is the vote threshold to change preference.
	AlphaPreference int

	// AlphaConfidence is the vote threshold for confidence.
	AlphaConfidence int

	// Beta is the number of consecutive successful polls required for finalization.
	Beta int

	// ConcurrentRepolls is the number of concurrent polls.
	ConcurrentRepolls int

	// OptimalProcessing is the number of blocks to process optimally.
	OptimalProcessing int

	// MaxOutstandingItems is the maximum number of outstanding items.
	MaxOutstandingItems int

	// MaxItemProcessingTime is the maximum time to process an item.
	MaxItemProcessingTime int64
}

Parameters defines the consensus parameters.

type Topological

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

Topological is the implementation of the Snowman/Chain consensus algorithm

func (*Topological) Add

func (ts *Topological) Add(ctx context.Context, blk Block) error

Add a block to consensus

func (*Topological) Decided

func (ts *Topological) Decided(blk Block) bool

Decided returns whether the block has been decided

func (*Topological) Finalized

func (ts *Topological) Finalized() bool

Finalized returns whether consensus has finalized

func (*Topological) HealthCheck

func (ts *Topological) HealthCheck(ctx context.Context) (interface{}, error)

HealthCheck returns health status of consensus

func (*Topological) Initialize

func (ts *Topological) Initialize(ctx context.Context, parameters Parameters, lastAcceptedID string, lastAcceptedHeight uint64, lastAcceptedTime uint64) error

Initialize the consensus engine

func (*Topological) IsPreferred

func (ts *Topological) IsPreferred(blk Block) bool

IsPreferred returns whether the block is on the preferred chain

func (*Topological) Issued

func (ts *Topological) Issued(blk Block) bool

Issued returns whether the block has been issued into consensus

func (*Topological) NumProcessing

func (ts *Topological) NumProcessing() int

NumProcessing returns the number of currently processing blocks

func (*Topological) Parameters

func (ts *Topological) Parameters() Parameters

Parameters returns the parameters of this consensus instance

func (*Topological) Preference

func (ts *Topological) Preference() ids.ID

Preference returns the ID of the preferred block

func (*Topological) Processing

func (ts *Topological) Processing(blkID ids.ID) bool

Processing returns whether the block ID is currently processing

func (*Topological) RecordPoll

func (ts *Topological) RecordPoll(ctx context.Context, votes []ids.ID) error

RecordPoll records the results of a network poll

type TopologicalFactory

type TopologicalFactory struct {
	Parameters params.Parameters
}

TopologicalFactory implements Factory by returning a topological consensus

func (TopologicalFactory) Default

func (f TopologicalFactory) Default() Parameters

func (TopologicalFactory) New

func (f TopologicalFactory) New() Consensus

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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