Merge pull request #5625 from therealyingtong/orchard-remove-with-anchor

Orchard: invalidate mempool transactions that use orphaned anchors.
This commit is contained in:
Kris Nuttycombe 2022-03-03 10:58:08 -07:00 committed by GitHub
commit ceff068e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -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.

View File

@ -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;