Help us shape the future of Go! Take the 2026 Go Developer Survey

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: 17 Imported by: 0

README

Beam Consensus Engine

Beam is the linear chain consensus engine in the Quasar family, equivalent to Snowman++ in Avalanche.

Overview

Beam provides:

  • Linear chain consensus for blockchain ordering
  • Dual-certificate finality (BLS + Ringtail)
  • Sub-second finality with quantum security
  • Automatic slashing for protocol violations

Architecture

beam/
├── engine.go          # Main consensus engine
├── block.go           # Block structure with dual certificates
├── voter.go           # Voting and polling logic
├── issuer.go          # Block proposal logic
├── transitive.go      # Transitive voting
└── metrics.go         # Performance metrics

Block Structure

type Block struct {
    Header Header
    Txs    [][]byte
    Certs  CertBundle
}

type CertBundle struct {
    BLSAgg [96]byte  // BLS aggregate signature
    RTCert []byte    // Ringtail certificate
}

Consensus Flow

  1. Block Proposal

    • Proposer creates block
    • Signs with BLS private key
    • Initiates Ringtail share collection
  2. Share Collection

    • Collect Ringtail shares from validators
    • Aggregate when threshold reached
    • Attach dual certificates to block
  3. Voting

    • Validators verify dual certificates
    • Vote accept/reject
    • Achieve consensus through sampling
  4. Finalization

    • Block accepted when supermajority agrees
    • Both certificates must be valid
    • Quantum-secure finality achieved

Performance

  • Block time: 500ms
  • Dual-cert finality: <350ms
  • Network overhead: ~50ms
  • CPU overhead: +8%

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyDualCertificates

func VerifyDualCertificates(block *Block, blsPK []byte, rtPK []byte) error

VerifyDualCertificates verifies both BLS and RT certificates

Types

type AncestorTracker

type AncestorTracker interface {
	// Add adds a block to track
	Add(blkID ids.ID) error

	// Remove removes a block from tracking
	Remove(blkID ids.ID) error

	// IsAncestor returns true if ancestor is an ancestor of descendant
	IsAncestor(ancestor, descendant ids.ID) (bool, error)
}

AncestorTracker tracks block ancestors

type Block

type Block struct {
	PrntID     ids.ID
	Hght       uint64
	Tmstmp     int64
	ProposerID ids.NodeID
	TxList     [][]byte
	Certs      CertBundle
	// contains filtered or unexported fields
}

Block represents a block in the Beam consensus

func BuildBlock

func BuildBlock(
	parentID ids.ID,
	height uint64,
	timestamp int64,
	proposerID ids.NodeID,
	txs [][]byte,
) *Block

BuildBlock creates a new block

func ParseBlock

func ParseBlock(data []byte) (*Block, error)

ParseBlock parses a block from bytes

func (*Block) Accept

func (b *Block) Accept() error

Accept marks this block as accepted

func (*Block) AttachCertificates

func (b *Block) AttachCertificates(blsAgg [96]byte, rtCert []byte) error

AttachCertificates attaches dual certificates to a block

func (*Block) BLSSignature

func (b *Block) BLSSignature() []byte

BLSSignature returns the BLS aggregate signature

func (*Block) Bytes

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

Bytes returns the byte representation of this block

func (*Block) HasDualCert

func (b *Block) HasDualCert() bool

HasDualCert returns true if both BLS and RT certificates are present

func (*Block) Height

func (b *Block) Height() uint64

Height returns the height of this block

func (*Block) ID

func (b *Block) ID() ids.ID

ID returns the ID of this block

func (*Block) Parent

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

Parent returns the parent block ID

func (*Block) RTCertificate

func (b *Block) RTCertificate() []byte

RTCertificate returns the Ringtail certificate

func (*Block) Reject

func (b *Block) Reject() error

Reject marks this block as rejected

func (*Block) SetQuantum

func (b *Block) SetQuantum() error

SetQuantum marks this block as having quantum-secure finality

func (*Block) SetStatus

func (b *Block) SetStatus(status choices.Status)

SetStatus sets the status

func (*Block) Status

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

Status returns the current status

func (*Block) Timestamp

func (b *Block) Timestamp() int64

Timestamp returns the timestamp of this block

func (*Block) Verify

func (b *Block) Verify() error

Verify verifies the block

type CertBundle

type CertBundle struct {
	BLSAgg [96]byte // BLS aggregate signature
	RTCert []byte   // Ringtail certificate (~3KB)
}

CertBundle contains dual certificates for quantum security

type Config

type Config struct {
	// Consensus parameters
	Params          Parameters
	StartupTracker  StartupTracker
	Sender          Sender
	Timer           Timer
	AncestorTracker AncestorTracker

	// Quantum parameters
	QuasarEnabled     bool
	QuasarTimeout     time.Duration
	RingtailThreshold int
}

Config contains the configuration for the Beam engine

type Engine

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

Engine implements the Beam consensus engine

func NewEngine

func NewEngine(
	config Config,
	ctx *quasar.ConsensusContext,
	vm VM,
) (*Engine, error)

NewEngine creates a new Beam consensus engine

func (*Engine) BuildBlock

func (e *Engine) BuildBlock(ctx context.Context) (quasar.Block, error)

BuildBlock builds a new block

func (*Engine) GetSlashChannel

func (e *Engine) GetSlashChannel() <-chan SlashEvent

GetSlashChannel returns the slash event channel

func (*Engine) Start

func (e *Engine) Start(ctx context.Context) error

Start starts the consensus engine

func (*Engine) Stop

func (e *Engine) Stop() error

Stop stops the consensus engine

type Parameters

type Parameters struct {
	K                     int           // Sample size
	AlphaPreference       int           // Preference threshold
	AlphaConfidence       int           // Confidence threshold
	Beta                  int           // Decision threshold
	MaxItemProcessingTime time.Duration // Max time to process an item
}

Parameters contains consensus parameters

func (Parameters) Valid

func (p Parameters) Valid() error

Valid returns true if the parameters are valid

type PrecompPool

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

PrecompPool manages precomputed Ringtail data

func NewPrecompPool

func NewPrecompPool(capacity int) *PrecompPool

NewPrecompPool creates a new precomputation pool

func (*PrecompPool) Get

func (p *PrecompPool) Get() []byte

Get gets a precomputed value

func (*PrecompPool) Start

func (p *PrecompPool) Start(sk []byte)

Start starts precomputation

type Quasar

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

Quasar manages quantum-secure consensus operations

func NewQuasar

func NewQuasar(nodeID ids.NodeID, rtSK []byte, config QuasarConfig) (*Quasar, error)

NewQuasar creates a new Quasar instance

func (*Quasar) OnRTShare

func (q *Quasar) OnRTShare(height uint64, nodeID ids.NodeID, share []byte)

OnRTShare handles incoming Ringtail shares

func (*Quasar) QuickSign

func (q *Quasar) QuickSign(msg []byte) ([]byte, error)

QuickSign creates a Ringtail share using precomputed data

func (*Quasar) RegisterForCertificate

func (q *Quasar) RegisterForCertificate(height uint64, ch chan []byte)

RegisterForCertificate registers to receive a certificate when ready

type QuasarConfig

type QuasarConfig struct {
	Threshold     int
	QuasarTimeout time.Duration
	Validators    validators.State
}

QuasarConfig contains Quasar configuration

type Sender

type Sender interface {
	// SendGetAncestors sends a GetAncestors message
	SendGetAncestors(ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID) error

	// SendPullQuery sends a PullQuery message
	SendPullQuery(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, containerID ids.ID) error

	// SendPushQuery sends a PushQuery message
	SendPushQuery(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, container []byte) error

	// SendChits sends a Chits message
	SendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, acceptedID ids.ID) error
}

Sender sends consensus messages

type SlashEvent

type SlashEvent struct {
	ProposerID ids.NodeID
	Height     uint64
	Reason     string
	Timestamp  time.Time
}

SlashEvent represents a slashing event

type StartupTracker

type StartupTracker interface {
	Started() bool
}

StartupTracker tracks if the node is started

type Timer

type Timer interface {
	// SetTimeout sets a timeout
	SetTimeout(duration time.Duration) error

	// Cancel cancels the current timeout
	Cancel() error
}

Timer manages timeouts

type VM

type VM interface {
	// GetBlock returns the block with the given ID
	GetBlock(context.Context, ids.ID) (quasar.Block, error)

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

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

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

	// VerifyWithContext verifies a block with context
	VerifyWithContext(context.Context, quasar.Block) error
}

VM is the interface for the virtual machine

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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