wave

package
v1.22.41 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package wave computes per-round thresholds and drives a poll.

Each round has two thresholds—α_pref and α_conf—that gate preference and confidence. The default selector is FPC: a phase-dependent threshold chosen from [θ_min, θ_max], reproducibly derived from a PRF.

Wave doesn't decide anything alone; it transforms a committee's tallies into a boolean (preferOK, confOK) that downstream focus can integrate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	K         int           // Sample size
	Alpha     float64       // Threshold ratio (used when FPC disabled)
	Beta      uint32        // Confidence threshold
	RoundTO   time.Duration // Round timeout
	EnableFPC bool          // Enable Fast Probabilistic Consensus
	ThetaMin  float64       // FPC minimum threshold (default: 0.5)
	ThetaMax  float64       // FPC maximum threshold (default: 0.8)
}

Config holds configuration for wave consensus

type Photon

type Photon[T comparable] struct {
	Item      T
	Prefer    bool
	Sender    types.NodeID
	Timestamp time.Time
}

Photon represents a vote message in the consensus protocol

type State

type State[ID comparable] struct {
	// The item ID
	ID ID

	// Confidence score
	Confidence int

	// Whether the item is finalized
	Finalized bool

	// Parent IDs
	Parents []ID

	// Height in the consensus graph
	Height uint64
}

State represents the consensus state for an item

func NewState

func NewState[ID comparable](id ID) State[ID]

NewState creates a new consensus state

func (*State[ID]) Finalize

func (s *State[ID]) Finalize()

Finalize marks the state as finalized

func (*State[ID]) IncrementConfidence

func (s *State[ID]) IncrementConfidence()

IncrementConfidence increments the confidence score

func (State[ID]) IsPreferred

func (s State[ID]) IsPreferred() bool

IsPreferred returns whether this state is preferred

type Transport

type Transport[T comparable] interface {
	RequestVotes(ctx context.Context, peers []types.NodeID, item T) <-chan Photon[T]
	MakeLocalPhoton(item T, prefer bool) Photon[T]
}

Transport handles network communication for voting

type Wave

type Wave[T comparable] struct {
	// contains filtered or unexported fields
}

Wave manages threshold voting and confidence building

func New

func New[T comparable](cfg Config, cut prism.Cut[T], tx Transport[T]) Wave[T]

New creates a new Wave instance

func (*Wave[T]) Preference

func (w *Wave[T]) Preference(item T) bool

Preference returns the current preference for an item

func (*Wave[T]) State

func (w *Wave[T]) State(item T) (*WaveState, bool)

State returns the current polling state of an item

func (*Wave[T]) Tick

func (w *Wave[T]) Tick(ctx context.Context, item T)

Tick performs one round of sampling and threshold checking for an item

type WaveState

type WaveState struct {
	Decided bool
	Result  types.Decision
	Count   uint32
}

WaveState represents the polling state of an item in wave consensus

Directories

Path Synopsis
Package fpc implements Fast Probabilistic Consensus thresholds.
Package fpc implements Fast Probabilistic Consensus thresholds.

Jump to

Keyboard shortcuts

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