Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards compatible patch for bug with market map antehandler gas usage. #2178

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading