Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Bound estimated gas limit before relaying a bundle txn. #339

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions pkg/modules/relay/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package relay

import (
"errors"
"math/big"
"time"

Expand Down Expand Up @@ -93,16 +94,34 @@ func (r *Relayer) SendUserOperation() modules.BatchHandlerFunc {
}
ctx.Data["relayer_est_revert_reasons"] = estRev

if len(ctx.Batch) == 0 {
return nil
}

// Accumulate the total gas limit of all user operations.
totalGasLimit := big.NewInt(0)
for _, op := range ctx.Batch {
totalGasLimit.Add(totalGasLimit, op.GetMaxGasAvailable())
}

// Estimated gas limit should be no less than the total gas limit, otherwise this transaction
// may be failed due to out of gas.
if opts.GasLimit <= totalGasLimit.Uint64() {
opts.GasLimit = totalGasLimit.Uint64()
} else {
// Also, bundler could lose money if estimated gas limit exceeds the sum of gas limits
// for all user operations.
return errors.New("estimated gas limit over all user ops limit")
}

// Call handleOps() with gas estimate. Any userOps that cause a revert at this stage will be
// caught and dropped in the next iteration.
if len(ctx.Batch) > 0 {
if txn, err := transaction.HandleOps(&opts); err != nil {
return err
} else {
ctx.Data["txn_hash"] = txn.Hash().String()
}
txn, err := transaction.HandleOps(&opts)
if err != nil {
return err
}

ctx.Data["txn_hash"] = txn.Hash().String()
return nil
}
}