storage

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

Documentation

Overview

Package storage provides a persistent storage layer for the Davinci node sequencer.

Storage Organization

The storage uses a key-value database with prefixed namespaces to organize different types of data:

## Process Management - p/ : processID → Process metadata (status, times, ballot mode, census info) - ek/ : processID → Encryption keys (public and private keys for ballot encryption)

## Ballot Processing Pipeline

The ballot processing follows these stages:

1. Pending Ballots

  • b/ : voteID → Ballot (incoming ballots waiting to be verified)
  • r/b/ : voteID → reservation timestamp (prevents concurrent processing)

2. Verified Ballots

  • vb/ : processID + voteID → VerifiedBallot (ballots that passed verification)
  • r/vb/ : processID + voteID → reservation timestamp

3. Aggregated Batches

  • ag/ : processID + hash → AggregatorBallotBatch (groups of verified ballots)
  • r/ag/ : processID + hash → reservation timestamp

4. State Transitions

  • st/ : processID + hash → StateTransitionBatch (state changes ready for chain)
  • r/st/ : processID + hash → reservation timestamp

5. Verified Results

  • vr/ : processID → VerifiedResults (final tally results with proof)

## Vote Tracking

  • vs/ : processID + voteID → status byte Status values: 0=pending, 1=verified, 2=aggregated, 3=processed, 4=settled, 5=error

## Statistics - s/ : various keys for process and global statistics

  • processID → process-specific stats
  • "totalStatsStorageKey" → global aggregated stats
  • "totalPendingBallotsKey" → total pending ballot count

## Worker Stats - ws/ : workerAddress → WorkerStats (success/failure counts per worker)

## Pending OnChain Transactions - ptx/: ProcessID → nil (tracks if there are pending on-chain tx for a process)

## Separate Databases - cs_ : prefix for census database (merkle trees for voter eligibility) - st_ : prefix for state database (merkle trees for vote state)

Index

Constants

View Source
const (
	VoteIDStatusPending = iota
	VoteIDStatusVerified
	VoteIDStatusAggregated
	VoteIDStatusProcessed
	VoteIDStatusDone
	VoteIDStatusError
	VoteIDStatusTimeout
	VoteIDStatusSettled
)

Vote ID status constants

View Source
const MaxStateTransitionAttempts = 5

MaxStateTransitionAttempts defines the maximum number of attempts to process a state transition batch before marking it as failed.

Variables

View Source
var (
	ErrKeyAlreadyExists    = errors.New("key already exists")
	ErrNotFound            = errors.New("not found")
	ErrNoMoreElements      = errors.New("no more elements")
	ErrNullifierProcessing = errors.New("nullifier is being processed")
	ErrAddressProcessing   = errors.New("address is already processing a vote")
)
View Source
var ErroBallotAlreadyExists = errors.New("ballot already exists")

ErroBallotAlreadyExists is returned when a ballot already exists in the pending queue.

Functions

func DecodeArtifact

func DecodeArtifact(data []byte, out any, encoding ...ArtifactEncoding) error

DecodeArtifact decodes an artifact from the specified format. If no format is specified, CBOR is used by default. If a format is specified, it will be used instead, only if it is supported.

func DecodeArtifactCBOR

func DecodeArtifactCBOR(data []byte, out any) error

DecodeArtifactCBOR decodes a CBOR-encoded artifact into the provided output variable.

func DecodeArtifactJSON

func DecodeArtifactJSON(data []byte, out any) error

DecodeArtifactJSON decodes a JSON-encoded artifact into the provided output variable.

func EncodeArtifact

func EncodeArtifact(a any, encoding ...ArtifactEncoding) ([]byte, error)

EncodeArtifact encodes an artifact into the specified encoding format. If no format is specified, CBOR is used by default. If a format is specified, it will be used instead, only if it is supported.

func EncodeArtifactCBOR

func EncodeArtifactCBOR(a any) ([]byte, error)

EncodeArtifactCBOR encodes an artifact into CBOR format.

func EncodeArtifactJSON

func EncodeArtifactJSON(a any) ([]byte, error)

EncodeArtifactJSON encodes an artifact into JSON format.

func ProcessEncryptionKeyToPoint added in v0.0.2

func ProcessEncryptionKeyToPoint(pk *types.EncryptionKey) ecc.Point

ProcessEncryptionKeyToPoint converts a process encryption key to an ecc.Point using the Baby-Jubjub curve.

func ProcessUpdateCallbackFinalization

func ProcessUpdateCallbackFinalization(results []*types.BigInt) func(*types.Process) error

ProcessUpdateCallbackFinalization returns a function that marks a process as finalized with results

func ProcessUpdateCallbackSetCensusRoot

func ProcessUpdateCallbackSetCensusRoot(censusRoot types.HexBytes, censusURI string) func(*types.Process) error

ProcessUpdateCallbackSetCensusRoot returns a function that updates the census root of a process. This function is used when an update over the census root is received from the process monitor.

func ProcessUpdateCallbackSetMaxVoters

func ProcessUpdateCallbackSetMaxVoters(maxVoters *types.BigInt) func(*types.Process) error

ProcessUpdateCallbackSetMaxVoters returns a function that updates the max voters of a process.

func ProcessUpdateCallbackSetStateRoot

func ProcessUpdateCallbackSetStateRoot(stateRoot, votersCount, overwrittenVotesCount *types.BigInt) func(*types.Process) error

ProcessUpdateCallbackSetStateRoot returns a function that updates the state root and voters counts of a process. This function is used when a update over the state root is received from the process monitor.

func ProcessUpdateCallbackSetStatus

func ProcessUpdateCallbackSetStatus(status types.ProcessStatus) func(*types.Process) error

ProcessUpdateCallbackSetStatus returns a function that updates the process status. This function is used to set the status of a process, such as ready, ended, canceled, etc.

func VoteIDStatusName

func VoteIDStatusName(status int) string

VoteIDStatusName returns the human-readable name of a vote ID status.

Types

type AggregatorBallot

type AggregatorBallot struct {
	VoteID          types.VoteID       `json:"voteId"`
	Address         *big.Int           `json:"address"`
	Weight          *big.Int           `json:"weight"`
	EncryptedBallot *elgamal.Ballot    `json:"encryptedBallot"`
	CensusProof     *types.CensusProof `json:"censusProof"`
}

AggregatorBallot is the struct that contains the information of a ballot which has been verified and aggregated in a batch by the sequencer. It includes the address and the encrypted ballot.

type AggregatorBallotBatch

type AggregatorBallotBatch struct {
	ProcessID       types.ProcessID       `json:"processId"`
	Proof           *groth16_bw6761.Proof `json:"proof"`
	Ballots         []*AggregatorBallot   `json:"ballots"`
	Attempts        int                   `json:"attempts"`
	LastAttemptTime time.Time             `json:"lastAttemptTime"`
}

AggregatorBallotBatch is the struct that contains the information of a batch of ballots which have been verified and aggregated by the sequencer. It includes the process ID, the proof of the batch and the ballots. The proof should be in the BW6-761 curve, which is the one used by the aggregator circuit and verified by the statetransition circuit.

type ArtifactEncoding

type ArtifactEncoding int

ArtifactEncoding defines the encoding formats for artifacts. There are two supported formats: ArtifactEncodingCBOR and ArtifactEncodingJSON.

const (
	// ArtifactEncodingCBOR is the CBOR encoding format.
	ArtifactEncodingCBOR ArtifactEncoding = iota
	// ArtifactEncodingJSON is the JSON encoding format.
	ArtifactEncodingJSON
)

type Ballot

type Ballot struct {
	ProcessID        types.ProcessID                                       `json:"processId"`
	VoterWeight      *big.Int                                              `json:"voterWeight"`
	EncryptedBallot  *elgamal.Ballot                                       `json:"encryptedBallot"`
	Address          *big.Int                                              `json:"address"`
	BallotInputsHash *big.Int                                              `json:"ballotInputsHash"`
	BallotProof      recursion.Proof[sw_bn254.G1Affine, sw_bn254.G2Affine] `json:"ballotProof"`
	Signature        *ethereum.ECDSASignature                              `json:"signature"`
	CensusProof      *types.CensusProof                                    `json:"censusProof"`
	PubKey           types.HexBytes                                        `json:"publicKey"`
	VoteID           types.VoteID                                          `json:"voteId"`
}

Ballot is the struct that contains the information of a ballot. It includes the process ID, the voter weight, the encrypted ballot, the address, the inputs hash of the proof and the proof itself. The proof should be in the BN254 curve and ready for recursive verification. It also includes the signature of the ballot, which is a ECDSA signature. Finally, it includes the census proof, which proves that the voter is in the census; and the public key of the voter, a compressed ECDSA public key.

func (*Ballot) String

func (b *Ballot) String() string

func (*Ballot) Valid

func (b *Ballot) Valid() bool

Valid method checks if the Ballot is valid. A ballot is valid if all its components are valid. The BallotProof is not checked because it is a struct that comes from a third-party library (gnark) and it should be checked by the library itself.

type EncryptionKeys

type EncryptionKeys struct {
	X          *big.Int `json:"publicKeyX" cbor:"0,keyasint,omitempty"`
	Y          *big.Int `json:"publicKeyY" cbor:"1,keyasint,omitempty"`
	PrivateKey *big.Int `json:"-" cbor:"2,keyasint,omitempty"`
}

EncryptionKeys is the struct that contains the public key used to encrypt the ballots. The public key is a point on the elliptic curve. It also contains the private key, but it is not exported in the JSON.

func (*EncryptionKeys) Point added in v0.0.2

func (e *EncryptionKeys) Point() ecc.Point

Point returns the public key as a point on the elliptic curve.

type PendingTxType

type PendingTxType []byte
var StateTransitionTx PendingTxType = []byte("st/")

StateTransitionTx indicates a pending state transition transaction

type Process

type Process struct {
	CensusRoot    types.HexBytes  `json:"censusRoot"`
	BallotMode    spec.BallotMode `json:"ballotMode"`
	MetadataHash  types.HexBytes  `json:"metadataID"`
	EncryptionKey EncryptionKeys  `json:"encryptionKey"`
}

Process is the struct that contains the information of a process. It includes the census root, the ballot mode, the metadata hash and the encryption key. The census root is the root of the Merkle tree that contains the voters. The ballot mode contains the parameters that define the ballot protocol for the process. The metadata hash is the hash of the metadata of the process. The encryption key is the public key used to encrypt the ballots.

type ProcessStatsUpdate

type ProcessStatsUpdate struct {
	TypeStats types.TypeStats
	Delta     int
}

ProcessStatsUpdate represents a single stats update operation

type ResultsVerifierProofInputs

type ResultsVerifierProofInputs struct {
	StateRoot *big.Int                         `json:"stateRoot"`
	Results   [params.FieldsPerBallot]*big.Int `json:"results"`
}

ResultsVerifierProofInputs is the struct that contains the inputs of the results verifier proof. It includes the state root and the decrypted results of the votes.

func (*ResultsVerifierProofInputs) ABIEncode

func (r *ResultsVerifierProofInputs) ABIEncode() ([]byte, error)

ABIEncode packs the state root and results as a single static uint256[1 + N] blob, where N is the number of fields in the ballot (i.e., 4). The first element is the state root, followed by the results for each field.

[ stateRoot, result1, result2, ..., resultN ]

func (*ResultsVerifierProofInputs) String

func (s *ResultsVerifierProofInputs) String() string

String returns a JSON representation of the ResultsVerifierProofInputs as a string. This is useful for debugging or logging purposes. If marshalling fails, it returns an empty JSON object as a string.

type StateTransitionBatch

type StateTransitionBatch struct {
	ProcessID       types.ProcessID                 `json:"processId"`
	Proof           *groth16_bn254.Proof            `json:"proof"`
	Ballots         []*AggregatorBallot             `json:"ballots"`
	Inputs          StateTransitionBatchProofInputs `json:"inputs"`
	BlobVersionHash common.Hash                     `json:"blobVersionHash"`
	BlobSidecar     *types.BlobTxSidecar            `json:"blobSidecar"`
	BatchID         []byte                          `json:"batchId"`
}

StateTransitionBatch is the struct that contains the information of a transition of the state after include a batch of ballots. It includes the process ID, the proof of the batch and the ballots. The proof should be in the BN254 curve, which is the one used to verify the transition by the smart contract.

type StateTransitionBatchProofInputs

type StateTransitionBatchProofInputs struct {
	RootHashBefore        *big.Int    `json:"rootHashBefore"`
	RootHashAfter         *big.Int    `json:"rootHashAfter"`
	VotersCount           int         `json:"votersCount"`
	OverwrittenVotesCount int         `json:"overwrittenVotesCount"`
	CensusRoot            *big.Int    `json:"censusRoot"`
	BlobCommitmentLimbs   [3]*big.Int `json:"blobCommitmentLimbs"`
}

StateTransitionBatchProofInputs is the struct that contains the inputs of the proof of the state transition batch. It includes the root hash before and after the transition, the number of voters and the number of overwrites.

func (*StateTransitionBatchProofInputs) ABIEncode

func (s *StateTransitionBatchProofInputs) ABIEncode() ([]byte, error)

ABIEncode packs the fields as a single static uint256[8] blob:

	[ rootHashBefore, rootHashAfter, votersCount, overwrittenVotesCount, censusRoot,
      blobEvaluationPointZ, blobEvaluationPointY[0], blobEvaluationPointY[1],
      blobEvaluationPointY[2], blobEvaluationPointY[3], blobCommitment, blobProof ]

where the first five elements are the root hashes, counts and the census root, and the next three elements are the blob commitment limbs (3 × 16 bytes). Note: BlobProofLimbs and BlobEvaluationPointY are now private witness values and are verified in-circuit, so they are not included in the public inputs.

func (*StateTransitionBatchProofInputs) String

String returns a JSON representation of the StateTransitionBatchProofInputs as a string. This is useful for debugging or logging purposes. If marshalling fails, it returns an empty JSON object as a string.

type Stats

type Stats struct {
	VerifiedVotesCount          int       `json:"verifiedVotes" cbor:"0,keyasint,omitempty"`
	AggregatedVotesCount        int       `json:"aggregatedVotes" cbor:"2,keyasint,omitempty"`
	StateTransitionCount        int       `json:"stateTransitions" cbor:"3,keyasint,omitempty"`
	SettledStateTransitionCount int       `json:"settledStateTransitions" cbor:"4,keyasint,omitempty"`
	LastStateTransitionDate     time.Time `json:"lastStateTransitionDate" cbor:"5,keyasint,omitempty"`
}

Stats holds statistics for all processes.

type StatsPendingBallots

type StatsPendingBallots struct {
	TotalPendingBallots int       `json:"totalPendingBallots" cbor:"0,keyasint,omitempty"`
	LastUpdateDate      time.Time `json:"lastUpdateDate" cbor:"1,keyasint,omitempty"`
}

StatsPendingBallots holds the total number of pending ballots and the last update time.

type Storage

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

Storage manages artifacts in various stages with reservations.

func New

func New(db db.Database) *Storage

New creates a new Storage instance.

func (*Storage) Ballot

func (s *Storage) Ballot(voteID types.VoteID) (*Ballot, error)

Ballot retrieves a ballot from the pending queue by its voteID. Returns the ballot or ErrNotFound if it doesn't exist. This is a read-only operation that doesn't create reservations or modify the ballot.

func (*Storage) CensusDB

func (s *Storage) CensusDB() *censusdb.CensusDB

CensusDB returns the census database instance.

func (*Storage) CleanAllPending

func (s *Storage) CleanAllPending() error

CleanAllPending removes all pending verified votes, all pending aggregated batches and all pending state transitions across all processes. All cleaned votes are marked with VoteIDStatusError status. This is a global cleanup operation that should be used with caution.

func (*Storage) CleanProcessStaleVotes

func (s *Storage) CleanProcessStaleVotes(processID types.ProcessID) error

CleanProcessStaleVotes removes all votes and related data for a given process ID. It cleans up pending ballots, verified ballots, aggregated ballots, and pending state transition batches associated with the process.

func (*Storage) Close

func (s *Storage) Close()

Close closes the storage.

func (*Storage) CountPendingBallots

func (s *Storage) CountPendingBallots() int

CountPendingBallots returns the number of pending ballots in the queue which are not reserved. These are ballots added with PushBallot() that haven't been processed yet via NextBallot().

func (*Storage) CountVerifiedBallots

func (s *Storage) CountVerifiedBallots(processID types.ProcessID) int

CountVerifiedBallots returns the number of verified ballots for a given processID which are not reserved.

func (*Storage) DB added in v0.0.4

func (s *Storage) DB() db.Database

func (*Storage) GenerateProcessEncryptionKeys added in v0.0.2

func (s *Storage) GenerateProcessEncryptionKeys() (ecc.Point, *big.Int, error)

GenerateProcessEncryptionKeys generates a new encryption key pair and stores it in storage by using the public key as the key.

func (*Storage) HasPendingTx

func (s *Storage) HasPendingTx(txType PendingTxType, processID types.ProcessID) bool

HasPendingTx checks if a process has a pending state transition transaction.

func (*Storage) HasVerifiedResults

func (s *Storage) HasVerifiedResults(processID types.ProcessID) bool

HasVerifiedResults checks if verified results exist for a given processID. This is used to prevent re-generation of results that have already been generated but may have failed to upload to the contract.

func (*Storage) IncreaseWorkerFailedJobCount

func (s *Storage) IncreaseWorkerFailedJobCount(address string, delta int64) error

IncreaseWorkerFailedJobCount increases the failed job count for a worker

func (*Storage) IncreaseWorkerJobCount

func (s *Storage) IncreaseWorkerJobCount(address string, delta int64) error

IncreaseWorkerJobCount increases the success job count for a worker

func (*Storage) IsVoteIDProcessing

func (s *Storage) IsVoteIDProcessing(voteID types.VoteID) bool

IsVoteIDProcessing checks if a voteID is currently being processed.

func (*Storage) ListEndedProcessWithEncryptionKeys

func (s *Storage) ListEndedProcessWithEncryptionKeys() ([]types.ProcessID, error)

ListEndedProcessWithEncryptionKeys returns the list of process IDs that are ended and have their encryption keys stored in the storage.

func (*Storage) ListProcessWithEncryptionKeys

func (s *Storage) ListProcessWithEncryptionKeys() ([]types.ProcessID, error)

ListProcessWithEncryptionKeys returns a list of process IDs that have encryption keys stored.

func (*Storage) ListProcesses

func (s *Storage) ListProcesses() ([]types.ProcessID, error)

ListProcesses returns the list of process IDs stored in the storage (by SetProcessMetadata) as a list of byte slices.

func (*Storage) ListWorkerJobCount

func (s *Storage) ListWorkerJobCount() (map[string]*WorkerStats, error)

ListWorkerJobCount returns a map of all workers and their job counts The returned map has the format: address -> [successCount, failedCount]

func (*Storage) LoadCensus

func (s *Storage) LoadCensus(censusInfo *types.Census) (ref *censusdb.CensusRef, err error)

LoadCensus loads a census from the local census database based on the provided census info.

func (*Storage) MarkAggregatorBatchDone

func (s *Storage) MarkAggregatorBatchDone(k []byte) error

MarkAggregatorBatchDone called after processing aggregator batch. For simplicity, we just remove it from aggregator queue and reservation.

func (*Storage) MarkAggregatorBatchFailed

func (s *Storage) MarkAggregatorBatchFailed(key []byte) error

MarkAggregatorBatchFailed marks a ballot batch as failed, sets all ballots in the batch to error status, removes the reservation, and deletes the batch from the aggregator queue. This is typically called when the batch processing fails or is not valid.

func (*Storage) MarkAggregatorBatchPending

func (s *Storage) MarkAggregatorBatchPending(batch *AggregatorBallotBatch) error

MarkAggregatorBatchPending moves an aggregator batch to the pending state. This is used when an aggregator batch needs to be retried or reprocessed. It ensures that the batch is stored in the pending queue and can be picked up for processing again. If the batch already exists in the pending queue, it returns ErrKeyAlreadyExists. Only one pending batch per process is allowed.

func (*Storage) MarkBallotVerified

func (s *Storage) MarkBallotVerified(voteID types.VoteID, vb *VerifiedBallot) error

MarkBallotVerified called after we have processed the ballot. We push the verified ballot to the next queue. In this scenario, next stage is verifiedBallot so we do not store the original ballot.

func (*Storage) MarkProcessVoteIDsTimeout

func (s *Storage) MarkProcessVoteIDsTimeout(processID types.ProcessID) (int, error)

MarkProcessVoteIDsTimeout marks all unsettled vote IDs for a process as timeout. This is called when a process ends to indicate that votes were not processed due to process termination, but preserves the vote ID records for voter queries.

func (*Storage) MarkStateTransitionBatchDone

func (s *Storage) MarkStateTransitionBatchDone(k []byte, processID types.ProcessID) error

func (*Storage) MarkStateTransitionBatchFailed

func (s *Storage) MarkStateTransitionBatchFailed(key []byte, processID types.ProcessID) error

MarkStateTransitionBatchFailed marks a state transition batch as failed, sets all ballots in the batch to error status, removes the reservation, and deletes the batch from the state transition queue. This is typically called when the state transition processing fails or is not valid.

func (*Storage) MarkStateTransitionBatchOutdated

func (s *Storage) MarkStateTransitionBatchOutdated(key []byte) error

MarkStateTransitionBatchOutdated marks a state transition batch as outdated, removes the reservation, and deletes the batch from the state transition queue. This is called when the Ethereum smart contract state root differs from the local one, indicating that the state transition proof needs to be regenerated. The ballots and vote IDs remain valid and keep their current status (processed), but the proof is outdated.

func (*Storage) MarkVerifiedBallotsDone

func (s *Storage) MarkVerifiedBallotsDone(keys ...[]byte) error

MarkVerifiedBallotsDone removes the reservation and the verified ballots. It removes the verified ballots from the verified ballots queue and deletes their reservations. It also releases the vote ID and address locks since processing is complete and the ballots have been successfully aggregated. This allows overwrites from the same address.

func (*Storage) MarkVerifiedBallotsFailed

func (s *Storage) MarkVerifiedBallotsFailed(keys ...[]byte) error

MarkVerifiedBallotsFailed marks the verified ballots as failed, sets their status to error, removes their reservations, and deletes them from the verified ballots queue. This is typically called when the ballot processing fails or is not valid. It returns an error if any of the operations fail.

func (*Storage) MarkVerifiedResultsDone

func (s *Storage) MarkVerifiedResultsDone(processID types.ProcessID) error

MarkVerifiedResultsDone marks the results for a given processID as verified.

func (*Storage) MarkVoteIDsDone added in v0.0.4

func (s *Storage) MarkVoteIDsDone(processID types.ProcessID, voteIDs []types.VoteID) error

MarkVoteIDsDone marks a list of vote IDs as settled for a given processID. This function is called after a state transition batch is confirmed on the blockchain.

func (*Storage) NewProcess

func (s *Storage) NewProcess(process *types.Process) error

NewProcess stores a new process and its metadata into the storage. It checks that the process doesn't already exist to prevent accidental overwrites. For updating existing processes, use UpdateProcess instead to avoid race conditions.

func (*Storage) NextAggregatorBatch

func (s *Storage) NextAggregatorBatch(processID types.ProcessID) (*AggregatorBallotBatch, []byte, error)

NextAggregatorBatch returns the next aggregated ballot batch for a given processID, sets a reservation. Returns ErrNoMoreElements if no more elements are available.

func (*Storage) NextPendingBallot

func (s *Storage) NextPendingBallot() (*Ballot, types.VoteID, error)

NextPendingBallot returns the next non-reserved ballot, creates a reservation, and returns it. It returns the ballot, the key, and an error. If no ballots are available, returns ErrNoMoreElements. The key is used to mark the ballot as done after processing and to pass it to the next stage.

func (*Storage) NextStateTransitionBatch

func (s *Storage) NextStateTransitionBatch(processID types.ProcessID) (*StateTransitionBatch, []byte, error)

func (*Storage) NextVerifiedResults

func (s *Storage) NextVerifiedResults() (*VerifiedResults, error)

NextVerifiedResults retrieves the next verified results from the storage. It does not make any reservations, so its up to the calle to ensure that the results are processed and marked as verified before calling this function again. It returns the next verified results or ErrNoMoreElements if there are no more verified results available.

func (*Storage) PendingAggregatorBatch

func (s *Storage) PendingAggregatorBatch(processID types.ProcessID) (*AggregatorBallotBatch, error)

PendingAggregatorBatch retrieves a pending aggregator batch for a given processID. If no pending batch is found, it returns ErrNotFound.

func (*Storage) Process

func (s *Storage) Process(processID types.ProcessID) (*types.Process, error)

Process retrieves the process data from the storage. It returns nil data and ErrNotFound if the metadata is not found.

func (*Storage) ProcessEncryptionKeys added in v0.0.2

func (s *Storage) ProcessEncryptionKeys(processID types.ProcessID) (ecc.Point, *big.Int, error)

ProcessEncryptionKeys loads the encryption keys for a process. It checks for the public key in storage and then tries to load the full encryption keys. If the encryption keys are not found, it returns an error.

func (*Storage) ProcessIsAcceptingVotes

func (s *Storage) ProcessIsAcceptingVotes(processID types.ProcessID) (bool, error)

ProcessIsAcceptingVotes checks if the process is ready to accept votes, which means that the process is in the "Ready" state.

func (*Storage) ProcessMaxVotersReached

func (s *Storage) ProcessMaxVotersReached(processID types.ProcessID) (bool, error)

ProcessMaxVotersReached checks if the process has reached its maximum number of voters based on the process ID provided.

func (*Storage) PrunePendingTx

func (s *Storage) PrunePendingTx(txType PendingTxType, processID types.ProcessID) error

PrunePendingTx removes the pending transaction marker for a process.

func (*Storage) PullVerifiedBallots

func (s *Storage) PullVerifiedBallots(processID types.ProcessID, numFields int) ([]*VerifiedBallot, [][]byte, error)

PullVerifiedBallots returns a list of non-reserved verified ballots for a given processID and creates reservations for them. The numFields parameter is used to limit the number of results. If no ballots are available, returns ErrNotFound.

func (*Storage) PushAggregatorBatch

func (s *Storage) PushAggregatorBatch(abb *AggregatorBallotBatch) error

PushAggregatorBatch pushes an aggregated ballot batch to the aggregator queue.

func (*Storage) PushPendingBallot

func (s *Storage) PushPendingBallot(b *Ballot) error

PushPendingBallot stores a new ballot into the pending ballots queue.

func (*Storage) PushStateTransitionBatch

func (s *Storage) PushStateTransitionBatch(stb *StateTransitionBatch) error

PushStateTransitionBatch pushes a state transition batch to the state transition queue.

func (*Storage) PushVerifiedResults

func (s *Storage) PushVerifiedResults(res *VerifiedResults) error

PushVerifiedResults stores the verified results for a given processID. It encodes the VerifiedResults struct and stores it in the database under the verifiedResultPrefix with the processID as the key. It does not calculate the key by the current value because the results should be unique for each processID. If the processID already exists, it will overwrite the existing value. If any error occurs during encoding or writing to the database, it returns an error with a descriptive message.

func (*Storage) ReleasePendingBallotReservation

func (s *Storage) ReleasePendingBallotReservation(voteID types.VoteID) error

ReleasePendingBallotReservation removes the reservation for a ballot.

func (*Storage) ReleaseVerifiedBallotReservations

func (s *Storage) ReleaseVerifiedBallotReservations(keys [][]byte) error

ReleaseVerifiedBallotReservations removes the reservations for the given verified ballots list. The ballots will be available for pulling again.

func (*Storage) RemoveAggregatorBatchesByProcess

func (s *Storage) RemoveAggregatorBatchesByProcess(processID types.ProcessID) error

RemoveAggregatorBatchesByProcess removes all ballot batches for a given processID.

func (*Storage) RemovePendingBallot

func (s *Storage) RemovePendingBallot(processID types.ProcessID, voteID types.VoteID) error

RemovePendingBallot removes a ballot from the pending queue and its reservation.

func (*Storage) RemovePendingBallotsByProcess

func (s *Storage) RemovePendingBallotsByProcess(processID types.ProcessID) error

RemovePendingBallotsByProcess removes all pending ballots for a given process ID.

func (*Storage) RemoveStateTransitionBatchesByProcess

func (s *Storage) RemoveStateTransitionBatchesByProcess(processID types.ProcessID) error

RemoveStateTransitionBatchesByProcess removes all state transition batches for a given processID.

func (*Storage) RemoveVerifiedBallotsByProcess

func (s *Storage) RemoveVerifiedBallotsByProcess(processID types.ProcessID) error

RemoveVerifiedBallotsByProcess removes all verified ballots for a given processID.

func (*Storage) SetPendingTx

func (s *Storage) SetPendingTx(txType PendingTxType, processID types.ProcessID) error

SetPendingTx marks a process as having a pending on-chain transaction. If the process already has a pending transaction, it does nothing. If an error occurs during the operation, it returns the error.

func (*Storage) StateDB

func (s *Storage) StateDB() db.Database

StateDB returns the state database instance.

func (*Storage) TotalPendingBallots

func (s *Storage) TotalPendingBallots() int

TotalPendingBallots returns the total number of pending ballots across all processes

func (*Storage) TotalStats

func (s *Storage) TotalStats() (*Stats, error)

TotalStats returns the total statistics across all processes.

func (*Storage) UpdateProcess

func (s *Storage) UpdateProcess(processID types.ProcessID, updateFunc ...func(*types.Process) error) error

UpdateProcess performs an atomic read-modify-write operation on a process. The updateFunc is called with the current process state and can modify it. This ensures no race conditions between concurrent process updates.

func (*Storage) VoteIDStatus

func (s *Storage) VoteIDStatus(processID types.ProcessID, voteID types.VoteID) (int, error)

VoteIDStatus returns the status of a vote ID for a given processID and voteID. Returns ErrNotFound if the vote ID status doesn't exist.

func (*Storage) WorkerJobCount

func (s *Storage) WorkerJobCount(address string) (int64, int64)

WorkerJobCount returns the success and failed job counts for a worker

func (*Storage) WorkerStats

func (s *Storage) WorkerStats(address string) *WorkerStats

WorkerStats retrieves the statistics for a worker node including its name, success count, and failed count. If the worker does not exist, it returns empty stats with zero counts.

type VerifiedBallot

type VerifiedBallot struct {
	VoteID          types.VoteID            `json:"voteId"`
	ProcessID       types.ProcessID         `json:"processId"`
	VoterWeight     *big.Int                `json:"voterWeight"`
	EncryptedBallot *elgamal.Ballot         `json:"encryptedBallot"`
	Address         *big.Int                `json:"address"`
	InputsHash      *big.Int                `json:"inputsHash"`
	Proof           *groth16_bls12377.Proof `json:"proof"`
	CensusProof     *types.CensusProof      `json:"censusProof"`
}

VerifiedBallot is the struct that contains the information of a ballot which has been verified by the sequencer. It includes the process ID, the voter weight, the encrypted ballot, the address, the inputs hash of the proof and the proof itself. The proof should be in the BLS12-377 curve, which is the one used by the verifier circuit and verified by the aggregator circuit.

type VerifiedResults

type VerifiedResults struct {
	ProcessID types.ProcessID            `json:"processId"`
	Proof     *groth16_bn254.Proof       `json:"proof"`
	Inputs    ResultsVerifierProofInputs `json:"inputs"`
}

VerifiedResults is the struct that contains the information of a results of a process which has been verified by the sequencer. It includes the process ID, the proof of the results and the inputs of the proof.

type WorkerStats

type WorkerStats struct {
	SuccessCount int64 `json:"successCount"`
	FailedCount  int64 `json:"failedCount"`
}

WorkerStats represents the statistics for a worker node

Jump to

Keyboard shortcuts

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