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
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Backport of #1432 to
release/node-0.22.5.The cNight observation Inherent Data Provider was querying cardano-db-sync from
NextCardanoPositionall 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.CardanoBlockWindowSizealready exists as runtime storage onpallet-cnight-observation(default 1000) and is already exposed viaCNightObservationApi::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
MidnightCNightObservationInherentDataProvider::newreadsblock_window_sizefrom the runtime API.MidnightCNightObservationDataSource::get_utxos_up_to_capacitytakes a newblock_window_size: u32parameter.start + block_window_size. When tip is closer thanstart + window, behavior is unchanged.db::get_block_by_block_nohelper is added (uses runtime-checkedsqlx::query_asso it doesn't require regenerating the offline sqlx cache).u32::MAXto preserve its existing full-history scan.DEFAULT_CARDANO_BLOCK_WINDOW_SIZEconstant in the IDP module is removed.The cap on
endalso tightens theget_high_boundsinteger-id ranges that constraintx/tx_out/ma_tx_out/tx_injoins, so each query benefits twice from the smaller window.🗹 TODO before merging
📌 Submission Checklist
🧪 Testing Evidence
SQLX_OFFLINE=true cargo check -p midnight-primitives-mainchain-follower— cleanSKIP_WASM_BUILD=1 SQLX_OFFLINE=true cargo check -p midnight-node— cleancargo fmt -p midnight-primitives-mainchain-follower -p midnight-node— no diffFunctional 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
bpsto recover to normal AURA cadence.Please describe any additional testing aside from CI:
🔱 Fork Strategy
Node-client behavior change only — the runtime API surface is unchanged (the
get_cardano_block_window_sizeAPI 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.Links