Skip to content

feat: advertise maintenance mode in the info event, republish on change (Phase 3) - #935

Merged
grunch merged 2 commits into
mainfrom
feat/maintenance-mode-phase3
Sep 2, 2026
Merged

feat: advertise maintenance mode in the info event, republish on change (Phase 3)#935
grunch merged 2 commits into
mainfrom
feat/maintenance-mode-phase3

Conversation

@grunch

@grunch grunch commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

Phase 3 of the maintenance-mode / Lightning node migration spec (#932, §3.5): client signalling.

  • maintenance_mode tag in the NIP-33 info event (info_to_tags(ln_status, maintenance)), always emitted as "true"/"false" like bond_enabled, so clients can tell "maintenance off" from "older daemon" and warn the user before mining PoW for a new-order/take that will be rejected. Documented in the protocol book (docs: document maintenance mode (cant-do reason + info-event tag) protocol#57).
  • Immediate republish. MaintenanceState gains a tokio::sync::Notify signalled after every successful set (changed() resolves on it; a permit is kept if nobody is waiting yet; a failed write signals nothing). job_info_event_send reads the flag on every tick and waits on select!(interval, changed()), factored into wait_for_info_wake so the wake rule is unit-testable without a nostr client. Result: a SetMaintenanceMode is visible to clients right away instead of after publish_mostro_info_interval.
  • Log line at each publish says whether maintenance is ON.

Independent of Phase 2 apart from sharing MaintenanceState; the RPC needs no change because set itself notifies.

Test plan

  • info_to_tags_emits_maintenance_mode_false_by_default / _true_when_enabled
  • set_wakes_a_changed_waiter_and_stores_a_permit — waiter registered before the change wakes; a change before the wait is still observed; a failed set (closed pool) does not signal
  • info_wake_fires_on_maintenance_change_before_the_interval — 1 h interval, flag flips, helper returns MaintenanceChanged within 1 s
  • info_wake_falls_back_to_the_interval — paused clock, returns Interval
  • cargo test: 1276 passed · cargo clippy --all-targets --all-features clean · cargo fmt --check

🤖 Generated with Claude Code

https://claude.ai/code/session_0148ZQvcc8LfrsTYx9VAiSxS

Summary by CodeRabbit

  • New Features

    • Added maintenance-mode status to published service information.
    • Information updates are now republished immediately when maintenance mode changes, rather than waiting for the next scheduled update.
    • Maintenance status changes are reliably reflected in event metadata.
  • Bug Fixes

    • Ensured rapidly successive information updates receive increasing timestamps, so newer updates are recognized correctly.

…ge (Phase 3)

- info_to_tags(ln_status, maintenance) always emits ["maintenance_mode",
  "true"|"false"] so clients can warn before mining PoW for a request
  that will be rejected (protocol book: MostroP2P/protocol#57).
- MaintenanceState gains a Notify signalled after every successful set;
  changed() resolves on it (permit kept if nobody is waiting yet, nothing
  on a failed write).
- job_info_event_send reads the flag each tick and waits on
  select!(interval, changed()) via a testable wait_for_info_wake helper,
  so a SetMaintenanceMode is visible to clients at once instead of after
  publish_mostro_info_interval.

Spec: docs/MAINTENANCE_MODE_LN_MIGRATION.md §3.5 (#932).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148ZQvcc8LfrsTYx9VAiSxS
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T01:19:38.407362Z 137d617 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 137d617a1e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/scheduler.rs
Comment on lines +243 to +244
if wait_for_info_wake(tokio::time::Duration::from_secs(interval), &maintenance).await
== InfoWake::MaintenanceChanged

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Give immediate republishes strictly increasing timestamps

When maintenance changes less than one second after the preceding info publication, this wake path creates the replacement through new_info_event, which uses second-precision Timestamp::now(). Both kind-38385 events can therefore have the same created_at; NIP-01 then selects the lower event ID rather than the later publication, so a relay may retain the old maintenance_mode value until the next interval. Use a per-info-event monotonic timestamp, as the dispute and order replacement paths already do.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 7202711: new_info_event now stamps created_at through a per-d-tag monotonic registry (monotonic_info_event_timestamp, same monotonic_created_at rule as orders and disputes) instead of passing None. Tests: registry bumps a same-second republish and lets wall clock win once ahead; two consecutive new_info_event calls yield strictly increasing created_at.

A maintenance-mode flip republishes the kind-38385 info event at once;
if that lands in the same second as the previous publish both revisions
tie on created_at and NIP-01 keeps the lower event id, possibly the stale
maintenance_mode value. new_info_event now stamps created_at through the
same monotonic registry the order and dispute events use, keyed by the
info event's d tag.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148ZQvcc8LfrsTYx9VAiSxS
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: fc5c8dd3-6b6f-40a8-a9c1-532365488524

📥 Commits

Reviewing files that changed from the base of the PR and between 5e5c559 and 7202711.

📒 Files selected for processing (4)
  • src/app/maintenance.rs
  • src/nip33.rs
  • src/scheduler.rs
  • src/util.rs

Walkthrough

Changes

The PR adds change notifications to MaintenanceState. The scheduler republishes the Mostro info event when maintenance changes. Info events always include maintenance_mode and use monotonic timestamps.

Maintenance-aware info events

Layer / File(s) Summary
Maintenance change notification
src/app/maintenance.rs
MaintenanceState signals successful writes and exposes changed(). Tests cover wake-ups, stored permits, and failed writes.
Info event tags and timestamps
src/nip33.rs, src/util.rs
Info events include the maintenance flag. A per-identifier timestamp registry orders same-second republishes. Tests cover both behaviors.
Maintenance-triggered scheduler publishing
src/scheduler.rs
The info job reads maintenance state and waits for either the regular interval or a maintenance change before publishing. Tests cover both wake paths.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: arkanoider, catrya

Poem

A rabbit toggles the service light,
The tags now tell the mode just right.
A signal hops, the scheduler knows,
Ordered timestamps mark each pose.
Fresh events spring without delay.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/maintenance-mode-phase3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@grunch
grunch merged commit f1d3f2f into main Sep 2, 2026
7 of 8 checks passed
@grunch
grunch deleted the feat/maintenance-mode-phase3 branch September 2, 2026 01:24
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.

1 participant