chore(verifytx): Updating VerifyTx to Cache between Transactions (#137)

* updating mev lane with cleaner impl

* nit

* lint

* updating anteverifytx to verify tx

* nit

* ignoring first height

* tidy
This commit is contained in:
David Terpay
2023-10-04 22:36:07 -04:00
committed by GitHub
parent cb9376e2f3
commit cbc0483e9f
12 changed files with 220 additions and 180 deletions
+16 -4
View File
@@ -51,6 +51,8 @@ func (l *BaseLane) PrepareLane(
"err", err,
"num_txs_to_add", len(txsToInclude),
"num_txs_to_remove", len(txsToRemove),
"lane_max_block_size", limit.MaxTxBytes,
"lane_max_gas_limit", limit.MaxGasLimit,
)
return proposal, err
@@ -61,6 +63,8 @@ func (l *BaseLane) PrepareLane(
"lane", l.Name(),
"num_txs_added", len(txsToInclude),
"num_txs_removed", len(txsToRemove),
"lane_max_block_size", limit.MaxTxBytes,
"lane_max_gas_limit", limit.MaxGasLimit,
)
return next(ctx, proposal)
@@ -122,12 +126,20 @@ func (l *BaseLane) ProcessLane(
return next(ctx, proposal)
}
// AnteVerifyTx verifies that the transaction is valid respecting the ante verification logic of
// VerifyTx verifies that the transaction is valid respecting the ante verification logic of
// of the antehandler chain.
func (l *BaseLane) AnteVerifyTx(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
func (l *BaseLane) VerifyTx(ctx sdk.Context, tx sdk.Tx, simulate bool) error {
if l.cfg.AnteHandler != nil {
return l.cfg.AnteHandler(ctx, tx, simulate)
// Only write to the context if the tx does not fail.
catchCtx, write := ctx.CacheContext()
if _, err := l.cfg.AnteHandler(catchCtx, tx, simulate); err != nil {
return err
}
write()
return nil
}
return ctx, nil
return nil
}
+2 -2
View File
@@ -89,7 +89,7 @@ func (l *BaseLane) DefaultPrepareLaneHandler() PrepareLaneHandler {
}
// Verify the transaction.
if ctx, err = l.AnteVerifyTx(ctx, tx, false); err != nil {
if err = l.VerifyTx(ctx, tx, false); err != nil {
l.Logger().Info(
"failed to verify tx",
"tx_hash", txInfo.Hash,
@@ -128,7 +128,7 @@ func (l *BaseLane) DefaultProcessLaneHandler() ProcessLaneHandler {
return fmt.Errorf("transaction at index %d has a higher priority than %d", index, index-1)
}
if _, err := l.AnteVerifyTx(ctx, tx, false); err != nil {
if err := l.VerifyTx(ctx, tx, false); err != nil {
return fmt.Errorf("failed to verify tx: %w", err)
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ type (
// attempt to insert, remove transactions from all lanes it belongs to. It is recommended,
// that mutex is set to true when creating the mempool. This will ensure that each
// transaction cannot be inserted into the lanes before it.
func NewLanedMempool(logger log.Logger, mutex bool, lanes ...Lane) *LanedMempool {
func NewLanedMempool(logger log.Logger, mutex bool, lanes ...Lane) Mempool {
mempool := &LanedMempool{
logger: logger,
registry: lanes,
+6
View File
@@ -20,6 +20,12 @@ type (
}
)
// NewProposalWithContext returns a new empty proposal.
func NewProposalWithContext(ctx sdk.Context, txEncoder sdk.TxEncoder) Proposal {
maxBlockSize, maxGasLimit := GetBlockLimits(ctx)
return NewProposal(txEncoder, maxBlockSize, maxGasLimit)
}
// NewProposal returns a new empty proposal. Any transactions added to the proposal
// will be subject to the given max block size and max gas limit.
func NewProposal(txEncoder sdk.TxEncoder, maxBlockSize int64, maxGasLimit uint64) Proposal {