From d359a988e4b36424b81435c3ac8375ac5b4c1be5 Mon Sep 17 00:00:00 2001 From: codchen Date: Wed, 28 Feb 2024 13:47:25 +0800 Subject: [PATCH] Integrate with tendermint EVM tx replacement logic --- baseapp/abci.go | 11 +++++++++-- baseapp/baseapp.go | 2 +- types/context.go | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index e98bc51cb..7e528d121 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -293,7 +293,7 @@ func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, tx sdk telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted") }() - gInfo, result, anteEvents, _, _, _, _, err := app.runTx(ctx.WithTxBytes(req.Tx).WithVoteInfos(app.voteInfos), runTxModeDeliver, tx, checksum) + gInfo, result, anteEvents, _, _, _, resCtx, err := app.runTx(ctx.WithTxBytes(req.Tx).WithVoteInfos(app.voteInfos), runTxModeDeliver, tx, checksum) if err != nil { resultStr = "failed" // if we have a result, use those events instead of just the anteEvents @@ -303,13 +303,20 @@ func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, tx sdk return sdkerrors.ResponseDeliverTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, sdk.MarkEventsToIndex(anteEvents, app.indexEvents), app.trace) } - return abci.ResponseDeliverTx{ + res = abci.ResponseDeliverTx{ GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? Log: result.Log, Data: result.Data, Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents), } + if resCtx.IsEVM() { + res.EvmTxInfo = &abci.EvmTxInfo{ + SenderAddress: resCtx.EVMSenderAddress(), + Nonce: resCtx.EVMNonce(), + } + } + return } func (app *BaseApp) WriteStateToCommitAndGetWorkingHash() []byte { diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index b3f11e68b..f91cbb52c 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -985,7 +985,7 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, tx sdk.Tx, checksum [ result.Events = append(anteEvents, result.Events...) } if ctx.CheckTxCallback() != nil { - ctx.CheckTxCallback()(err) + ctx.CheckTxCallback()(ctx, err) } return gInfo, result, anteEvents, priority, pendingTxChecker, expireHandler, ctx, err } diff --git a/types/context.go b/types/context.go index c4336c154..b2c467257 100644 --- a/types/context.go +++ b/types/context.go @@ -42,7 +42,7 @@ type Context struct { eventManager *EventManager priority int64 // The tx priority, only relevant in CheckTx pendingTxChecker abci.PendingTxChecker // Checker for pending transaction, only relevant in CheckTx - checkTxCallback func(error) // callback to make at the end of CheckTx. Input param is the error (nil-able) of `runMsgs` + checkTxCallback func(Context, error) // callback to make at the end of CheckTx. Input param is the error (nil-able) of `runMsgs` expireTxHandler func() // callback that the mempool invokes when a tx is expired txBlockingChannels acltypes.MessageAccessOpsChannelMapping @@ -145,7 +145,7 @@ func (c Context) PendingTxChecker() abci.PendingTxChecker { return c.pendingTxChecker } -func (c Context) CheckTxCallback() func(error) { +func (c Context) CheckTxCallback() func(Context, error) { return c.checkTxCallback } @@ -402,7 +402,7 @@ func (c Context) WithPendingTxChecker(checker abci.PendingTxChecker) Context { return c } -func (c Context) WithCheckTxCallback(checkTxCallback func(error)) Context { +func (c Context) WithCheckTxCallback(checkTxCallback func(Context, error)) Context { c.checkTxCallback = checkTxCallback return c }