abci

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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, log log.Logger) (*AbciApp, error)

func (*AbciApp) Activations added in v0.8.1

func (a *AbciApp) Activations(height int64) []*consensus.Hardfork

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

ApplySnapshotChunk is on the state sync connection

func (*AbciApp) ChainID

func (a *AbciApp) ChainID() string

func (*AbciApp) CheckTx

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) Commit

Commit persists the state changes. This is called under mempool lock in cometbft, unlike FinalizeBlock.

func (*AbciApp) ExtendVote

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

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) Info

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 (*AbciApp) ListSnapshots

ListSnapshots is on the state sync connection

func (*AbciApp) LoadSnapshotChunk

LoadSnapshotChunk is on the state sync connection

func (*AbciApp) OfferSnapshot

OfferSnapshot is on the state sync connection

func (*AbciApp) ProcessProposal

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 (*AbciApp) SetEventBroadcaster

func (a *AbciApp) SetEventBroadcaster(fn EventBroadcaster)

func (*AbciApp) TxInMempool added in v0.8.1

func (a *AbciApp) TxInMempool(txHash []byte) bool

func (*AbciApp) VerifyVoteExtension

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
}

AbciConfig includes data that defines the chain and allow the application to satisfy the ABCI Application interface.

type AbciOpt

type AbciOpt func(*AbciApp)

func WithLogger

func WithLogger(logger log.Logger) AbciOpt

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 EventBroadcaster

type EventBroadcaster func(ctx context.Context, proposer []byte) 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)
}

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 {
	// GenesisInit is used outside of the consensus thread, creating it's own
	// transient outer DB transaction.
	GenesisInit(ctx context.Context, validators []*types.Validator, accounts []*types.Account, initialHeight int64, appHash []byte) error

	// Read-only methods. Do NOT use these from consensus connection methods.
	ChainInfo(ctx context.Context) (int64, []byte, error)
	GetValidators(ctx context.Context) ([]*types.Validator, error)
	AccountInfo(ctx context.Context, acctID []byte, unconfirmed bool) (balance *big.Int, nonce int64, err error)
	ApplyMempool(ctx context.Context, tx *transactions.Transaction) error

	// ProposerTxs is used when a validator prepares a block proposal This is
	// prior to the Begin->Commit cycle, and as such does not use the DB
	// transaction or a writer connection.
	ProposerTxs(ctx context.Context, txNonce uint64, maxTxSize int64, proposerAddr []byte) ([][]byte, error)

	// Begin signals that a new block has begun. The following methods are
	// expected to use either an encompassing DB transaction started with Begin
	// and ended with Commit.
	Begin(ctx context.Context, height int64) error
	Execute(ctx txapp.TxContext, tx *transactions.Transaction) *txapp.TxResponse
	UpdateValidator(ctx context.Context, validator []byte, power int64) error
	Finalize(ctx context.Context, height int64) (appHash []byte, validatorUpgrades []*types.Validator, err error)
	Commit(ctx context.Context) (int64, error)

	// ConsensusAccountInfo and ConsensusValidators are used in two different
	// contexts, but always from the ABCI consensus connection. During block
	// execution (between Begin and Commit) the active write transaction is used
	// to read uncommitted data. From PrepareProposal and ProcessProposal, an
	// ephemeral read-only transaction is created.
	ConsensusAccountInfo(ctx context.Context, acctID []byte) (balance *big.Int, nonce int64, err error)
	ConsensusValidators(ctx context.Context) ([]*types.Validator, error)

	// Reload reloads the state of engine and txapp.
	Reload(ctx context.Context) error
}

TxApp is an application that can process transactions. It has methods for beginning and ending blocks, applying transactions, and managing a mempool

Directories

Path Synopsis
Package meta defines a chain metadata store for the ABCI application.
Package meta defines a chain metadata store for the ABCI application.

Jump to

Keyboard shortcuts

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