indexer

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxEnvelopeListSize is the maximum number of envelopes a process can store.
	// 8.3M seems enough for now
	MaxEnvelopeListSize = 32 << 18
)

Variables

View Source
var ErrNoResultsYet = fmt.Errorf("no results yet")

ErrNoResultsYet is an error returned to indicate the process exist but it does not have yet reuslts.

View Source
var (
	ErrProcessNotFound = fmt.Errorf("process not found")
)
View Source
var (
	// ErrTransactionNotFound is returned if the transaction is not found.
	ErrTransactionNotFound = fmt.Errorf("transaction not found")
)
View Source
var ErrVoteNotFound = fmt.Errorf("vote not found")

ErrVoteNotFound is returned if the vote is not found in the indexer database.

Functions

func BuildProcessResult

func BuildProcessResult(results *results.Results, entityID []byte) *models.ProcessResult

BuildProcessResult takes the indexer Results type and builds the protobuf type ProcessResult. EntityId should be provided as addition field to include in ProcessResult.

func GetFriendlyResults

func GetFriendlyResults(votes [][]*types.BigInt) [][]string

GetFriendlyResults translates votes into a matrix of strings

Types

type EventListener

type EventListener interface {
	OnComputeResults(results *results.Results, process *indexertypes.Process, height uint32)
	OnOracleResults(oracleResults *models.ProcessResult, pid []byte, height uint32)
}

EventListener is an interface used for executing custom functions during the events of the tally of a process.

type Indexer

type Indexer struct {
	App *vochain.BaseApplication
	// contains filtered or unexported fields
}

Indexer is the component which makes the accounting of the voting processes and keeps it indexed in a local database.

func NewIndexer

func NewIndexer(dbPath string, app *vochain.BaseApplication, countLiveResults bool) (*Indexer, error)

NewIndexer returns an instance of the Indexer using the local storage database of dbPath and integrated into the state vochain instance

func (*Indexer) AddEventListener

func (idx *Indexer) AddEventListener(l EventListener)

AddEventListener adds a new event listener, to receive method calls on block events as documented in EventListener.

func (*Indexer) AfterSyncBootstrap

func (idx *Indexer) AfterSyncBootstrap()

AfterSyncBootstrap is a blocking function that waits until the Vochain is synchronized and then execute a set of recovery actions. It mainly checks for those processes which are still open (live) and updates all temporary data (current voting weight and live results if unecrypted). This method might be called on a goroutine after initializing the Indexer. TO-DO: refactor and use blockHeight for reusing existing live results

func (*Indexer) Close

func (idx *Indexer) Close() error

func (*Indexer) Commit

func (idx *Indexer) Commit(height uint32) error

Commit is called by the APP when a block is confirmed and included into the chain

func (*Indexer) ComputeResult

func (s *Indexer) ComputeResult(processID []byte) error

ComputeResult process a finished voting, compute the results and saves it in the Storage. Once this function is called, any future live vote event for the processId will be discarted.

func (*Indexer) EntityCount

func (s *Indexer) EntityCount() uint64

EntityCount return the number of entities indexed by the indexer

func (*Indexer) EntityList

func (s *Indexer) EntityList(max, from int, searchTerm string) []types.HexBytes

EntityList returns the list of entities indexed by the indexer searchTerm is optional, if declared as zero-value will be ignored. Searches against the ID field.

func (*Indexer) EntityProcessCount

func (s *Indexer) EntityProcessCount(entityId []byte) (uint32, error)

EntityProcessCount returns the number of processes that an entity holds

func (*Indexer) GetEnvelope

func (s *Indexer) GetEnvelope(nullifier []byte) (*indexertypes.EnvelopePackage, error)

GetEnvelope retrieves an Envelope from the Blockchain block store identified by its nullifier. Returns the envelope and the signature (if any).

func (*Indexer) GetEnvelopeHeight

func (s *Indexer) GetEnvelopeHeight(processID []byte) (uint64, error)

GetEnvelopeHeight returns the number of envelopes for a processId. If processId is empty, returns the total number of envelopes.

func (*Indexer) GetEnvelopeReference

func (s *Indexer) GetEnvelopeReference(nullifier []byte) (*indexertypes.VoteReference, error)

GetEnvelopeReference gets the reference for an AddVote transaction. This reference can then be used to fetch the vote transaction directly from the BlockStore.

func (*Indexer) GetEnvelopes

func (s *Indexer) GetEnvelopes(processId []byte, max, from int,
	searchTerm string) ([]*indexertypes.EnvelopeMetadata, error)

GetEnvelopes retrieves all envelope metadata for a ProcessId. Returns ErrVoteNotFound if the envelope reference is not found.

func (*Indexer) GetLastTxReferences

func (s *Indexer) GetLastTxReferences(limit, offset int32) ([]*indexertypes.TxReference, error)

GetLastTxReferences fetches a number of the latest indexed transactions. The first one returned is the newest, so they are in descending order.

func (*Indexer) GetResults

func (s *Indexer) GetResults(processID []byte) (*results.Results, error)

GetResults returns the current result for a processId

func (*Indexer) GetResultsWeight

func (s *Indexer) GetResultsWeight(processID []byte) (*big.Int, error)

GetResultsWeight returns the current weight of cast votes for a processId.

func (*Indexer) GetTokenTransfersByFromAccount

func (idx *Indexer) GetTokenTransfersByFromAccount(from []byte, offset, maxItems int32) ([]*indexertypes.TokenTransferMeta, error)

GetTokenTransfersByFromAccount returns all the token transfers made from a given account from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTxHashReference

func (s *Indexer) GetTxHashReference(hash types.HexBytes) (*indexertypes.TxReference, error)

GetTxHashReference fetches the txReference for the given tx hash

func (*Indexer) GetTxReference

func (s *Indexer) GetTxReference(height uint64) (*indexertypes.TxReference, error)

GetTxReference fetches the txReference for the given tx height

func (*Indexer) OnCancel

func (idx *Indexer) OnCancel(pid []byte, txIndex int32)

OnCancel indexer stores the processID and entityID

func (*Indexer) OnNewTx

func (s *Indexer) OnNewTx(tx *vochaintx.VochainTx, blockHeight uint32, txIndex int32)

OnNewTx stores the transaction reference in the indexer database

func (*Indexer) OnProcess

func (idx *Indexer) OnProcess(pid, eid []byte, censusRoot, censusURI string, txIndex int32)

OnProcess indexer stores the processID and entityID

func (*Indexer) OnProcessKeys

func (idx *Indexer) OnProcessKeys(pid []byte, pub string, txIndex int32)

OnProcessKeys does nothing

func (*Indexer) OnProcessResults

func (idx *Indexer) OnProcessResults(pid []byte, presults *models.ProcessResult,
	txIndex int32)

OnProcessResults verifies the results for a process and appends it to the updateProcessPool

func (*Indexer) OnProcessStatusChange

func (idx *Indexer) OnProcessStatusChange(pid []byte, status models.ProcessStatus,
	txIndex int32)

OnProcessStatusChange adds the process to the updateProcessPool and, if ended, the resultsPool

func (*Indexer) OnProcessesStart

func (idx *Indexer) OnProcessesStart(pids [][]byte)

OnProcessesStart adds the processes to the updateProcessPool. This is required to update potential changes when a process is started, such as the rolling census.

func (*Indexer) OnRevealKeys

func (idx *Indexer) OnRevealKeys(pid []byte, priv string, txIndex int32)

OnRevealKeys checks if all keys have been revealed and in such case add the process to the results queue

func (*Indexer) OnSetAccount

func (idx *Indexer) OnSetAccount(addr []byte, account *state.Account)

NOT USED but required for implementing the vochain.EventListener interface

func (*Indexer) OnTransferTokens

func (idx *Indexer) OnTransferTokens(tx *vochaintx.TokenTransfer)

func (*Indexer) OnVote

func (idx *Indexer) OnVote(v *state.Vote, txIndex int32)

OnVote indexer stores the votes if the processId is live results (on going) and the blockchain is not synchronizing. voterID is the identifier of the voter, the most common case is an ethereum address but can be any kind of id expressed as bytes.

func (*Indexer) ProcessCount

func (s *Indexer) ProcessCount(entityID []byte) uint64

ProcessCount returns the number of processes of a given entityID indexed. If entityID is zero-value, returns the total number of processes of all entities.

func (*Indexer) ProcessInfo

func (s *Indexer) ProcessInfo(pid []byte) (*indexertypes.Process, error)

ProcessInfo returns the available information regarding an election process id

func (*Indexer) ProcessList

func (s *Indexer) ProcessList(entityID []byte,
	from,
	max int,
	searchTerm string,
	namespace uint32,
	srcNetworkId int32,
	status string,
	withResults bool) ([][]byte, error)

ProcessList returns a list of process identifiers (PIDs) registered in the Vochain. EntityID, searchTerm, namespace, status, and withResults are optional filters, if declared as zero-values will be ignored. SearchTerm is a partial or full PID. Status is one of READY, CANCELED, ENDED, PAUSED, RESULTS

func (*Indexer) Rollback

func (idx *Indexer) Rollback()

Rollback removes the non committed pending operations

func (*Indexer) TransactionCount

func (s *Indexer) TransactionCount() (uint64, error)

TransactionCount returns the number of transactions indexed

func (*Indexer) WaitIdle

func (idx *Indexer) WaitIdle()

WaitIdle waits until there are no live asynchronous goroutines, such as those started by the Commit method.

Note that this method is racy by nature if the indexer keeps committing more blocks, as it simply waits for any goroutines already started to stop.

func (*Indexer) WalkEnvelopes

func (s *Indexer) WalkEnvelopes(processId []byte, async bool,
	callback func(*models.StateDBVote)) error

WalkEnvelopes executes callback for each envelopes of the ProcessId. The callback function is executed async (in a goroutine) if async=true. The method will return once all goroutines have finished the work.

type VoteWithIndex

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

VoteWithIndex holds a Vote and a txIndex. Model for the VotePool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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