Skip to content

perf(drive-abci): don't read every withdrawal document to build a debug log line - #4569

Open
PastaPastaPasta wants to merge 1 commit into
v4.2-devfrom
perf/withdrawal-doc-scan
Open

perf(drive-abci): don't read every withdrawal document to build a debug log line#4569
PastaPastaPasta wants to merge 1 commit into
v4.2-devfrom
perf/withdrawal-doc-scan

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Sep 1, 2026

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

pool_withdrawals_into_transactions_queue_v1 reads every withdrawal document the chain has ever produced, on nearly every block, and throws the result away.

When nothing is queued — which is almost always — it calls fetch_oldest_withdrawal_documents, which passes limit: None. That deserializes every withdrawal document, groups them by status and sorts each group. The result feeds one tracing::debug! line and is otherwise discarded.

Withdrawal documents are never removed, so the cost grows with chain history. Replaying mainnet with per-block phase timing:

height window cost of this call
0–25k 0 µs
50k 43 µs
100k 375 µs
150k 3,741 µs
175–200k 4,791 µs

Against roughly 7,000 µs for everything else in a block put together, and still climbing at 200k. Every other per-block phase is flat with depth; this one is the entire slope.

What was done?

Return before the diagnostic query when a DEBUG line would not be emitted. The counting block below it was already guarded by tracing::enabled!; the expensive fetch that feeds it was not.

How Has This Been Tested?

Replaying mainnet history from a local peer, genesis to 424,981, comparing against v4.2-dev. Every committed app hash matched between the two runs across all 424,971 heights, and the final app hash matched an independent reference sync.

cargo test -p drive-abci --lib withdrawal — 176 passed.

Breaking Changes

None. The skipped work only ever fed a log line that is off by default.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
    • Improved withdrawal processing efficiency by avoiding unnecessary historical data reads when debug logging is disabled.
    • Reduced overhead during block processing, particularly for workloads with extensive withdrawal history.

…ug log line

pool_withdrawals_into_transactions_queue_v1 fetches every withdrawal document the chain has ever produced, groups them by status and sorts each group, on any block with nothing queued — nearly every block — and then throws the result away unless debug logging is on.

fetch_oldest_withdrawal_documents passes limit: None, and withdrawal documents are never removed, so the cost grows with chain history: measured at 4.8 ms per block by height 200,000 on mainnet and still climbing, against about 7 ms for everything else in a block put together. Do the work only when the line it feeds will be emitted.
@thepastaclaw

thepastaclaw commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

🕓 Ready for review — 7 ahead in queue (commit 05403a9)
Queue position: 8/52 · 2 reviews active
ETA: start ~18:29 UTC · complete ~19:24 UTC (median 54m across 30 recent reviews; 2 slots)
Queued 2d 15h ago · Last checked: 2026-09-03 15:40 UTC

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: f9a80e5f-6fcd-488b-a152-c7595c1636fc

📥 Commits

Reviewing files that changed from the base of the PR and between c0e9a86 and 05403a9.

📒 Files selected for processing (1)
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The withdrawal queue now checks debug logging before fetching historical withdrawal documents. The status-counting branch relies on this earlier check.

Changes

Withdrawal queue processing

Layer / File(s) Summary
Gate historical withdrawal lookup
packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs
The method returns early when debug logging is disabled. The existing status-counting block now uses a plain else branch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 05403

This change removes an unnecessary history-wide read from the normal no-withdrawal path while preserving withdrawal processing and externally visible behavior. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: quantumexplorer, shumkov

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main performance change: avoiding reads of every withdrawal document when building a debug log line.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 perf/withdrawal-doc-scan

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.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.01%. Comparing base (7c77247) to head (05403a9).
⚠️ Report is 8 commits behind head on v4.2-dev.

Files with missing lines Patch % Lines
...pool_withdrawals_into_transactions_queue/v1/mod.rs 22.22% 7 Missing ⚠️

❌ Your patch check has failed because the patch coverage (22.22%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4569      +/-   ##
============================================
- Coverage     87.68%   85.01%   -2.68%     
============================================
  Files          2778     2786       +8     
  Lines        359190   369647   +10457     
============================================
- Hits         314960   314237     -723     
- Misses        44230    55410   +11180     
Components Coverage Δ
dpp 83.94% <ø> (-5.12%) ⬇️
drive 83.91% <ø> (-2.71%) ⬇️
drive-abci 89.53% <22.22%> (-0.35%) ⬇️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.92% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 41.28% <ø> (-7.37%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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