photon

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryPhotonSampler

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

BinaryPhotonSampler implements binary consensus sampling (Previously BinaryPoll in Avalanche)

Binary photon sampling chooses between exactly two options, like a photon passing through a beam splitter.

func NewBinaryPhotonSampler

func NewBinaryPhotonSampler(k int, seed int64) *BinaryPhotonSampler

NewBinaryPhotonSampler creates a new binary photon sampler

func (*BinaryPhotonSampler) GetK

func (b *BinaryPhotonSampler) GetK() int

GetK returns the sample size

func (*BinaryPhotonSampler) Reset

func (b *BinaryPhotonSampler) Reset()

Reset clears the sampler state

func (*BinaryPhotonSampler) Sample

func (b *BinaryPhotonSampler) Sample(ctx context.Context, validatorSet set.Set[ids.NodeID], k int) (set.Set[ids.NodeID], error)

Sample selects K validators uniformly at random

type Factory

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

Factory creates photon samplers with specific configurations (Previously PollFactory in Avalanche)

func NewFactory

func NewFactory(k int) *Factory

NewFactory creates a new photon sampler factory

func (*Factory) New

func (f *Factory) New(samplerType SamplerType) Sampler

New creates a sampler of the specified type

func (*Factory) NewBinary

func (f *Factory) NewBinary() Sampler

NewBinary creates a binary photon sampler

func (*Factory) NewUnary

func (f *Factory) NewUnary() Sampler

NewUnary creates a unary photon sampler

func (*Factory) WithSeed

func (f *Factory) WithSeed(seed int64) *Factory

WithSeed sets a specific random seed

func (*Factory) WithTerminationThreshold

func (f *Factory) WithTerminationThreshold(threshold int) *Factory

WithTerminationThreshold sets the early termination threshold

type PhotonQuery

type PhotonQuery struct {
	RequestID  uint32
	ChainID    ids.ID
	Height     uint64
	Containers []ids.ID // Options being queried
}

PhotonQuery represents a query sent to validators (Previously known as Poll message)

type PhotonReflection

type PhotonReflection struct {
	RequestID  uint32
	ChainID    ids.ID
	Height     uint64
	Container  ids.ID // The validator's choice
	Confidence int    // Confidence level
}

PhotonReflection represents a response from a validator (Previously known as Vote message)

type Response

type Response struct {
	NodeID     ids.NodeID
	Preference ids.ID // The validator's preference
	Confidence int    // Confidence level (0-100)
}

Response represents a validator's response to a photon query (Previously known as Vote in Avalanche consensus)

type Sampler

type Sampler interface {
	// Sample returns a sample of K validators to query
	// This is like emitting photons to specific targets
	Sample(ctx context.Context, validatorSet set.Set[ids.NodeID], k int) (set.Set[ids.NodeID], error)

	// GetK returns the sample size
	GetK() int

	// Reset clears any internal state
	Reset()
}

Sampler represents photonic sampling of validators (Previously known as Poll in Avalanche consensus)

The photon sampler emits "photons" (queries) to a sample of K validators and collects their "reflections" (responses).

type SamplerType

type SamplerType int

SamplerType identifies the type of photon sampler

const (
	Binary SamplerType = iota
	Unary
)

type UnaryPhotonSampler

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

UnaryPhotonSampler implements unary consensus sampling (Previously UnaryPoll in Avalanche)

Unary photon sampling is used when there's only one option, like measuring photon presence/absence rather than direction.

func NewUnaryPhotonSampler

func NewUnaryPhotonSampler(k int, seed int64, termThreshold int) *UnaryPhotonSampler

NewUnaryPhotonSampler creates a new unary photon sampler

func (*UnaryPhotonSampler) GetK

func (u *UnaryPhotonSampler) GetK() int

GetK returns the sample size

func (*UnaryPhotonSampler) RecordEarlyTermination

func (u *UnaryPhotonSampler) RecordEarlyTermination(containerID ids.ID)

RecordEarlyTermination records when a unary query terminates early

func (*UnaryPhotonSampler) Reset

func (u *UnaryPhotonSampler) Reset()

Reset clears the sampler state

func (*UnaryPhotonSampler) Sample

func (u *UnaryPhotonSampler) Sample(ctx context.Context, validatorSet set.Set[ids.NodeID], k int) (set.Set[ids.NodeID], error)

Sample selects K validators, with possible early termination

Jump to

Keyboard shortcuts

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