Skip to content

refactor(nns-delegation): publish the NNS delegation builder behind an Arc - #12096

Closed
pierugo-dfinity wants to merge 4 commits into
masterfrom
pierugo/delegations/arc-builder
Closed

pierugo-dfinity wants to merge 4 commits into
masterfrom
pierugo/delegations/arc-builder

Conversation

@pierugo-dfinity

Copy link
Copy Markdown
Contributor

Stacked on #12065.

What

The NNS delegation manager now publishes Option<Arc<NNSDelegationBuilder>> on its watch channel instead of Option<NNSDelegationBuilder>. A new method, NNSDelegationReader::builder(), returns an immutable snapshot of the latest builder.

Why

This is a preparatory step for verifying the NNS delegation embedded in query responses against the certified state the data certificate is built from. With a snapshot, the query handler can take an Option<Arc<NNSDelegationBuilder>> and does not need an NNSDelegationReader (i.e. a watch::Receiver) in its input. The snapshot is immutable, so the delegation that is verified is exactly the one that is built.

The change has two side benefits:

  • NNSDelegationReader::get_delegation and get_delegation_with_metadata now take the snapshot first, then verify and build the delegation. They no longer hold the watch channel's read lock during that work, so the manager's send_replace does not have to wait on readers.
  • The manager no longer deep-clones the whole builder each time it publishes a delegation. The builder holds the full certificate, its labeled tree and the precomputed delegations. PublishedDelegation::Present now stores an Arc, so #[allow(clippy::large_enum_variant)] could be dropped as well.

There is no behavior change.

Testing

Existing tests cover this change; the test harnesses were only updated to wrap builders in Arc. The following pass:

  • the affected Bazel targets (nns_delegation_manager, nns_delegation_reader, the public integration tests, pocket-ic-server-lib);
  • the PocketIC client tests.

🤖 Generated with Claude Code

pierugo-dfinity and others added 4 commits November 10, 2026 16:45
…n Arc

The delegation manager now publishes `Option<Arc<NNSDelegationBuilder>>`
on the watch channel, and `NNSDelegationReader::builder()` returns a cheap,
immutable snapshot of the latest builder.

This lets a consumer verify the delegation against a certified state and
build exactly the verified delegation without holding on to the channel,
e.g. the query handler can be handed a snapshot instead of a receiver.
It also means that:
- the reader's `get_delegation*` methods no longer hold the channel's read
  lock while verifying and building the delegation;
- the manager no longer deep-clones the builder every time it publishes one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

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.

🟢 Approval recommended

The shared-snapshot delegation refactor has no active review issues.

No open issues 🎉

What changed in this PR

This refactor publishes NNS delegation builders through shared Arc snapshots, preparing query handlers to verify and build delegations from the same immutable snapshot without retaining a watch receiver.

Changes:

  • Add NNSDelegationReader::builder() and release the watch read lock before verification and construction.
  • Share builders between the manager and watch channel, avoiding deep clones during publication.
  • Update PocketIC and HTTP endpoint test harnesses for the new channel type.
File Description
rs/​pocket_ic_server/​src/​pocket_ic.rs Wrap delegation builders in Arc for PocketIC request handlers.
rs/​http_endpoints/​public/​tests/​test.rs Adapt delegation-drift tests to publish shared builders.
rs/​http_endpoints/​public/​tests/​common/​mod.rs Update test channel types and builder initialization.
rs/​http_endpoints/​nns_delegation_reader/​src/​reader.rs Expose snapshots and use them outside the watch read lock.
rs/​http_endpoints/​nns_delegation_manager/​src/​nns_delegation_manager.rs Store and publish shared builders; remove the large-enum lint exemption.

Review effort: Balanced

Base automatically changed from pierugo/delegations/remove-unused-logger to master November 13, 2026 10:51
@pierugo-dfinity

Copy link
Copy Markdown
Contributor Author

Superseded: this commit was folded into #12064.

@pierugo-dfinity
pierugo-dfinity deleted the pierugo/delegations/arc-builder branch November 13, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants