Documentation
ยถ
Overview ยถ
Package consensus provides the Lux consensus implementation.
Package consensus provides the Lux consensus implementation.
Package consensus defines a minimal set of orthogonal primitives for probabilistic agreement.
The terminology follows a physics / cosmology metaphor:
photon โ the atomic unit: select K "rays" (a committee sample) wave โ per-round thresholds (ฮฑ_pref, ฮฑ_conf) and phase shifts (FPC) focus โ ฮฒ consecutive rounds concentrate confidence into a decision prism โ geometric views of a DAG: frontiers, cuts, refractions horizon โ order-theoretic structure: reachability, antichains, cert/skip
Together these stages form the optics of consensus: light is emitted (photon), amplified and interfered (wave), reinforced (focus), bent through a DAG (prism), and ultimately anchored against the limits of visibility (horizon).
Engines (chain, dag, quasar) compose these primitives into full protocols, while remaining modular and substitutable.
Example (ConsensusRound) ยถ
Example of how to run a consensus round programmatically
package main
import (
"fmt"
"github.com/luxfi/consensus"
"github.com/luxfi/consensus/config"
"github.com/luxfi/ids"
)
func main() {
// Create engine
engine := consensus.NewChainEngine()
params := config.LocalParams()
// Generate block ID
blockID := ids.GenerateTestID()
// Collect votes (in real scenario, from network)
votes := map[string]bool{
"node1": true,
"node2": true,
"node3": true,
"node4": false,
"node5": true,
}
// Calculate confidence
acceptCount := 0
for _, vote := range votes {
if vote {
acceptCount++
}
}
confidence := float64(acceptCount) / float64(len(votes))
finalized := confidence >= params.Alpha
_ = engine // Use engine for actual consensus
fmt.Printf("Block %s: confidence=%.0f%%, finalized=%v\n",
blockID, confidence*100, finalized)
}
Index ยถ
- Constants
- Variables
- func Config(nodes int) config.Parameters
- func LuxAssetID(ctx context.Context) interface{}
- func QuantumNetworkID(ctx context.Context) uint32
- type Acceptor
- type AcceptorGroup
- type AppError
- type BasicAcceptor
- type CodecVersion
- type Context
- type ContextInitializable
- type Contextualizable
- type Engine
- type Fx
- type IDs
- type QuantumIDs
- type State
- type ValidatorState
Examples ยถ
Constants ยถ
const ( // CurrentCodecVersion is the current codec version CurrentCodecVersion = codec.CurrentVersion )
Export constants
Variables ยถ
var ( GetTimestamp = consensuscontext.GetTimestamp GetChainID = consensuscontext.GetChainID GetNetID = consensuscontext.GetNetID GetNetworkID = consensuscontext.GetNetworkID GetValidatorState = consensuscontext.GetValidatorState GetSubnetID = consensuscontext.GetNetID // GetSubnetID is an alias for GetNetID for backward compatibility WithContext = consensuscontext.WithContext FromContext = consensuscontext.FromContext GetNodeID = consensuscontext.GetNodeID WithIDs = consensuscontext.WithIDs WithValidatorState = consensuscontext.WithValidatorState )
Export functions from context
var ( // Codec is the consensus codec Codec = codec.Codec )
Export variables
Functions ยถ
func Config ยถ
func Config(nodes int) config.Parameters
Config returns default consensus parameters for different network sizes
func LuxAssetID ยถ
LuxAssetID returns the ID of the LUX asset
func QuantumNetworkID ยถ
QuantumNetworkID returns the quantum network ID from context
Types ยถ
type Acceptor ยถ
type Acceptor interface {
// Accept processes an accepted item
Accept(ctx context.Context, containerID ids.ID, container []byte) error
}
Acceptor interface for consensus acceptors
type AcceptorGroup ยถ
type AcceptorGroup interface {
RegisterAcceptor(chainID ids.ID, acceptorName string, acceptor Acceptor, dieOnError bool) error
DeregisterAcceptor(chainID ids.ID, acceptorName string) error
}
AcceptorGroup manages a group of acceptors
func NewAcceptorGroup ยถ
func NewAcceptorGroup() AcceptorGroup
NewAcceptorGroup creates a new acceptor group
type BasicAcceptor ยถ
type BasicAcceptor struct {
// contains filtered or unexported fields
}
BasicAcceptor is a simple implementation of the Acceptor interface
func NewBasicAcceptor ยถ
func NewBasicAcceptor() *BasicAcceptor
NewBasicAcceptor creates a new basic acceptor
type ContextInitializable ยถ
ContextInitializable can be initialized with context
type Contextualizable ยถ
Contextualizable can be contextualized
type Engine ยถ
type Engine interface {
// Start starts the engine
Start(context.Context, uint32) error
// Stop stops the engine
Stop(context.Context) error
// HealthCheck performs a health check
HealthCheck(context.Context) (interface{}, error)
// IsBootstrapped returns whether the engine is bootstrapped
IsBootstrapped() bool
}
Engine is the main consensus engine interface
func NewChainEngine ยถ
func NewChainEngine() Engine
NewChainEngine creates a new chain consensus engine
func NewPQEngine ยถ
func NewPQEngine() Engine
NewPQEngine creates a new post-quantum consensus engine
type QuantumIDs ยถ
type QuantumIDs struct {
// QuantumID is the root quantum network identifier
QuantumID uint32
NodeID ids.NodeID
// NetID identifies networks within the quantum network
NetID ids.ID
ChainID ids.ID
// P-Chain is the quantum validation chain
PChainID ids.ID
XChainID ids.ID
CChainID ids.ID
AVAXAssetID ids.ID
}
QuantumIDs contains various quantum network and chain IDs
func GetQuantumIDs ยถ
func GetQuantumIDs(ctx context.Context) *QuantumIDs
GetQuantumIDs retrieves QuantumIDs from context
type ValidatorState ยถ
type ValidatorState = consensuscontext.ValidatorState
ValidatorState provides validator information
Directories
ยถ
| Path | Synopsis |
|---|---|
|
Package block provides block interfaces for consensus
|
Package block provides block interfaces for consensus |
|
cmd
|
|
|
bench
command
Package main provides the bench CLI tool for consensus benchmarking
|
Package main provides the bench CLI tool for consensus benchmarking |
|
checker
command
Package main provides the checker CLI tool for consensus health checking
|
Package main provides the checker CLI tool for consensus health checking |
|
consensus
command
Package main provides the main consensus CLI tool
|
Package main provides the main consensus CLI tool |
|
params
command
Package main provides the params CLI tool for viewing consensus network parameters
|
Package main provides the params CLI tool for viewing consensus network parameters |
|
server
command
|
|
|
sim
command
Package main provides the sim CLI tool for consensus simulation
|
Package main provides the sim CLI tool for consensus simulation |
|
Package codec provides encoding/decoding for consensus types
|
Package codec provides encoding/decoding for consensus types |
|
Package context provides consensus context for VMs
|
Package context provides consensus context for VMs |
|
Package core provides core consensus interfaces and contracts.
|
Package core provides core consensus interfaces and contracts. |
|
appsender
Package appsender defines the AppSender interface for application-level messaging
|
Package appsender defines the AppSender interface for application-level messaging |
|
coremock
Package coremock provides mock implementations for testing
|
Package coremock provides mock implementations for testing |
|
interfaces
Package interfaces defines core consensus interfaces
|
Package interfaces defines core consensus interfaces |
|
tracker
Package tracker provides consensus tracking utilities
|
Package tracker provides consensus tracking utilities |
|
Package engine houses the three consensus engines: chain, dag, and pq.
|
Package engine houses the three consensus engines: chain, dag, and pq. |
|
chain
Package chain implements linear consensus protocol.
|
Package chain implements linear consensus protocol. |
|
chain/block/blockmock
Package blockmock provides mock implementations for testing
|
Package blockmock provides mock implementations for testing |
|
chain/block/blocktest
Package blocktest provides test utilities for blocks
|
Package blocktest provides test utilities for blocks |
|
chain/chainmock
Package chainmock provides mock implementations for testing
|
Package chainmock provides mock implementations for testing |
|
chain/chaintest
Package chaintest provides test utilities for chains
|
Package chaintest provides test utilities for chains |
|
core/coremock
Package coremock provides mock implementations for core consensus
|
Package coremock provides mock implementations for core consensus |
|
dag
Package dag provides DAG consensus functionality
|
Package dag provides DAG consensus functionality |
|
enginetest
Package enginetest provides test utilities for consensus engines
|
Package enginetest provides test utilities for consensus engines |
|
pq
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. |
|
Package examples demonstrates integration between consensus and node packages
|
Package examples demonstrates integration between consensus and node packages |
|
Package flare finalizes DAG cuts via a cascading accept protocol.
|
Package flare finalizes DAG cuts via a cascading accept protocol. |
|
Package focus accumulates confidence by counting ฮฒ consecutive successes.
|
Package focus accumulates confidence by counting ฮฒ consecutive successes. |
|
Package horizon houses DAG order-theory predicates.
|
Package horizon houses DAG order-theory predicates. |
|
Package interfaces provides common consensus interfaces
|
Package interfaces provides common consensus interfaces |
|
networking
|
|
|
benchlist
Package benchlist is DEPRECATED.
|
Package benchlist is DEPRECATED. |
|
router
Package router is DEPRECATED.
|
Package router is DEPRECATED. |
|
router/routermock
Package routermock provides mock implementations for message routing
|
Package routermock provides mock implementations for message routing |
|
sender/sendertest
Package sendertest provides test utilities for message sending
|
Package sendertest provides test utilities for message sending |
|
tracker
Package tracker is DEPRECATED.
|
Package tracker is DEPRECATED. |
|
Package photon chooses a K-sized committee each round.
|
Package photon chooses a K-sized committee each round. |
|
Package prism provides DAG geometry: frontiers, cuts, and refractions.
|
Package prism provides DAG geometry: frontiers, cuts, and refractions. |
|
protocol
|
|
|
field
Package field orchestrates DAG finality via distributed state reduction.
|
Package field orchestrates DAG finality via distributed state reduction. |
|
flare
Package flare finalizes DAG cuts via a cascading accept protocol.
|
Package flare finalizes DAG cuts via a cascading accept protocol. |
|
focus
Package focus accumulates confidence by counting ฮฒ consecutive successes.
|
Package focus accumulates confidence by counting ฮฒ consecutive successes. |
|
horizon
Package horizon houses DAG order-theory predicates.
|
Package horizon houses DAG order-theory predicates. |
|
quasar
Package quasar provides post-quantum overlay: dual BLS + ring certificates.
|
Package quasar provides post-quantum overlay: dual BLS + ring certificates. |
|
ray
Package ray finalizes linear chains through single-threaded consensus.
|
Package ray finalizes linear chains through single-threaded consensus. |
|
Package qzmq provides post-quantum secure transport over ZeroMQ.
|
Package qzmq provides post-quantum secure transport over ZeroMQ. |
|
Package uptime provides uptime calculation functionality
|
Package uptime provides uptime calculation functionality |
|
uptimemock
Package uptimemock provides mock implementations for uptime tracking
|
Package uptimemock provides mock implementations for uptime tracking |
|
validatorsmock
Package validatorsmock provides mock implementations for validator management
|
Package validatorsmock provides mock implementations for validator management |
|
Package verify provides verification utilities
|
Package verify provides verification utilities |
|
Package version provides version information
|
Package version provides version information |
|
Package wave computes per-round thresholds and drives a poll.
|
Package wave computes per-round thresholds and drives a poll. |
|
fpc
Package fpc implements Fast Probabilistic Consensus thresholds.
|
Package fpc implements Fast Probabilistic Consensus thresholds. |