Repository navigation
fix: keep a MN's pending updates when a reorg re-mines its ProRegTx #7638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1077,10 +1077,9 @@ void CTxMemPool::removeProTxReferences(const uint256& proTxHash) | |
| } | ||
| } | ||
|
|
||
| void CTxMemPool::removeProTxSpentCollateralConflicts(const CTransaction &tx) | ||
| void CTxMemPool::removeProTxSpentCollateralConflicts(const CTransaction &tx, const CDeterministicMNList& mnList) | ||
| { | ||
| // Remove TXs that refer to a MN for which the collateral was spent | ||
| auto mnList = m_dmnman.GetListAtChainTip(); | ||
| for (const auto& in : tx.vin) { | ||
| auto collateralIt = mapProTxCollaterals.find(in.prevout); | ||
| if (collateralIt != mapProTxCollaterals.end()) { | ||
|
|
@@ -1223,9 +1222,12 @@ void CTxMemPool::removeProTxVotingPayeeConflicts(const uint256& proTxHash, const | |
| } | ||
| } | ||
|
|
||
| void CTxMemPool::removeProTxConflicts(const CTransaction &tx) | ||
| void CTxMemPool::removeProTxConflicts(const CTransaction &tx, const CBlockIndex* pindex_prev) | ||
| { | ||
| removeProTxSpentCollateralConflicts(tx); | ||
| // The list tx is applied to, not the list at the chain tip: while a reorg is connecting its | ||
| // new branch, the tip list is still the one of the disconnected branch. | ||
| const CDeterministicMNList prev_mn_list{pindex_prev ? m_dmnman.GetListForBlock(pindex_prev) : CDeterministicMNList{}}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: Cache the historical masternode list for the whole block
source: |
||
| removeProTxSpentCollateralConflicts(tx, prev_mn_list); | ||
|
|
||
| const uint256 tx_hash{tx.GetHash()}; | ||
| if (tx.nType == TRANSACTION_PROVIDER_REGISTER) { | ||
|
|
@@ -1261,7 +1263,7 @@ void CTxMemPool::removeProTxConflicts(const CTransaction &tx) | |
| // currently backs, so that MN ceases to exist. Drop any mempool update that | ||
| // still targets its proTxHash; such an update can never be mined afterwards. | ||
| // removeProTxSpentCollateralConflicts only covers collateral *spends*, not reuse. | ||
| if (auto dmn = m_dmnman.GetListAtChainTip().GetMNByCollateral(proTx.collateralOutpoint)) { | ||
| if (auto dmn = prev_mn_list.GetMNByCollateral(proTx.collateralOutpoint)) { | ||
| removeProTxReferences(dmn->proTxHash); | ||
| } | ||
| } else { | ||
|
|
@@ -1332,7 +1334,7 @@ void CTxMemPool::removeProTxConflicts(const CTransaction &tx) | |
| /** | ||
| * Called when a block is connected. Removes from mempool and updates the miner fee estimator. | ||
| */ | ||
| void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight) | ||
| void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, const CBlockIndex* pindex_prev) | ||
| { | ||
| AssertLockHeld(cs); | ||
| std::vector<const CTxMemPoolEntry*> entries; | ||
|
|
@@ -1355,7 +1357,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne | |
| RemoveStaged(stage, true, MemPoolRemovalReason::BLOCK); | ||
| } | ||
| removeConflicts(*tx); | ||
| removeProTxConflicts(*tx); | ||
| removeProTxConflicts(*tx, pindex_prev); | ||
| removeAssetUnlockConflicts(*tx); | ||
| ClearPrioritisation(tx->GetHash()); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Cover collateral-spend eviction with a stale parent list
This collateral-spend check passes
chainman.ActiveChain().Tip()aspindex_prev, so the new historical lookup selects the same list as the old tip-based implementation. It therefore cannot fail if the collateral-spend path is accidentally reverted toGetListAtChainTip(). Add a separate case where the active tip contains the masternode butpindex_previs an ancestor whose list does not, assert that the spend preserves the pending updates under that historical parent, and retain the existing active-tip case to verify that a real collateral spend still evicts them.source:
gpt-6.1-sol(phase2-reviewer: general, dash-core-commit-history)