refactor(ntx-builder): replace dataless Notify with per-account watch#2301
refactor(ntx-builder): replace dataless Notify with per-account watch#2301SantiagoPittella wants to merge 7 commits into
Conversation
1976ec1 to
70a3d2d
Compare
Mirko-von-Leipzig
left a comment
There was a problem hiding this comment.
Thank you!
This is beginning to get quite complex. Not your fault; but I am wondering if I made a mistake advocating for this sort of actor model over a more centralized process. lmkwyt - I'll try think about whether its just the nature of the database access model.
| // coordinator pushes a view to every actor on every committed block, so a relative timer | ||
| // would restart on each update and a workless actor would never expire on an active chain. | ||
| // The deadline is only pushed back when the actor actually executes a transaction. |
There was a problem hiding this comment.
Is this still accurate? Does it wake every actor, or only every actor impacted by the block?
There was a problem hiding this comment.
Ah. I see that notes may become viable after some period and therefore require block notifications?. That's rather frustrating.
There was a problem hiding this comment.
Yeah, it is still accurate. It wakes every active actor on every committed block, not just the ones the block touched. That's deliberate. A note can become viable purely from the chain tip advancing
The part that used to be expensive was that each of those wakeups hit SQLite to re-derive state. But that's what this PR removes and it is entirely in memory from the pushed AccountView, and no-ops when there's no new work and no due retry. So we keep the per-block wake but it's now an in-memory compare rather than a DB query per actor per block.
I agree that the complexity here is inherent to the DB access model plus the per-block retry/expiry. And now that we use the block subscription and don't simply just notify the actors and wait for them to process things, having a centralized process with a map like |
Closes #2259
Summary
Replaces the dataless
Notifythe ntx-builder coordinator used to wake account actors with a per-accountwatch::channel<AccountView>that carries the committed-block state to each actor directly.Why:
How:
AccountView { chain_tip, last_committed_tx, notes_seen }per account via a watch channel. Fields are cumulative, so an actor that slept through several blocks reads one summarised view and answers everything in memory.account_last_txquery.available_notesnow also returns next_retry_block. Actors schedule a single re-check instead of polling each block.biasedselect! + an authoritative account_has_pending_notes recheck on reap, replacing the old Notify-permit trick.Changelog