Skip to content

Commit

Permalink
Revert "Problem: require gas in RecvPacket is inaccurate when Receive…
Browse files Browse the repository at this point in the history
…rChainIsSource (crypto-org-chain#1458)" (crypto-org-chain#1478)

This reverts commit 0ef63b9.

Co-authored-by: yihuang <huang@crypto.com>
  • Loading branch information
mmsqe and yihuang authored Jun 18, 2024
1 parent fb3477e commit 6169d92
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
### State Machine Breaking

* [#1407](https://github.com/crypto-org-chain/cronos/pull/1407) Add end-to-end encryption module.
* [#1458](https://github.com/crypto-org-chain/cronos/pull/1458) Adjust require gas for recvPacket when ReceiverChainIsSource.

### Improvements

Expand Down
38 changes: 2 additions & 36 deletions x/cronos/keeper/precompiles/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/ethereum/go-ethereum/params"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
"github.com/crypto-org-chain/cronos/v2/x/cronos/events/bindings/cosmos/precompile/relayer"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
Expand Down Expand Up @@ -60,10 +58,6 @@ const (
UpdateClientAndAcknowledgement = "updateClientAndAcknowledgement"
UpdateClientAndTimeout = "updateClientAndTimeout"
UpdateClientAndTimeoutOnClose = "updateClientAndTimeoutOnClose"

GasForUpdateClient = 111894
GasWhenReceiverChainIsSource = 51705
GasWhenReceiverChainIsNotSource = 144025
)

func init() {
Expand Down Expand Up @@ -99,7 +93,7 @@ func init() {
case ChannelCloseConfirm:
relayerGasRequiredByMethod[methodID] = 31199
case RecvPacket:
relayerGasRequiredByMethod[methodID] = GasWhenReceiverChainIsNotSource
relayerGasRequiredByMethod[methodID] = 144025
case Acknowledgement:
relayerGasRequiredByMethod[methodID] = 61781
case Timeout:
Expand All @@ -113,7 +107,7 @@ func init() {
case UpdateClientAndChannelOpenConfirm:
relayerGasRequiredByMethod[methodID] = 132734
case UpdateClientAndRecvPacket:
relayerGasRequiredByMethod[methodID] = GasForUpdateClient + GasWhenReceiverChainIsNotSource
relayerGasRequiredByMethod[methodID] = 257120
case UpdateClientAndConnectionOpenInit:
relayerGasRequiredByMethod[methodID] = 131649
case UpdateClientAndConnectionOpenAck:
Expand Down Expand Up @@ -171,34 +165,6 @@ func (bc *RelayerContract) RequiredGas(input []byte) (gas uint64) {
var methodID [4]byte
copy(methodID[:], input[:4])
requiredGas, ok := relayerGasRequiredByMethod[methodID]
method, err := irelayerABI.MethodById(methodID[:])
if err != nil {
panic(err)
}
if method.Name == RecvPacket || method.Name == UpdateClientAndRecvPacket {
args, err := method.Inputs.Unpack(input[4:])
if err != nil {
panic(err)
}
i := args[0].([]byte)
if method.Name == UpdateClientAndRecvPacket {
i = args[1].([]byte)
}
var msg channeltypes.MsgRecvPacket
if err = bc.cdc.Unmarshal(i, &msg); err != nil {
panic(err)
}
var data ibctransfertypes.FungibleTokenPacketData
if err = ibctransfertypes.ModuleCdc.UnmarshalJSON(msg.Packet.GetData(), &data); err != nil {
panic(err)
}
if ibctransfertypes.ReceiverChainIsSource(msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), data.Denom) {
requiredGas = GasWhenReceiverChainIsSource
if method.Name == UpdateClientAndRecvPacket {
requiredGas += GasForUpdateClient
}
}
}
intrinsicGas, _ := core.IntrinsicGas(input, nil, false, bc.isHomestead, bc.isIstanbul, bc.isShanghai)
defer func() {
methodName := relayerMethodNamedByMethod[methodID]
Expand Down

0 comments on commit 6169d92

Please sign in to comment.