Documentation ¶
Overview ¶
Package vochain provides all the functions for creating and managing a vocdoni voting blockchain
Index ¶
- Variables
- func GenerateFaucetPackage(from *ethereum.SignKeys, to ethcommon.Address, amount uint64) (*models.FaucetPackage, error)
- func NewNodeKey(tmPrivKey, nodeKeyFilePath string) (*tmp2p.NodeKey, error)
- func NewPrivateValidator(tmPrivKey, keyFilePath, stateFilePath string) (*privval.FilePV, error)
- func NewTemplateGenesisFile(dir string, validators int) (*tmtypes.GenesisDoc, error)
- func NodePvKeyToAddress(pubk crypto.PubKey) (ethcommon.Address, error)
- type BaseApplication
- func (app *BaseApplication) AdvanceTestBlock()
- func (app *BaseApplication) AdvanceTestBlocksUntilHeight(n uint32)
- func (*BaseApplication) ApplySnapshotChunk(context.Context, *abcitypes.RequestApplySnapshotChunk) (*abcitypes.ResponseApplySnapshotChunk, error)
- func (app *BaseApplication) ChainID() string
- func (app *BaseApplication) CheckTx(_ context.Context, req *abcitypes.RequestCheckTx) (*abcitypes.ResponseCheckTx, error)
- func (app *BaseApplication) CircuitConfigurationTag() string
- func (app *BaseApplication) Commit(_ context.Context, _ *abcitypes.RequestCommit) (*abcitypes.ResponseCommit, error)
- func (app *BaseApplication) CommitState() ([]byte, error)
- func (app *BaseApplication) ExecuteBlock(txs [][]byte, height uint32, blockTime time.Time) (*ExecuteBlockResponse, error)
- func (*BaseApplication) ExtendVote(_ context.Context, req *abcitypes.RequestExtendVote) (*abcitypes.ResponseExtendVote, error)
- func (app *BaseApplication) FinalizeBlock(_ context.Context, req *abcitypes.RequestFinalizeBlock) (*abcitypes.ResponseFinalizeBlock, error)
- func (app *BaseApplication) Genesis() *tmtypes.GenesisDoc
- func (app *BaseApplication) GetBlockByHash(hash []byte) *tmtypes.Block
- func (app *BaseApplication) GetBlockByHeight(height int64) *tmtypes.Block
- func (app *BaseApplication) GetTx(height uint32, txIndex int32) (*models.SignedTx, error)
- func (app *BaseApplication) GetTxHash(height uint32, txIndex int32) (*models.SignedTx, []byte, error)
- func (app *BaseApplication) Height() uint32
- func (app *BaseApplication) Info(_ context.Context, req *abcitypes.RequestInfo) (*abcitypes.ResponseInfo, error)
- func (app *BaseApplication) InitChain(_ context.Context, req *abcitypes.RequestInitChain) (*abcitypes.ResponseInitChain, error)
- func (app *BaseApplication) IsSynchronizing() bool
- func (*BaseApplication) ListSnapshots(context.Context, *abcitypes.RequestListSnapshots) (*abcitypes.ResponseListSnapshots, error)
- func (*BaseApplication) LoadSnapshotChunk(context.Context, *abcitypes.RequestLoadSnapshotChunk) (*abcitypes.ResponseLoadSnapshotChunk, error)
- func (app *BaseApplication) MempoolDeleteTx(txID [32]byte)
- func (app *BaseApplication) MempoolSize() int
- func (*BaseApplication) OfferSnapshot(context.Context, *abcitypes.RequestOfferSnapshot) (*abcitypes.ResponseOfferSnapshot, error)
- func (app *BaseApplication) PrepareProposal(ctx context.Context, req *abcitypes.RequestPrepareProposal) (*abcitypes.ResponsePrepareProposal, error)
- func (app *BaseApplication) ProcessProposal(_ context.Context, req *abcitypes.RequestProcessProposal) (*abcitypes.ResponseProcessProposal, error)
- func (*BaseApplication) Query(_ context.Context, _ *abcitypes.RequestQuery) (*abcitypes.ResponseQuery, error)
- func (app *BaseApplication) SendTx(tx []byte) (*ctypes.ResultBroadcastTx, error)
- func (app *BaseApplication) SetChainID(chainID string)
- func (app *BaseApplication) SetCircuitConfigTag(tag string) error
- func (app *BaseApplication) SetDefaultMethods()
- func (app *BaseApplication) SetFnGetBlockByHash(fn func(hash []byte) *tmtypes.Block)
- func (app *BaseApplication) SetFnGetBlockByHeight(fn func(height int64) *tmtypes.Block)
- func (app *BaseApplication) SetFnGetTx(fn func(height uint32, txIndex int32) (*models.SignedTx, error))
- func (app *BaseApplication) SetFnGetTxHash(fn func(height uint32, txIndex int32) (*models.SignedTx, []byte, error))
- func (app *BaseApplication) SetFnIsSynchronizing(fn func() bool)
- func (app *BaseApplication) SetFnMempoolPrune(fn func([32]byte) error)
- func (app *BaseApplication) SetFnMempoolSize(fn func() int)
- func (app *BaseApplication) SetFnSendTx(fn func(tx []byte) (*ctypes.ResultBroadcastTx, error))
- func (app *BaseApplication) SetNode(vochaincfg *config.VochainCfg, genesis []byte) error
- func (app *BaseApplication) SetTestingMethods()
- func (app *BaseApplication) Timestamp() int64
- func (app *BaseApplication) TimestampFromBlock(height int64) *time.Time
- func (app *BaseApplication) TimestampStartBlock() int64
- func (*BaseApplication) VerifyVoteExtension(context.Context, *abcitypes.RequestVerifyVoteExtension) (*abcitypes.ResponseVerifyVoteExtension, error)
- type DeliverTxResponse
- type ExecuteBlockResponse
- type TenderLogger
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTransactionNotFound is returned when the transaction is not found in the blockstore. ErrTransactionNotFound = fmt.Errorf("transaction not found") )
Functions ¶
func GenerateFaucetPackage ¶ added in v1.3.0
func GenerateFaucetPackage(from *ethereum.SignKeys, to ethcommon.Address, amount uint64) (*models.FaucetPackage, error)
GenerateFaucetPackage generates a faucet package. The package is signed by the given `from` key (holder of the funds) and sent to the `to` address. The `amount` is the amount of tokens to be sent.
func NewNodeKey ¶
NewNodeKey returns and saves to the disk storage a tendermint node key. If tmPrivKey not specified, generates a new one
func NewPrivateValidator ¶
NewPrivateValidator returns a tendermint file private validator (key and state) if tmPrivKey not specified, uses the existing one or generates a new one
func NewTemplateGenesisFile ¶ added in v1.4.0
func NewTemplateGenesisFile(dir string, validators int) (*tmtypes.GenesisDoc, error)
NewTemplateGenesisFile creates a genesis file with the given number of validators and its private keys. Also includes faucet account. The genesis document is returned.
Types ¶
type BaseApplication ¶
type BaseApplication struct { State *vstate.State Istc *ist.Controller Node *tmnode.Node NodeClient *tmcli.Local NodeAddress ethcommon.Address TransactionHandler *transaction.TransactionHandler // contains filtered or unexported fields }
BaseApplication reflects the ABCI application implementation.
func NewBaseApplication ¶
func NewBaseApplication(dbType, dbpath string) (*BaseApplication, error)
NewBaseApplication creates a new BaseApplication given a name and a DB backend. Node still needs to be initialized with SetNode. Callback functions still need to be initialized.
func NewVochain ¶
func NewVochain(vochaincfg *config.VochainCfg, genesis []byte) *BaseApplication
NewVochain starts a node with an ABCI application
func TestBaseApplication ¶ added in v1.3.0
func TestBaseApplication(tb testing.TB) *BaseApplication
TestBaseApplication creates a new BaseApplication for testing purposes. It initializes the State, TransactionHandler and all the callback functions. Once the application is create, it is the caller's responsibility to call app.AdvanceTestBlock() to advance the block height and commit the state.
func TestBaseApplicationWithChainID ¶ added in v1.10.0
func TestBaseApplicationWithChainID(tb testing.TB, chainID string) *BaseApplication
TestBaseApplicationWithChainID creates a new BaseApplication for testing purposes. It initializes the State, TransactionHandler and all the callback functions. Once the application is create, it is the caller's responsibility to call app.AdvanceTestBlock() to advance the block height and commit the state.
func (*BaseApplication) AdvanceTestBlock ¶ added in v1.3.0
func (app *BaseApplication) AdvanceTestBlock()
AdvanceTestBlock commits the current state, ends the current block and starts a new one. Advances the block height and timestamp.
func (*BaseApplication) AdvanceTestBlocksUntilHeight ¶ added in v1.10.0
func (app *BaseApplication) AdvanceTestBlocksUntilHeight(n uint32)
AdvanceTestBlocksUntilHeight loops over AdvanceTestBlock until reaching height n
func (*BaseApplication) ApplySnapshotChunk ¶
func (*BaseApplication) ApplySnapshotChunk(context.Context, *abcitypes.RequestApplySnapshotChunk) (*abcitypes.ResponseApplySnapshotChunk, error)
ApplySnapshotChunk returns the response to a snapshot chunk applying request.
func (*BaseApplication) ChainID ¶ added in v1.0.3
func (app *BaseApplication) ChainID() string
ChainID returns the Node ChainID
func (*BaseApplication) CheckTx ¶
func (app *BaseApplication) CheckTx(_ context.Context, req *abcitypes.RequestCheckTx) (*abcitypes.ResponseCheckTx, error)
CheckTx unmarshals req.Tx and checks its validity
func (*BaseApplication) CircuitConfigurationTag ¶ added in v1.4.0
func (app *BaseApplication) CircuitConfigurationTag() string
CircuitConfigurationTag returns the Node CircuitConfigurationTag
func (*BaseApplication) Commit ¶
func (app *BaseApplication) Commit(_ context.Context, _ *abcitypes.RequestCommit) (*abcitypes.ResponseCommit, error)
Commit is the CometBFT implementation of the ABCI Commit method. We currently do nothing here.
func (*BaseApplication) CommitState ¶ added in v1.10.0
func (app *BaseApplication) CommitState() ([]byte, error)
CommitState saves the state to persistent storage and returns the hash. Before save the state, app.State.PrepareCommit() should be called.
func (*BaseApplication) ExecuteBlock ¶ added in v1.10.0
func (app *BaseApplication) ExecuteBlock(txs [][]byte, height uint32, blockTime time.Time) (*ExecuteBlockResponse, error)
ExecuteBlock delivers a block of transactions to the Application. It modifies the state according to the transactions and returns the resulting Merkle root hash. It returns a list of ResponseDeliverTx, one for each transaction in the block. This call rollbacks the current state.
func (*BaseApplication) ExtendVote ¶ added in v1.9.0
func (*BaseApplication) ExtendVote(_ context.Context, req *abcitypes.RequestExtendVote) (*abcitypes.ResponseExtendVote, error)
ExtendVote creates application specific vote extension
func (*BaseApplication) FinalizeBlock ¶ added in v1.9.0
func (app *BaseApplication) FinalizeBlock(_ context.Context, req *abcitypes.RequestFinalizeBlock) (*abcitypes.ResponseFinalizeBlock, error)
FinalizeBlock is executed by cometBFT when a new block is decided. Cryptographic commitments to the block and transaction results, returned via the corresponding parameters in ResponseFinalizeBlock, are included in the header of the next block.
func (*BaseApplication) Genesis ¶ added in v1.4.0
func (app *BaseApplication) Genesis() *tmtypes.GenesisDoc
Genesis returns the tendermint genesis information
func (*BaseApplication) GetBlockByHash ¶ added in v1.0.3
func (app *BaseApplication) GetBlockByHash(hash []byte) *tmtypes.Block
GetBlockByHash retreies a full block indexed by its Hash
func (*BaseApplication) GetBlockByHeight ¶ added in v1.0.3
func (app *BaseApplication) GetBlockByHeight(height int64) *tmtypes.Block
GetBlockByHeight retrieves a full block indexed by its height. This method uses an LRU cache for the blocks so in general it is more convenient for high load operations than GetBlockByHash(), which does not use cache.
func (*BaseApplication) GetTx ¶ added in v1.0.3
GetTx retrieves a vochain transaction from the blockstore
func (*BaseApplication) GetTxHash ¶ added in v1.0.3
func (app *BaseApplication) GetTxHash(height uint32, txIndex int32) (*models.SignedTx, []byte, error)
GetTxHash retrieves a vochain transaction, with its hash, from the blockstore
func (*BaseApplication) Height ¶ added in v1.0.3
func (app *BaseApplication) Height() uint32
Height returns the current blockchain height, including the latest (under construction) block.
func (*BaseApplication) Info ¶
func (app *BaseApplication) Info(_ context.Context, req *abcitypes.RequestInfo) (*abcitypes.ResponseInfo, error)
Info Return information about the application state. Used to sync Tendermint with the application during a handshake that happens on startup. The returned AppVersion will be included in the Header of every block. Tendermint expects LastBlockAppHash and LastBlockHeight to be updated during Commit, ensuring that Commit is never called twice for the same block height.
We use this method to initialize some state variables.
func (*BaseApplication) InitChain ¶
func (app *BaseApplication) InitChain(_ context.Context, req *abcitypes.RequestInitChain) (*abcitypes.ResponseInitChain, error)
InitChain called once upon genesis ResponseInitChain can return a list of validators. If the list is empty, Tendermint will use the validators loaded in the genesis file.
func (*BaseApplication) IsSynchronizing ¶ added in v1.0.3
func (app *BaseApplication) IsSynchronizing() bool
IsSynchronizing informs if the blockchain is synchronizing or not. The value is updated every new block.
func (*BaseApplication) ListSnapshots ¶
func (*BaseApplication) ListSnapshots(context.Context, *abcitypes.RequestListSnapshots) (*abcitypes.ResponseListSnapshots, error)
ListSnapshots returns a list of available snapshots.
func (*BaseApplication) LoadSnapshotChunk ¶
func (*BaseApplication) LoadSnapshotChunk(context.Context, *abcitypes.RequestLoadSnapshotChunk) (*abcitypes.ResponseLoadSnapshotChunk, error)
LoadSnapshotChunk returns the response to a snapshot chunk loading request.
func (*BaseApplication) MempoolDeleteTx ¶ added in v1.10.0
func (app *BaseApplication) MempoolDeleteTx(txID [32]byte)
MempoolDeleteTx removes a transaction from the mempool. If the mempool implementation does not allow it, its a no-op function. Errors are logged but not returned.
func (*BaseApplication) MempoolSize ¶ added in v1.3.0
func (app *BaseApplication) MempoolSize() int
MempoolSize returns the size of the transaction mempool
func (*BaseApplication) OfferSnapshot ¶
func (*BaseApplication) OfferSnapshot(context.Context, *abcitypes.RequestOfferSnapshot) (*abcitypes.ResponseOfferSnapshot, error)
OfferSnapshot returns the response to a snapshot offer.
func (*BaseApplication) PrepareProposal ¶ added in v1.8.0
func (app *BaseApplication) PrepareProposal(ctx context.Context, req *abcitypes.RequestPrepareProposal) (*abcitypes.ResponsePrepareProposal, error)
PrepareProposal allows the block proposer to perform application-dependent work in a block before proposing it. This enables, for instance, batch optimizations to a block, which has been empirically demonstrated to be a key component for improved performance. Method PrepareProposal is called every time CometBFT is about to broadcast a Proposal message and validValue is nil. CometBFT gathers outstanding transactions from the mempool, generates a block header, and uses them to create a block to propose. Then, it calls RequestPrepareProposal with the newly created proposal, called raw proposal. The Application can make changes to the raw proposal, such as modifying the set of transactions or the order in which they appear, and returns the (potentially) modified proposal, called prepared proposal in the ResponsePrepareProposal call. The logic modifying the raw proposal MAY be non-deterministic.
func (*BaseApplication) ProcessProposal ¶ added in v1.8.0
func (app *BaseApplication) ProcessProposal(_ context.Context, req *abcitypes.RequestProcessProposal) (*abcitypes.ResponseProcessProposal, error)
ProcessProposal allows a validator to perform application-dependent work in a proposed block. This enables features such as immediate block execution, and allows the Application to reject invalid blocks. CometBFT calls it when it receives a proposal and validValue is nil. The Application cannot modify the proposal at this point but can reject it if invalid. If that is the case, the consensus algorithm will prevote nil on the proposal, which has strong liveness implications for CometBFT. As a general rule, the Application SHOULD accept a prepared proposal passed via ProcessProposal, even if a part of the proposal is invalid (e.g., an invalid transaction); the Application can ignore the invalid part of the prepared proposal at block execution time. The logic in ProcessProposal MUST be deterministic.
func (*BaseApplication) Query ¶
func (*BaseApplication) Query(_ context.Context, _ *abcitypes.RequestQuery) (*abcitypes.ResponseQuery, error)
Query does nothing
func (*BaseApplication) SendTx ¶ added in v1.0.3
func (app *BaseApplication) SendTx(tx []byte) (*ctypes.ResultBroadcastTx, error)
SendTx sends a transaction to the mempool (sync)
func (*BaseApplication) SetChainID ¶ added in v1.3.0
func (app *BaseApplication) SetChainID(chainID string)
SetChainID sets the app and state chainID
func (*BaseApplication) SetCircuitConfigTag ¶ added in v1.4.0
func (app *BaseApplication) SetCircuitConfigTag(tag string) error
SetCircuitConfigTag sets the current BaseApplication circuit config tag attribute to the provided one and loads the circuit configuration based on it. The available circuit config tags are defined in /crypto/zk/circuit/config.go
func (*BaseApplication) SetDefaultMethods ¶ added in v1.0.3
func (app *BaseApplication) SetDefaultMethods()
SetDefaultMethods assigns fnGetBlockByHash, fnGetBlockByHeight, fnSendTx to use the BlockStore from app.Node to load blocks. Assumes app.Node has been set.
func (*BaseApplication) SetFnGetBlockByHash ¶ added in v1.0.3
func (app *BaseApplication) SetFnGetBlockByHash(fn func(hash []byte) *tmtypes.Block)
SetFnGetBlockByHash sets the getter for blocks by hash
func (*BaseApplication) SetFnGetBlockByHeight ¶ added in v1.0.3
func (app *BaseApplication) SetFnGetBlockByHeight(fn func(height int64) *tmtypes.Block)
SetFnGetBlockByHeight sets the getter for blocks by height
func (*BaseApplication) SetFnGetTx ¶ added in v1.3.0
func (app *BaseApplication) SetFnGetTx(fn func(height uint32, txIndex int32) (*models.SignedTx, error))
SetFnGetTx sets the getTx method
func (*BaseApplication) SetFnGetTxHash ¶ added in v1.3.0
func (app *BaseApplication) SetFnGetTxHash(fn func(height uint32, txIndex int32) (*models.SignedTx, []byte, error))
SetFnGetTxHash sets the getTxHash method
func (*BaseApplication) SetFnIsSynchronizing ¶ added in v1.8.0
func (app *BaseApplication) SetFnIsSynchronizing(fn func() bool)
SetFnIsSynchronizing sets the is synchronizing method
func (*BaseApplication) SetFnMempoolPrune ¶ added in v1.8.0
func (app *BaseApplication) SetFnMempoolPrune(fn func([32]byte) error)
SetFnMempoolPrune sets the mempool prune method for a transaction.
func (*BaseApplication) SetFnMempoolSize ¶ added in v1.3.0
func (app *BaseApplication) SetFnMempoolSize(fn func() int)
SetFnMempoolSize sets the mempool size method
func (*BaseApplication) SetFnSendTx ¶ added in v1.0.3
func (app *BaseApplication) SetFnSendTx(fn func(tx []byte) (*ctypes.ResultBroadcastTx, error))
SetFnSendTx sets the sendTx method
func (*BaseApplication) SetNode ¶ added in v1.0.3
func (app *BaseApplication) SetNode(vochaincfg *config.VochainCfg, genesis []byte) error
SetNode initializes the cometbft consensus node service and client.
func (*BaseApplication) SetTestingMethods ¶ added in v1.0.3
func (app *BaseApplication) SetTestingMethods()
SetTestingMethods assigns fnGetBlockByHash, fnGetBlockByHeight, fnSendTx to use mockBlockStore
func (*BaseApplication) Timestamp ¶ added in v1.0.3
func (app *BaseApplication) Timestamp() int64
Timestamp returns the last block end timestamp
func (*BaseApplication) TimestampFromBlock ¶ added in v1.3.0
func (app *BaseApplication) TimestampFromBlock(height int64) *time.Time
TimestampFromBlock returns the timestamp for a specific block height. If the block is not found, it returns nil. If the block is the current block, it returns the current block start timestamp.
func (*BaseApplication) TimestampStartBlock ¶ added in v1.3.0
func (app *BaseApplication) TimestampStartBlock() int64
TimestampStartBlock returns the current block start timestamp
func (*BaseApplication) VerifyVoteExtension ¶ added in v1.9.0
func (*BaseApplication) VerifyVoteExtension(context.Context, *abcitypes.RequestVerifyVoteExtension) (*abcitypes.ResponseVerifyVoteExtension, error)
VerifyVoteExtension verifies application's vote extension data
type DeliverTxResponse ¶ added in v1.9.0
DeliverTxResponse is the response returned by DeliverTx after executing the transaction.
type ExecuteBlockResponse ¶ added in v1.10.0
type ExecuteBlockResponse struct { Responses []*DeliverTxResponse Root []byte InvalidTransactions [][32]byte }
ExecuteBlockResponse is the response returned by ExecuteBlock after executing the block. If InvalidTransactions is true, it means that at least one transaction in the block was invalid.
type TenderLogger ¶
type TenderLogger struct { Artifact string // contains filtered or unexported fields }
TenderLogger implements tendermint's Logger interface, with a couple of modifications.
First, it routes the logs to go-dvote's logger, so that we don't end up with two loggers writing directly to stdout or stderr.
Second, because we generally don't care about tendermint errors such as failures to connect to peers, we route all log levels to our debug level. They will only surface if dvote's log level is "debug".
func NewTenderLogger ¶
func NewTenderLogger(artifact string, logLevel string) *TenderLogger
NewTenderLogger creates a Tendermint compatible logger for specified artifact
func (*TenderLogger) Debug ¶
func (l *TenderLogger) Debug(msg string, keyvals ...any)
func (*TenderLogger) Error ¶
func (l *TenderLogger) Error(msg string, keyvals ...any)
func (*TenderLogger) Info ¶
func (l *TenderLogger) Info(msg string, keyvals ...any)
func (*TenderLogger) SetLogLevel ¶ added in v1.4.0
func (l *TenderLogger) SetLogLevel(logLevel string)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ist provides the Internal State Transition (IST) mechanism for Vochain.
|
Package ist provides the Internal State Transition (IST) mechanism for Vochain. |
electionprice
Package electionprice provides a mechanism for calculating the price of an election based on its characteristics.
|
Package electionprice provides a mechanism for calculating the price of an election based on its characteristics. |