Merge pull request #5625 from therealyingtong/orchard-remove-with-anchor
Orchard: invalidate mempool transactions that use orphaned anchors.
This commit is contained in:
commit
ceff068e20
|
@ -3805,6 +3805,7 @@ bool static DisconnectTip(CValidationState &state, const CChainParams& chainpara
|
|||
// Apply the block atomically to the chain state.
|
||||
uint256 sproutAnchorBeforeDisconnect = pcoinsTip->GetBestAnchor(SPROUT);
|
||||
uint256 saplingAnchorBeforeDisconnect = pcoinsTip->GetBestAnchor(SAPLING);
|
||||
uint256 orchardAnchorBeforeDisconnect = pcoinsTip->GetBestAnchor(ORCHARD);
|
||||
int64_t nStart = GetTimeMicros();
|
||||
{
|
||||
CCoinsViewCache view(pcoinsTip);
|
||||
|
@ -3816,6 +3817,7 @@ bool static DisconnectTip(CValidationState &state, const CChainParams& chainpara
|
|||
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
|
||||
uint256 sproutAnchorAfterDisconnect = pcoinsTip->GetBestAnchor(SPROUT);
|
||||
uint256 saplingAnchorAfterDisconnect = pcoinsTip->GetBestAnchor(SAPLING);
|
||||
uint256 orchardAnchorAfterDisconnect = pcoinsTip->GetBestAnchor(ORCHARD);
|
||||
// Write the chain state to disk, if necessary.
|
||||
if (!FlushStateToDisk(chainparams, state, FLUSH_STATE_IF_NEEDED))
|
||||
return false;
|
||||
|
@ -3839,6 +3841,11 @@ bool static DisconnectTip(CValidationState &state, const CChainParams& chainpara
|
|||
// in which case we don't want to evict from the mempool yet!
|
||||
mempool.removeWithAnchor(saplingAnchorBeforeDisconnect, SAPLING);
|
||||
}
|
||||
if (orchardAnchorBeforeDisconnect != orchardAnchorAfterDisconnect) {
|
||||
// The anchor may not change between block disconnects,
|
||||
// in which case we don't want to evict from the mempool yet!
|
||||
mempool.removeWithAnchor(orchardAnchorBeforeDisconnect, ORCHARD);
|
||||
}
|
||||
}
|
||||
|
||||
// Update chainActive and related variables.
|
||||
|
|
|
@ -387,6 +387,14 @@ void CTxMemPool::removeWithAnchor(const uint256 &invalidRoot, ShieldedType type)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case ORCHARD:
|
||||
{
|
||||
auto anchor = tx.GetOrchardBundle().GetAnchor();
|
||||
if (anchor == invalidRoot) {
|
||||
transactionsToRemove.push_back(tx);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw runtime_error("Unknown shielded type");
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue