Skip to content

Commit

Permalink
Backwards compatible patch for bug with market map antehandler gas us…
Browse files Browse the repository at this point in the history
…age.
  • Loading branch information
vincentwschau committed Aug 30, 2024
1 parent 9f207d5 commit 9d1f462
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions protocol/app/ante/market_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions protocol/app/ante/market_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
})
}
}
Expand Down

0 comments on commit 9d1f462

Please sign in to comment.