consensus

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: BSD-3-Clause Imports: 4 Imported by: 1

Documentation

Overview

Package consensus provides GPU-accelerated consensus primitives.

Used for accelerating vote processing, validator set computations, and other consensus-critical operations that can benefit from parallelization.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInput     = errors.New("consensus: invalid input")
	ErrInvalidBatchSize = errors.New("consensus: invalid batch size")
	ErrNotInitialized   = errors.New("consensus: not initialized")
)

Functions

func AggregateVotes

func AggregateVotes(votes []VoteData, validators []ValidatorWeight) (map[[32]byte]uint64, error)

AggregateVotes aggregates votes by block, returning vote counts per block. Returns a map of block ID to total weight voted for that block.

func BatchVerifyVoteSignatures

func BatchVerifyVoteSignatures(votes []VoteData, signatures, pubkeys [][]byte) ([]bool, error)

BatchVerifyVoteSignatures verifies vote signatures in parallel. Returns a slice of booleans indicating validity of each vote.

func ComputeValidatorSetHash

func ComputeValidatorSetHash(validators []ValidatorWeight) ([32]byte, error)

ComputeValidatorSetHash computes a hash of the validator set for checkpointing.

func ProcessVotesBatch

func ProcessVotesBatch(votes []VoteData) (int, error)

ProcessVotesBatch processes a batch of votes in parallel. Returns the number of votes successfully processed.

Types

type QuorumResult

type QuorumResult struct {
	HasQuorum    bool
	TotalWeight  uint64
	VotedWeight  uint64
	QuorumWeight uint64
}

QuorumResult contains the result of a quorum check.

func ComputeQuorum

func ComputeQuorum(votes []VoteData, validators []ValidatorWeight, threshold float64) (*QuorumResult, error)

ComputeQuorum checks if a quorum is reached given votes and validators. threshold is the fraction of stake required (e.g., 0.67 for 2/3).

type ValidatorWeight

type ValidatorWeight struct {
	ValidatorID [32]byte
	Weight      uint64
}

ValidatorWeight represents a validator and its stake weight.

type VoteData

type VoteData struct {
	VoterID      [32]byte
	BlockID      [32]byte
	IsPreference bool
}

VoteData represents a vote for batch processing.

Jump to

Keyboard shortcuts

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