abci

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ABCIPeerFilterPath    = "/p2p/filter/"
	ABCIPeerFilterPathLen = len(ABCIPeerFilterPath)
)
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, peers WhitelistPeersModule, migrator MigratorModule, db DB, logger 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) Close added in v0.9.0

func (a *AbciApp) Close() error

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

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) GetMigrationMetadata added in v0.9.0

func (a *AbciApp) GetMigrationMetadata(ctx context.Context) (*types.MigrationMetadata, error)

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

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) SetReplayStatusChecker added in v0.9.0

func (a *AbciApp) SetReplayStatusChecker(fn func() bool)

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

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

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

func (a *AbciApp) TxSigVerified(txHash chainHash) bool

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

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 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 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 EventBroadcaster func(ctx context.Context, db sql.DB, block *common.BlockContext) error

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.

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