Documentation
¶
Overview ¶
package tx_router routes transactions to the appropriate module(s)
Index ¶
- Variables
- func RegisterRoute(payloadType types.PayloadType, route Route) error
- func RegisterRouteImpl(payloadType types.PayloadType, route consensus.Route) error
- func TxSenderAcctID(t *types.Transaction) (*types.AccountID, error)
- type Accounts
- type ConsensusParams
- type DB
- type Pricer
- type Rebroadcaster
- type Route
- type TxApp
- func (r *TxApp) AccountInfo(ctx context.Context, db sql.DB, acctID *types.AccountID, getUnconfirmed bool) (balance *big.Int, nonce int64, err error)
- func (r *TxApp) ApplyMempool(ctx *common.TxContext, db sql.DB, tx *types.Transaction) error
- func (r *TxApp) Begin(ctx context.Context, height int64) error
- func (r *TxApp) Commit() error
- func (r *TxApp) Execute(ctx *common.TxContext, db sql.DB, tx *types.Transaction) *TxResponse
- func (r *TxApp) Finalize(ctx context.Context, db sql.DB, block *common.BlockContext) (approvedJoins, expiredJoins []*types.AccountID, err error)
- func (r *TxApp) GenesisInit(ctx context.Context, db sql.DB, genCfg *config.GenesisConfig, ...) error
- func (r *TxApp) GetValidators() []*types.Validator
- func (r *TxApp) NumAccounts(ctx context.Context, db sql.Executor) (int64, int64, error)
- func (r *TxApp) Price(ctx context.Context, dbTx sql.DB, tx *types.Transaction, ...) (*big.Int, error)
- func (r *TxApp) Rollback()
- func (r *TxApp) UpdateValidator(ctx context.Context, db sql.DB, pubKey []byte, pubKeyType crypto.KeyType, ...) error
- type TxResponse
- type Validators
Constants ¶
This section is empty.
Variables ¶
var ( ErrCallerNotValidator = errors.New("caller is not a validator") ErrCallerIsValidator = errors.New("caller is already a validator") ErrCallerNotProposer = errors.New("caller is not the block proposer") ErrTargetNotValidator = errors.New("target is not a validator") )
var ( ValidatorVoteBodyBytePrice int64 = 1000 // Per byte cost ValidatorVoteIDPrice = big.NewInt(1000 * 16) // 16 bytes for the UUID )
Functions ¶
func RegisterRoute ¶
func RegisterRoute(payloadType types.PayloadType, route Route) error
RegisterRoute associates a Route with a payload type. See also RegisterRouteImpl to register a consensus.Route.
func RegisterRouteImpl ¶
func RegisterRouteImpl(payloadType types.PayloadType, route consensus.Route) error
RegisterRouteImpl associates a consensus.Route with a payload type. This is shorthand for RegisterRoute(payloadType, NewRoute(route)).
func TxSenderAcctID ¶
func TxSenderAcctID(t *types.Transaction) (*types.AccountID, error)
TxSenderAcctID returns the transaction sender's account ID information.
Types ¶
type Accounts ¶
type Accounts interface {
Spend(ctx context.Context, tx sql.Executor, acctID *types.AccountID, amount *big.Int, nonce int64) error
Credit(ctx context.Context, tx sql.Executor, acctID *types.AccountID, amount *big.Int) error
Transfer(ctx context.Context, tx sql.TxMaker, from, to *types.AccountID, amount *big.Int) error
GetAccount(ctx context.Context, tx sql.Executor, acctID *types.AccountID) (*types.Account, error)
NumAccounts(ctx context.Context, tx sql.Executor) (int64, error)
ApplySpend(ctx context.Context, tx sql.Executor, acctID *types.AccountID, amount *big.Int, nonce int64) error
Commit() error
Rollback()
}
type ConsensusParams ¶
type ConsensusParams struct {
// VotingPeriod is the maximum length of a voting period.
// It is measured in blocks, and is applied additively.
// e.g. if the current block is 50, and VotingPeriod is 100,
// then the current voting period ends at block 150.
VotingPeriod int64
// JoinVoteExpiration is the voting period for any validator
// join or removal vote. It is measured in blocks, and is applied additively.
// e.g. if the current block is 50, and JoinVoteExpiration is 100,
// then the current voting period ends at block 150.
JoinVoteExpiration int64
}
ConsensusParams holds network level parameters that may evolve over time.
type DB ¶
type DB interface {
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 Rebroadcaster ¶
type Rebroadcaster interface {
// MarkRebroadcast marks events for rebroadcasting.
MarkRebroadcast(ctx context.Context, ids []*types.UUID) error
}
Rebroadcaster is a service that marks events for rebroadcasting.
type Route ¶
type Route interface {
Pricer
// Execute is responsible for committing or rolling back types.
// All transactions should spend, regardless of success or failure.
// Therefore, a nested transaction should be used for all database
// operations after the initial checkAndSpend.
Execute(ctx *common.TxContext, router *TxApp, db sql.DB, tx *types.Transaction) *TxResponse
}
Route is a type that the router uses to handle a certain payload type.
type TxApp ¶
type TxApp struct {
Engine common.Engine // tracks deployed schemas
Accounts Accounts // tracks account balances and nonces
Validators Validators // tracks validator power
// contains filtered or unexported fields
}
TxApp is the transaction processor for the Kwil node. It is responsible for interpreting payload bodies and routing them properly, maintaining a mempool for uncommitted accounts, pricing transactions, managing atomicity of the database, and managing the validator set.
func NewTxApp ¶
func NewTxApp(ctx context.Context, db sql.Executor, engine common.Engine, signer auth.Signer, events Rebroadcaster, service *common.Service, accounts Accounts, validators Validators) (*TxApp, error)
NewTxApp creates a new router.
func (*TxApp) AccountInfo ¶
func (r *TxApp) AccountInfo(ctx context.Context, db sql.DB, acctID *types.AccountID, getUnconfirmed bool) (balance *big.Int, nonce int64, err error)
AccountInfo gets account info from either the mempool or the account store. It takes a flag to indicate whether it should check the mempool first.
func (*TxApp) ApplyMempool ¶
ApplyMempool applies the transactions in the mempool. If it returns an error, then the transaction is invalid.
func (*TxApp) Begin ¶
Begin signals that a new block has begun. This creates an outer database transaction that may be committed, or rolled back on error or crash. It is given the starting networkParams, and is expected to use them to use them to store any changes to the network parameters in the database during Finalize.
func (*TxApp) Execute ¶
func (r *TxApp) Execute(ctx *common.TxContext, db sql.DB, tx *types.Transaction) *TxResponse
Execute executes a transaction. It will route the transaction to the appropriate module(s) for execution and return the response. This method must only be called from the consensus engine, sequentially, when executing transactions in a block.
func (*TxApp) Finalize ¶
func (r *TxApp) Finalize(ctx context.Context, db sql.DB, block *common.BlockContext) (approvedJoins, expiredJoins []*types.AccountID, err error)
Finalize signals that a block has been finalized. No more changes can be applied to the database.
func (*TxApp) GenesisInit ¶
func (r *TxApp) GenesisInit(ctx context.Context, db sql.DB, genCfg *config.GenesisConfig, chainCtx *common.ChainContext) error
GenesisInit initializes the TxApp. It must be called outside of a session, and before any session is started. It can assign the initial validator set and initial account balances. It is only called once for a new chain.
func (*TxApp) GetValidators ¶
func (*TxApp) NumAccounts ¶
func (*TxApp) Price ¶
func (r *TxApp) Price(ctx context.Context, dbTx sql.DB, tx *types.Transaction, chainContext *common.ChainContext) (*big.Int, error)
Price estimates the price of a transaction. It returns the estimated price in tokens.
func (*TxApp) UpdateValidator ¶
func (r *TxApp) UpdateValidator(ctx context.Context, db sql.DB, pubKey []byte, pubKeyType crypto.KeyType, power int64) error
UpdateValidator updates a validator's power. It can only be called in between Begin and Finalize. The value passed as power will simply replace the current power.
type TxResponse ¶
type TxResponse struct {
// ResponseCode is the response code from the transaction
ResponseCode types.TxCode
// Spend is the amount of tokens spent by the transaction
Spend int64
// Log is a formatted log message from the DB that is associated with the transaction
Log string
// Error is the error returned by the transaction, if any
Error error
}
TxResponse is the response from a transaction. It contains information about the transaction, such as the amount spent.
type Validators ¶
type Validators interface {
SetValidatorPower(ctx context.Context, tx sql.Executor, pubKey []byte, keyType crypto.KeyType, power int64) error
GetValidatorPower(ctx context.Context, pubKey []byte, pubKeyType crypto.KeyType) (int64, error)
GetValidators() []*types.Validator
Commit() error
Rollback()
}