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:
- Channel opened successfully (with a 0
to_self_delay)
- Executor does something invalid, causing LDK to initiate force close, broadcasting the commitment and a
to_local output sweep
- Before LDK completes the tx broadcasts, several blocks are mined and a chain sync triggered on LDK
- LDK completes the initial broadcasts
- Executor calls
mine_block_including, snapshotting the mempool with LDK's initial commitment and to_local sweep
- LDK processes the new blocks from (3) and RBF fee-bumps its
to_local sweep
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.
Got a false positive while fuzzing LDK:
The issue is that
BitcoinCli::mine_block_includingtakes a snapshot of the mempool viagetrawmempooland then passes those txids togenerateblock, which resolves the txids against the current mempool. If any of passed txids are evicted from the mempool between the snapshot and thegenerateblock, the RPC fails.What happened with LDK was something like this:
to_self_delay)to_localoutput sweepmine_block_including, snapshotting the mempool with LDK's initial commitment andto_localsweepto_localsweepmine_block_includingattempts to mine, but the mempool has changed. Error code -5.Suggested fix
Retry the snapshot and
generateblockinsidemine_block_includinga bounded number of times whengenerateblockfails with a "not in mempool" error.