Skip to content

Commit

Permalink
Rename GetMedianGasPriceInUint to GetMedianGasValues
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 committed Jul 22, 2024
1 parent aab53c8 commit 7c16387
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion x/crosschain/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func CheckAndUpdateCctxGasPrice(

// compute gas price increase
chainID := cctx.GetCurrentOutboundParam().ReceiverChainId
medianGasPrice, priorityFee, isFound := k.GetMedianGasPriceInUint(ctx, chainID)
medianGasPrice, priorityFee, isFound := k.GetMedianGasValues(ctx, chainID)
if !isFound {
return math.ZeroUint(), math.ZeroUint(), cosmoserrors.Wrap(
types.ErrUnableToGetGasPrice,
Expand Down
12 changes: 8 additions & 4 deletions x/crosschain/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func TestCheckAndUpdateCctxGasPrice(t *testing.T) {
flags observertypes.GasPriceIncreaseFlags
blockTimestamp time.Time
medianGasPrice uint64
medianPriorityFee uint64
withdrawFromGasStabilityPoolReturn error
expectWithdrawFromGasStabilityPoolCall bool
expectedGasPriceIncrease math.Uint
Expand All @@ -140,6 +141,7 @@ func TestCheckAndUpdateCctxGasPrice(t *testing.T) {
flags: observertypes.DefaultGasPriceIncreaseFlags,
blockTimestamp: retryIntervalReached,
medianGasPrice: 50,
medianPriorityFee: 60,
withdrawFromGasStabilityPoolReturn: nil,
expectWithdrawFromGasStabilityPoolCall: true,
expectedGasPriceIncrease: math.NewUint(50), // 100% medianGasPrice
Expand Down Expand Up @@ -354,15 +356,17 @@ func TestCheckAndUpdateCctxGasPrice(t *testing.T) {
// set median gas price if not zero
if tc.medianGasPrice != 0 {
k.SetGasPrice(ctx, types.GasPrice{
ChainId: chainID,
Prices: []uint64{tc.medianGasPrice},
MedianIndex: 0,
ChainId: chainID,
Prices: []uint64{tc.medianGasPrice},
PriorityFees: []uint64{tc.medianPriorityFee},
MedianIndex: 0,
})

// ensure median gas price is set
medianGasPrice, _, isFound := k.GetMedianGasPriceInUint(ctx, chainID)
medianGasPrice, medianPriorityFee, isFound := k.GetMedianGasValues(ctx, chainID)
require.True(t, isFound)
require.True(t, medianGasPrice.Equal(math.NewUint(tc.medianGasPrice)))
require.True(t, medianPriorityFee.Equal(math.NewUint(tc.medianPriorityFee)))
}

// set block timestamp
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/cctx_gateway_observers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c CCTXGatewayObservers) InitiateOutbound(
return err
}
} else {
gasPrice, priorityFee, found := c.crosschainKeeper.GetMedianGasPriceInUint(ctx, config.CCTX.GetCurrentOutboundParam().ReceiverChainId)
gasPrice, priorityFee, found := c.crosschainKeeper.GetMedianGasValues(ctx, config.CCTX.GetCurrentOutboundParam().ReceiverChainId)
if !found {
return fmt.Errorf("gasprice not found for %d", config.CCTX.GetCurrentOutboundParam().ReceiverChainId)
}
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/gas_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (k Keeper) ChainGasParams(ctx sdk.Context, chainID int64) (ChainGasParams,
}

// get the gas price
gasPrice, priorityFee, isFound := k.GetMedianGasPriceInUint(ctx, chainID)
gasPrice, priorityFee, isFound := k.GetMedianGasValues(ctx, chainID)
if !isFound {
return ChainGasParams{}, types.ErrUnableToGetGasPrice
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func (k Keeper) PayGasInZetaAndUpdateCctx(
}

// get the gas price
gasPrice, priorityFee, isFound := k.GetMedianGasPriceInUint(ctx, chainID)
gasPrice, priorityFee, isFound := k.GetMedianGasValues(ctx, chainID)
if !isFound {
return cosmoserrors.Wrapf(types.ErrUnableToGetGasPrice,
"chain %d; identifiers %q",
Expand Down
5 changes: 2 additions & 3 deletions x/crosschain/keeper/gas_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ func (k Keeper) GetGasPrice(ctx sdk.Context, chainID int64) (types.GasPrice, boo
return val, true
}

// GetMedianGasPriceInUint returns the median gas price (and median priority fee) from the store
// or false if it doesn't exist.
func (k Keeper) GetMedianGasPriceInUint(ctx sdk.Context, chainID int64) (math.Uint, math.Uint, bool) {
// GetMedianGasValues returns *median* gas price and priority fee (for EIP-1559) from the store or false if it doesn't exist.
func (k Keeper) GetMedianGasValues(ctx sdk.Context, chainID int64) (math.Uint, math.Uint, bool) {
entity, found := k.GetGasPrice(ctx, chainID)
if !found {
return math.ZeroUint(), math.ZeroUint(), false
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/grpc_query_zeta_conversion_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (k Keeper) ConvertGasToZeta(
return nil, zetaObserverTypes.ErrSupportedChains
}

medianGasPrice, _, isFound := k.GetMedianGasPriceInUint(ctx, chain.ChainId)
medianGasPrice, _, isFound := k.GetMedianGasValues(ctx, chain.ChainId)
if !isFound {
return nil, status.Error(codes.InvalidArgument, "invalid request: param chain")
}
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/msg_server_migrate_tss_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (k Keeper) MigrateTSSFundsForChain(
) error {
// Always migrate to the latest TSS if multiple TSS addresses have been generated
newTss := tssList[len(tssList)-1]
medianGasPrice, priorityFee, isFound := k.GetMedianGasPriceInUint(ctx, chainID)
medianGasPrice, priorityFee, isFound := k.GetMedianGasValues(ctx, chainID)
if !isFound {
return types.ErrUnableToGetGasPrice
}
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/msg_server_migrate_tss_funds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) {
msgServer := keeper.NewMsgServerImpl(*k)

indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true)
gp, priorityFee, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId)
gp, priorityFee, found := k.GetMedianGasValues(ctx, chain.ChainId)
require.True(t, found)
msg := crosschaintypes.MsgMigrateTssFunds{
Creator: admin,
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) {

msgServer := keeper.NewMsgServerImpl(*k)
indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true)
gp, priorityFee, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId)
gp, priorityFee, found := k.GetMedianGasValues(ctx, chain.ChainId)
require.True(t, found)

msg := crosschaintypes.MsgMigrateTssFunds{
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/msg_server_whitelist_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (k msgServer) WhitelistERC20(
if !found {
return nil, errorsmod.Wrapf(types.ErrInvalidChainID, "chain params not found for chain id (%d)", msg.ChainId)
}
medianGasPrice, priorityFee, isFound := k.GetMedianGasPriceInUint(ctx, msg.ChainId)
medianGasPrice, priorityFee, isFound := k.GetMedianGasValues(ctx, msg.ChainId)
if !isFound {
return nil, errorsmod.Wrapf(
types.ErrUnableToGetGasPrice,
Expand Down

0 comments on commit 7c16387

Please sign in to comment.