Documentation ¶
Overview ¶
package tx_router routes transactions to the appropriate module(s)
Index ¶
- Variables
- type ConsensusParams
- type CreditPayload
- type DB
- type Pricer
- type Rebroadcaster
- type Route
- type TxApp
- func (r *TxApp) AccountInfo(ctx context.Context, acctID []byte, getUncommitted bool) (balance *big.Int, nonce int64, err error)
- func (r *TxApp) ApplyMempool(ctx context.Context, tx *transactions.Transaction) error
- func (r *TxApp) Begin(ctx context.Context) error
- func (r *TxApp) ChainInfo(ctx context.Context) (int64, []byte, error)
- func (r *TxApp) Commit(ctx context.Context) error
- func (r *TxApp) Execute(ctx TxContext, tx *transactions.Transaction) *TxResponse
- func (r *TxApp) Finalize(ctx context.Context, blockHeight int64) (appHash []byte, finalValidators []*types.Validator, err error)
- func (r *TxApp) GenesisInit(ctx context.Context, validators []*types.Validator, ...) error
- func (r *TxApp) GetValidators(ctx context.Context) ([]*types.Validator, error)
- func (r *TxApp) Price(ctx context.Context, tx *transactions.Transaction) (*big.Int, error)
- func (r *TxApp) ProposerTxs(ctx context.Context, txNonce uint64, maxTxsSize int64, proposerAddr []byte) ([][]byte, error)
- func (r *TxApp) UpdateValidator(ctx context.Context, validator []byte, power int64) error
- type TxContext
- type TxResponse
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") )
var ( ValidatorVoteBodyBytePrice int64 = 1000 // Per byte cost ValidatorVoteIDPrice = big.NewInt(1000 * 16) // 16 bytes for the UUID )
Functions ¶
This section is empty.
Types ¶
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 CreditPayload ¶
type CreditPayload struct { DepositID string // the transaction ID from the source chain that created the deposit Account []byte // the account to be credited Amount *big.Int // the amount of tokens to be credited }
func (*CreditPayload) MarshalBinary ¶
func (p *CreditPayload) MarshalBinary() ([]byte, error)
func (*CreditPayload) UnmarshalBinary ¶
func (p *CreditPayload) UnmarshalBinary(data []byte) error
type DB ¶
type DB interface { sql.OuterTxMaker sql.ReadTxMaker }
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 Pricer ¶
type Pricer interface {
Price(ctx context.Context, router *TxApp, tx *transactions.Transaction) (*big.Int, error)
}
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 transactions. // 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 TxContext, router *TxApp, tx *transactions.Transaction) *TxResponse }
type TxApp ¶
type TxApp struct { Database DB // postgres database Engine common.Engine // tracks deployed schemas GasEnabled bool // contains filtered or unexported fields }
TxApp maintains the state for Kwil's ABCI application. 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(db DB, engine common.Engine, signer *auth.Ed25519Signer, events Rebroadcaster, chainID string, GasEnabled bool, extensionConfigs map[string]map[string]string, log log.Logger) (*TxApp, error)
NewTxApp creates a new router.
func (*TxApp) AccountInfo ¶
func (r *TxApp) AccountInfo(ctx context.Context, acctID []byte, getUncommitted 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 ¶
func (r *TxApp) ApplyMempool(ctx context.Context, tx *transactions.Transaction) error
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. It contains information on any validators whose power should be updated.
func (*TxApp) ChainInfo ¶
ChainInfo is called be the ABCI applications' Info method, which is called once on startup except when the node is at genesis, in which case GenesisInit is called by the application's ChainInit method.
func (*TxApp) Execute ¶
func (r *TxApp) Execute(ctx TxContext, tx *transactions.Transaction) *TxResponse
Execute executes a transaction. It will route the transaction to the appropriate module(s) and return the response.
func (*TxApp) Finalize ¶
func (r *TxApp) Finalize(ctx context.Context, blockHeight int64) (appHash []byte, finalValidators []*types.Validator, err error)
Finalize signals that a block has been finalized. No more changes can be applied to the database. It returns the apphash and the validator set.
func (*TxApp) GenesisInit ¶
func (r *TxApp) GenesisInit(ctx context.Context, validators []*types.Validator, genesisAccounts []*types.Account, initialHeight int64, genesisAppHash []byte) 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 ¶
GetValidators returns the current validator set. It will not return uncommitted changes.
func (*TxApp) Price ¶
func (r *TxApp) Price(ctx context.Context, tx *transactions.Transaction) (*big.Int, error)
Price estimates the price of a transaction. It returns the estimated price in tokens.
func (*TxApp) ProposerTxs ¶
func (r *TxApp) ProposerTxs(ctx context.Context, txNonce uint64, maxTxsSize int64, proposerAddr []byte) ([][]byte, error)
ProposerTxs returns the transactions that the proposer should include in the next block. It takes txNonce as an argument because, the proposer may have its own transactions in the mempool that are included in the current block. Therefore, we need to know the largest nonce of the transactions included in the block that are authored by the proposer. This transaction only includes voteBodies for events whose bodies have not been received by the network. Therefore, there won't be more than 1 VoteBody transaction per event.
type TxContext ¶
type TxContext struct { Ctx context.Context // BlockHeight gets the height of the current block. BlockHeight int64 // Proposer gets the proposer public key of the current block. Proposer []byte // ConsensusParams holds network level parameters that can be evolved // over the lifetime of a network. ConsensusParams ConsensusParams }
TxContext is the context for transaction execution.
type TxResponse ¶
type TxResponse struct { // ResponseCode is the response code from the transaction ResponseCode transactions.TxCode // Spend is the amount of tokens spent by the transaction Spend int64 // 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.