Skip to content

refactor(pxe): migrate PrivateEventStore to BaseStagingStore - #110

Merged
nchamo merged 3 commits into
mainfrom
nchamo/private-event-store-base-staging
Sep 4, 2026
Merged

refactor(pxe): migrate PrivateEventStore to BaseStagingStore#110
nchamo merged 3 commits into
mainfrom
nchamo/private-event-store-base-staging

Conversation

@nchamo

@nchamo nchamo commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Moves PrivateEventStore onto BaseStagingStore (fix(pxe): per-change-set staging store that rejects dead change sets #47): the per-change-set maps, locks, commitChangeSet/discardChangeSet and the rollback guard now come from the base class, leaving flushChangeSet and applyRollback.
  • Not a pure refactor. getPrivateEvents takes a changeSetId and layers staged events over the committed index, and PXE.getPrivateEvents reads inside its runSynced block rather than after the commit. Same events either way: the sync that produces them stages them under that change set.
  • Removes eventIdsAtBlock, which had no production callers, as fix(pxe): per-change-set staging store that rejects dead change sets #47 did for NoteStore.nullifiersOfNotesAtBlock.
  • Last store in StagedWriteCoordinator's registry, so StagedStore.beginChangeSet is now required, resolving its TODO.
  • kv schema unchanged; backwards-compatibility snapshots untouched.

Stacked on #108.

@nchamo nchamo self-assigned this Aug 28, 2026
@nchamo nchamo added ci-draft Run CI on this draft PR ci-no-fail-fast Do not cancel remaining jobs on first failure labels Aug 28, 2026
@nchamo
nchamo marked this pull request as ready for review August 28, 2026 19:58
@nchamo
nchamo requested a review from nventuro August 28, 2026 19:58
@nchamo
nchamo force-pushed the nchamo/private-event-store-base-staging branch from 14ce305 to 3e2d9de Compare August 28, 2026 20:04
@nventuro
nventuro force-pushed the nchamo/private-event-store-base-staging branch from 3e2d9de to 21d7d81 Compare August 28, 2026 21:17
@nchamo
nchamo force-pushed the nchamo/private-event-store-base-staging branch from 21d7d81 to b851976 Compare September 4, 2026 02:51

// anchorBlockNumber is set during the operation and fixed to whatever it is after a block sync
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockHeader.getBlockNumber()).validate(filter);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There's a small behavioral change in that if this validation fails then we discard the sync result, even though everything that happens from this point on is read-only. We could technically commit the changeset after the contract sync runs, but we still need to read from the db (and hence keep the PXE lock). Probably not worth doing anything about now, but it's an interesting pattern.

Comment on lines +150 to +156
[...changeSet.entries()]
.filter(
([eventId, stagedEvent]) =>
!eventReadPromises.has(eventId) &&
this.#keyFor(stagedEvent.contractAddress, stagedEvent.eventSelector) === key,
)
.forEach(([eventId, stagedEvent]) => eventReadPromises.set(eventId, Promise.resolve(stagedEvent)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This reads a bit strange. We have the same code in note store in a plain for loop and I find that more readable. Your call

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I actually asked Claude to do it this way, I didn't like the loop + the conditional inside. Feels more "functional" this way

Base automatically changed from nchamo/sender-tagging-base-staging to main September 4, 2026 18:12
@nchamo
nchamo force-pushed the nchamo/private-event-store-base-staging branch from 1e92e5b to aeaac77 Compare September 4, 2026 18:12
@nchamo
nchamo merged commit 4dfe50f into main Sep 4, 2026
4 checks passed
@nchamo
nchamo deleted the nchamo/private-event-store-base-staging branch September 4, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on this draft PR ci-no-fail-fast Do not cancel remaining jobs on first failure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants