Browse Source

channel: Base the channel forget timeout on the headercount

We were basing the 2016 block timeout on the blockchain height that we had
processed at the time completed the funding, which could lag considerably
behind the network-wide blockheight. For example this could happen if we
started with `--rescan` from a low height, taking some time to catch up.

This means that we could end up forgetting channels even before reaching the
network blockheight. This patch instead uses the headercount reported by the
backend plugin if we aren't caught up yet. While the chances of this happening
are still there, the window it might happen are much reduced, since headers
can be synced in a couple of minutes.

Reported-by: Riccardo Masutti
Changelog-Changed: Funding timeout is now based on the header count reported by the bitcoin backend instead of our current blockheight which might be lower.
bump-pyln-proto
Christian Decker 4 years ago
committed by Rusty Russell
parent
commit
3dafddd717
  1. 11
      lightningd/chaintopology.c
  2. 11
      lightningd/chaintopology.h
  3. 2
      lightningd/opening_control.c

11
lightningd/chaintopology.c

@ -931,6 +931,15 @@ u32 get_block_height(const struct chain_topology *topo)
return topo->tip->height; return topo->tip->height;
} }
u32 get_network_blockheight(const struct chain_topology *topo)
{
if (topo->tip->height > topo->headercount)
return topo->tip->height;
else
return topo->headercount;
}
u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate) u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate)
{ {
return topo->feerate[feerate]; return topo->feerate[feerate];
@ -1068,6 +1077,8 @@ check_chain(struct bitcoind *bitcoind, const char *chain,
fatal("Wrong network! Our Bitcoin backend is running on '%s'," fatal("Wrong network! Our Bitcoin backend is running on '%s',"
" but we expect '%s'.", chain, chainparams->bip70_name); " but we expect '%s'.", chain, chainparams->bip70_name);
topo->headercount = headercount;
if (first_call) { if (first_call) {
/* Has the Bitcoin backend gone backward ? */ /* Has the Bitcoin backend gone backward ? */
check_blockcount(topo, blockcount); check_blockcount(topo, blockcount);

11
lightningd/chaintopology.h

@ -120,6 +120,10 @@ struct chain_topology {
/* Transactions/txos we are watching. */ /* Transactions/txos we are watching. */
struct txwatch_hash txwatches; struct txwatch_hash txwatches;
struct txowatch_hash txowatches; struct txowatch_hash txowatches;
/* The number of headers known to the bitcoin backend at startup. Not
* updated after the initial check. */
u32 headercount;
}; };
/* Information relevant to locating a TX in a blockchain. */ /* Information relevant to locating a TX in a blockchain. */
@ -140,6 +144,13 @@ size_t get_tx_depth(const struct chain_topology *topo,
/* Get highest block number. */ /* Get highest block number. */
u32 get_block_height(const struct chain_topology *topo); u32 get_block_height(const struct chain_topology *topo);
/* Get the highest block number in the network that we are aware of. Unlike
* `get_block_height` this takes into consideration the block header counter
* in the bitcoin backend as well. If an absolute time is required, rather
* than our current scan position this is preferable since it is far less
* likely to lag behind the rest of the network.*/
u32 get_network_blockheight(const struct chain_topology *topo);
/* Get fee rate in satoshi per kiloweight, or 0 if unavailable! */ /* Get fee rate in satoshi per kiloweight, or 0 if unavailable! */
u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate); u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate);

2
lightningd/opening_control.c

@ -265,7 +265,7 @@ wallet_commit_channel(struct lightningd *ld,
NULL, /* No commit sent yet */ NULL, /* No commit sent yet */
/* If we're fundee, could be a little before this /* If we're fundee, could be a little before this
* in theory, but it's only used for timing out. */ * in theory, but it's only used for timing out. */
get_block_height(ld->topology), get_network_blockheight(ld->topology),
feerate, feerate, feerate, feerate,
/* We are connected */ /* We are connected */
true, true,

Loading…
Cancel
Save