From 9d1f462dbe440449003a4fe5a8b59c8587aa2ccb Mon Sep 17 00:00:00 2001 From: Vincent Chau <99756290+vincentwschau@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:46:54 -0400 Subject: [PATCH] Backwards compatible patch for bug with market map antehandler gas usage. --- protocol/app/ante/market_update.go | 8 ++++++++ protocol/app/ante/market_update_test.go | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/protocol/app/ante/market_update.go b/protocol/app/ante/market_update.go index 66c0eca9a6..9d87c47ad1 100644 --- a/protocol/app/ante/market_update.go +++ b/protocol/app/ante/market_update.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + storetypes "cosmossdk.io/store/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -86,6 +88,12 @@ func (d ValidateMarketUpdateDecorator) AnteHandle( return ctx, fmt.Errorf("unrecognized message type: %T", msg) } + // FOR BACKWARDS COMPATABILITY + // For the bug found in https://github.com/dydxprotocol/v4-chain/pull/2176, this is a + // backwards compatible bug-fix, which lets a node sync past blocks that were committed + // by nodes running with the bug. + _ = d.doMarketsContainCrossMarket(ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()), markets) + if contains := d.doMarketsContainCrossMarket(ctx, markets); contains { return ctx, ErrNoCrossMarketUpdates } diff --git a/protocol/app/ante/market_update_test.go b/protocol/app/ante/market_update_test.go index 6ae0e46fb9..9aa2d4bb08 100644 --- a/protocol/app/ante/market_update_test.go +++ b/protocol/app/ante/market_update_test.go @@ -4,6 +4,8 @@ import ( "math/rand" "testing" + storetypes "cosmossdk.io/store/types" + sdkmath "cosmossdk.io/math" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/dydxprotocol/v4-chain/protocol/dtypes" @@ -820,12 +822,19 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) { ) require.NoError(t, err) + ctx = ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) _, err = anteHandler(ctx, tx, tt.args.simulate) if tt.wantErr { require.Error(t, err) return } require.NoError(t, err) + gasConsumed := ctx.GasMeter().GasConsumed() + // Execute twice to ensure deterministic gas usage + ctx = ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) + _, err = anteHandler(ctx, tx, tt.args.simulate) + require.NoError(t, err) + require.Equal(t, gasConsumed, ctx.GasMeter().GasConsumed()) }) } }