From a3936d977c4137d3ffc155a7c16847faf698e2a7 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 18 Dec 2023 11:59:50 +0800 Subject: [PATCH] Problem: simulate gas is less than require with feegrants --- CHANGELOG.md | 1 + relayer/chains/cosmos/tx.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5130d5d23..f97c27924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ * [\#1325](https://github.com/cosmos/relayer/pull/1325) Ignore only file not exist error when loadConfigFile. * [\#1326](https://github.com/cosmos/relayer/pull/1326) Avoid sending channel close confirm message after channel get closed successfully. * [\#11](https://github.com/crypto-org-chain/relayer/pull/11) Fix gasFeeCap and gasPrice when new evm tx. +* [\#1364](https://github.com/cosmos/relayer/pull/1364) Include feegrant message when calculate gas. ## v0.9.3 diff --git a/relayer/chains/cosmos/tx.go b/relayer/chains/cosmos/tx.go index 27160674e..91ec33f3f 100644 --- a/relayer/chains/cosmos/tx.go +++ b/relayer/chains/cosmos/tx.go @@ -671,16 +671,6 @@ func (cc *CosmosProvider) getTxFactoryAndBuilder( txf = txf.WithSequence(sequence) } - adjusted := gas - - if gas == 0 { - _, adjusted, err = cc.CalculateGas(ctx, txf, txSignerKey, cMsgs...) - - if err != nil { - return nil, nil, err - } - } - //Cannot feegrant your own TX if txSignerKey != feegranterKey && feegranterKey != "" { granterAddr, err := cc.GetKeyAddressForKey(feegranterKey) @@ -691,6 +681,16 @@ func (cc *CosmosProvider) getTxFactoryAndBuilder( txf = txf.WithFeeGranter(granterAddr) } + adjusted := gas + + if gas == 0 { + _, adjusted, err = cc.CalculateGas(ctx, txf, txSignerKey, cMsgs...) + + if err != nil { + return nil, nil, err + } + } + // Set the gas amount on the transaction factory txf = txf.WithGas(adjusted)