Skip to content

fix(cnight-observation): bound IDP queries by CardanoBlockWindowSize (0.22.5 backport)#1433

Open
skylar-simoncelli wants to merge 2 commits intorelease/node-0.22.5from
skylar/bound-cnight-observation-window-0.22.5
Open

fix(cnight-observation): bound IDP queries by CardanoBlockWindowSize (0.22.5 backport)#1433
skylar-simoncelli wants to merge 2 commits intorelease/node-0.22.5from
skylar/bound-cnight-observation-window-0.22.5

Conversation

@skylar-simoncelli
Copy link
Copy Markdown
Contributor

Overview

Backport of #1432 to release/node-0.22.5.

The cNight observation Inherent Data Provider was querying cardano-db-sync from NextCardanoPosition all the way to the current Cardano tip on every Midnight block. For sparse assets like cNight — which appear in only a tiny fraction of Cardano outputs — this caused db-sync queries that effectively scanned the entire Cardano history on every 6-second Midnight block, blocking block import to ~0.1 bps whenever the IDP's start position fell behind tip.

CardanoBlockWindowSize already exists as runtime storage on pallet-cnight-observation (default 1000) and is already exposed via CNightObservationApi::get_cardano_block_window_size, but the IDP never actually read it. The "window" was effectively [start, ∞). This PR finishes that wiring on the 0.22.5 release branch.

Change

  1. MidnightCNightObservationInherentDataProvider::new reads block_window_size from the runtime API.
  2. MidnightCNightObservationDataSource::get_utxos_up_to_capacity takes a new block_window_size: u32 parameter.
  3. The data source clamps the query upper bound to start + block_window_size. When tip is closer than start + window, behavior is unchanged.
  4. A new db::get_block_by_block_no helper is added (uses runtime-checked sqlx::query_as so it doesn't require regenerating the offline sqlx cache).
  5. The genesis-creation tool passes u32::MAX to preserve its existing full-history scan.
  6. The previously-unused DEFAULT_CARDANO_BLOCK_WINDOW_SIZE constant in the IDP module is removed.

The cap on end also tightens the get_high_bounds integer-id ranges that constrain tx/tx_out/ma_tx_out/tx_in joins, so each query benefits twice from the smaller window.

🗹 TODO before merging

  • Ready

📌 Submission Checklist

  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason:
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • Updated AGENTS.md if build commands, architecture, or workflows changed
  • No new todos introduced

🧪 Testing Evidence

  • SQLX_OFFLINE=true cargo check -p midnight-primitives-mainchain-follower — clean
  • SKIP_WASM_BUILD=1 SQLX_OFFLINE=true cargo check -p midnight-node — clean
  • cargo fmt -p midnight-primitives-mainchain-follower -p midnight-node — no diff

Functional verification: replace the running node binary with this build on a node that's currently stuck at 0.0–0.1 bps with ~118s db-sync queries. Expect query latency to drop to sub-second and bps to recover to normal AURA cadence.

Please describe any additional testing aside from CI:

  • Additional tests are provided (if possible)

🔱 Fork Strategy

Node-client behavior change only — the runtime API surface is unchanged (the get_cardano_block_window_size API already exists in 0.22.5 and is implemented; only its consumer changed). Old nodes continue to function with the existing slow behavior; new nodes use the bounded window.

  • Node Runtime Update
  • Node Client Update
  • Other:
  • N/A

Links

Backport of #1432 to release/node-0.22.5.

The cNight observation IDP was querying cardano-db-sync from
NextCardanoPosition all the way to the current Cardano tip on every
Midnight block. For sparse assets like cNight, this caused multi-minute
db-sync queries that scanned essentially the full Cardano history on
each Midnight block, blocking block import to ~0.1 bps when the IDP's
start position was far behind tip.

CardanoBlockWindowSize already exists as runtime storage and is exposed
via CNightObservationApi::get_cardano_block_window_size, but the IDP
never read it. Read it in the IDP, thread it through the data source
trait, and clamp the query upper bound to start + window. The
genesis-creation tool passes u32::MAX to keep its full-history scan.

Removes the unused DEFAULT_CARDANO_BLOCK_WINDOW_SIZE constant in the
IDP module since the value now comes from the runtime API.
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.

1 participant