Skip to content

Serve /node/state without blocking on NodeState::lock during snapshot installation - #8889

Open
Amaury Chamayou (achamayou) wants to merge 2 commits into
mainfrom
achamayou-legendary-tribble
Open

Amaury Chamayou (achamayou) wants to merge 2 commits into
mainfrom
achamayou-legendary-tribble

Conversation

@achamayou

@achamayou Amaury Chamayou (achamayou) commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

GET /node/state was converted into a non-transactional Command endpoint in #8490 so operators can monitor node progress before the KV store becomes ready. However, NodeState::state(), NodeState::get_startup_snapshot_seqno(), and NodeState::get_last_recovered_signed_idx() all acquired NodeState::lock, which complete_join_unsafe() and install_recovery_snapshot_and_start_unsafe() hold for the entire duration of snapshot deserialisation (StoreReadiness::InstallingSnapshot). On large snapshots, /node/state therefore stalled until deserialisation completed.

This PR separates the read-only progress fields polled by /node/state from NodeState::lock:

  • The coupled startup-state and private-recovery progress fields (state, recovery_target_seqno, and last_recovered_private_seqno) are published into a PublishedProgress snapshot guarded by a leaf mutex (progress_lock), with state_transition_lock serialising sm.advance(...) and publication across transition helpers.
  • The scalar progress fields (startup_seqno and last_recovered_signed_idx) are stored as single std::atomic members on NodeState, avoiding duplicate copies across internal writers, friend helpers, and non-blocking getters.

All state transitions and recovery/rollback progress updates publish promptly without holding progress_lock across snapshot deserialisation, ledger replay, KV operations, logging, or NodeState::lock acquisition, allowing /node/state to respond throughout both public ledger recovery and snapshot installation.

Safety and compatibility

  • progress_lock is strictly a data-only leaf lock: callers compute any KV/store values before acquiring it and perform only trivial field copies while holding it, preventing lock-order inversions with NodeState::lock or KV locks.
  • state_transition_lock serialises sm.advance(...) and published_progress updates in both advance_state() and advance_to_reading_private_ledger(), preventing a concurrent transition (such as complete_join_unsafe() vs. on_secrets_global_commit() -> begin_private_recovery()) from overwriting newer published state while preserving the ordering that sm advances before /node/state observes the new state.
  • NodeState::state() reads the published private-recovery target and last-recovered version atomically under progress_lock without dereferencing recovery_store, avoiding races across begin_private_recovery(), rollback, and recovery_store.reset() in recover_private_ledger_end_unsafe().

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.

🟡 Changes recommended

A state-publication race can overwrite newer private-recovery state and clear its fields, causing /node/state to hide recovery progress until recovery finishes.

1 open issue
What changed in this PR

Builds on #8490 to keep /node/state responsive during snapshot installation and ledger recovery.

Changes:

  • Publishes progress behind a dedicated mutex instead of NodeState::lock.
  • Adds regression coverage for non-blocking queries and recovery progress.
  • Documents endpoint availability during snapshot installation.

Custom instructions used

  • .github/instructions/reviewing.instructions.md
File Description
src/​node/​rpc/​test/​node_frontend_test.cpp Tests responsiveness and recovery progress reporting.
src/​node/​recovery_decision_protocol.cpp Reads recovered progress through its accessor.
src/​node/​node_state.h Publishes state and progress under a dedicated mutex.
doc/​releases/​migration_7_x_to_8_x.rst Clarifies availability during snapshot installation.
doc/​operations/​recovery.rst Updates recovery-monitoring guidance.

Review effort: Balanced

Comment thread src/node/node_state.h Resolved
Copilot AI balanced review requested due to automatic review settings December 2, 2026 13:05

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.

🟡 Changes recommended

A race between join and private recovery can overwrite newer recovery state and clear its fields, causing /node/state to hide active private recovery.

2 open issues

Review effort: Balanced

Comment thread src/node/node_state.h Resolved
Base automatically changed from achamayou-issue-6188-check-snapshot-isolation-of-signature-tr-33860f to main December 3, 2026 15:11
…snapshot install

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:11

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.

🟡 Changes recommended

Critical issues remain: a test helper omits index publication, causing exceptions, and unsynchronized state transitions can overwrite recovery state and make /node/state report incorrectly.

4 open issues

Review effort: Balanced

Comment thread src/node/node_state.h Resolved
Comment thread src/node/recovery_decision_protocol.cpp Resolved
Serialize sm.advance() and published_progress updates under a dedicated
state_transition_lock so concurrent transitions (e.g. a public-only join
completing while a global commit hook starts private recovery) cannot
overwrite newer published progress, while keeping progress_lock a strict
data-only leaf lock.

Replace duplicated startup_seqno and last_recovered_signed_idx fields
with single std::atomic members on NodeState so internal writers, friend
helpers, and non-blocking getters always share one source of truth.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 047a18894fd2487bb74f63dfd52b95b3
Copilot AI balanced review requested due to automatic review settings December 3, 2026 16:56

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 remain for the snapshot-installation monitoring changes.

No open issues 🎉

4 resolved since last review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants