Skip to content

Commit cbde4fa

Browse files
authored
Merge pull request #61 from dai1975/lo5753-estimate-without-sign
skip sign for estimateGas and not to restore sender address from sign…
2 parents a589775 + 4009e27 commit cbde4fa

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

pkg/client/client.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,7 @@ func (c *CallFrame) UnmarshalJSON(input []byte) error {
190190
return nil
191191
}
192192

193-
func (cl *ETHClient) EstimateGasFromTx(ctx context.Context, tx *gethtypes.Transaction) (uint64, error) {
194-
from, err := gethtypes.LatestSignerForChainID(tx.ChainId()).Sender(tx)
195-
if err != nil {
196-
return 0, err
197-
}
198-
193+
func (cl *ETHClient) EstimateGasFromTx(ctx context.Context, tx *gethtypes.Transaction, from common.Address) (uint64, error) {
199194
callMsg := ethereum.CallMsg{
200195
From: from,
201196
To: tx.To(),

pkg/relay/ethereum/signer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type EthereumSigner struct {
1616
gethSigner gethtypes.Signer
1717
addressCache common.Address
1818
logger *log.RelayLogger
19+
NoSign bool
1920
}
2021

2122
func NewEthereumSigner(bytesSigner signer.Signer, chainID *big.Int) (*EthereumSigner, error) {
@@ -38,6 +39,7 @@ func NewEthereumSigner(bytesSigner signer.Signer, chainID *big.Int) (*EthereumSi
3839
gethSigner: gethSigner,
3940
addressCache: addr,
4041
logger: nil,
42+
NoSign: false,
4143
}, nil
4244
}
4345

@@ -58,6 +60,10 @@ func (s *EthereumSigner) Sign(address common.Address, tx *gethtypes.Transaction)
5860
return nil, fmt.Errorf("unauthorized address: authorized=%v, given=%v", s.Address(), address)
5961
}
6062

63+
if s.NoSign {
64+
return tx, nil
65+
}
66+
6167
txHash := s.gethSigner.Hash(tx)
6268

6369
if (s.logger != nil) {

pkg/relay/ethereum/tx.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func estimateGas(
553553
logger = &log.RelayLogger{Logger: logger.With(logAttrRawTxData, hex.EncodeToString(rawTxData))}
554554
}
555555

556-
estimatedGas, err := c.client.EstimateGasFromTx(ctx, tx)
556+
estimatedGas, err := c.client.EstimateGasFromTx(ctx, tx, c.ethereumSigner.Address())
557557
if err != nil {
558558
if revertReason, rawErrorData, err := c.getRevertReasonFromRpcError(err); err != nil {
559559
// Raw error data may be available even if revert reason isn't available.
@@ -666,7 +666,9 @@ func (iter *CallIter) buildSingleTx(ctx context.Context, c *Chain) (*CallIterBui
666666
// gas estimation
667667
{
668668
opts.GasLimit = math.MaxUint64
669+
c.ethereumSigner.NoSign = true
669670
tx, err := c.BuildMessageTx(opts, iter.Current(), iter.skipUpdateClientCommitment)
671+
c.ethereumSigner.NoSign = false
670672
if err != nil {
671673
logger.Error("failed to build tx for gas estimation", err)
672674
return nil, err
@@ -710,7 +712,9 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil
710712
logger := iter.updateLoggerMessageInfo(logger, i, 1)
711713

712714
// note that its nonce is not checked
715+
c.ethereumSigner.NoSign = true
713716
tx, err := c.BuildMessageTx(opts, iter.msgs[i], iter.skipUpdateClientCommitment)
717+
c.ethereumSigner.NoSign = false
714718
if err != nil {
715719
logger.Error("failed to build tx for gas estimation", err)
716720
return nil, err
@@ -745,7 +749,9 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil
745749
})
746750
}
747751

752+
c.ethereumSigner.NoSign = true
748753
multiTx, err := c.multicall3.Aggregate(opts, calls)
754+
c.ethereumSigner.NoSign = false
749755
if err != nil {
750756
return err
751757
}

0 commit comments

Comments
 (0)