ray

package
v1.22.45 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 ray finalizes linear chains through single-threaded consensus.

After focus accumulates β consecutive successes, Ray provides the final "yes/no" decision for the linear case. It's a single beam of light that marks a definitive state transition—bright, decisive, observable. This handles linear consensus finality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block interface {
	ID() ids.ID
	ParentID() ids.ID
	Height() uint64
	Bytes() []byte
	Verify(context.Context) error
	Accept(context.Context) error
	Reject(context.Context) error
}

Block defines a block

type Chain

type Chain interface {
	// GetBlock gets a block
	GetBlock(context.Context, ids.ID) (Block, error)

	// AddBlock adds a block
	AddBlock(Block) error

	// LastAccepted returns last accepted block
	LastAccepted() ids.ID

	// GetAncestor gets an ancestor
	GetAncestor(ids.ID, uint64) (ids.ID, error)
}

Chain defines a blockchain

type Config

type Config struct {
	PollSize int
	Alpha    float64
	Beta     uint32
	RoundTO  time.Duration
	MaxBatch int
}

type Driver

type Driver[T ID] struct {
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver[T ID](cfg Config, cut prism.Cut[T], tx Transport[T], src Source[T], out Sink[T]) *Driver[T]

func (*Driver[T]) GetPreference

func (d *Driver[T]) GetPreference() (T, bool)

GetPreference returns the current preferred item

func (*Driver[T]) Height

func (d *Driver[T]) Height() uint64

Height returns the current consensus height (for linear chains)

func (*Driver[T]) IsFinalized

func (d *Driver[T]) IsFinalized(item T) bool

IsFinalized checks if an item is finalized

func (*Driver[T]) Propose

func (d *Driver[T]) Propose(ctx context.Context, item T) error

Propose proposes an item for consensus (Nova will use this for blocks)

func (*Driver[T]) Start

func (d *Driver[T]) Start(ctx context.Context) error

Start begins the Ray engine operation

func (*Driver[T]) Stop

func (d *Driver[T]) Stop(ctx context.Context) error

Stop ends the Ray engine operation

func (*Driver[T]) Tick

func (d *Driver[T]) Tick(ctx context.Context) error

Tick drives one sampling round across up to MaxBatch pending items. Any that reach β are emitted to Sink in input order with their decision.

type ID

type ID interface{ comparable }

ID is your item identifier (block hash, tx id, etc.).

type Nova

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

Nova implements the Nova consensus protocol

func New

func New(nodeID types.NodeID) *Nova

New creates a new Nova instance

func (*Nova) Propose

func (n *Nova) Propose(ctx context.Context, value []byte) error

Propose proposes a value

func (*Nova) Round

func (n *Nova) Round() uint64

Round returns the current round

func (*Nova) Start

func (n *Nova) Start(ctx context.Context) error

Start starts the Nova protocol

func (*Nova) Stop

func (n *Nova) Stop(ctx context.Context) error

Stop stops the Nova protocol

type Sink

type Sink[T ID] interface {
	Decide(ctx context.Context, items []T, d types.Decision) error
}

Sink receives final decisions in order.

type Source

type Source[T ID] interface {
	NextPending(ctx context.Context, n int) []T
}

Source lets Ray pull next candidates to decide in linear order.

type Transport

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

Transport bridges network vote requests <-> Photons the Wave consumes.

type VM

type VM interface {
	// ParseBlock parses a block
	ParseBlock(context.Context, []byte) (Block, error)

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

	// GetBlock gets a block
	GetBlock(context.Context, ids.ID) (Block, error)

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

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

VM defines a chain VM

Jump to

Keyboard shortcuts

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