Skip to content

Commit 3d3deab

Browse files
authored
op-challenger: run-trace now picks a random block in the span batch (#13715)
Previously it always picked the first block which was the worst case pre-holocene. Now it biases towards the first and last blocks as they hit more corner cases but can pick a random block in the middle of the batch as well.
1 parent 9881eda commit 3d3deab

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

op-challenger/runner/runner.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"math/big"
8+
"math/rand"
89
"os"
910
"path/filepath"
1011
"regexp"
@@ -195,7 +196,7 @@ func (r *Runner) createGameInputs(ctx context.Context, client *sources.RollupCli
195196
}
196197
l1Head := status.FinalizedL1
197198
if status.FinalizedL1.Number > status.CurrentL1.Number {
198-
// Restrict the L1 head to a block that has actually be processed by op-node.
199+
// Restrict the L1 head to a block that has actually been processed by op-node.
199200
// This only matters if op-node is behind and hasn't processed all finalized L1 blocks yet.
200201
l1Head = status.CurrentL1
201202
}
@@ -235,15 +236,32 @@ func (r *Runner) findL2BlockNumberToDispute(ctx context.Context, client *sources
235236
return l2BlockNum, nil
236237
}
237238
l1HeadNum -= skipSize
238-
priorSafeHead, err := client.SafeHeadAtL1Block(ctx, l1HeadNum)
239+
prevSafeHead, err := client.SafeHeadAtL1Block(ctx, l1HeadNum)
239240
if err != nil {
240241
return 0, fmt.Errorf("failed to get prior safe head at L1 block %v: %w", l1HeadNum, err)
241242
}
242-
if priorSafeHead.SafeHead.Number < l2BlockNum {
243+
if prevSafeHead.SafeHead.Number < l2BlockNum {
244+
switch rand.Intn(3) {
245+
case 0: // First block of span batch
246+
return prevSafeHead.SafeHead.Number + 1, nil
247+
case 1: // Last block of span batch
248+
return prevSafeHead.SafeHead.Number, nil
249+
case 2: // Random block, probably but not guaranteed to be in the middle of a span batch
250+
firstBlockInSpanBatch := prevSafeHead.SafeHead.Number + 1
251+
if l2BlockNum <= firstBlockInSpanBatch {
252+
// There is only one block in the next batch so we just have to use it
253+
return l2BlockNum, nil
254+
}
255+
offset := rand.Intn(int(l2BlockNum - firstBlockInSpanBatch))
256+
return firstBlockInSpanBatch + uint64(offset), nil
257+
}
258+
259+
}
260+
if prevSafeHead.SafeHead.Number < l2BlockNum {
243261
// We walked back far enough to be before the batch that included l2BlockNum
244262
// So use the first block after the prior safe head as the disputed block.
245263
// It must be the first block in a batch.
246-
return priorSafeHead.SafeHead.Number + 1, nil
264+
return prevSafeHead.SafeHead.Number + 1, nil
247265
}
248266
}
249267
r.log.Warn("Failed to find prior batch", "l2BlockNum", l2BlockNum, "earliestCheckL1Block", l1HeadNum)

0 commit comments

Comments
 (0)