Skip to content

mine_block_including race #237

Description

@morehouse

Got a false positive while fuzzing LDK:

thread panicked at smite/src/bitcoin.rs:157:9:
bitcoin-cli generateblock failed: error code: -5
error message:
Transaction 67aa71e114ae03e4c1ac174f9482e6ef3b526a7fd5b92534d5d472ec7b8237c5 not in mempool.

The issue is that BitcoinCli::mine_block_including takes a snapshot of the mempool via getrawmempool and then passes those txids to generateblock, which resolves the txids against the current mempool. If any of passed txids are evicted from the mempool between the snapshot and the generateblock, the RPC fails.

What happened with LDK was something like this:

  1. Channel opened successfully (with a 0 to_self_delay)
  2. Executor does something invalid, causing LDK to initiate force close, broadcasting the commitment and a to_local output sweep
  3. Before LDK completes the tx broadcasts, several blocks are mined and a chain sync triggered on LDK
  4. LDK completes the initial broadcasts
  5. Executor calls mine_block_including, snapshotting the mempool with LDK's initial commitment and to_local sweep
  6. LDK processes the new blocks from (3) and RBF fee-bumps its to_local sweep
  7. mine_block_including attempts to mine, but the mempool has changed. Error code -5.

Suggested fix

Retry the snapshot and generateblock inside mine_block_including a bounded number of times when generateblock fails with a "not in mempool" error.

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