Documentation
¶
Overview ¶
Package sequencer provides functionality for processing and aggregating ballots into batches with zero-knowledge proofs for efficient verification.
Index ¶
- Variables
- type ProcessIDMap
- func (p *ProcessIDMap) Add(processID types.ProcessID) bool
- func (p *ProcessIDMap) ClearFirstBallotTime(processID types.ProcessID)
- func (p *ProcessIDMap) Exists(processID types.ProcessID) bool
- func (p *ProcessIDMap) ForEach(f func(processID types.ProcessID, t time.Time) bool)
- func (p *ProcessIDMap) Get(processID types.ProcessID) (time.Time, bool)
- func (p *ProcessIDMap) GetFirstBallotTime(processID types.ProcessID) (time.Time, bool)
- func (p *ProcessIDMap) Len() int
- func (p *ProcessIDMap) List() []types.ProcessID
- func (p *ProcessIDMap) Remove(processID types.ProcessID) bool
- func (p *ProcessIDMap) SetFirstBallotTime(processID types.ProcessID)
- type Sequencer
- func (s *Sequencer) ActiveProcessIDs() []types.ProcessID
- func (s *Sequencer) AddProcessID(processID types.ProcessID)
- func (f Sequencer) Close()
- func (s *Sequencer) DelProcessID(processID types.ProcessID)
- func (s *Sequencer) ExistsProcessID(processID types.ProcessID) bool
- func (s *Sequencer) SetBatchTimeWindow(window time.Duration)
- func (s *Sequencer) SetProver(p types.ProverFunc)
- func (s *Sequencer) Start(ctx context.Context) error
- func (s *Sequencer) Stop() error
- func (f Sequencer) WaitUntilResults(ctx context.Context, processID types.ProcessID) ([]*types.BigInt, error)
Constants ¶
This section is empty.
Variables ¶
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 )
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.
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 ¶
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 ¶
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 ¶
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 ¶
ActiveProcessIDs returns a list of process IDs that are currently being tracked by the sequencer.
func (*Sequencer) AddProcessID ¶
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) Close ¶
func (f Sequencer) Close()
Close gracefully shuts down the finalizer and waits for all goroutines to exit. This method should be called before closing the database to avoid panics.
func (*Sequencer) DelProcessID ¶
DelProcessID unregisters a process ID from the sequencer. If the process ID is not registered, this operation has no effect.
func (*Sequencer) ExistsProcessID ¶
ExistsProcessID checks if a process ID is registered with the sequencer.
func (*Sequencer) SetBatchTimeWindow ¶
SetBatchTimeWindow sets the maximum time window to wait for a batch to be processed. If this time elapses, the batch will be processed even if not full.
func (*Sequencer) SetProver ¶
func (s *Sequencer) SetProver(p types.ProverFunc)
SetProver sets a custom prover function for the Sequencer. This is particularly useful for tests that need to debug circuit execution.
func (*Sequencer) Start ¶
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 ¶
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 (f 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.