Skip to content

Commit 8979b99

Browse files
author
Daisuke Kanda
committed
skip sign for estimateGas and not to restore sender address from signature
Signed-off-by: Daisuke Kanda <[email protected]>
1 parent a589775 commit 8979b99

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-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/chain.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,9 @@ func (c *Chain) confirmConnectionOpened(ctx context.Context) (bool, error) {
568568
c.connectionOpenedConfirmed = true
569569
return true, nil
570570
}
571+
572+
func (c *Chain) Balance(ctx context.Context) (*big.Int) {
573+
addr := c.ethereumSigner.Address()
574+
b, _ := c.client.BalanceAt(ctx, addr, nil)
575+
return b
576+
}

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: 9 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
@@ -679,6 +681,7 @@ func (iter *CallIter) buildSingleTx(ctx context.Context, c *Chain) (*CallIterBui
679681
opts.GasLimit = txGasLimit
680682
}
681683

684+
c.ethereumSigner.NoSign = false
682685
tx, err := c.BuildMessageTx(opts, iter.Current(), iter.skipUpdateClientCommitment)
683686
if err != nil {
684687
logger.Error("failed to build tx", err)
@@ -710,7 +713,9 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil
710713
logger := iter.updateLoggerMessageInfo(logger, i, 1)
711714

712715
// note that its nonce is not checked
716+
c.ethereumSigner.NoSign = true
713717
tx, err := c.BuildMessageTx(opts, iter.msgs[i], iter.skipUpdateClientCommitment)
718+
c.ethereumSigner.NoSign = false
714719
if err != nil {
715720
logger.Error("failed to build tx for gas estimation", err)
716721
return nil, err
@@ -745,7 +750,9 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil
745750
})
746751
}
747752

753+
c.ethereumSigner.NoSign = true
748754
multiTx, err := c.multicall3.Aggregate(opts, calls)
755+
c.ethereumSigner.NoSign = false
749756
if err != nil {
750757
return err
751758
}
@@ -774,6 +781,7 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil
774781
opts.GasLimit = lastOkGasLimit
775782

776783
// add raw tx to log attribute
784+
c.ethereumSigner.NoSign = false
777785
tx, err := c.multicall3.Aggregate(opts, lastOkCalls)
778786
if err != nil {
779787
logger.Error("failed to build multicall tx with real send parameters", err)

0 commit comments

Comments
 (0)