channel lease: fail leased channel if peer offline + blockheight behind

If the channel is leased and our peer is too far behind, fail the
channel.
This commit is contained in:
niftynei 2021-07-02 15:25:40 -05:00 committed by neil saitug
parent 0dde74f99e
commit 19d4f18241
1 changed files with 31 additions and 5 deletions

View File

@ -75,12 +75,38 @@ static void try_update_blockheight(struct lightningd *ld,
{
u8 *msg;
/* We use the same heuristic for channel states as feerates */
if (!channel_fees_can_change(channel))
return;
log_debug(channel->log, "attempting update blockheight %s",
type_to_string(tmpctx, struct channel_id, &channel->cid));
/* Can't if no daemon listening. */
if (!channel->owner)
/* If they're offline, check that we're not too far behind anyway */
if (!channel->owner) {
if (channel->opener == REMOTE
&& channel->lease_expiry > 0) {
u32 peer_height
= get_blockheight(channel->blockheight_states,
channel->opener, REMOTE);
/* Lease no longer active, we don't (really) care */
if (peer_height >= channel->lease_expiry)
return;
assert(peer_height + 1008 > peer_height);
if (peer_height + 1008 < blockheight)
channel_fail_permanent(channel,
REASON_PROTOCOL,
"Offline peer is too"
" far behind,"
" terminating leased"
" channel. Our current"
" %u, theirs %u",
blockheight,
peer_height);
}
return;
}
/* If we're not opened/locked in yet, don't send update */
if (!channel_fees_can_change(channel))
return;
/* We don't update the blockheight for non-leased chans */