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

Commit

Permalink
Add estimate revert reason and txn hash to searcher mode logs (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSolante authored Dec 7, 2023
1 parent 06dc515 commit 206b256
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions pkg/modules/builder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (b *BuilderClient) SetWaitTimeout(timeout time.Duration) {
// that supports eth_sendBundle.
func (b *BuilderClient) SendUserOperation() modules.BatchHandlerFunc {
return func(ctx *modules.BatchHandlerCtx) error {
// Estimate gas for handleOps() and drop all userOps that cause unexpected reverts.
opts := transaction.Opts{
EOA: b.eoa,
Eth: b.eth,
Expand All @@ -76,18 +75,27 @@ func (b *BuilderClient) SendUserOperation() modules.BatchHandlerFunc {
NoSend: true,
WaitTimeout: b.waitTimeout,
}
// Estimate gas for handleOps() and drop all userOps that cause unexpected reverts.
estRev := []string{}
for len(ctx.Batch) > 0 {
est, revert, err := transaction.EstimateHandleOpsGas(&opts)

if err != nil {
return err
} else if revert != nil {
ctx.MarkOpIndexForRemoval(revert.OpIndex)
estRev = append(estRev, revert.Reason)
} else {
opts.GasLimit = est
break
}
}
ctx.Data["estimate_revert_reasons"] = estRev

// No need to continue if the batch size is 0. Otherwise we would just be sending empty batches.
if len(ctx.Batch) == 0 {
return nil
}

// Calculate the max base fee up to a future block number.
bn, err := b.eth.BlockNumber(context.Background())
Expand Down Expand Up @@ -135,7 +143,11 @@ func (b *BuilderClient) SendUserOperation() modules.BatchHandlerFunc {
}

// Wait for transaction to be included on-chain.
_, err = transaction.Wait(txn, opts.Eth, opts.WaitTimeout)
return err
if _, err := transaction.Wait(txn, opts.Eth, opts.WaitTimeout); err != nil {
return err
}
ctx.Data["txn_hash"] = txn.Hash().String()

return nil
}
}
2 changes: 1 addition & 1 deletion pkg/modules/relay/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *Relayer) SendUserOperation() modules.BatchHandlerFunc {
break
}
}
ctx.Data["relayer_est_revert_reasons"] = estRev
ctx.Data["estimate_revert_reasons"] = estRev

// Call handleOps() with gas estimate. Any userOps that cause a revert at this stage will be
// caught and dropped in the next iteration.
Expand Down

0 comments on commit 206b256

Please sign in to comment.