Skip to content

Commit

Permalink
more fixes for out of gas, only check if its not a canonical token!
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed May 17, 2023
1 parent 2f82868 commit a4ae672
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/relayer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.netrc
.env
.l1l2.env
.l2l3.env
.test.env
main
coverage.txt
Expand Down
29 changes: 15 additions & 14 deletions packages/relayer/message/process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ func (p *Processor) sendProcessMessageCall(

var cost *big.Int

var needsContractDeployment bool = false
// node is unable to estimate gas correctly for contract deployments, we need to check if the token
// is deployed, and always hardcode in this case. we need to check this before calling
// estimategas, as the node will soemtimes return a gas estimate for a contract deployment, however,
// it is incorrect and the tx will revert.
if eventType == relayer.EventTypeSendERC20 {
if eventType == relayer.EventTypeSendERC20 && event.Message.DestChainId.Cmp(canonicalToken.ChainId) != 0 {
// determine whether the canonical token is bridged or not on this chain
bridgedAddress, err := p.destTokenVault.CanonicalToBridged(nil, canonicalToken.ChainId, canonicalToken.Addr)
if err != nil {
Expand All @@ -180,22 +181,22 @@ func (p *Processor) sendProcessMessageCall(
// needs large gas limit because it has to deploy an ERC20 contract on destination
// chain. deploying ERC20 can be 2 mil by itself. we want to skip estimating gas entirely
// in this scenario.
auth.GasLimit = 3000000
} else {
// otherwise we can estimate gas
gas, cost, err = p.estimateGas(ctx, event.Message, proof)
needsContractDeployment = true
}
} else {
// always try to estimate gas for eth events
gas, cost, err = p.estimateGas(ctx, event.Message, proof)
}

// and if gas estimation failed, we just try to hardcore a value no matter what type of event,
// or whether the contract is deployed.
if err != nil || gas == 0 {
cost, err = p.hardcodeGasLimit(ctx, auth, event, eventType, canonicalToken)
if err != nil {
return nil, errors.Wrap(err, "p.hardcodeGasLimit")
if needsContractDeployment {
auth.GasLimit = 3000000
} else {
// otherwise we can estimate gas
gas, cost, err = p.estimateGas(ctx, event.Message, proof)
// and if gas estimation failed, we just try to hardcore a value no matter what type of event,
// or whether the contract is deployed.
if err != nil || gas == 0 {
cost, err = p.hardcodeGasLimit(ctx, auth, event, eventType, canonicalToken)
if err != nil {
return nil, errors.Wrap(err, "p.hardcodeGasLimit")
}
}
}

Expand Down

0 comments on commit a4ae672

Please sign in to comment.