Repository navigation
perf: fill the credit pool's block data cache at connect time - #8262
Conversation
|
✅ Final review complete — no blockers (commit a66dea7) · triage: critical |
|
No actionable comments were generated in the recent review. WalkthroughCredit-pool block-data extraction now uses a shared, mutex-protected LRU cache. The code caches only successfully extracted data. The credit-pool manager adds Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant SpecialTxProcessor
participant CCreditPoolManager
participant CreditPoolCache
SpecialTxProcessor->>CCreditPoolManager: CacheBlockData(block, block_index) when conditions pass
CCreditPoolManager->>CreditPoolCache: Store successfully extracted data
Suggested reviewers: Merge Risk:
|
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Changes requested: 1 blocker
- Clang builds fail when acquiring the new file-scope cache mutex —
src/evo/creditpool.cpp:61(new)
Impact: Developers and CI building with Clang thread-safety warnings treated as errors cannot compile the node, so the affected jobs cannot run their tests.
This change caches credit-pool data from the in-memory block as it connects, so the next block can reuse its predecessor’s data without rereading it from disk. The standard Linux and no-wallet tests passed; the macOS, Linux ASan, TSan, fuzz, and multiprocess builds failed in Clang’s thread-safety analysis.
🔴 1 blocking | 🟡 2 suggestion(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.2-sol(effort low) — The diff is a contained cache refactor that reuses the existing credit-pool data parser to populate the cache at block connect time without changing credit-pool rules. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(zai below 15% reserve: 5h 100% left, weekly 0% left) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— dash-core-commit-history (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `src/evo/creditpool.cpp`:
- [BLOCKING] src/evo/creditpool.cpp:61: Clang builds fail when acquiring the new file-scope cache mutex
Impact: Developers and CI building with Clang thread-safety warnings treated as errors cannot compile the node, so the affected jobs cannot run their tests.
The macOS, Linux ASan, TSan, fuzz, and multiprocess builds in CI run `46026761978` all stop at `creditpool.cpp:112` and `:135` with `calling function 'MaybeCheckNotHeld' requires negative capability '!cache_mutex' [-Werror,-Wthread-safety-analysis]`. Moving the mutex from function scope to file scope while leaving it a plain `Mutex` makes the first `LOCK` in each function require proof that the file-scope mutex is not held. The diagnostic is on lock acquisition, not on the cache accessor or the `if` initializer. Use `GlobalMutex`, which `sync.h` documents for this case: it selects the `LOCKS_EXCLUDED` overload without changing the mutex’s non-recursive behavior or the accessor’s held-lock requirement.
- [SUGGESTION] src/evo/creditpool.cpp:134-136: Reconnecting a block reparses credit-pool data that is already cached
Impact: Nodes reconnecting recent post-v20 blocks do another transaction scan and rebuild the unlock-index set if the cached entry survived the disconnect.
`CacheBlockData` decodes the coinbase and scans the transactions before checking the cache, and `insert` replaces the entry even when the hash is already present. The old lazy lookup returned a hit without doing that work. Skip extraction for hashes already in the cache. On a miss, normal validation can also reuse the checked coinbase balance and the diff’s withdrawal total and new indexes; keep the block extractor for paths such as replay that do not produce a validated diff.
In `src/evo/specialtxman.cpp`:
- [SUGGESTION] src/evo/specialtxman.cpp:992-994: Existing credit-pool tests do not detect a return to predecessor disk reads
Impact: If a later change stops populating the cache during connection, nodes can resume rereading each predecessor without failing the existing accounting and reorg checks.
The existing tests check balances and reorg outcomes, which are unchanged when reconstruction takes the disk fallback. Extend an existing asset-lock test to connect a prebuilt successor without first warming the predecessor through block assembly or a pool lookup. A hash-specific credit-pool debug message at the disk fallback would let the test verify that the predecessor is not read on the warm path and that cold reconstruction yields the same balance, withdrawal total, and unlock-index behavior, without asserting on timings.
| if (const std::optional<CreditPoolDataPerBlock> opt_block_data{ReadCreditData(block, block_index->nHeight)}) { | ||
| LOCK(::cache_mutex); | ||
| BlockDataCache().insert(block_index->GetBlockHash(), *opt_block_data); |
There was a problem hiding this comment.
🟡 Suggestion: Reconnecting a block reparses credit-pool data that is already cached
Impact: Nodes reconnecting recent post-v20 blocks do another transaction scan and rebuild the unlock-index set if the cached entry survived the disconnect.
CacheBlockData decodes the coinbase and scans the transactions before checking the cache, and insert replaces the entry even when the hash is already present. The old lazy lookup returned a hit without doing that work. Skip extraction for hashes already in the cache. On a miss, normal validation can also reuse the checked coinbase balance and the diff’s withdrawal total and new indexes; keep the block extractor for paths such as replay that do not produce a validated diff.
source: gpt-6.2-sol (phase2-reviewer: general, dash-core-commit-history)
| if (!fJustCheck && DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20)) { | ||
| m_cpoolman->CacheBlockData(block, pindex); | ||
| } |
There was a problem hiding this comment.
🟡 Suggestion: Existing credit-pool tests do not detect a return to predecessor disk reads
Impact: If a later change stops populating the cache during connection, nodes can resume rereading each predecessor without failing the existing accounting and reorg checks.
The existing tests check balances and reorg outcomes, which are unchanged when reconstruction takes the disk fallback. Extend an existing asset-lock test to connect a prebuilt successor without first warming the predecessor through block assembly or a pool lookup. A hash-specific credit-pool debug message at the disk fallback would let the test verify that the predecessor is not read on the warm path and that cold reconstruction yields the same balance, withdrawal total, and unlock-index behavior, without asserting on timings.
source: gpt-6.2-sol (phase2-reviewer: general, dash-core-commit-history)
39ebcf7 to
6497db2
Compare
|
This pull request has conflicts, please rebase. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
New on this head: The PR populates the credit-pool block-data cache from the in-memory block during connection, avoiding predecessor disk reads during subsequent pool construction. Since the prior review, the rewritten head changes the file-scope cache mutex to GlobalMutex; completed builds, lint, cppcheck, and platform checks pass, while ASAN, TSAN, and multiprocess test jobs remain in progress.
🟡 2 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Still open from earlier rounds (2)
- 🟡 Suggestion: Existing credit-pool tests do not detect a return to predecessor disk reads —
src/evo/specialtxman.cpp:992-994(thread) - 🟡 Suggestion: Reconnecting a block reparses credit-pool data that is already cached —
src/evo/creditpool.cpp:134-136(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — This changes consensus-adjacent block validation and caching logic in creditpool.cpp and specialtxman.cpp, but the contained performance optimization does not itself alter consensus rules, funds movement, cryptography, networking, or storage migrations. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— dash-core-commit-history (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `src/evo/specialtxman.cpp`:
- [SUGGESTION] src/evo/specialtxman.cpp:992-994: Existing credit-pool tests do not detect a return to predecessor disk reads
(carried; thread: https://github.com/dashpay/dash/pull/8262#discussion_r4721744374)
In `src/evo/creditpool.cpp`:
- [SUGGESTION] src/evo/creditpool.cpp:134-136: Reconnecting a block reparses credit-pool data that is already cached
(carried; thread: https://github.com/dashpay/dash/pull/8262#discussion_r4721744369)
ConstructCreditPool reads the previous block's CbTx balance and asset unlock amounts through a per-block cache keyed by block hash, but that cache was only filled by the disk read itself. During IBD the previous block is never in it, so every connected block re-read its predecessor from disk (one extra "Load block from disk" per block) and parsed its coinbase payload again. Record the data of the block being connected from the in-memory block, after its unlock transactions and coinbase have been checked, so the next block's pool construction finds it in the cache.
6497db2 to
a66dea7
Compare
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
New on this head: This head is a rebase of the existing performance change that populates the credit-pool block-data cache from the connected in-memory block; the substantive cache behavior is unchanged. No code checks have failed, while the source builds, lint, and several platform cache checks remain queued or in progress; Cppcheck and ClangFormat have passed.
🟡 2 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Still open from earlier rounds (2)
- 🟡 Suggestion: Existing credit-pool tests do not detect a return to predecessor disk reads —
src/evo/specialtxman.cpp:986-988(thread) - 🟡 Suggestion: Reconnecting a block reparses credit-pool data that is already cached —
src/evo/creditpool.cpp:143-145(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The change modifies consensus validation data flow in src/evo/creditpool.cpp, including the cache used by GetCreditDataFromBlock and the new CCreditPoolManager::CacheBlockData path, with nontrivial parsing and cache-concurrency behavior. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— dash-core-commit-history (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `src/evo/specialtxman.cpp`:
- [SUGGESTION] src/evo/specialtxman.cpp:986-988: Existing credit-pool tests do not detect a return to predecessor disk reads
(carried; thread: https://github.com/dashpay/dash/pull/8262#discussion_r4721744374)
In `src/evo/creditpool.cpp`:
- [SUGGESTION] src/evo/creditpool.cpp:143-145: Reconnecting a block reparses credit-pool data that is already cached
(carried; thread: https://github.com/dashpay/dash/pull/8262#discussion_r4721744369)
Issue being fixed or feature implemented
ConstructCreditPool reads the previous block's CbTx balance and asset unlock amounts through a per-block cache keyed by block hash, but that cache was only filled by the disk read itself. During IBD the previous block is never in it, so every connected block re-read its predecessor from disk (one extra "Load block from disk" per block) and parsed its coinbase payload again.
What was done?
Record the data of the block being connected from the in-memory block, after its unlock transactions and coinbase have been checked, so the next block's pool construction finds it in the cache.
How Has This Been Tested?
invalidate + reconsider 9k blocks on mainnet close to tip
CheckCreditPoolDiffForBlock expected to get slower due to extra ops there, but grow is tiny compare to overall win.
Total speedup for block validation is 4% for post-v20 blocks [credit pool introduction].
Breaking Changes
N/A
Checklist: