Skip to content

refactor(messaging): read the registry in the state machine - #12408

Open
pierugo-dfinity wants to merge 3 commits into
masterfrom
pierugo/messaging/registry-reader-in-state-machine
Open

pierugo-dfinity wants to merge 3 commits into
masterfrom
pierugo/messaging/registry-reader-in-state-machine

Conversation

@pierugo-dfinity

@pierugo-dfinity pierugo-dfinity commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Moves reading the registry from BatchProcessorImpl::process_batch() into StateMachineImpl::execute_round().

This change is motivated by the stacked #12409 which reads the registry for the new subnet ID in case of a subnet-split, instead of doing it only in the next round. Though without the current PR, we would have to introduce a special case for splitting batches in process_batch, whereas thanks to this change, we can read the registry inside the state machine's online_split.

No functional changes, except that blockmaker metrics are now observed before reading the registry, and the time taken in the read_registry phase is more accurately measured.

We put the RegistryReader behind a trait such that tests can mock it, instead of having to build an actual registry which saves a lot of test boilerplate code.

🤖 Generated with Claude Code, trimmed by me

Move registry reading from `BatchProcessorImpl::process_batch()` into
`StateMachineImpl::execute_round()`, behind a new `RegistryReader` trait
(implemented by the existing reader, renamed to `RegistryReaderImpl`).
`StateMachine::execute_round()` now only takes the state and the batch.

`BatchProcessorImpl` no longer needs a registry (nor its `RegistryClient`
type parameter), so its tests no longer set one up; the registry reading
tests construct a `RegistryReaderImpl` directly; and the state machine tests
use a mock `RegistryReader`.

No functional changes.

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

No active review issues are reported for the registry-read ownership refactor.

No open issues 🎉

What changed in this PR

Moves registry reads into the messaging state machine, preparing for the subnet-split metadata fix in #12409 without intended functional changes.

Changes:

  • Introduces a RegistryReader trait owned by StateMachineImpl.
  • Simplifies execute_round() to accept only state and batch, and relocates registry-read timing.
  • Separates registry-reader tests from batch-processor tests and adds mocked registry reads to state-machine tests.
File Description
rs/​messaging/​src/​state_machine/​tests.rs Adds mock registry readers and checks registry records populate state.
rs/​messaging/​src/​state_machine.rs Owns the registry reader and reads records at round start.
rs/​messaging/​src/​message_routing/​tests.rs Tests the registry reader directly and simplifies batch fixtures.
rs/​messaging/​src/​message_routing.rs Defines the reader trait and implementation; removes reader ownership from the batch processor.

Review effort: Balanced

pierugo-dfinity and others added 2 commits December 4, 2026 14:57
…t fixture

`StateMachineTestFixture` now holds the registry reader, rather than the
network topology that each test turned into one. The readers of
`test_fixture()` and `checkpoint_round_fixture()` (which now takes the batch
too) expect a single read, at the batch's registry version and for the own
subnet, before any other mock is called. `fake_registry_reader()` is inlined
into its one remaining caller, and `own_subnet_info()` now gives every
subnet a different node.

Also move the `registry_version` read in `process_batch()` next to the other
values taken from the batch before it is consumed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he batch's version

Rename `state_machine_populates_registry_records` to
`state_machine_populates_registry_records_at_batch_registry_version` and
have it use a registry version other than the `BatchBuilder` default, so
that it checks that the registry is read at the batch's registry version
(which `test_fixture()` expects).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/messaging/registry-reader-in-state-machine branch from 5d15831 to 6dc56df Compare December 4, 2026 15:04
@pierugo-dfinity
pierugo-dfinity marked this pull request as ready for review December 4, 2026 15:33
@pierugo-dfinity
pierugo-dfinity requested a review from a team as a code owner December 4, 2026 15:33
Copilot AI balanced review requested due to automatic review settings December 4, 2026 15:33
@zeropath-ai

zeropath-ai Bot commented Dec 4, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 6dc56df.

Security Overview
Detected Code Changes
Change Type Relevant files
Refactor ► rs/messaging/src/message_routing.rs
    Remove RegistryReader generic parameter from BatchProcessorImpl; switch to concrete RegistryReaderImpl; update BatchProcessorImpl to hold registry reader via concrete type and adjust creation accordingly
► rs/messaging/src/message_routing.rs
    Introduce RegistryReader trait and RegistryReaderImpl; adapt tests to use RegistryReaderImpl
► rs/messaging/src/message_routing.rs
    Rename RegistryReader to RegistryReaderImpl in various references and implement trait for RegistryReaderImpl
► rs/messaging/src/message_routing.rs
    Adjust BatchProcessor to implement trait without RegistryClient generic parameter
Enhancement ► rs/messaging/src/message_routing.rs
    Add RegistryReader trait with read_registry method and documentation
► rs/messaging/src/message_routing.rs
    Add RegistryReaderImpl struct and implement RegistryReader for it
► rs/messaging/src/message_routing.rs
    Add concrete registry_reader creation path in BatchProcessorImpl::new and wire through to StateMachineImpl
► rs/messaging/src/message_routing.rs
    Update try_to_read_registry and related tests to use RegistryReaderImpl directly rather than BatchProcessor's registry_reader
Bug Fix / Test Update ► rs/messaging/src/message_routing/tests.rs
    Adjust tests to reference RegistryReaderImpl and RegistryReader trait instead of BatchProcessor's internal registry reader
► rs/messaging/src/state_machine.rs
    Update imports to use RegistryReader trait and RegistryReader type; ensure StateMachineImpl constructs with RegistryReader
Other ► rs/messaging/src/message_routing.rs
    Adjust comments and documentation strings to reflect RegistryReaderImpl usage and trait-based design
► rs/messaging/src/message_routing.rs
    Update minimal batch generation helper and test scaffolding to align with RegistryReader changes

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

No active review issues are reported for the change moving registry reads into the messaging state machine.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants