wave

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Type            ThresholdType
	AlphaPreference int
	AlphaConfidence int
}

Config represents wave threshold configuration

type DynamicWaveThreshold

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

DynamicWaveThreshold implements decoupled alpha thresholding (Previously DynamicQuorum/DecoupledQuorum in Avalanche)

Uses separate thresholds for preference (alpha1) and confidence (alpha2), allowing for more nuanced consensus detection through wave interference.

func NewDynamicWaveThreshold

func NewDynamicWaveThreshold(alphaPreference, alphaConfidence int) *DynamicWaveThreshold

NewDynamicWaveThreshold creates a threshold with decoupled alphas

func (*DynamicWaveThreshold) AddVote

func (d *DynamicWaveThreshold) AddVote(nodeID ids.NodeID, choice ids.ID) bool

AddVote adds a vote and returns true if current threshold is reached

func (*DynamicWaveThreshold) CheckConfidence

func (d *DynamicWaveThreshold) CheckConfidence() (ids.ID, bool)

CheckConfidence returns true if any choice meets confidence threshold

func (*DynamicWaveThreshold) CheckPreference

func (d *DynamicWaveThreshold) CheckPreference() (ids.ID, bool)

CheckPreference returns true if any choice meets preference threshold

func (*DynamicWaveThreshold) GetLeader

func (d *DynamicWaveThreshold) GetLeader() (ids.ID, int)

GetLeader returns the current leading choice and its vote count

func (*DynamicWaveThreshold) GetThreshold

func (d *DynamicWaveThreshold) GetThreshold() int

GetThreshold returns the current active threshold

func (*DynamicWaveThreshold) GetTotalVotes

func (d *DynamicWaveThreshold) GetTotalVotes() int

GetTotalVotes returns total votes received

func (*DynamicWaveThreshold) GetVoteCount

func (d *DynamicWaveThreshold) GetVoteCount(choice ids.ID) int

GetVoteCount returns votes for a specific choice

func (*DynamicWaveThreshold) Reset

func (d *DynamicWaveThreshold) Reset()

Reset clears all votes

func (*DynamicWaveThreshold) SetMode

func (d *DynamicWaveThreshold) SetMode(preferenceMode bool)

SetMode switches between preference and confidence modes

type Factory

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

Factory creates wave threshold mechanisms (Previously QuorumFactory in Avalanche)

func NewFactory

func NewFactory(alphaPreference, alphaConfidence int) *Factory

NewFactory creates a new wave threshold factory

func (*Factory) New

func (f *Factory) New(thresholdType ThresholdType) Threshold

New creates a threshold of the specified type

func (*Factory) NewDynamic

func (f *Factory) NewDynamic() Threshold

NewDynamic creates a dynamic wave threshold with decoupled alphas

func (*Factory) NewStatic

func (f *Factory) NewStatic() Threshold

NewStatic creates a static wave threshold

type StaticWaveThreshold

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

StaticWaveThreshold implements fixed alpha thresholding (Previously StaticQuorum in Avalanche)

Uses a fixed threshold for determining when constructive interference (consensus) has been achieved.

func NewStaticWaveThreshold

func NewStaticWaveThreshold(alpha int) *StaticWaveThreshold

NewStaticWaveThreshold creates a threshold with fixed alpha

func (*StaticWaveThreshold) AddVote

func (s *StaticWaveThreshold) AddVote(nodeID ids.NodeID, choice ids.ID) bool

AddVote adds a vote and returns true if threshold is reached

func (*StaticWaveThreshold) GetLeader

func (s *StaticWaveThreshold) GetLeader() (ids.ID, int)

GetLeader returns the current leading choice and its vote count

func (*StaticWaveThreshold) GetThreshold

func (s *StaticWaveThreshold) GetThreshold() int

GetThreshold returns the alpha threshold

func (*StaticWaveThreshold) GetTotalVotes

func (s *StaticWaveThreshold) GetTotalVotes() int

GetTotalVotes returns total votes received

func (*StaticWaveThreshold) GetVoteCount

func (s *StaticWaveThreshold) GetVoteCount(choice ids.ID) int

GetVoteCount returns votes for a specific choice

func (*StaticWaveThreshold) GetWavePattern

func (s *StaticWaveThreshold) GetWavePattern() *WavePattern

GetWavePattern returns the current voting state

func (*StaticWaveThreshold) Reset

func (s *StaticWaveThreshold) Reset()

Reset clears all votes

type Threshold

type Threshold interface {
	// AddVote adds a vote and returns if threshold is reached
	AddVote(nodeID ids.NodeID, choice ids.ID) bool

	// GetThreshold returns the current alpha threshold
	GetThreshold() int

	// GetVoteCount returns votes for a specific choice
	GetVoteCount(choice ids.ID) int

	// GetTotalVotes returns total votes received
	GetTotalVotes() int

	// GetLeader returns the current leading choice and its vote count
	GetLeader() (ids.ID, int)

	// Reset clears all votes
	Reset()
}

Threshold represents wave interference patterns for vote counting (Previously known as Quorum in Avalanche consensus)

When photon reflections (votes) return, they create interference patterns. Constructive interference above the threshold indicates consensus forming.

func NewFromConfig

func NewFromConfig(cfg Config) Threshold

NewFromConfig creates a threshold from configuration

type ThresholdType

type ThresholdType int

ThresholdType identifies the type of threshold mechanism

const (
	Static ThresholdType = iota
	Dynamic
	Adaptive
)

type WavePattern

type WavePattern struct {
	Choices    map[ids.ID]int // Vote counts per choice
	TotalVotes int
	Threshold  int // Alpha threshold
}

WavePattern represents the voting state at a given moment (Previously QuorumState)

func (*WavePattern) GetAmplitude

func (w *WavePattern) GetAmplitude(choice ids.ID) int

GetAmplitude returns the "amplitude" (vote count) for a choice

func (*WavePattern) IsConstructive

func (w *WavePattern) IsConstructive() bool

IsConstructive returns true if the pattern shows constructive interference (i.e., one choice has exceeded the threshold)

Jump to

Keyboard shortcuts

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