Skip to content

Forget channel if we are fundee and it has not confirmed yet for a long time - #1468

Merged
cdecker merged 4 commits into
ElementsProject:masterfrom
ZmnSCPxj:forget-fundee-channel
May 23, 2018
Merged

cdecker merged 4 commits into
ElementsProject:masterfrom
ZmnSCPxj:forget-fundee-channel

Conversation

@ZmnSCPxj

@ZmnSCPxj ZmnSCPxj commented May 6, 2018

Copy link
Copy Markdown
Contributor

As per BOLT spec:

A non-funding node (fundee):

  • SHOULD forget the channel if it does not see the
    funding transaction after a reasonable timeout.

We use blocks as unit of timeout. We forget the channel, if we are the fundee, if it has been 2016 blocks (--max-funding-unconfirmed-blocks, two weeks) since the channel was opened, and we have not seen it locked in yet.

@ZmnSCPxj

ZmnSCPxj commented May 6, 2018

Copy link
Copy Markdown
Contributor Author

Work in Progress since no test yet.

@cdecker @rustyrussell is there a simple way to suppress sendrawtransaction from within the test_lightningd.py? My intent is to add a test like the below:

  1. Get l1 l2.
  2. Give funds to l1.
  3. Turn off sendrawtransaction.
  4. l1.rpc.fundchannel(l2.info['id'], amount)
  5. Wait 2016 blocks.
  6. Check l2 forgot the channel.

@cdecker

cdecker commented May 6, 2018

Copy link
Copy Markdown
Member

We have a fake-bitcoin-cli that could be used to selectively fail a sendrawtransaction.

@ZmnSCPxj

ZmnSCPxj commented May 6, 2018

Copy link
Copy Markdown
Contributor Author

Thank you, will go make the test.

@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch 3 times, most recently from 2710f08 to 02f0957 Compare May 7, 2018 00:55
@ZmnSCPxj

ZmnSCPxj commented May 7, 2018

Copy link
Copy Markdown
Contributor Author

Forgetting the channel has the side effect that we disconnect from the peer; is that desirable?

@cdecker

cdecker commented May 7, 2018

Copy link
Copy Markdown
Member

Probably yes, since we don't really tell the other side about just having a lobotomy, and they'll expect us to know what they're talking about. By disconnecting (and potentially reconnecting) we can tell them to go away 😉

@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch from e68c56a to 4d6bbb1 Compare May 7, 2018 13:22
@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch 2 times, most recently from 0370fcf to 8e614e7 Compare May 7, 2018 15:24
@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch from 8e614e7 to 0178149 Compare May 8, 2018 21:41
@ZmnSCPxj

ZmnSCPxj commented May 8, 2018

Copy link
Copy Markdown
Contributor Author

Rebased, should fix the test regressions. Ready for review.

@rustyrussell rustyrussell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes, it's pretty nice as-is. Thanks!

Comment thread lightningd/channel_control.c Outdated
* by other checks that get added in the future, only
* first timer triggers. */
notleak(new_reltimer(&ld->timers, channel, time_from_sec(0),
&delete_channel, channel));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hanging off a timer like this is always a hack. What happens without this?

If it needs to be outside loop, I would change this to a simple "is_fundee_timed_out", then do:

const tal_t *expired = tal(NULL, char);

list_for_each(peer) {
    list_for_each(channel) {
        if (is_fundee_timed_out(channel, blockheight))
            tal_steal(expired, channel);
    }
}

/* Now we free them all at once */
tal_free(expired);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, yes, that is indeed better.

@ZmnSCPxj ZmnSCPxj May 9, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe not safe? delete_channel does more than just tal_free, it also deletes the channel from the DB. However a side effect of delete_channel is to also do a tal_free of the channel, which could also tal_free the peer while we are iterating over peer->channels.

How about putting it in an array then having a separate loop to destroy the array?

struct channel **expired = tal_arr(NULL, struct channel *, 0);

list_for_each(peer) {
    list_for_each(channel) {
        if (is_fundee_should_forget(ld, channel, block_height)) {
            tal_resize(&expired, tal_count(expired) + 1);
            expired[tal_count(expired) - 1] = channel;
        }
    }
}
for (size_t i = 0; i < tal_count(expired); ++i)
    delete_channel(expired[i]);
tal_free(expired);

Comment thread lightningd/chaintopology.c Outdated
/* Tell lightningd about new block. */
notify_new_block(topo->bitcoind->ld, topo->tip->height);
channel_notify_new_block(topo->bitcoind->ld,
topo->tip->height);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor cleanup:

I'd put the call to notify_new_block() in lightningd.c, rename the current one to (say) htlcs_notify_new_block() and have notify_new_block() call htlcs_notify_new_block and channel_notify_new_block.

it's a bit cleaner to have it outside chaintopology I think...

Comment thread lightningd/options.c
"Maximum number of blocks we wait for a channel "
"funding transaction to confirm, if we are the "
"fundee.");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been removing options like this in my documentation patch; I think this should just be a constant in a header somewhere. I can't see why anyone would want to change it, unless we want to change it for everyone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it since it is useful in the test to lower the threshold. Or should I make it into a dev- option instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this a dev- option would probably be sensible, yes :-)

@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch 6 times, most recently from 8baf1fc to 83ba690 Compare May 15, 2018 00:41
@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Ping!

@cdecker cdecker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 83ba690

Excellent PR, as always @ZmnSCPxj 👍

Comment thread lightningd/channel_control.c Outdated
return false;

/* Does not apply if we already saw the funding tx. */
/* FIXME: This is only set when the funding tx is confirmed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is a huge problem, and I think seeing it in the mempool could still hold us up indefinitely due to low fees. Happy to keep this as is. scid is set after the first confirmation.

@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch from 83ba690 to df9126e Compare May 16, 2018 23:40
@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

s/--max-funding-unconfirmed-blocks/--dev-max-funding-unconfirmed-blocks/

The `new_channel` constructor accepts u32, and the
`get_block_height` function returns u32, so the
extra 32 bits is unuseable anyway.
@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch from df9126e to 6d0737b Compare May 22, 2018 23:26
…dee.

We should forget this as it is a potential DoS if we remember every
funding txid that an attacker gave in a `funding_created` but never
broadcasted.
ZmnSCPxj added 2 commits May 23, 2018 00:20
Maximum number of blocks where funding tx is unconfirmed,
after which if we are the fundee, we forget the channel.
@ZmnSCPxj
ZmnSCPxj force-pushed the forget-fundee-channel branch from 6d0737b to 6389477 Compare May 23, 2018 00:20
@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Rebased to fix conflict.

Also, ping!

@cdecker

cdecker commented May 23, 2018

Copy link
Copy Markdown
Member

ACK 6389477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants