Skip to content

Commit

Permalink
Integrate with tendermint EVM tx replacement logic (#446)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
See description in
sei-protocol/sei-tendermint#206

## Testing performed to validate your change

---------

Co-authored-by: Steven Landers <[email protected]>
Co-authored-by: Philip Su <[email protected]>
Co-authored-by: Yiming Zang <[email protected]>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Uday Patil <[email protected]>
  • Loading branch information
6 people authored Mar 7, 2024
1 parent 20c9db4 commit 01cf97f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
25 changes: 23 additions & 2 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -1063,6 +1070,20 @@ func (app *BaseApp) ProcessProposal(ctx context.Context, req *abci.RequestProces
}
}()

defer func() {
if err := recover(); err != nil {
app.logger.Error(
"panic recovered in ProcessProposal",
"height", req.Height,
"time", req.Time,
"hash", fmt.Sprintf("%X", req.Hash),
"panic", err,
)

resp = &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
}()

if app.processProposalHandler != nil {
resp, err = app.processProposalHandler(app.processProposalState.ctx, req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ replace (
github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.28
// Latest goleveldb is broken, we have to stick to this version
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2
// latest grpc doesn't work with with our modified proto compiler, so we need to enforce
// the following version across all dependencies.
google.golang.org/grpc => google.golang.org/grpc v1.33.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ github.com/sei-protocol/sei-db v0.0.28 h1:RE4k2aXSERUixJC2kZri201w1fG3WJ7PZfvCJH
github.com/sei-protocol/sei-db v0.0.28/go.mod h1:F/ZKZA8HJPcUzSZPA8yt6pfwlGriJ4RDR4eHKSGLStI=
github.com/sei-protocol/sei-iavl v0.1.9 h1:y4mVYftxLNRs6533zl7N0/Ch+CzRQc04JDfHolIxgBE=
github.com/sei-protocol/sei-iavl v0.1.9/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase h1:+c9PFgoHwYV+FGPGnJK8ySmUqlwfE0dbDri5zmxBQQI=
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2 h1:y740HdzTehlJaBrwy/T1ncwJ9D10xu4r6gSHtNRzqF0=
github.com/sei-protocol/sei-tendermint v0.2.38-evm-rebase-2/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY=
github.com/sei-protocol/sei-tm-db v0.0.5/go.mod h1:Cpa6rGyczgthq7/0pI31jys2Fw0Nfrc+/jKdP1prVqY=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down
7 changes: 4 additions & 3 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ type Context struct {
voteInfo []abci.VoteInfo
gasMeter GasMeter
occEnabled bool
blockGasMeter GasMeter
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
minGasPrice DecCoins
consParams *tmproto.ConsensusParams
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
Expand Down Expand Up @@ -144,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
}

Expand Down Expand Up @@ -401,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
}
Expand Down

0 comments on commit 01cf97f

Please sign in to comment.