Skip to content

Commit

Permalink
Reset block gas meter if concurrent processing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed May 21, 2023
1 parent 98c60f0 commit f808b30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f808b30

Please sign in to comment.