Documentation ¶
Index ¶
- Variables
- type AbciApp
- func (a *AbciApp) Activations(height int64) []*consensus.Hardfork
- func (a *AbciApp) ApplySnapshotChunk(ctx context.Context, req *abciTypes.RequestApplySnapshotChunk) (*abciTypes.ResponseApplySnapshotChunk, error)
- func (a *AbciApp) ChainID() string
- func (a *AbciApp) CheckTx(ctx context.Context, incoming *abciTypes.RequestCheckTx) (*abciTypes.ResponseCheckTx, error)
- func (a *AbciApp) Close() error
- func (a *AbciApp) Commit(ctx context.Context, _ *abciTypes.RequestCommit) (*abciTypes.ResponseCommit, error)
- func (a *AbciApp) ExtendVote(ctx context.Context, req *abciTypes.RequestExtendVote) (*abciTypes.ResponseExtendVote, error)
- func (a *AbciApp) FinalizeBlock(ctx context.Context, req *abciTypes.RequestFinalizeBlock) (*abciTypes.ResponseFinalizeBlock, error)
- func (a *AbciApp) GetMigrationMetadata(ctx context.Context) (*types.MigrationMetadata, error)
- func (a *AbciApp) Info(ctx context.Context, _ *abciTypes.RequestInfo) (*abciTypes.ResponseInfo, error)
- func (a *AbciApp) InitChain(ctx context.Context, req *abciTypes.RequestInitChain) (*abciTypes.ResponseInitChain, error)
- func (a *AbciApp) ListSnapshots(ctx context.Context, req *abciTypes.RequestListSnapshots) (*abciTypes.ResponseListSnapshots, error)
- func (a *AbciApp) LoadSnapshotChunk(ctx context.Context, req *abciTypes.RequestLoadSnapshotChunk) (*abciTypes.ResponseLoadSnapshotChunk, error)
- func (a *AbciApp) OfferSnapshot(ctx context.Context, req *abciTypes.RequestOfferSnapshot) (*abciTypes.ResponseOfferSnapshot, error)
- func (a *AbciApp) PrepareProposal(ctx context.Context, req *abciTypes.RequestPrepareProposal) (*abciTypes.ResponsePrepareProposal, error)
- func (a *AbciApp) Price(ctx context.Context, db sql.DB, tx *transactions.Transaction) (*big.Int, error)
- func (a *AbciApp) ProcessProposal(ctx context.Context, req *abciTypes.RequestProcessProposal) (*abciTypes.ResponseProcessProposal, error)
- func (a *AbciApp) Query(ctx context.Context, req *abciTypes.RequestQuery) (*abciTypes.ResponseQuery, error)
- func (a *AbciApp) SetEventBroadcaster(fn EventBroadcaster)
- func (a *AbciApp) SetReplayStatusChecker(fn func() bool)
- func (a *AbciApp) TxInMempool(txHash []byte) bool
- func (a *AbciApp) TxSigVerified(txHash chainHash) bool
- func (a *AbciApp) VerifyVoteExtension(ctx context.Context, req *abciTypes.RequestVerifyVoteExtension) (*abciTypes.ResponseVerifyVoteExtension, error)
- type AbciConfig
- type AbciOpt
- type ConsensusParams
- type DB
- type EventBroadcaster
- type MigratorModule
- type SnapshotModule
- type StateSyncModule
- type TxApp
- type WhitelistPeersModule
Constants ¶
This section is empty.
Variables ¶
var ( ABCIPeerFilterPath = "/p2p/filter/" ABCIPeerFilterPathLen = len(ABCIPeerFilterPath) )
var ( // ErrTxNotFound is indicates when the a transaction was not found in the // nodes blocks or mempool. ErrTxNotFound = errors.New("transaction not found") )
Functions ¶
This section is empty.
Types ¶
type AbciApp ¶
type AbciApp struct {
// contains filtered or unexported fields
}
func NewAbciApp ¶
func NewAbciApp(ctx context.Context, cfg *AbciConfig, snapshotter SnapshotModule, statesyncer StateSyncModule, txRouter TxApp, consensusParams *chain.ConsensusParams, peers WhitelistPeersModule, migrator MigratorModule, db DB, logger log.Logger) (*AbciApp, error)
func (*AbciApp) Activations ¶ added in v0.8.1
Activations consults chain config for the names of hard forks that activate at the given block height, and retrieves the associated changes from the consensus package that contains the canonical and extended fork definitions.
func (*AbciApp) ApplySnapshotChunk ¶
func (a *AbciApp) ApplySnapshotChunk(ctx context.Context, req *abciTypes.RequestApplySnapshotChunk) (*abciTypes.ResponseApplySnapshotChunk, error)
ApplySnapshotChunk is on the state sync connection
func (*AbciApp) CheckTx ¶
func (a *AbciApp) CheckTx(ctx context.Context, incoming *abciTypes.RequestCheckTx) (*abciTypes.ResponseCheckTx, error)
CheckTx is the "Guardian of the mempool: every node runs CheckTx before letting a transaction into its local mempool". Also "The transaction may come from an external user or another node". Further "CheckTx validates the transaction against the current state of the application, for example, checking signatures and account balances, but does not apply any of the state changes described in the transaction."
This method must reject transactions that are invalid and/or may be crafted to attack the network by flooding the mempool or filling blocks with rejected transactions.
This method is also used to re-check mempool transactions after blocks are mined. This is used to *evict* previously accepted transactions that become invalid, which may happen for a variety of reason only the application can decide, such as changes in account balance and last mined nonce.
It is important to use this method rather than include failing transactions in blocks, particularly if the failure mode involves the transaction author spending no gas or achieving including in the block with little effort.
func (*AbciApp) Close ¶ added in v0.9.0
Close is used to end any active database transaction that may exist if the application tries to shut down before closing the transaction with a call to Commit. Neglecting to rollback such a transaction may prevent the DB connection from being closed and released to the connection pool.
func (*AbciApp) Commit ¶
func (a *AbciApp) Commit(ctx context.Context, _ *abciTypes.RequestCommit) (*abciTypes.ResponseCommit, error)
Commit persists the state changes. This is called under mempool lock in cometbft, unlike FinalizeBlock.
func (*AbciApp) ExtendVote ¶
func (a *AbciApp) ExtendVote(ctx context.Context, req *abciTypes.RequestExtendVote) (*abciTypes.ResponseExtendVote, error)
ExtendVote creates an application specific vote extension.
- ResponseExtendVote.vote_extension is application-generated information that will be signed by CometBFT and attached to the Precommit message.
- The Application may choose to use an empty vote extension (0 length).
- The contents of RequestExtendVote correspond to the proposed block on which the consensus algorithm will send the Precommit message.
- ResponseExtendVote.vote_extension will only be attached to a non-nil Precommit message. If the consensus algorithm is to precommit nil, it will not call RequestExtendVote.
- The Application logic that creates the extension can be non-deterministic.
func (*AbciApp) FinalizeBlock ¶
func (a *AbciApp) FinalizeBlock(ctx context.Context, req *abciTypes.RequestFinalizeBlock) (*abciTypes.ResponseFinalizeBlock, error)
FinalizeBlock is on the consensus connection. Note that according to CometBFT docs, "ResponseFinalizeBlock.app_hash is included as the Header.AppHash in the next block."
func (*AbciApp) GetMigrationMetadata ¶ added in v0.9.0
func (*AbciApp) Info ¶
func (a *AbciApp) Info(ctx context.Context, _ *abciTypes.RequestInfo) (*abciTypes.ResponseInfo, error)
Info is part of the Info/Query connection. CometBFT will call this during it's handshake, and if height 0 is returned it will then use InitChain. This method should also be usable at any time (and read only) as it is used for cometbft's /abci_info RPC endpoint.
CometBFT docs say:
- LastBlockHeight is the "Latest height for which the app persisted its state"
- LastBlockAppHash is the "Latest AppHash returned by FinalizeBlock"
- "ResponseFinalizeBlock.app_hash is included as the Header.AppHash in the next block." Notably, the *next* block's header. This is verifiable with the /block RPC endpoint.
Thus, LastBlockAppHash is not NOT AppHash in the header of the block at the returned height. Our meta data store has to track the above values, where the stored app hash corresponds to the block at height+1. This is simple, but the discrepancy is worth noting.
func (*AbciApp) InitChain ¶
func (a *AbciApp) InitChain(ctx context.Context, req *abciTypes.RequestInitChain) (*abciTypes.ResponseInitChain, error)
func (*AbciApp) ListSnapshots ¶
func (a *AbciApp) ListSnapshots(ctx context.Context, req *abciTypes.RequestListSnapshots) (*abciTypes.ResponseListSnapshots, error)
ListSnapshots is on the state sync connection
func (*AbciApp) LoadSnapshotChunk ¶
func (a *AbciApp) LoadSnapshotChunk(ctx context.Context, req *abciTypes.RequestLoadSnapshotChunk) (*abciTypes.ResponseLoadSnapshotChunk, error)
LoadSnapshotChunk is on the state sync connection
func (*AbciApp) OfferSnapshot ¶
func (a *AbciApp) OfferSnapshot(ctx context.Context, req *abciTypes.RequestOfferSnapshot) (*abciTypes.ResponseOfferSnapshot, error)
OfferSnapshot is on the state sync connection
func (*AbciApp) PrepareProposal ¶
func (a *AbciApp) PrepareProposal(ctx context.Context, req *abciTypes.RequestPrepareProposal) (*abciTypes.ResponsePrepareProposal, error)
func (*AbciApp) Price ¶ added in v0.9.0
func (a *AbciApp) Price(ctx context.Context, db sql.DB, tx *transactions.Transaction) (*big.Int, error)
Price estimates the price for a transaction. Consumers who do not have information about the current chain parameters / who wanmt a guarantee that they have the most up-to-date parameters without reading from the DB can use this method.
func (*AbciApp) ProcessProposal ¶
func (a *AbciApp) ProcessProposal(ctx context.Context, req *abciTypes.RequestProcessProposal) (*abciTypes.ResponseProcessProposal, error)
ProcessProposal should validate the received blocks and reject the block if: 1. transactions are not ordered by nonces 2. nonce is less than the last committed nonce for the account 3. duplicates or gaps in the nonces 4. transaction size is greater than the max_tx_bytes else accept the proposed block.
func (*AbciApp) Query ¶
func (a *AbciApp) Query(ctx context.Context, req *abciTypes.RequestQuery) (*abciTypes.ResponseQuery, error)
func (*AbciApp) SetEventBroadcaster ¶
func (a *AbciApp) SetEventBroadcaster(fn EventBroadcaster)
func (*AbciApp) SetReplayStatusChecker ¶ added in v0.9.0
SetReplayStatusChecker sets the function to check if the node is in replay mode. This has to be set here because it is a CometBFT node function. Since ABCI is a dependency to CometBFT, this is a circular dependency, so we have to set it here.
func (*AbciApp) TxInMempool ¶ added in v0.8.1
TxInMempool wraps TxSigVerified for callers that require a slice to check if a transaction is (still) in mempool.
func (*AbciApp) TxSigVerified ¶ added in v0.9.0
TxSigVerified indicates if ABCI has verified this unconfirmed transaction's signature. This also returns false if the transaction is not in mempool. This logic is not broadly applicable, but since the tx hash is computed over the entire serialized transaction including the signature, the same hash implies the same signature.
func (*AbciApp) VerifyVoteExtension ¶
func (a *AbciApp) VerifyVoteExtension(ctx context.Context, req *abciTypes.RequestVerifyVoteExtension) (*abciTypes.ResponseVerifyVoteExtension, error)
Verify application's vote extension data
type AbciConfig ¶
type AbciConfig struct { // GenesisAppHash is considered only when doing InitChain (genesis). GenesisAppHash []byte ChainID string ApplicationVersion uint64 GenesisAllocs map[string]*big.Int GasEnabled bool ForkHeights map[string]*uint64 InitialHeight int64 ABCIDir string }
AbciConfig includes data that defines the chain and allow the application to satisfy the ABCI Application interface.
type ConsensusParams ¶
type ConsensusParams interface { // VotingPeriod is the vote expiration period // for validator joins and resolutions. // We may want these to be separate in the future. VotingPeriod() int64 }
ConsensusParams returns kwil specific consensus parameters. I made this its own separate interface (instead of adding it to AbciConfig) since this should be dynamic and changeable via voting.
type DB ¶ added in v0.9.0
type DB interface { sql.TxMaker // for out-of-consensus writes e.g. setup and meta table writes sql.PreparedTxMaker sql.ReadTxMaker sql.SnapshotTxMaker }
DB is the interface for the main SQL database. All queries must be executed from within a transaction. A DB can create read transactions or the special two-phase outer write transaction.
type EventBroadcaster ¶
type MigratorModule ¶ added in v0.9.0
type MigratorModule interface { NotifyHeight(ctx context.Context, block *common.BlockContext, db migrations.Database) error StoreChangesets(height int64, changes <-chan any) error PersistLastChangesetHeight(ctx context.Context, tx sql.Executor) error GetMigrationMetadata(ctx context.Context, status types.MigrationStatus) (*types.MigrationMetadata, error) }
type SnapshotModule ¶
type SnapshotModule interface { // Lists all the available snapshots in the snapshotstore and returns the snapshot metadata ListSnapshots() []*statesync.Snapshot // Returns the snapshot chunk of index chunkId at a given height LoadSnapshotChunk(height uint64, format uint32, chunkID uint32) ([]byte, error) // CreateSnapshot creates a snapshot of the current state. CreateSnapshot(ctx context.Context, height uint64, snapshotID string, schemas, excludedTables []string, excludeTableData []string) error // IsSnapshotDue returns true if a snapshot is due at the given height. IsSnapshotDue(height uint64) bool }
SnapshotModule is an interface for a struct that implements snapshotting
type StateSyncModule ¶ added in v0.8.1
type StateSyncModule interface { // Offers a snapshot (metadata) to the bootstrapper and decides whether to accept the snapshot or not OfferSnapshot(ctx context.Context, snapshot *statesync.Snapshot) error // Offers a snapshot Chunk to the bootstrapper, once all the chunks corresponding to the snapshot are received, the databases are restored from the chunks ApplySnapshotChunk(ctx context.Context, chunk []byte, index uint32) (bool, error) }
DBBootstrapModule is an interface for a struct that implements bootstrapping
type TxApp ¶
type TxApp interface { AccountInfo(ctx context.Context, db sql.DB, acctID []byte, getUnconfirmed bool) (balance *big.Int, nonce int64, err error) ApplyMempool(ctx *common.TxContext, db sql.DB, tx *transactions.Transaction) error Begin(ctx context.Context, height int64) error Commit(ctx context.Context) Execute(ctx *common.TxContext, db sql.DB, tx *transactions.Transaction) *txapp.TxResponse Finalize(ctx context.Context, db sql.DB, block *common.BlockContext) (finalValidators []*types.Validator, approvedJoins, expiredJoins [][]byte, err error) GenesisInit(ctx context.Context, db sql.DB, validators []*types.Validator, genesisAccounts []*types.Account, initialHeight int64, chain *common.ChainContext) error GetValidators(ctx context.Context, db sql.DB) ([]*types.Validator, error) ProposerTxs(ctx context.Context, db sql.DB, txNonce uint64, maxTxsSize int64, block *common.BlockContext) ([][]byte, error) Reload(ctx context.Context, db sql.DB) error UpdateValidator(ctx context.Context, db sql.DB, validator []byte, power int64) error Price(ctx context.Context, db sql.DB, tx *transactions.Transaction, chainCtx *common.ChainContext) (*big.Int, error) }
TxApp is an application that can process transactions. It has methods for beginning and ending blocks, applying transactions, and managing a mempool
type WhitelistPeersModule ¶ added in v0.9.0
type WhitelistPeersModule interface { // AddPeer adds a peer to the Peers object. AddPeer(ctx context.Context, peer string) error // RemovePeer removes a peer from the Peers object. RemovePeer(ctx context.Context, peer string) error // IsPeerWhitelisted checks if a peer is in the PeerWhitelist object. // If private mode is distabled, it always returns true. IsPeerWhitelisted(peer string) bool }
PeerModule is an interface that manages network peers.