Skip to content

InstantSend: re-check stored locks against the active chain after a restart #8225

Open

Description

@PastaPastaPasta

Problem

A node can keep a block that conflicts with an InstantSend lock it has already stored, and nothing checks that block against the lock again after a restart.

ConnectBlock rejects a block that conflicts with a stored lock. A block that was connected before the lock was stored is handled instead by NetInstantSend::ResolveBlockConflicts, which runs right after the lock is written and invalidates the conflicting block. That resolution is not persisted. If it does not finish, nothing retries it:

  • Shutdown in between. InvalidateBlock gives up without disconnecting anything once shutdown is requested (fix: do not abort when shutdown interrupts InstantSend block conflict resolution #8212 stops treating that as a crash). The final flush then writes the conflicting tip, and on restart LoadChainTip adopts it without reconnecting the block.
  • Crash in between. Blocks reconnected at startup skip the InstantSend check in ConnectBlock, because the node is still importing blocks then, which counts as initial block download, so a block whose index entry was already flushed is accepted again.

In both cases the lock is already known after the restart, so a peer relaying it again doesn't trigger resolution either. The node stays on the conflicting block until its chain is reorged away, usually by a ChainLock.

Expected

After startup, every stored lock is enforced against the active chain the same way it would have been had resolution completed: a non-ChainLocked block that conflicts with a stored lock is invalidated, and the node moves to the best valid chain.

Possible approach

Once the chainstate and the InstantSend db are loaded, and the node leaves initial block download, check the stored locks' inputs against the active chain (or check the blocks connected since the last flush against the stored locks) and run the existing conflict resolution for any hit. The InstantSend db already indexes locks by input, so the check can work from the coins spent by recent blocks rather than scanning every lock.

Context

Raised in review of #8212, which replaces the assert that previously crashed the node when shutdown interrupted conflict resolution.

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