Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/evo/specialtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,20 @@ uint256 CalcTxOutputsHash(const CTransaction& tx)
}
return hw.GetHash();
}

bool IsProviderTx(const CTransaction& tx)
{
if (!tx.IsSpecialTxVersion()) return false;
switch (tx.nType) {
case TRANSACTION_PROVIDER_REGISTER:
case TRANSACTION_PROVIDER_UPDATE_SERVICE:
case TRANSACTION_PROVIDER_UPDATE_REGISTRAR:
case TRANSACTION_PROVIDER_UPDATE_REVOKE:
case TRANSACTION_PROVIDER_DISSOLVE:
case TRANSACTION_PROVIDER_UPDATE_SHARE:
case TRANSACTION_PROVIDER_UPDATE_SHARED_REGISTRAR:
return true;
default:
return false;
}
}
2 changes: 2 additions & 0 deletions src/evo/specialtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ void SetTxPayload(CMutableTransaction& tx, const T& payload)
uint256 CalcTxInputsHash(const CTransaction& tx);
uint256 CalcTxOutputsHash(const CTransaction& tx);

bool IsProviderTx(const CTransaction& tx);

#endif // BITCOIN_EVO_SPECIALTX_H
6 changes: 6 additions & 0 deletions src/instantsend/net_instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ void NetInstantSend::ResolveBlockConflicts(const uint256& islockHash, const inst

bool hasTxForLock = m_is_manager.HasTxForLock(islockHash);

if (conflicts.empty()) return;
// The blocks are invalidated and reconsidered one by one. Another thread's activation in between
// must not recheck the provider transactions in the mempool at a tip this is about to leave.
auto& held_chainstate{m_chainman.ActiveChainstate()};
WITH_LOCK(::cs_main, held_chainstate.HoldProviderTxRecheck());
bool activateBestChain = false;
for (const auto& p : conflicts) {
const auto* pindex = p.first;
Expand All @@ -633,6 +638,7 @@ void NetInstantSend::ResolveBlockConflicts(const uint256& islockHash, const inst
m_chainman.ActiveChainstate().ResetBlockFailureFlags(pindex2);
}
}
held_chainstate.ReleaseProviderTxRecheck();

if (activateBestChain) {
BlockValidationState state;
Expand Down
19 changes: 0 additions & 19 deletions src/instantsend/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,6 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
using node::GetTransaction;

namespace instantsend {
namespace {
bool IsProviderTx(const CTransaction& tx)
{
if (!tx.IsSpecialTxVersion()) return false;
switch (tx.nType) {
case TRANSACTION_PROVIDER_REGISTER:
case TRANSACTION_PROVIDER_UPDATE_SERVICE:
case TRANSACTION_PROVIDER_UPDATE_REGISTRAR:
case TRANSACTION_PROVIDER_UPDATE_REVOKE:
case TRANSACTION_PROVIDER_DISSOLVE:
case TRANSACTION_PROVIDER_UPDATE_SHARE:
case TRANSACTION_PROVIDER_UPDATE_SHARED_REGISTRAR:
return true;
default:
return false;
}
}
} // anonymous namespace

InstantSendSigner::InstantSendSigner(const ChainstateManager& chainman, const chainlock::Chainlocks& chainlocks,
llmq::CInstantSendManager& isman, llmq::CSigningManager& sigman,
llmq::CSigSharesManager& shareman, llmq::CQuorumManager& qman,
Expand Down
166 changes: 166 additions & 0 deletions src/test/evo_deterministicmns_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,166 @@ void FuncTestMinerKeyChangeNotHeldBackAfterReorg(TestChainSetup& setup)
BOOST_CHECK(!positions.count(tx_serv.GetHash()));
}

// A reorg changes the masternode list under provider transactions that are already in the mempool.
// Those the best chain no longer admits are removed once it is active, and not on the way there.
void FuncTestMempoolReorgRevalidatesProviderTxs(TestChainSetup& setup)
{
auto& chainman = *Assert(setup.m_node.chainman.get());
auto& dmnman = *Assert(setup.m_node.dmnman);
auto& mempool = *Assert(setup.m_node.mempool.get());
auto tip_index = [&] { return WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()); };
auto sync_dmn_tip = [&] { dmnman.UpdatedBlockTip(tip_index()); };
auto submit = [&](const CMutableTransaction& tx) {
return WITH_LOCK(::cs_main, return chainman.ProcessTransaction(MakeTransactionRef(tx)));
};
auto mine = [&](const std::vector<CMutableTransaction>& txs) {
const auto block = std::make_shared<CBlock>(
setup.CreateBlock(txs, GetScriptForRawPubKey(setup.coinbaseKey.GetPubKey()), chainman.ActiveChainstate()));
BOOST_REQUIRE(chainman.ProcessNewBlock(block, true, nullptr));
sync_dmn_tip();
return tip_index();
};
auto in_mempool = [&](const CMutableTransaction& tx) {
return WITH_LOCK(mempool.cs, return mempool.exists(tx.GetHash()));
};
// A branch built by invalidating its competitor returns that competitor's transactions to the
// mempool, where they would not be in a real reorg.
auto invalidate = [&](CBlockIndex* index, const std::vector<CMutableTransaction>& returned) {
BlockValidationState state;
BOOST_REQUIRE(chainman.ActiveChainstate().InvalidateBlock(state, index));
for (const auto& tx : returned) {
WITH_LOCK(mempool.cs, mempool.removeRecursive(CTransaction(tx), MemPoolRemovalReason::MANUAL));
}
sync_dmn_tip();
};
auto reconsider = [&](CBlockIndex* index) {
BlockValidationState state;
WITH_LOCK(::cs_main, chainman.ActiveChainstate().ResetBlockFailureFlags(index));
BOOST_REQUIRE(chainman.ActiveChainstate().ActivateBestChain(state));
sync_dmn_tip();
};

auto utxos = BuildSimpleUtxoMap(setup.m_coinbase_txns);
const SimpleUTXOMap coins{utxos};
const CScript scriptPayout = GenerateRandomAddress();
const CAmount fee{10000};

CKey ownerKey;
CBLSSecretKey operatorKey;
const auto tx_reg = CreateProRegTx(chainman, utxos, /*port=*/1, scriptPayout, setup.coinbaseKey, ownerKey, operatorKey);
const uint256 proTxHash = tx_reg.GetHash();
const auto first_reg_index = mine({tx_reg});
const auto version = ProTxVersionForNextBlock(chainman);

// A longer branch mines the registration again, two blocks later than the first one did.
CKey otherOwnerKey;
CBLSSecretKey otherOperatorKey;
const auto tx_other_reg = CreateProRegTx(chainman, utxos, /*port=*/9, scriptPayout, setup.coinbaseKey,
otherOwnerKey, otherOperatorKey);
invalidate(first_reg_index, {tx_reg});
const auto branch_index = mine({});
mine({});
const auto reg_index = mine({tx_reg, tx_other_reg});
invalidate(branch_index, {tx_reg, tx_other_reg});
reconsider(first_reg_index);
BOOST_REQUIRE_EQUAL(tip_index(), first_reg_index);

// The reorg to that branch stops once it has more work, one block short of the registration.
// An update of the masternode is invalid there and stays, as the rest of the branch follows.
const auto tx_serv = CreateProUpServTx(chainman, utxos, proTxHash, operatorKey, /*port=*/2, CScript(),
setup.coinbaseKey, version, fee);
BOOST_REQUIRE(submit(tx_serv).m_result_type == MempoolAcceptResult::ResultType::VALID);
reconsider(branch_index);
BOOST_REQUIRE_EQUAL(tip_index(), reg_index);
BOOST_CHECK(in_mempool(tx_serv));

// The best chain no longer has the registration: the update goes, and with it its hold on the
// address it announces. The registration is back in the mempool.
CKey sameAddrOwnerKey;
CBLSSecretKey sameAddrOperatorKey;
sameAddrOwnerKey.MakeNewKey(true);
sameAddrOperatorKey.MakeNewKey();
auto same_addr_payload = *Assert(GetTxPayload<CProRegTx>(tx_reg));
same_addr_payload.netInfo = Assert(GetTxPayload<CProUpServTx>(tx_serv))->netInfo;
same_addr_payload.keyIDOwner = sameAddrOwnerKey.GetPubKey().GetID();
same_addr_payload.pubKeyOperator.Set(sameAddrOperatorKey.GetPublicKey());
CMutableTransaction tx_reg_same_addr_mut{tx_reg};
SetTxPayload(tx_reg_same_addr_mut, same_addr_payload);
const CTransaction tx_reg_same_addr{tx_reg_same_addr_mut};
BOOST_REQUIRE(mempool.existsProviderTxConflict(tx_reg_same_addr));
{
// Not while a caller that takes several steps holds the recheck back, and not when that
// caller leaves a better chain to activate.
auto& chainstate = chainman.ActiveChainstate();
BlockValidationState state;
WITH_LOCK(::cs_main, chainstate.HoldProviderTxRecheck());
BOOST_REQUIRE(chainstate.InvalidateBlock(state, reg_index));
WITH_LOCK(::cs_main, chainstate.ResetBlockFailureFlags(reg_index));
chainstate.ReleaseProviderTxRecheck();
BOOST_CHECK(in_mempool(tx_serv));

// An activation that settles during the hold leaves the recheck to the release.
WITH_LOCK(::cs_main, chainstate.HoldProviderTxRecheck());
BOOST_REQUIRE(chainstate.InvalidateBlock(state, reg_index));
BOOST_REQUIRE(chainstate.ActivateBestChain(state));
BOOST_CHECK(in_mempool(tx_serv));
chainstate.ReleaseProviderTxRecheck();
sync_dmn_tip();
}
BOOST_CHECK(!in_mempool(tx_serv));
BOOST_CHECK(in_mempool(tx_reg));
BOOST_CHECK(!mempool.existsProviderTxConflict(tx_reg_same_addr));
reconsider(reg_index);
BOOST_REQUIRE_EQUAL(tip_index(), reg_index);

// Two branches on the registration: one changes the operator key, the other spends an input of
// that key change, so the key change cannot return to the mempool.
CBLSSecretKey newOperatorKey;
newOperatorKey.MakeNewKey();
const auto tx_key_change = CreateProUpRegTx(chainman, utxos, proTxHash, ownerKey, newOperatorKey.GetPublicKey(),
ownerKey.GetPubKey().GetID(), scriptPayout, setup.coinbaseKey, version,
fee);
CMutableTransaction tx_key_change_ds;
tx_key_change_ds.vin = tx_key_change.vin;
tx_key_change_ds.vout.emplace_back(0, CScript() << OP_RETURN);
SignTransaction(tx_key_change_ds, coins, setup.coinbaseKey);

const auto key_change_index = mine({tx_key_change});
invalidate(key_change_index, {tx_key_change});
BOOST_REQUIRE_EQUAL(tip_index(), reg_index);
const auto ds_index = mine({tx_key_change_ds});
mine({});
invalidate(ds_index, {tx_key_change_ds});
reconsider(key_change_index);
BOOST_REQUIRE_EQUAL(tip_index(), key_change_index);

// Signed with the key only the losing branch sets. Left in the mempool, block assembly would
// select it without checking its signature and then fail to validate its own template.
const auto tx_serv_new_key = CreateProUpServTx(chainman, utxos, proTxHash, newOperatorKey, /*port=*/3, CScript(),
setup.coinbaseKey, version, fee);
const auto tx_other_serv = CreateProUpServTx(chainman, utxos, tx_other_reg.GetHash(), otherOperatorKey, /*port=*/8,
CScript(), setup.coinbaseKey, version, fee);
CMutableTransaction tx_serv_new_key_child;
tx_serv_new_key_child.vin.emplace_back(tx_serv_new_key.GetHash(), 0);
tx_serv_new_key_child.vout.emplace_back(tx_serv_new_key.vout[0].nValue - fee, scriptPayout);
SignTransaction(tx_serv_new_key_child,
{{tx_serv_new_key_child.vin[0].prevout,
Coin(tx_serv_new_key.vout[0], /*nHeightIn=*/0, /*fCoinBaseIn=*/false)}},
setup.coinbaseKey);
for (const auto& tx : {tx_serv_new_key, tx_serv_new_key_child, tx_other_serv}) {
BOOST_REQUIRE(submit(tx).m_result_type == MempoolAcceptResult::ResultType::VALID);
}
reconsider(ds_index);
BOOST_REQUIRE_EQUAL(tip_index()->pprev, ds_index);
BOOST_REQUIRE(!in_mempool(tx_key_change));
BOOST_CHECK(!in_mempool(tx_serv_new_key));
BOOST_CHECK(!in_mempool(tx_serv_new_key_child));
BOOST_CHECK(in_mempool(tx_other_serv));

const auto positions = TemplatePositions(setup, {});
BOOST_CHECK(positions.count(tx_other_serv.GetHash()));
}

// A ProUpServTx funded by an ordinary pending transaction is pulled in ahead of a key change of its
// masternode together with that parent. With room for all of them they go in as parent, service
// update, key change. With room for either the parent and the update or the key change, but not for
Expand Down Expand Up @@ -4809,6 +4969,12 @@ BOOST_AUTO_TEST_CASE(test_miner_key_change_not_held_back_after_reorg)
FuncTestMinerKeyChangeNotHeldBackAfterReorg(setup);
}

BOOST_AUTO_TEST_CASE(test_mempool_reorg_revalidates_provider_txs)
{
TestChainV19Setup setup;
FuncTestMempoolReorgRevalidatesProviderTxs(setup);
}

BOOST_AUTO_TEST_CASE(test_miner_service_update_with_parent_before_key_change)
{
TestChainV19Setup setup;
Expand Down
43 changes: 43 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,31 @@ static bool IsCurrentForFeeEstimation(Chainstate& active_chainstate) EXCLUSIVE_L
return true;
}

void Chainstate::RemoveProviderTxsInvalidAtTip()
{
AssertLockHeld(cs_main);
AssertLockHeld(m_mempool->cs);
m_provider_txs_need_recheck = false;
const CBlockIndex* tip{m_chain.Tip()};
if (!tip) return;

const SpecialTxRules rules{GetSpecialTxRules(tip, m_chainman)};
std::vector<CTransactionRef> invalid;
for (const CTxMemPoolEntry& entry : m_mempool->entryAll()) {
Comment thread
PastaPastaPasta marked this conversation as resolved.
Resolved
const CTransaction& tx{entry.GetTx()};
if (!IsProviderTx(tx)) continue;
TxValidationState state;
if (!m_special_tx.CheckSpecialTx(tx, tip, rules, CoinsTip(), /*check_sigs=*/true, state)) {
LogPrint(BCLog::MEMPOOL, "%s: removing %s, invalid after the reorg: %s\n", __func__,
tx.GetHash().ToString(), state.ToString());
invalid.push_back(entry.GetSharedTx());
}
}
for (const auto& tx : invalid) {
m_mempool->removeRecursive(*tx, MemPoolRemovalReason::REORG);
}
}

void Chainstate::MaybeUpdateMempoolForReorg(
DisconnectedBlockTransactions& disconnectpool,
bool fAddToMempool)
Expand Down Expand Up @@ -3444,6 +3469,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
}

m_chain.SetTip(*pindexDelete->pprev);
m_provider_txs_need_recheck = true;
Comment on lines 3471 to +3472

@thepastaclaw thepastaclaw Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏭️ Deferred (maintainer decision; not blocking) at 64d8da6f; see the replies below.

🔴 Blocking: Recheck provider transactions after an InstantSend disconnect that skips activation

DisconnectTip() sets the recheck flag, but only ActivateBestChain() consumes it. When an InstantSend lock arrives before its transaction, ResolveBlockConflicts() invalidates the conflicting blocks, resets their failure flags, and deliberately skips activation (src/instantsend/net_instantsend.cpp:611–644). The node stays at the shorter tip while it waits, as test/functional/feature_llmq_is_cl_conflicts.py:227–236 confirms. If that rollback disconnects a masternode registration, an independently funded update can remain in the mempool and block a new registration from claiming its address until another activation. Finalize the provider recheck when InstantSend deliberately leaves the shorter tip active, without reactivating the conflicting branch. Extend the existing test to assert cleanup before the locked transaction arrives.

source: gpt-6.2-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real, fixed in b5f5842. ResolveBlockConflicts() now calls the new Chainstate::RecheckMempoolProviderTxs() when it leaves the chain at the shorter tip. It takes cs_main and the mempool lock and runs the recheck if a disconnect left it pending. The conflicting branch is not reactivated.

feature_llmq_is_cl_conflicts.py covers it in the existing ISLOCK-before-transaction scenario. An operator-key change is mined in the blocks the lock disconnects, with an update signed by the new key pending. After the rollback, and before the locked transaction arrives, the update must be gone from the mempool and the key change back in it. With the call removed, the update stays and the test times out there.

I used a key change, not a registration, in those blocks: a registration there changes the masternode-list root two blocks later, which the scenario's hand-built ChainLock block cannot follow.


🤖 Posted autonomously by Claude (claude-fable-5-2) on behalf of pasta.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved (re-reviewed at d951e6a6): The incomplete-lock rollback now rechecks without activating the conflicting branch. The operator-key case exercises the needed behavior: it checks that the stale update is gone and the key change is back in the mempool before the locked transaction is submitted.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thread shows as open again at 9e1c2a9. The rollback still rechecks without activating the conflicting branch. At 6ff3c89 it does so once, after all conflicting blocks are invalidated and before their failure flags are reset (see the per-block thread).


🤖 Posted autonomously by Claude (claude-fable-5-2) on behalf of pasta.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still applies (re-reviewed at 6ff3c898): Your post-loop call handles the case covered by the test, but keeping the failure flags set excludes only the disconnected branch. InvalidateBlock() can make an already-downloaded side branch eligible, so the helper can still skip the scan on a path that does not start activation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved (re-reviewed at 71ac9d94): Your post-loop ActivateBestChain() call now runs before the temporary flags are reset, so an eligible side branch is processed and the no-replacement path can recheck before returning. The functional test checks that the stale update is gone before the locked transaction is submitted.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferring this one after all, as of 747e1eb. The fix for it (activating in the missing-transaction rollback) is what the newer thread shows can cost a pending lock its transaction, so it is reverted and the InstantSend path is as on develop.

What remains is narrower than on develop: stale provider transactions stay only until the next ActivateBestChain(), which rechecks because the flag is still set. On develop they stay until they expire. Please file a tracking issue for rechecking at the rollback boundary under one m_chainstate_mutex hold.


🤖 Posted autonomously by Claude (claude-fable-5-2) on behalf of pasta.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still applies (re-reviewed at 747e1eb4): Keeping the activation revert is right. The reset only restores candidate eligibility; it does not run the scan, so please link the dedicated rollback issue here before deferring the remaining gap.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked in #8219: recheck at the rollback boundary, with the whole rollback serialized under m_chainstate_mutex and no activation.


🤖 Posted autonomously by Claude (claude-fable-5-2) on behalf of pasta.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred (re-reviewed at 64d8da6f): Thanks for linking #8219. When the handler leaves the shorter tip in place without activation, the scan stays pending; the linked issue covers doing that cleanup at the rollback boundary without activating a fork.


UpdateTip(pindexDelete->pprev);
// Let wallets know transactions went from 1-confirmed to
Expand Down Expand Up @@ -3935,6 +3961,10 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
break;
}
} while (!m_chain.Tip() || (starting_tip && CBlockIndexWorkComparator()(m_chain.Tip(), starting_tip)));
if (m_mempool && m_provider_txs_need_recheck && !m_provider_txs_recheck_held &&
(!pindexMostWork || pindexMostWork == m_chain.Tip()) && FindMostWorkChain() == m_chain.Tip()) {
RemoveProviderTxsInvalidAtTip();
}
if (!blocks_connected) return true;

const CBlockIndex* pindexFork = m_chain.FindFork(starting_tip);
Expand Down Expand Up @@ -3981,6 +4011,19 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
return true;
}

void Chainstate::ReleaseProviderTxRecheck()
{
AssertLockNotHeld(m_chainstate_mutex);
AssertLockNotHeld(::cs_main);

LOCK(m_chainstate_mutex);
LOCK(cs_main);
m_provider_txs_recheck_held = false;
if (!m_mempool || !m_provider_txs_need_recheck) return;
LOCK(m_mempool->cs);
if (FindMostWorkChain() == m_chain.Tip()) RemoveProviderTxsInvalidAtTip();
Comment on lines +4019 to +4024

@thepastaclaw thepastaclaw Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏭️ Deferred (maintainer decision; not blocking; tracked in #8219) at 630b7ba0; see the replies below.

🔴 Blocking: Do not suppress an unrelated reorg’s provider scan for an off-chain conflict

The release takes the same locks as activation, but it checks the candidate set after the InstantSend handler has changed it. If an unrelated activation settles on branch B during the hold, it skips the provider scan and moves the recorded conflict block A off-chain. InvalidateBlock(A) then disconnects nothing, but ResetBlockFailureFlags(A) clears failure flags on descendants and reinserts eligible candidates (src/validation.cpp:4346–4359,4391–4398). If A has a downloaded descendant with more work than B that was previously marked failed, for example by invalidateblock, that descendant now wins FindMostWorkChain(). The release skips the scan, and the missing-transaction path does not call ActivateBestChain() (src/instantsend/net_instantsend.cpp:633–645). A service update signed with the operator key that B rolled back can therefore stay in the mempool and cause bad-protx-sig during block template validation. Unlike the rollback tracked in #8219, InstantSend did not disconnect anything here. Serialize the conflict batch with activation in one Chainstate operation so the unrelated reorg can complete its own scan, without adding activation to the pending-lock path.

source: gpt-6.2-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interleaving is real. Deferring it to #8219, where I have added it.

It needs a descendant of the conflicting block that was invalidated earlier and has more work than the tip, an unrelated reorg that settles inside the hold, and a lock that is still missing its transaction. In that state ResetBlockFailureFlags() has made that descendant the best chain, so the node is no longer on its best chain when the hold ends. Rechecking there would be a recheck at a tip the next activation leaves, which is what this PR must not do. The recheck stays due and runs when that chain is activated, as in the rollback case #8219 already tracks. Until then the mempool is as stale as on develop.

The fix you describe, one Chainstate operation for the conflict batch, is the fix #8219 asks for: InvalidateBlock() takes m_chainstate_mutex itself, so it needs a multi-block invalidation in validation. That is a change to how InstantSend rolls the chain back and belongs in its own PR.


🤖 Posted autonomously by Claude (claude-fable-5-2) on behalf of pasta.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m fine deferring this to #8219: the off-chain reset can delay the scan, but it leaves the recheck pending for the next settled activation, and the stale mempool state in the meantime already occurs on develop.

Tracked in #8219. Deferred on a maintainer's call: this finding no longer blocks this pull request.

}

bool Chainstate::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
{
AssertLockNotHeld(m_chainstate_mutex);
Expand Down
18 changes: 18 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,14 @@ class Chainstate
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
LOCKS_EXCLUDED(::cs_main);

/** Keep ActivateBestChain() from rechecking the provider transactions in the mempool while a
* caller invalidates and reconsiders blocks in several steps. A recheck that is due stays due. */
void HoldProviderTxRecheck() EXCLUSIVE_LOCKS_REQUIRED(cs_main) { m_provider_txs_recheck_held = true; }

/** End the hold. A recheck that is due runs now if the chain is on its best chain, as an
* activation that got there during the hold has skipped it. */
void ReleaseProviderTxRecheck() EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex) LOCKS_EXCLUDED(::cs_main);

/** Remove invalidity status from a block and its descendants. */
void ResetBlockFailureFlags(CBlockIndex* pindex, bool ignore_chainlocks = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

Expand Down Expand Up @@ -809,6 +817,16 @@ class Chainstate
DisconnectedBlockTransactions& disconnectpool,
bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);

/** Remove the provider transactions, and their descendants, that CheckSpecialTx() rejects at
* the current tip, as a reorg can change the masternode list under those in the mempool. */
void RemoveProviderTxsInvalidAtTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);

/** Set when a block is disconnected, until the chain has settled and the provider transactions
* in the mempool were rechecked. Checking them on the way there would remove the updates of a
* masternode whose registration the new branch has yet to connect. */
bool m_provider_txs_need_recheck GUARDED_BY(::cs_main){false};
bool m_provider_txs_recheck_held GUARDED_BY(::cs_main){false};

/** Check warning conditions and do some notifications on new chain tip set. */
void UpdateTip(const CBlockIndex* pindexNew)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
Expand Down
Loading