feat: commit current fork#21908
Conversation
a7e9e38 to
59c8fd1
Compare
73b1f3b to
86238e0
Compare
01f788b to
6cbfdad
Compare
spalladino
left a comment
There was a problem hiding this comment.
Reviewed the ts side of things. Looks good, but left a few comments.
| await worldState.handleL2BlockAndMessages(block, messages); | ||
| } | ||
|
|
||
| await tempFork.close(); |
There was a problem hiding this comment.
We don't need to close it explicitly because the commit_fork already does, right?
There was a problem hiding this comment.
Yes, in happy case we close them in commit_fork. Also we close them on TS in finally clause in checkpoint_proposal_job.ts or when we do setFork
| // Register the fork so SYNC_BLOCK can commit it instead of recalculating. | ||
| this.worldState.registerForkForBlock(block.archive.root, checkpointBuilder.getForkId()); | ||
|
|
||
| // If this is the last block, exit the loop so we can build the checkpoint and start collecting attestations. |
| // sync and reuse the current fork for the next block. | ||
| if (!this.config.skipPushProposedBlocksToArchiver) { | ||
| await this.worldState.syncImmediate(blockNumber); | ||
| const newFork = await this.worldState.fork(undefined, { closeDelayMs: 12_000 }); |
There was a problem hiding this comment.
Let's always be explicit on the blocknumber (and block hash) for forking, just in case. I wouldn't want to be in a situation where a reorg hits and changes world-state underneaths the checkpoint proposal job.
There was a problem hiding this comment.
Also, who's responsibility is it to close this fork?
| if (!this.config.skipPushProposedBlocksToArchiver) { | ||
| await this.worldState.syncImmediate(blockNumber); | ||
| const newFork = await this.worldState.fork(undefined, { closeDelayMs: 12_000 }); | ||
| await checkpointBuilder.setFork(newFork); |
There was a problem hiding this comment.
I'm not sure I like this setFork call inbetween blocks. If now we have to supply a new fork for each block we build, can't we make the fork an argument of the buildBlock method, rather than a field that we need to re-set before each call?
| // COMMIT_FORK runs on the canonical queue, but we need to clean up the fork's queue | ||
| const actualForkId = (body as { forkId: number }).forkId; | ||
| const forkQueue = this.queues.get(actualForkId); | ||
| if (forkQueue) { | ||
| await forkQueue.stop(); | ||
| this.queues.delete(actualForkId); | ||
| } |
There was a problem hiding this comment.
Should this honor the closeDelay?
| if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver === false) { | ||
| this.worldState.registerForkForBlock(reexecutionResult.block.archive.root, fork.forkId); | ||
| await this.blockSource.addBlock(reexecutionResult.block); | ||
| await this.worldState.syncImmediate(blockNumber); |
There was a problem hiding this comment.
Heads up this syncImmediate may fail. Given this is an optimization, let's have a trySyncImmediate that swallows the error so we can carry on if the sync fails.
There was a problem hiding this comment.
I'm not sure it's needed. As I understand it can fail only if something is wrong with world state. I'm not sure we can just move on in this case
| // Close forks to release native resources. Already-committed forks silently handle "Fork not found". | ||
| const currentFork = checkpointBuilder?.getFork(); | ||
| if (currentFork && currentFork !== fork) { | ||
| await currentFork.close(); | ||
| } | ||
| await fork?.close(); |
There was a problem hiding this comment.
I'd expect this to be handled by the checkpoint builder maybe? Looks odd such explicit handling of forks in here.
|
Also, in case it helps, some notes from Claude Bugs: TypeScriptBug 1 (Medium): WorldStateOpsQueue leak after COMMIT_FORK + subsequent close()
In a proposer building 3 blocks per checkpoint, at least 2 orphan queues are created per checkpoint. Over hours of operation, this grows unbounded. Fix: Either wrap the post- Bug 2 (Low):
|
2789222 to
3438b2d
Compare
refactor simplify buildOne fix formatting
3438b2d to
72db43d
Compare
|
Comments on Claude review: Agree on 1 and 4. All other issues are fixed |
Ref: A-311
pruning metadata, and destroys the fork after commit.
instead of SYNC_BLOCK, with automatic fallback if the commit fails.