From f808b30a8a1ebf224a63a4e7d6bf3f2628a9c24e Mon Sep 17 00:00:00 2001 From: codchen Date: Sun, 21 May 2023 13:43:55 +0800 Subject: [PATCH] Reset block gas meter if concurrent processing fails --- app/app.go | 8 ++++++++ app/test_helpers.go | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index f8d3e8b44c..4f240c979a 100644 --- a/app/app.go +++ b/app/app.go @@ -1188,6 +1188,10 @@ func (app *App) ProcessTxs( // CacheMultiStore where it writes the data to the parent store (DeliverState) in sorted Key order to maintain // deterministic ordering between validators in the case of concurrent deliverTXs processBlockCtx, processBlockCache := app.CacheContext(ctx) + blockGasMeterConsumed := uint64(0) + if processBlockCtx.BlockGasMeter() != nil { + blockGasMeterConsumed = processBlockCtx.BlockGasMeter().GasConsumed() + } concurrentResults, ok := processBlockConcurrentFunction( processBlockCtx, txs, @@ -1215,6 +1219,10 @@ func (app *App) ProcessTxs( dexMemState.Clear(ctx) dexMemState.ClearContractToDependencies() + if ctx.BlockGasMeter() != nil { + ctx.BlockGasMeter().RefundGas(ctx.BlockGasMeter().GasConsumed()-blockGasMeterConsumed, "concurrent failure rollback") + } + txResults := app.ProcessBlockSynchronous(ctx, txs) processBlockCache.Write() return txResults, ctx diff --git a/app/test_helpers.go b/app/test_helpers.go index c16615e794..0169d03dc6 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -15,6 +15,7 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + dexutils "github.com/sei-protocol/sei-chain/x/dex/utils" minttypes "github.com/sei-protocol/sei-chain/x/mint/types" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" @@ -50,9 +51,11 @@ type TestWrapper struct { func NewTestWrapper(t *testing.T, tm time.Time, valPub crptotypes.PubKey) *TestWrapper { appPtr := Setup(false) + ctx := appPtr.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "sei-test", Time: tm}) + ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, appPtr.MemState)) wrapper := &TestWrapper{ App: appPtr, - Ctx: appPtr.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "sei-test", Time: tm}), + Ctx: ctx, } wrapper.SetT(t) wrapper.setupValidator(stakingtypes.Bonded, valPub)