Skip to content

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

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

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

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Aug 31, 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

  • Bug Fixes
    • Improved withdrawal queue processing when no pending withdrawals are available.
    • Avoided unnecessary processing in empty-queue scenarios, improving efficiency without changing user-visible behavior.

…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.
@github-actions github-actions Bot added this to the v4.2.0 milestone Aug 31, 2026
@coderabbitai

coderabbitai Bot commented Aug 31, 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: Pro Plus

Run ID: 21e1fc8d-f04c-4bd6-96b6-230c52809800

📥 Commits

Reviewing files that changed from the base of the PR and between 7c77247 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 handler now avoids counting withdrawal documents when no documents are queued and DEBUG tracing is disabled. The debug status-counting branch now relies on the earlier tracing guard.

Changes

Withdrawal queue processing

Layer / File(s) Summary
Guard debug-only document counting
packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs
The empty-document path returns early when DEBUG tracing is disabled. The status-counting branch uses the existing DEBUG guard.

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

Merge Risk: ⚪ Minimal · up to 05403

The change removes unnecessary historical withdrawal-document reads when debug logging is disabled while preserving withdrawal queue behavior and application state. No actionable merge-blocking risk remains beyond 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 a full withdrawal-document scan 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 unit tests (beta)
  • Create PR with unit tests

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.

@thepastaclaw

thepastaclaw commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

🕓 Ready for review — 12 ahead in queue (commit 05403a9)
Queue position: 13/33 · 2 reviews active
ETA: start ~07:00 UTC · complete ~08:04 UTC (median 1h 4m across 30 recent reviews; 2 slots)
Queued 9h 20m ago · Last checked: 2026-09-01 00:30 UTC

@PastaPastaPasta

Copy link
Copy Markdown
Member Author

Superseded by #4569, which is the same change from a branch in dashpay/platform rather than my fork.


🤖 Posted autonomously by Claude on behalf of pasta.

@PastaPastaPasta
PastaPastaPasta deleted the perf/withdrawal-doc-scan branch September 1, 2026 00:39
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