lightningd: fix occasional missing txid detection.

I was working on rewriting our (somewhat chaotic) tx watching code
for 0.7.2, when I found this bug: we don't always notice the funding
tx in corner cases where more than one block is detected at
once.

This is just the one commit needed to fix the problem: it has some
unnecessary changes, but I'd prefer not to diverge too far from my
cleanup-txwatch branch.

Fixes: #2352
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-06-28 11:28:31 +09:30
parent 707ce4cf66
commit f1bea55395
8 changed files with 108 additions and 6 deletions

View File

@@ -79,17 +79,31 @@ static void onchain_tx_depth(struct channel *channel,
static enum watch_result onchain_tx_watched(struct lightningd *ld,
struct channel *channel,
const struct bitcoin_txid *txid,
const struct bitcoin_tx *tx,
unsigned int depth)
{
u32 blockheight = get_block_height(ld->topology);
if (tx != NULL) {
struct bitcoin_txid txid2;
bitcoin_txid(tx, &txid2);
if (!bitcoin_txid_eq(txid, &txid2)) {
channel_internal_error(channel, "Txid for %s is not %s",
type_to_string(tmpctx,
struct bitcoin_tx,
tx),
type_to_string(tmpctx,
struct bitcoin_txid,
txid));
return DELETE_WATCH;
}
}
if (depth == 0) {
log_unusual(channel->log, "Chain reorganization!");
channel_set_owner(channel, NULL, false);
/* FIXME!
topology_rescan(peer->ld->topology, peer->funding_txid);
*/
/* We will most likely be freed, so this is a noop */
return KEEP_WATCHING;
}