refactor: remove dependencies of CChainState on CMasternodeSync#7212
refactor: remove dependencies of CChainState on CMasternodeSync#7212knst wants to merge 7 commits intodashpay:developfrom
Conversation
|
This pull request has conflicts, please rebase. |
|
d65c9b9 to
521f1fc
Compare
521f1fc to
f552476
Compare
…PackageSelection, final part)
There's new helper IsValidAndSynced in CGovernanceManager that incapsulate usages of CMasternodeSync in CMNPayment
…otifier is introduced to use it for CChainState
f552476 to
24f2705
Compare
|
✅ Review complete (commit 24f2705) |
WalkthroughThis change removes the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
🧹 Nitpick comments (1)
src/test/miner_tests.cpp (1)
583-584: Consider extracting a helper to reduce repetition.The
UpdateTxFirstSeenMapcall with the time calculation is repeated many times throughout these tests. A small helper function would improve readability.🔧 Optional helper function
// At the top of the test file or within MinerTestingSetup void AgeTxForInstantSend(const Uint256HashSet& txids, int64_t base_time = -1) { if (base_time < 0) { base_time = std::chrono::duration_cast<std::chrono::seconds>( Now<NodeSeconds>().time_since_epoch()).count(); } m_node.clhandler->UpdateTxFirstSeenMap(txids, base_time - WAIT_FOR_ISLOCK_TIMEOUT); }Then calls become:
AgeTxForInstantSend({hashMediumFeeTx, hashPrioritsedChild, ...});🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/miner_tests.cpp` around lines 583 - 584, Extract a small helper (e.g. AgeTxForInstantSend) near the top of the test file or inside MinerTestingSetup that wraps the repeated call to m_node.clhandler->UpdateTxFirstSeenMap by computing the epoch seconds via std::chrono::duration_cast<std::chrono::seconds>(Now<NodeSeconds>().time_since_epoch()).count() and passing (base_time - WAIT_FOR_ISLOCK_TIMEOUT), provide an optional base_time parameter defaulting to the current epoch seconds, and replace all repeated direct UpdateTxFirstSeenMap(..., Now<NodeSeconds>()... - WAIT_FOR_ISLOCK_TIMEOUT) calls with AgeTxForInstantSend(txid_set) to reduce duplication and improve readability while keeping existing semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/test/miner_tests.cpp`:
- Around line 583-584: Extract a small helper (e.g. AgeTxForInstantSend) near
the top of the test file or inside MinerTestingSetup that wraps the repeated
call to m_node.clhandler->UpdateTxFirstSeenMap by computing the epoch seconds
via
std::chrono::duration_cast<std::chrono::seconds>(Now<NodeSeconds>().time_since_epoch()).count()
and passing (base_time - WAIT_FOR_ISLOCK_TIMEOUT), provide an optional base_time
parameter defaulting to the current epoch seconds, and replace all repeated
direct UpdateTxFirstSeenMap(..., Now<NodeSeconds>()... -
WAIT_FOR_ISLOCK_TIMEOUT) calls with AgeTxForInstantSend(txid_set) to reduce
duplication and improve readability while keeping existing semantics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 632b3c82-edc1-4141-81be-782473d695b8
📒 Files selected for processing (17)
src/evo/chainhelper.cppsrc/evo/chainhelper.hsrc/governance/governance.cppsrc/governance/governance.hsrc/init.cppsrc/instantsend/instantsend.cppsrc/instantsend/instantsend.hsrc/llmq/context.cppsrc/llmq/context.hsrc/masternode/payments.cppsrc/masternode/payments.hsrc/masternode/sync.cppsrc/masternode/sync.hsrc/node/chainstate.cppsrc/node/chainstate.hsrc/test/miner_tests.cppsrc/test/util/setup_common.cpp
💤 Files with no reviewable changes (2)
- src/node/chainstate.h
- src/init.cpp
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
The PR successfully removes several direct CMasternodeSync dependencies, but it also changes validation behavior in a way that is not safe during initial sync. ConnectBlock now enforces InstantSend conflicts whenever spork 3 is active, even though the network layer still accepts and stores ISLOCKs before IsBlockchainSynced() is true.
Reviewed commit: 24f2705
🔴 1 blocking
1 additional finding
🔴 blocking: Removing the blockchain-sync gate makes block acceptance depend on pre-sync ISLOCK state
src/instantsend/instantsend.cpp (lines 469-475)
This method used to disable conflict rejection until masternode sync had reached the blockchain-synced stage, which kept transient InstantSend state out of ConnectBlock. After this change, validation.cpp calls ShouldInstantSendRejectConflicts() and returns conflict-tx-lock for any locally known conflicting lock, while NetInstantSend::ProcessMessage() still accepts and queues incoming ISLOCKs without checking IsBlockchainSynced(). A node that is still catching up can therefore learn a conflicting ISLOCK from the network and reject an otherwise valid block before it has finished syncing, which is a behavioral regression in the block-validation path.
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `src/instantsend/instantsend.cpp`:
- [BLOCKING] lines 469-475: Removing the blockchain-sync gate makes block acceptance depend on pre-sync ISLOCK state
This method used to disable conflict rejection until masternode sync had reached the blockchain-synced stage, which kept transient InstantSend state out of `ConnectBlock`. After this change, `validation.cpp` calls `ShouldInstantSendRejectConflicts()` and returns `conflict-tx-lock` for any locally known conflicting lock, while `NetInstantSend::ProcessMessage()` still accepts and queues incoming ISLOCKs without checking `IsBlockchainSynced()`. A node that is still catching up can therefore learn a conflicting ISLOCK from the network and reject an otherwise valid block before it has finished syncing, which is a behavioral regression in the block-validation path.
Issue being fixed or feature implemented
The class CMasternodeSync is about network communication. It should not be a direct dependency of CChainState.
Most changes are split-off from #7178 to keep 7178 tidy.
What was done?
CMNPaymentsProcessoruses a new helperCGovernanceManager::IsValidAndSyncedinstead direct usages ofCMasternodeSyncNote: usages of RejectConflictingBlocks
IsBlockchainSyncedstill checked directlyBlockAssembler::TestPackageTransactionsis changed now. But it should not affect anything beside regression tests, because blocks are not expected to be mined when sync is not done yet.CChainState::ConnectBlockuses it indirectly over helperCChainstateHelper::ShouldInstantSendRejectConflictsHow Has This Been Tested?
Run unit & functional tests.
Breaking Changes
N/A
Checklist:
Go over all the following points, and put an
xin all the boxes that apply.