Skip to content

Commit

Permalink
feat(relayer): pad if contract (#18131)
Browse files Browse the repository at this point in the history
Co-authored-by: maskpp <maskpp266@gmail.com>
  • Loading branch information
cyberhorsey and mask-pp authored Sep 18, 2024
1 parent b6cd50b commit 56143f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/relayer/pkg/mock/eth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ func (c *EthClient) BalanceAt(
blockNumber *big.Int) (*big.Int, error) {
return big.NewInt(100), nil
}

func (c *EthClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
return []byte{}, nil
}
12 changes: 11 additions & 1 deletion packages/relayer/processor/process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,19 @@ func (p *Processor) sendProcessMessageCall(
return nil, err
}

// mul by 1.05 for padding
gasLimit := uint64(float64(event.Message.GasLimit))

// if destination address is a contract, add padding. check message.to
// to see if it is a contract address.
code, err := p.destEthClient.CodeAt(ctx, event.Message.To, nil)
if err != nil {
return nil, err
}

if len(code) != 0 {
gasLimit = uint64(float64(gasLimit) * 1.05)
}

var estimatedMaxCost uint64

if bool(p.profitableOnly) {
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type ethClient interface {
SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
}

// hop is a struct which needs to be created based on the config parameters
Expand Down

0 comments on commit 56143f0

Please sign in to comment.