Skip to content

Commit

Permalink
Merge pull request #61 from dai1975/lo5753-estimate-without-sign
Browse files Browse the repository at this point in the history
skip sign for estimateGas and not to restore sender address from sign…
  • Loading branch information
siburu authored Feb 3, 2025
2 parents a589775 + 4009e27 commit cbde4fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 1 addition & 6 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,7 @@ func (c *CallFrame) UnmarshalJSON(input []byte) error {
return nil
}

func (cl *ETHClient) EstimateGasFromTx(ctx context.Context, tx *gethtypes.Transaction) (uint64, error) {
from, err := gethtypes.LatestSignerForChainID(tx.ChainId()).Sender(tx)
if err != nil {
return 0, err
}

func (cl *ETHClient) EstimateGasFromTx(ctx context.Context, tx *gethtypes.Transaction, from common.Address) (uint64, error) {
callMsg := ethereum.CallMsg{
From: from,
To: tx.To(),
Expand Down
6 changes: 6 additions & 0 deletions pkg/relay/ethereum/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type EthereumSigner struct {
gethSigner gethtypes.Signer
addressCache common.Address
logger *log.RelayLogger
NoSign bool
}

func NewEthereumSigner(bytesSigner signer.Signer, chainID *big.Int) (*EthereumSigner, error) {
Expand All @@ -38,6 +39,7 @@ func NewEthereumSigner(bytesSigner signer.Signer, chainID *big.Int) (*EthereumSi
gethSigner: gethSigner,
addressCache: addr,
logger: nil,
NoSign: false,
}, nil
}

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

if s.NoSign {
return tx, nil
}

txHash := s.gethSigner.Hash(tx)

if (s.logger != nil) {
Expand Down
8 changes: 7 additions & 1 deletion pkg/relay/ethereum/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func estimateGas(
logger = &log.RelayLogger{Logger: logger.With(logAttrRawTxData, hex.EncodeToString(rawTxData))}
}

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

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

c.ethereumSigner.NoSign = true
multiTx, err := c.multicall3.Aggregate(opts, calls)
c.ethereumSigner.NoSign = false
if err != nil {
return err
}
Expand Down

0 comments on commit cbde4fa

Please sign in to comment.