Skip to content

Recheck mempool provider transactions when an InstantSend lock rolls the chain back without activating #8219

Open

Description

@PastaPastaPasta

An InstantSend lock that arrives before its transaction rolls the chain back and leaves it there, but the mempool's provider transactions are not rechecked against that tip until the next block.

What happens

NetInstantSend::ResolveBlockConflicts() handles a lock whose transaction conflicts with mined, non-ChainLocked blocks. When the locked transaction is not known yet, it calls InvalidateBlock() on each conflicting block, resets the failure flags again and returns without calling ActivateBestChain(). The node stays at the shorter tip until the transaction arrives (feature_llmq_is_cl_conflicts.py checks this).

#8214 rechecks the provider transactions in the mempool after a reorg, but only inside ActivateBestChain(), once it has reached its best chain. This rollback never calls it, so the recheck waits for the next activation, normally the next block. Until then:

  • A ProUpServTx or ProUpRevTx signed with an operator key that only the disconnected blocks set stays in the mempool. Block assembly selects it without checking the signature and then fails TestBlockValidity with bad-protx-sig, so the node cannot build a template on the rollback tip.
  • An update of a masternode registered in the disconnected blocks keeps its service address reserved.

Without #8214 these transactions stay until they expire.

Why #8214 does not fix it

Two approaches were tried there and dropped:

  • Calling ActivateBestChain() in this rollback. It can connect another downloaded fork that contains the same conflicting spend while the lock is still pending, and the locked transaction is then rejected when it arrives.
  • A separate recheck call after the rollback. InvalidateBlock() releases m_chainstate_mutex between blocks and before the recheck, so another thread's activation, or an unrelated lock, can run in between and recheck at the wrong tip.

What a fix needs

The whole rollback has to be one operation under m_chainstate_mutex: invalidate every conflicting block, recheck the provider transactions at the resulting tip without activating anything, then reset the failure flags. That also closes the windows that remain between the separate calls today:

  • The failure flags are reset per block. For a lock that conflicts with two blocks on the active chain, the first reset makes both eligible again and the second InvalidateBlock() then marks only the higher one. A waiting activation can reconnect the lower block alone and recheck there, before the second reset.
  • A lock that conflicts with blocks on two branches can have another thread activate the second branch between the two invalidations.

In both cases the cost is a provider transaction that is valid at the final tip and gets dropped at the tip in between.

A third window keeps a stale transaction instead of dropping a valid one:

  • A conflicting block that is no longer on the active chain is invalidated and reset as well. The reset also clears the failure flags of its descendants, so a descendant that was invalidated earlier (for example with invalidateblock) and has more work than the tip becomes the best chain again, with nothing disconnected and no activation to follow. In fix: drop mempool provider transactions a reorg invalidated #8214 the rollback holds the recheck back while it runs and the end of the hold rechecks only when the node is on its best chain. If another thread's reorg settled during the hold, its recheck was left to the end of the hold, and in this state it then waits for the next activation too.

How to reproduce

In feature_llmq_is_cl_conflicts.py, test_chainlock_overrides_islock_overrides_nonchainlock: register a masternode beforehand, mine an operator-key change (protx update_registrar) in the blocks the ISLOCK will disconnect, and submit a protx update_service signed with the new key. After the ISLOCK arrives and the node is back at the earlier tip, the update is still in getrawmempool.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions