beam

package
v1.14.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeamBlock

type BeamBlock struct {
	// Embedded chain block for compatibility
	chain.Block
	// contains filtered or unexported fields
}

BeamBlock implements the Block interface for beam consensus (Previously a concrete implementation of snowman.Block)

func NewBeamBlock

func NewBeamBlock(
	id ids.ID,
	parentID ids.ID,
	height uint64,
	timestamp time.Time,
	bytes []byte,
) *BeamBlock

NewBeamBlock creates a new beam block

func (*BeamBlock) Accept

func (b *BeamBlock) Accept() error

Accept marks the block as accepted (finalized in the beam)

func (*BeamBlock) BeamHeight

func (b *BeamBlock) BeamHeight() uint64

BeamHeight returns the block's position in the beam

func (*BeamBlock) BeamScore

func (b *BeamBlock) BeamScore() uint64

BeamScore returns the block's consensus score

func (*BeamBlock) Bytes

func (b *BeamBlock) Bytes() []byte

Bytes returns the block bytes

func (*BeamBlock) Height

func (b *BeamBlock) Height() uint64

Height returns the block height

func (*BeamBlock) ID

func (b *BeamBlock) ID() string

ID returns the block ID as string

func (*BeamBlock) IncrementPhotons

func (b *BeamBlock) IncrementPhotons()

IncrementPhotons increments the photon query count

func (*BeamBlock) Parent

func (b *BeamBlock) Parent() ids.ID

Parent returns the parent block ID

func (*BeamBlock) Photons

func (b *BeamBlock) Photons() int

Photons returns the number of photon queries for this block

func (*BeamBlock) Reject

func (b *BeamBlock) Reject() error

Reject marks the block as rejected (excluded from the beam)

func (*BeamBlock) Status

func (b *BeamBlock) Status() choices.Status

Status returns the block status

func (*BeamBlock) Timestamp

func (b *BeamBlock) Timestamp() time.Time

Timestamp returns the block timestamp

func (*BeamBlock) UpdateBeamScore

func (b *BeamBlock) UpdateBeamScore(score uint64)

UpdateBeamScore updates the consensus score

func (*BeamBlock) Verify

func (b *BeamBlock) Verify(ctx context.Context) error

Verify ensures the block is valid according to beam rules

type BeamBlockWrapper

type BeamBlockWrapper struct {
	chain.Block
	// contains filtered or unexported fields
}

BeamBlockWrapper wraps an existing chain.Block for beam consensus

func WrapBlock

func WrapBlock(block chain.Block, height uint64) *BeamBlockWrapper

WrapBlock wraps an existing chain block for beam consensus

func (*BeamBlockWrapper) BeamHeight

func (w *BeamBlockWrapper) BeamHeight() uint64

BeamHeight returns the block's position in the beam

func (*BeamBlockWrapper) BeamScore

func (w *BeamBlockWrapper) BeamScore() uint64

BeamScore returns the block's consensus score

func (*BeamBlockWrapper) Photons

func (w *BeamBlockWrapper) Photons() int

Photons returns the number of photon queries for this block

type BeamMetrics

type BeamMetrics struct {
	BlocksAdded      uint64
	BlocksFinalized  uint64
	PollsProcessed   uint64
	BeamSplits       uint64 // Times the beam split (reorgs)
	AveragePollTime  time.Duration
	AverageFocusTime time.Duration
}

BeamMetrics tracks beam consensus performance

type BeamState

type BeamState struct {
	PreferredID       ids.ID
	PreferredHeight   uint64
	FinalizedID       ids.ID
	FinalizedHeight   uint64
	OutstandingBlocks int
	BeamIntensity     int // Consensus strength (0-100)
}

BeamState represents the current state of linear consensus

type Block

type Block interface {
	chain.Block

	// BeamHeight returns the block's position in the beam
	BeamHeight() uint64

	// BeamScore returns the block's consensus score
	BeamScore() uint64

	// Photons returns the number of photon queries for this block
	Photons() int
}

Block represents a block in the linear beam (Previously snowman.Block)

type Engine

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

Engine implements the beam linearizer for linear chain consensus (Previously Topological/Snowman++ in Avalanche)

func NewEngine

func NewEngine(params Parameters) *Engine

NewEngine creates a new beam consensus engine

func (*Engine) Add

func (e *Engine) Add(ctx context.Context, block Block) error

Add a new block to the beam

func (*Engine) Finalized

func (e *Engine) Finalized() []ids.ID

Finalized returns finalized blocks since last call

func (*Engine) HealthCheck

func (e *Engine) HealthCheck(ctx context.Context) (Health, error)

HealthCheck returns consensus health metrics

func (*Engine) IsFinalized

func (e *Engine) IsFinalized(blockID ids.ID) bool

IsFinalized checks if a block has been finalized

func (*Engine) Preferred

func (e *Engine) Preferred() ids.ID

Preferred returns the current preferred block

func (*Engine) RecordPoll

func (e *Engine) RecordPoll(ctx context.Context, votes map[ids.ID]int) error

RecordPoll records the result of photon sampling

func (*Engine) Vote

func (e *Engine) Vote(ctx context.Context, blockID ids.ID) error

Vote for a block preference

type Health

type Health struct {
	Healthy           bool
	BeamCoherence     float64 // 0-1, how coherent the beam is
	FocusStrength     int     // Current focus strength
	LastPollTime      time.Time
	ConsecutivePolls  int
	OutstandingBlocks int
}

Health represents consensus health metrics

type Linearizer

type Linearizer interface {
	// Add a new block to the beam
	Add(ctx context.Context, block Block) error

	// Vote for a block preference
	Vote(ctx context.Context, blockID ids.ID) error

	// RecordPoll records the result of photon sampling
	RecordPoll(ctx context.Context, votes map[ids.ID]int) error

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

	// Finalized returns finalized blocks since last call
	Finalized() []ids.ID

	// IsFinalized checks if a block has been finalized
	IsFinalized(blockID ids.ID) bool

	// HealthCheck returns consensus health metrics
	HealthCheck(ctx context.Context) (Health, error)
}

Linearizer represents beam-based linear chain consensus (Previously known as Snowman in Avalanche)

The beam linearizer ensures blocks form a single coherent beam of light, with each block building on exactly one parent, creating a linear history.

type Parameters

type Parameters struct {
	K               int           // Photon sample size
	AlphaPreference int           // Wave threshold for preference
	AlphaConfidence int           // Wave threshold for confidence
	Beta            int           // Focus rounds for finality
	MaxPollTime     time.Duration // Maximum time for a poll
}

Parameters configures the beam engine

Jump to

Keyboard shortcuts

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