Skip to content

peer_control: Make close wait for complete closure, with timeout. - #1355

Merged
rustyrussell merged 4 commits into
ElementsProject:masterfrom
ZmnSCPxj:close-wait-timeout
Apr 23, 2018
Merged

peer_control: Make close wait for complete closure, with timeout.#1355
rustyrussell merged 4 commits into
ElementsProject:masterfrom
ZmnSCPxj:close-wait-timeout

Conversation

@ZmnSCPxj

Copy link
Copy Markdown
Contributor

Also report tx and txid, and whether we closed unilaterally or
bilaterally, if we could close the channel.

Also make a manpage.

Fixes: #1207
Fixes: #714
Fixes: #622

@rustyrussell

Copy link
Copy Markdown
Contributor

This closely mirrors my https://github.com/rustyrussell/lightning/tree/guilt/remove-dev-fail branch which I obviously forgot to put a PR in for! But yours is better anyway...

I avoided putting in a timeout for simplicity, but OTOH you return more information from close, which is nice but makes the timeout a necessity. You're clearly not from Australia though, because 2 seconds is grossly insufficient as a default :)

You also force a connection initiation to the peer, which is nice. And wrote the man page!

Can I ask you to cherry-pick commits or steal stuff as appropriate from my branch?

@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

You're clearly not from Australia though, because 2 seconds is grossly insufficient as a default :)

I am also obviously not an embedded semi-independent agent in an AI agent network sharing computational and network resources with other competing and cooperating knowledge agents, especially since 2 seconds would also be grossly insufficient as a default in that situation.

What would be a plausible default for a human being in Australia?

Can I ask you to cherry-pick commits or steal stuff as appropriate from my branch?

Okay, I shall check. There are no useful tests for the new closing functionality in particular, so if I see any tests I will steal them.

@ZmnSCPxj ZmnSCPxj mentioned this pull request Apr 11, 2018
10 tasks
@rustyrussell

Copy link
Copy Markdown
Contributor

30 seconds seems to be the modern default.

@ZmnSCPxj
ZmnSCPxj force-pushed the close-wait-timeout branch from 49e5829 to 2e77181 Compare April 14, 2018 00:53
@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Rebased, changed timeout to 30 seconds, added some code from @rustyrussell , please review again.

@ZmnSCPxj
ZmnSCPxj force-pushed the close-wait-timeout branch 4 times, most recently from 451112d to 31850c3 Compare April 14, 2018 13:47

@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.

Just some minor things that are a bit off.

Comment thread doc/lightning-close.7.txt Outdated
Normally the peer needs to be live and connected in order to negotiate
a bilateral close.
Forcing a unilateral close can be used if you suspect you can no longer
access the peer.

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.

access -> contact

Comment thread doc/lightning-close.7.txt Outdated
On success, an object with fields 'tx' and 'txid' containing the
closing transaction are returned.
It will also have a field 'type' which is either the JSON string
'bilateral' or the JSON string 'unilateral'.

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.

I usually use collaborative close to describe the bilateral close, which is a bit nicer. The spec talks about a "mutual close" or "cooperative close" which is also slightly nicer than bilateral (and you use cooperative in the code later).

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. Grepping lightning-rfc:

  • cooperative: 1 time, in 00-introduction.md
  • bilateral: 0 times, ha
  • mutual: many times, in 00-introduction.md, 02-peer-protocol.md, 05-onchain.md

Perhaps we should go with 'mutual' instead, as that seems to be the preferred term in the RFC. Note that the BOLT spec uses 'mutual' and 'unilateral'.

Comment thread lightningd/peer_control.c Outdated
#include <wire/gen_onion_wire.h>

struct close_command {
/* Off struct lightningd close_commands. */

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.

Off -> Of?

Comment thread lightningd/peer_control.c
cc->channel = NULL;
command_fail(cc->cmd, "Channel forgotten before proper close.");
}
/* Destroy the close command structure. */

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.

Nit: one empty line between functions.

Comment thread tests/test_lightningd.py

# Close the channel to forget the peer
l1.rpc.close(l2.info['id'])
self.assertRaisesRegex(ValueError,

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.

I don't understand why now all of these closes fail in the integration tests. Aren't these supposed to be collaborative closes? The 0 timeout everywhere is a bit excessive IMHO

@ZmnSCPxj ZmnSCPxj Apr 15, 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.

The tests assume that close does not wait for the close to complete. This PR makes close wait either for the timeout or the close to complete; to emulate the old behavior we set timeout to 0 and let the command fail due to timeout. Otherwise I would have to check each instance of .rpc.close to see if I can remove the wait_for_logs afterwards or if they scan for something more substantial than bilateral close. Being lazy. I shall see if they will still work properly if I make them wait.

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.

Well, ok, we should slowly make these closes normal again though (noting this for my cleanup queue).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, you should have put a FIXME above each of these!

Comment thread lightningd/channel.h Outdated
struct short_channel_id *scid;

/* Closing txid, for reporting to JSON */
struct bitcoin_txid *closing_txid;

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.

This field will not be repopulated when restarting / loading from DB, could that lead us into an inconsistent behavior? Before restart we show the closing_txid after the restart we lose that. If we broadcast the transaction we'll have it in the transactions table btw.

@ZmnSCPxj
ZmnSCPxj force-pushed the close-wait-timeout branch 2 times, most recently from ff7c19b to 602bee5 Compare April 16, 2018 11:05
@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Rebased, fixed nits. Removed closing_txid from listpeers command instead as I decided it was complicated to have to save it to the DB too, and the new close now reports the transaction that actually closes the channel. Also did some minor cleanups of some calls to the close RPC in the test. @cdecker please review again!

@cdecker

cdecker commented Apr 16, 2018

Copy link
Copy Markdown
Member

Thanks @ZmnSCPxj, I oversaw the removal of dev-fail by @rustyrussell, which I think is a bit eager. Forced closes do have the side effect of potentially sending close messages to the peer, which might not be desired in the test cases, so maybe we should keep dev-fail for integration tests?

@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Okay, I will remove that commit that removes dev-fail.

ZmnSCPxj and others added 3 commits April 16, 2018 15:00
Also report tx and txid, and whether we closed unilaterally or
bilaterally, if we could close the channel.

Also make a manpage.

Fixes: ElementsProject#1207
Fixes: ElementsProject#714
Fixes: ElementsProject#622
It should, indeed, close once they reconnect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@ZmnSCPxj
ZmnSCPxj force-pushed the close-wait-timeout branch from d3b03a1 to 28868b8 Compare April 16, 2018 15:01
@cdecker

cdecker commented Apr 17, 2018

Copy link
Copy Markdown
Member

Just kicked Travis, let's see if the failure was a flake.

Edit: I'm afraid it failed again, did something change with that test? It seems to get hung up on sendrawtransaction. I'm tempted to remove checking for symptoms and go to a more effect based approach, i.e., let some of the wait_for_logs fail and then check whether the desired state has been reached.

@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Well, I notice that the retry system does not seem to work well with this particular test, sigh.

@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Can you teach me how to remove the rerunfailures? I tried, to run without rerunfailures, as I suspect that an earlier run will show the root cause, and rerunfailures does not completely clear the test environment, so that reruns will fail for spurious reason once the first run fails for the real reason.

I tried removing the rerunfailures here: ZmnSCPxj@b8925ff but the CI still runs it with rerun. Hmm....

@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

Increasing the timeouts for closing in the test_closing_different_fees seems to make it work even in NO_VALGRIND=0 mode. Probably just a load problem in the CI (we are running 7 lightningd in parallel and performing 6 closes in parallel).

@cdecker

cdecker commented Apr 18, 2018

Copy link
Copy Markdown
Member

That's good news, any reason for it being 72? We can probably just overshoot and say 100 seconds, just to be safe.

@cdecker

cdecker commented Apr 18, 2018

Copy link
Copy Markdown
Member

And to answer your question: rerunfailures is enabled automagically on Travis using the following lines in the Makefile:

lightning/Makefile

Lines 43 to 47 in 774af5f

PYTEST := $(shell command -v pytest 2> /dev/null)
PYTEST_OPTS := -v -x
ifeq ($(TRAVIS),true)
PYTEST_OPTS += --reruns=3
endif

So if you set TRAVIS=false it'll not rerun.

@cdecker

cdecker commented Apr 18, 2018

Copy link
Copy Markdown
Member

I also missed this comment:

Removed closing_txid from listpeers command instead as I decided it was complicated to have to save it to the DB too, and the new close now reports the transaction that actually closes the channel.

We are now storing all transactions that we broadcast or that we watched in the transactions table, so you could just add the txid into the table and then fetch it from there 😉 But we can add that later as well.

@ZmnSCPxj

Copy link
Copy Markdown
Contributor Author

We already store last_tx associated with the channel; the transactions table does not have an easy association between channel and transaction. I just need to figure out when to show it as closing_tx/closing_txid. Definitely when it is in CLOSINGD_COMPLETE, possibly ONCHAIN too (but I am uncertain about the case where we trigger an error and the other side gets its commitment onchain before we do; do we track the transaction in this case?). Let us do it in another PR though, as arguably the important bit (reporting the closing transaction on return of close command) is here already and closing_txid is an enhancement.

@rustyrussell rustyrussell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ack fa3cff6

Comment thread tests/test_lightningd.py

# Close the channel to forget the peer
l1.rpc.close(l2.info['id'])
self.assertRaisesRegex(ValueError,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, you should have put a FIXME above each of these!

@rustyrussell
rustyrussell merged commit d6bf793 into ElementsProject:master Apr 23, 2018
@ZmnSCPxj
ZmnSCPxj deleted the close-wait-timeout branch April 23, 2018 05:45
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.

Timeout on close, then force unilateral. closing a channel should output more info close should reveal full tx hex, or txid, like fundchannel

3 participants