Skip to content

Commit e122913

Browse files
execution/stagedsync: check batch fullness after every block (#21193)
## Summary Move the batch-fullness check out of a 5-second ticker and into per-block. When blocks process quickly, exec was overshooting the configured `--batchSize` by hundreds of MB between ticks. With 4 blk/s and 33 MB of CommitmentVals per block, 5 s of unchecked exec adds ~660 MB to the buffer — well past a configured 100 MB or 256 MB batchSize. Smaller batchSize → worse overshoot ratio. The check itself is cheap (a single `readState().SizeEstimateBeforeCommitment()` call), so per-block is fine. This lets `--batchSize` actually bound the per-commit working set, which directly bounds the per-CommitCycle trie-hash cost — the dominant slowdown source on heavy-state runs. ## Test plan - [ ] CI on `performance` - [ ] Mainnet sync still healthy
1 parent e574a75 commit e122913

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

execution/stagedsync/exec3_serial.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ func (se *serialExecutor) exec(ctx context.Context, execStage *StageState, u Unw
5858

5959
se.resetWorkers(ctx, se.rs, se.applyTx)
6060

61-
checkIsBatchFullEvery := time.NewTicker(5 * time.Second)
62-
defer checkIsBatchFullEvery.Stop()
63-
6461
havePartialBlock := false
6562
blockNum := startBlockNum
6663

@@ -226,23 +223,21 @@ func (se *serialExecutor) exec(ctx context.Context, execStage *StageState, u Unw
226223
if se.isApplyingBlocks {
227224
se.LogExecution()
228225
}
229-
case <-checkIsBatchFullEvery.C:
230-
if !se.isApplyingBlocks {
231-
break
232-
}
233-
isBatchFull := se.readState().SizeEstimateBeforeCommitment() >= se.cfg.batchSize.Bytes()
234-
needCalcRoot := isBatchFull || havePartialBlock
235-
// If we have a partial first block it may not be validated, then we should compute root hash ASAP for fail-fast
236-
// this will only happen for the first executed block
237-
havePartialBlock = false
238-
if !needCalcRoot {
239-
break
240-
}
226+
default:
227+
}
228+
229+
isBatchFull := se.isApplyingBlocks && se.readState().SizeEstimateBeforeCommitment() >= se.cfg.batchSize.Bytes()
230+
// havePartialBlock: partial first block isn't validated, compute root ASAP for fail-fast.
231+
needCalcRoot := se.isApplyingBlocks && (isBatchFull || havePartialBlock)
232+
havePartialBlock = false
233+
234+
if needCalcRoot {
241235
resetExecGauges(ctx)
242236
ok, times, err := computeAndCheckCommitmentV3(ctx, b.HeaderNoCopy(), rwTx, se.doms, se.cfg, execStage, false, se.logger, u)
243237
if err != nil {
244238
return nil, rwTx, err
245-
} else if !ok {
239+
}
240+
if !ok {
246241
return b.HeaderNoCopy(), rwTx, nil
247242
}
248243
resetCommitmentGauges(ctx)
@@ -258,7 +253,6 @@ func (se *serialExecutor) exec(ctx context.Context, execStage *StageState, u Unw
258253
if isBatchFull {
259254
return b.HeaderNoCopy(), rwTx, &ErrLoopExhausted{From: startBlockNum, To: blockNum, Reason: "block batch is full"}
260255
}
261-
default:
262256
}
263257

264258
select {

0 commit comments

Comments
 (0)