Skip to content

async updateBase#4174

Draft
advaita-saha wants to merge 1 commit intomasterfrom
smooth-fcu
Draft

async updateBase#4174
advaita-saha wants to merge 1 commit intomasterfrom
smooth-fcu

Conversation

@advaita-saha
Copy link
Copy Markdown
Contributor

updateBase is now async, yielding once after db.persist() and once every 16 ancestors during the cleanup loop — so a full 256-block batch gets

~17 yield points instead of 0.

  • Reordered so c.base / c.baseTxFrame pointer updates happen before the cleanup burst, with oldFrontier = base.parent captured first. If a shutdown cancels us mid-cleanup, ForkedChain invariants stay coherent.
  • Split wall-clock into persistMs + cleanupMs aggregated over the batch and surfaced in the existing "Finalized blocks persisted" log — the cheapest possible instrumentation to tell you at a glance whether future stalls are disk or cleanup.
  • processUpdateBase now awaits the async updateBase.

… every 16 ancestors during the cleanup loop — so a full 256-block batch gets

  ~17 yield points instead of 0.
  - Reordered so c.base / c.baseTxFrame pointer updates happen before the cleanup burst, with oldFrontier = base.parent captured first. If a shutdown
   cancels us mid-cleanup, ForkedChain invariants stay coherent.
  - Split wall-clock into persistMs + cleanupMs aggregated over the batch and surfaced in the existing "Finalized blocks persisted" log — the
  cheapest possible instrumentation to tell you at a glance whether future stalls are disk or cleanup.
  - processUpdateBase now awaits the async updateBase.
@advaita-saha advaita-saha requested a review from bhartnett April 24, 2026 12:30
@bhartnett
Copy link
Copy Markdown
Contributor

bhartnett commented Apr 24, 2026

@advaita-saha I find all the comments in the PR to be overly verbose. I would suggest removing most of them, just keeping the most necessary.

inc sinceYield
if sinceYield >= cleanupYieldChunk:
sinceYield = 0
await sleepAsync(0.milliseconds)
Copy link
Copy Markdown
Contributor

@bhartnett bhartnett Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be implemented in a simpler way. Why not just add an i index to the iterator and then if i mod 16 == 0 then run the sleep.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes agreed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe the removeBlockFromCache function could become async so you can simply avoid the sleep altogether.

@advaita-saha
Copy link
Copy Markdown
Contributor Author

advaita-saha commented Apr 24, 2026

I find all the comments in the PR to be overly verbose

Yes the comments are there mostly for me so intentionally verbose, as I am working on multiple branches with different things.
Will remove when the PR is finalized

let
finishTime = Moment.now()
runTime = (finishTime - startTime).milliseconds
let runTime = (finishTime - startTime).milliseconds
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove cleanupMs since that part is no longer blocking the event loop after this change.

Then runTime used here should just equal persistMs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants