Skip to content

upstream of 0.22.5 changes#1429

Merged
gilescope merged 9 commits into
mainfrom
giles-rollup-0.22.5
Apr 27, 2026
Merged

upstream of 0.22.5 changes#1429
gilescope merged 9 commits into
mainfrom
giles-rollup-0.22.5

Conversation

@gilescope

@gilescope gilescope commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Overview

Backports the four cNIGHT db-sync observation perf commits from PR #1365 (which landed on release/node-0.22.5) onto main. The companion #934 (multi-asset cache) is already on main as 17ad5e8b, so this PR contains only the perf delta.

Net effect: significantly lower postgres CPU / query latency during cNIGHT observation, no behavioural change.

Commits

  • Increase performance of cNight db-sync queries — pre-queries coarse tx / tx_out / ma_tx_out id bounds for the block-range window, then constrains the four observation queries (registration / deregistration / asset-create / asset-spend) by primary-key range. Postgres can prune rows before the expensive joins. Introduces PagedQuery and QueryBounds.
  • Add tx_in indexes as well — adds the tx.id bounding to the tx_in-keyed queries (spend / deregistration) so they benefit from the same pruning.
  • refactor: use sqlx::query_as! macro for cNight observation queries — restores compile-time query verification against the db-sync schema via the .sqlx prepared cache.
  • chore: replace sqlx::query_as! with runtime form in get_block_by_hash — needed because the cherry-pick landed in a branch whose .sqlx cache key changed after trailing-whitespace normalisation; runtime form avoids the compile-time DB check.
  • fix: should be debug not warn — drops the leftover log::warn!("Bounds:…") from the perf commit down to debug!.

Supersedes / overlaps

Resolution note

The cherry-pick of the Increase performance commit conflicted on data_source/cnight_observation.rs: main has the start_sub_query_timer metrics infrastructure (added after release/node-0.22.5 branched), so the new bounds queries were wrapped in matching cnight_get_low_bounds / cnight_get_high_bounds timers for consistency with the rest of that function.

🗹 TODO before merging

  • Ready

📌 Submission Checklist

  • All commits are signed off (git commit -s) for the DCO
  • 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 (changes/changed/cnight-query-coarse-bounds.md)
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant) — N/A, no public API change
  • Updated AGENTS.md if build commands, architecture, or workflows changed — N/A
  • No new todos introduced

🧪 Testing Evidence

Observed reduced db-sync query times on a live cNIGHT observation workload (originally measured against release/node-0.22.5 on PR #1365).

  • Additional tests are provided (if possible)

🔱 Fork Strategy

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

Links

#1429

@gilescope gilescope enabled auto-merge April 27, 2026 13:09
Lech Głowiak and others added 9 commits April 27, 2026 15:41
First query for coarse bounds of tx, tx_out and ma_tx_out tables and use
them in the 'business' queries to reduce size of tables before joins are
made.

Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
Convert the runtime query_as form back to the compile-time macro form
for all queries in cnight_observation.rs. This restores static query
verification against the db-sync schema via the .sqlx prepared cache.

Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
…y_hash

Needed because cherry-pick landed in a branch whose .sqlx prepared cache
does not include this query (cached key changed after trailing-whitespace
normalisation). Using the runtime form avoids the compile-time DB check
entirely and matches the pattern used elsewhere in #934.

Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
…y args

Replaces the seven repeated arguments (start, end, limit, offset, low_bound,
high_bound + per-call locals) on the four cNight observation query helpers
with a single `PagedQuery<'a>` struct.

Squashed from PR #1365 fixup commits b9497e8 + b146dc2 + b1ffce6
(originally landed as "fix: cargo clippy" / "Apply suggestion").
Also drops the now-unused `QueryBounds` import in the data_source module.

Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Tomasz Bartos <tomasz.bartos@shielded.io>
Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope gilescope force-pushed the giles-rollup-0.22.5 branch from ef9460d to 763912a Compare April 27, 2026 14:42
@gilescope

Copy link
Copy Markdown
Contributor Author

fixed unverified commits.

@gilescope gilescope added this pull request to the merge queue Apr 27, 2026
Merged via the queue into main with commit 05ed697 Apr 27, 2026
33 checks passed
@gilescope gilescope deleted the giles-rollup-0.22.5 branch April 27, 2026 15:46
@gilescope gilescope mentioned this pull request Apr 27, 2026
15 tasks
gilescope added a commit that referenced this pull request Apr 27, 2026
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.

5 participants