sequencer

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 48 Imported by: 0

Documentation

Overview

Package sequencer provides functionality for processing and aggregating ballots into batches with zero-knowledge proofs for efficient verification.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AggregatorTickerInterval is the interval at which the aggregator will check for new ballots to process.
	// This value can be changed before starting the sequencer.
	AggregatorTickerInterval = 10 * time.Second

	// NewProcessMonitorInterval is the interval at which the sequencer will check for new processes to participate in.
	// This value can be changed before starting the sequencer.
	NewProcessMonitorInterval = 10 * time.Second

	// ParticipateInAllProcesses determines if the sequencer should process ballots from all processes that are registered.
	// This is a temporary flag to simplify testing and will be removed in the future. The Sequencer caller must somehow
	// decide which processes to participate in.
	ParticipateInAllProcesses = true
)
View Source
var (
	ErrNoJobAvailable = errors.New("no job available")
	ErrWorkerBanned   = errors.New("worker is banned")
	ErrWorkerBusy     = errors.New("worker is busy")

	CooldownDuration = 30 * time.Second // Default cooldown duration when worker is busy or banned
)

ErrNoJobAvailable is returned when there are no jobs available for the worker to process. This can happen if the sequencer node has no ballots assigned to this worker or if all ballots have been processed.

View Source
var ErrProcessEncryptionKeysMissing = errors.New("process encryption keys missing")

Functions

This section is empty.

Types

type ProcessIDMap

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

ProcessIDMap provides a thread-safe map for storing and retrieving process IDs. It handles the conversion of process IDs from byte slices to hexadecimal strings internally.

func NewProcessIDMap

func NewProcessIDMap() *ProcessIDMap

NewProcessIDMap creates a new empty ProcessIDMap.

func (*ProcessIDMap) Add

func (p *ProcessIDMap) Add(processID types.ProcessID) bool

Add adds a process ID to the map with the current time. If the process ID already exists, this operation has no effect. Returns true if the process ID was added, false if it already existed.

func (*ProcessIDMap) ClearFirstBallotTime

func (p *ProcessIDMap) ClearFirstBallotTime(processID types.ProcessID)

ClearFirstBallotTime clears the first ballot timestamp for a process ID. This should be called after a batch is processed.

func (*ProcessIDMap) Exists

func (p *ProcessIDMap) Exists(processID types.ProcessID) bool

Exists checks if a process ID is in the map.

func (*ProcessIDMap) ForEach

func (p *ProcessIDMap) ForEach(f func(processID types.ProcessID, t time.Time) bool)

ForEach executes the given function for each process ID in the map. Takes a snapshot of the data and releases the lock before executing callbacks, ensuring long-running operations don't block other map operations.

func (*ProcessIDMap) Get

func (p *ProcessIDMap) Get(processID types.ProcessID) (time.Time, bool)

Get returns the time when a process ID was added and a boolean indicating whether the process ID exists in the map.

func (*ProcessIDMap) GetFirstBallotTime

func (p *ProcessIDMap) GetFirstBallotTime(processID types.ProcessID) (time.Time, bool)

GetFirstBallotTime returns the timestamp of when the first ballot arrived after the last batch processing, and a boolean indicating if it exists.

func (*ProcessIDMap) Len

func (p *ProcessIDMap) Len() int

Len returns the number of process IDs in the map.

func (*ProcessIDMap) List

func (p *ProcessIDMap) List() []types.ProcessID

List returns a slice of all process IDs in the map as byte slices.

func (*ProcessIDMap) Remove

func (p *ProcessIDMap) Remove(processID types.ProcessID) bool

Remove removes a process ID from the map. If the process ID is not in the map, this operation has no effect. Returns true if the process ID was removed, false if it wasn't in the map.

func (*ProcessIDMap) SetFirstBallotTime

func (p *ProcessIDMap) SetFirstBallotTime(processID types.ProcessID)

SetFirstBallotTime sets the timestamp for when the first ballot arrived after the last batch, but only if it hasn't been set already.

type Sequencer

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

Sequencer is a worker that takes verified ballots and aggregates them into a single proof. It processes ballots and creates batches of proofs for efficient verification.

func New

func New(stg *storage.Storage, contracts *web3.Contracts, batchTimeWindow time.Duration) (*Sequencer, error)

New creates a new Sequencer instance that processes ballots and aggregates them into batches. It loads all necessary cryptographic artifacts for proof verification and generation.

Parameters:

  • stg: Storage instance for accessing ballots and other data
  • contracts: Web3 contracts for on-chain interaction
  • batchTimeWindow: Maximum time to wait before processing a batch even if not full

Returns a configured Sequencer instance or an error if initialization fails.

func NewWorker

func NewWorker(stg *storage.Storage, rawSequencerURL, workerAddr, workerToken, workerName string) (*Sequencer, error)

NewWorker creates a Sequencer instance configured for worker mode. Only loads the necessary artifacts for ballot processing (vote verifier).

Parameters:

  • stg: Storage instance for accessing ballots and other data
  • sequencerURL: URL of the sequencer node to connect to
  • sequencerUUID: UUID of the sequencer node to connect to
  • workerAddr: Ethereum address identifying this worker
  • workerToken: Hex-encoded authentication token for the worker
  • workerName: Name of the worker (optional)

Returns a configured Sequencer instance for worker mode or an error if initialization fails.

func (*Sequencer) ActiveProcessIDs

func (s *Sequencer) ActiveProcessIDs() []types.ProcessID

ActiveProcessIDs returns a list of process IDs that are currently being tracked by the sequencer.

func (*Sequencer) AddProcessID

func (s *Sequencer) AddProcessID(processID types.ProcessID)

AddProcessID registers a process ID with the sequencer for ballot processing. Only ballots belonging to registered process IDs will be processed. If the process ID is already registered, this operation has no effect.

func (*Sequencer) DelProcessID

func (s *Sequencer) DelProcessID(processID types.ProcessID)

DelProcessID unregisters a process ID from the sequencer. If the process ID is not registered, this operation has no effect.

func (*Sequencer) ExistsProcessID

func (s *Sequencer) ExistsProcessID(processID types.ProcessID) bool

ExistsProcessID checks if a process ID is registered with the sequencer.

func (*Sequencer) Start

func (s *Sequencer) Start(ctx context.Context) error

Start begins the ballot processing and aggregation routines. It creates a new context derived from the provided one and starts the background goroutines for processing ballots and aggregating them. In worker mode, it only starts the worker processor.

Parameters:

  • ctx: Parent context for controlling the sequencer's lifecycle

Returns an error if either processor fails to start.

func (*Sequencer) Stop

func (s *Sequencer) Stop() error

Stop gracefully shuts down the sequencer by canceling its context. This will cause all background goroutines to terminate. It's safe to call Stop multiple times.

func (*Sequencer) WaitUntilResults

func (s *Sequencer) WaitUntilResults(ctx context.Context, processID types.ProcessID) ([]*types.BigInt, error)

WaitUntilResults waits until the process is finalized. Returns the result of the process. It ensures proper timeout handling and provides detailed logging for troubleshooting.

Jump to

Keyboard shortcuts

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