fix: add cycle block cache to InstantSendManager#297
Conversation
📝 WalkthroughWalkthroughInstantSendManager adds two LRU-bounded, synchronized caches for deterministic islock cycle hash block lookups. A new ChangesCycle Hash Block Lookup Caching
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
core/src/main/java/org/bitcoinj/quorums/InstantSendManager.java (1)
231-250:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd NPE handling for shutdown race condition.
The
getCycleBlock()call at line 233 can throwNullPointerExceptionifblockChainbecomes null during shutdown. Line 624 has explicit NPE handling for this case, but this location does not. During a shutdown race condition, the NPE will propagate to the network thread, potentially causing errors.🛡️ Proposed fix to add NPE handling
if (isLock.isDeterministic()) { try { StoredBlock blockIndex = getCycleBlock(isLock.cycleHash); if (blockIndex == null) { // Maybe we don't have the block yet or maybe some peer spams invalid values for cycleHash // TODO: DashCore increases ban score by 1 return; } final LLMQParameters.LLMQType llmqType = context.getParams().isDIP0024Active(blockIndex) ? context.getParams().getLlmqDIP0024InstantSend() : context.getParams().getLlmqForInstantSend(); final int dkgInterval = LLMQParameters.fromType(llmqType).dkgInterval; if (blockIndex.getHeight() % dkgInterval != 0) { // TODO: Dash Core increases ban score by 100 return; } } catch (BlockStoreException x) { throw new RuntimeException(x); + } catch (NullPointerException e) { + // blockchain is now null? + if (isInitialized()) { + throw e; + } else { + return; + } } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@core/src/main/java/org/bitcoinj/quorums/InstantSendManager.java` around lines 231 - 250, In InstantSendManager, wrap the getCycleBlock(isLock.cycleHash) invocation in a try/catch that also catches NullPointerException (similar to the handling at line 624) so a shutdown race where blockChain becomes null won't propagate an NPE to the network thread; specifically, around the code that calls getCycleBlock and the subsequent logic for llmqType/dkgInterval, add a catch (NullPointerException npe) that logs or silently returns (same safe behavior used elsewhere) and then keep the existing catch (BlockStoreException) that throws a RuntimeException.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@core/src/main/java/org/bitcoinj/quorums/InstantSendManager.java`:
- Around line 231-250: In InstantSendManager, wrap the
getCycleBlock(isLock.cycleHash) invocation in a try/catch that also catches
NullPointerException (similar to the handling at line 624) so a shutdown race
where blockChain becomes null won't propagate an NPE to the network thread;
specifically, around the code that calls getCycleBlock and the subsequent logic
for llmqType/dkgInterval, add a catch (NullPointerException npe) that logs or
silently returns (same safe behavior used elsewhere) and then keep the existing
catch (BlockStoreException) that throws a RuntimeException.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b56c5f35-b959-464d-a792-05b8b2122d7e
📒 Files selected for processing (1)
core/src/main/java/org/bitcoinj/quorums/InstantSendManager.java
Issue being fixed or feature implemented
What was done?
How Has This Been Tested?
Breaking Changes
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit