abci

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 34 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

func GeneratePrivateKey added in v0.6.5

func GeneratePrivateKey() []byte

func ReadKeyFile added in v0.6.5

func ReadKeyFile(keyFile string) ([]byte, error)

ReadKeyFile reads a private key from a text file containing the hexadecimal encoding of the private key bytes.

Types

type AbciApp

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

func NewAbciApp

func NewAbciApp(cfg *AbciConfig, accounts AccountsModule, database DatasetsModule, vldtrs ValidatorModule, kv KVStore,
	committer AtomicCommitter, snapshotter SnapshotModule, bootstrapper DBBootstrapModule, opts ...AbciOpt) *AbciApp

func (*AbciApp) AccountInfo added in v0.6.5

func (a *AbciApp) AccountInfo(ctx context.Context, identifier []byte) (balance *big.Int, nonce int64, err error)

AccountInfo gets the pending balance and nonce for an account. If there are no unconfirmed transactions for the account, the latest confirmed values are returned.

func (*AbciApp) BeginBlock added in v0.6.5

BeginBlock begins a block. If the previous commit is not finished, it will wait for the previous commit to finish.

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

func (a *AbciApp) Commit() abciTypes.ResponseCommit

func (*AbciApp) DeliverTx added in v0.6.5

func (*AbciApp) EndBlock added in v0.6.5

func (*AbciApp) Info

func (*AbciApp) InitChain

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

type AbciConfig

type AbciConfig struct {
	GenesisAppHash     []byte
	ChainID            string
	ApplicationVersion uint64
	GenesisAllocs      map[string]*big.Int // genesisCft.Alloc

}

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 AccountsModule added in v0.6.5

type AccountsModule interface {
	Account(ctx context.Context, acctID []byte) (*accounts.Account, error)
	Credit(ctx context.Context, acctID []byte, amt *big.Int) error
	TransferTx(ctx context.Context, tx *modAcct.TxAcct, to []byte, amt *big.Int) error
}

type AtomicCommitter added in v0.6.5

type AtomicCommitter interface {
	Begin(ctx context.Context, idempotencyKey []byte) error
	Commit(ctx context.Context, idempotencyKey []byte) ([]byte, error)
}

AtomicCommitter is an interface for a struct that implements atomic commits across multiple stores

type DBBootstrapModule

type DBBootstrapModule interface {
	// Offers a snapshot (metadata) to the bootstrapper and decides whether to accept the snapshot or not
	OfferSnapshot(snapshot *snapshots.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(chunk []byte, index uint32) ([]uint32, snapshots.Status, error)

	// Signifies the end of the db restoration
	IsDBRestored() bool
}

DBBootstrapModule is an interface for a struct that implements bootstrapping

type DatasetsModule added in v0.6.5

type DatasetsModule interface {
	Deploy(ctx context.Context, schema *types.Schema, tx *transactions.Transaction) (*modDataset.ExecutionResponse, error)
	Drop(ctx context.Context, dbid string, tx *transactions.Transaction) (*modDataset.ExecutionResponse, error)
	Execute(ctx context.Context, dbid string, action string, args [][]any, tx *transactions.Transaction) (*modDataset.ExecutionResponse, error)

	PriceDeploy(ctx context.Context, schema *types.Schema) (*big.Int, error)
	PriceDrop(ctx context.Context, dbid string) (*big.Int, error)
	PriceExecute(ctx context.Context, dbid string, action string, args [][]any) (*big.Int, error)
}

type FatalError added in v0.6.5

type FatalError struct {
	AppMethod string
	Request   fmt.Stringer // entire request for debugging
	Message   string
}

FatalError is a type that can be used in an explicit panic so that the nature of the failure may bubble up through the cometbft Node to the top level kwil server type.

func (FatalError) String added in v0.6.5

func (fe FatalError) String() string

type Gas added in v0.6.5

type Gas uint64

type GasMeter added in v0.6.5

type GasMeter interface {
	// GasConsumed returns the amount of gas consumed.
	GasConsumed() Gas
	// GasRemaining returns the amount of gas remaining.
	GasRemaining() Gas
	// ConsumeGas consumes the given amount of gas from the meter.
	ConsumeGas(amount Gas, caller string) error
}

GasMeter is an interface to track gas consumption. It's expected to be used by the modules or store.

func NewSimpleGasMeter added in v0.6.5

func NewSimpleGasMeter(limit Gas) GasMeter

type KVStore added in v0.6.5

type KVStore interface {
	Get(key []byte) ([]byte, error)
	Set(key []byte, value []byte) error
	Delete(key []byte) error
}

KVStore is an interface for a basic key-value store

type PrivateKeyInfo added in v0.6.5

type PrivateKeyInfo struct {
	PrivateKeyHex         string `json:"private_key_hex"`
	PrivateKeyBase64      string `json:"private_key_base64"`
	PublicKeyBase64       string `json:"public_key_base64"`
	PublicKeyCometizedHex string `json:"public_key_cometized_hex"`
	PublicKeyPlainHex     string `json:"public_key_plain_hex"`
	Address               string `json:"address"`
	NodeID                string `json:"node_id"`
}

func PrivKeyInfo added in v0.6.5

func PrivKeyInfo(privateKey []byte) (*PrivateKeyInfo, error)

func (*PrivateKeyInfo) MarshalJSON added in v0.6.5

func (p *PrivateKeyInfo) MarshalJSON() ([]byte, error)

func (*PrivateKeyInfo) MarshalText added in v0.6.5

func (p *PrivateKeyInfo) MarshalText() ([]byte, error)

type SnapshotModule

type SnapshotModule interface {
	// Checks if databases are to be snapshotted at a particular height
	IsSnapshotDue(height uint64) bool

	// Starts the snapshotting process, Locking databases need to be handled outside this fn
	CreateSnapshot(height uint64) error

	// Lists all the available snapshots in the snapshotstore and returns the snapshot metadata
	ListSnapshots() ([]snapshots.Snapshot, error)

	// Returns the snapshot chunk of index chunkId at a given height
	LoadSnapshotChunk(height uint64, format uint32, chunkID uint32) []byte
}

SnapshotModule is an interface for a struct that implements snapshotting

type ValidatorModule added in v0.6.5

type ValidatorModule interface {
	// GenesisInit configures the initial set of validators for the genesis
	// block. This is only called once for a new chain.
	GenesisInit(ctx context.Context, vals []*validators.Validator, blockHeight int64) error

	// CurrentSet returns the current validator set. This is used on app
	// construction to initialize the addr=>pubkey mapping.
	CurrentSet(ctx context.Context) ([]*validators.Validator, error)

	// Punish may be used at the start of block processing when byzantine
	// validators are listed by the consensus client (no transaction).
	Punish(ctx context.Context, validator []byte, power int64) error

	// Join creates a join request for a prospective validator.
	Join(ctx context.Context, power int64, tx *transactions.Transaction) (*modVal.ExecutionResponse, error)
	// Leave processes a leave request for a validator.
	Leave(ctx context.Context, tx *transactions.Transaction) (*modVal.ExecutionResponse, error)
	// Approve records an approval transaction from a current validator. The
	// approver is the tx Sender.
	Approve(ctx context.Context, joiner []byte, tx *transactions.Transaction) (*modVal.ExecutionResponse, error)
	// Remove removes a validator from the validator set, if the sender is a
	// current validator.
	Remove(ctx context.Context, validator []byte, tx *transactions.Transaction) (*modVal.ExecutionResponse, error)

	// Finalize is used at the end of block processing to retrieve the validator
	// updates to be provided to the consensus client for the next block. This
	// is not idempotent. The modules working list of updates is reset until
	// subsequent join/approves are processed for the next block.
	Finalize(ctx context.Context) ([]*validators.Validator, error) // end of block processing requires providing list of updates to the node's consensus client

	// Updates block height stored by the validator manager. Called in the abci Commit
	UpdateBlockHeight(ctx context.Context, blockHeight int64)

	// PriceJoin returns the price of a join transaction.
	PriceJoin(ctx context.Context) (*big.Int, error)

	// PriceApprove returns the price of an approve transaction.
	PriceApprove(ctx context.Context) (*big.Int, error)

	// PriceLeave returns the price of a leave transaction.
	PriceLeave(ctx context.Context) (*big.Int, error)

	// PriceRemove returns the price of a remove transaction.
	PriceRemove(ctx context.Context) (*big.Int, error)
}

ValidatorModule handles the processing of validator approve/join/leave transactions, punishment, preparation of validator updates to be applied when a block is finalized, and performing transaction accounting (e.g. fee and nonce checks).

NOTE: this may be premature abstraction since we are designing this function for the needs for an abci/types.Application, yet using standard or Kwil types. But if a different blockchain package is used, this is unlikely to be what it needs, but it is as generic as possible.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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