Skip to content

utxonursery: handle remote spends [DO NOT REVIEW]#1890

Closed
joostjager wants to merge 11 commits into
lightningnetwork:masterfrom
joostjager:nursery
Closed

utxonursery: handle remote spends [DO NOT REVIEW]#1890
joostjager wants to merge 11 commits into
lightningnetwork:masterfrom
joostjager:nursery

Conversation

@joostjager
Copy link
Copy Markdown
Contributor

@joostjager joostjager commented Sep 12, 2018

PR will probably be abandoned, as we are on track to eventually remove nursery (#2000)

In this PR, utxonursery is made aware of the possibility that the remote party can spent outputs with the payment hash pre-image.

Currently, outgoing htlcs are sometimes handed off from resolvers to nursery when they are still contested. This can happen when:

  • In the broadcast delta period. This instantiates a timeout resolver that is not watching for remote spends.
  • Between expiry of the CTLV lock (that is when hand off to nursery takes place) and confirmation of the timeout tx (local commitment published) or sweep tx (remote commitment published).

Possible consequences of a remote spend after hand-off are:

  1. Incorrect htlc status reported in the pendingchannels rpc call.
  2. Trying to include a spent output in the sweep tx, making the sweep fail and losing the other mature outputs on that height.
  3. Not registering the pre-image, causing potential loss of funds by not being able to claim upstream.

This PR addresses issue 1 and part of issue 2. When a remote spend is detected, nursery moves the output into a seperate spnd bucket and removes it from the height index. It will not be included anymore in the subsequent sweep tx, unless the sweep tx was already constructed (*). When outputs are moved to the spnd bucket, they will be reported as "stage 0" in the htlc maturity report and also not count towards limbo balance anymore.

(*) This problem is to be solved in a follow-up PR. Possible fix could be to reconstruct the sweep tx when the height index is changed.

For issue 3, the ground work is laid by detecting the remote spend. One possible way to build this out is to extract the pre-image and signal it to the pre-image cache.

Now that nursery has a broader view on the status of the outputs that it is managing, the road is opened to broadcasting relevant output events (in particular the final states graduated and remote spend) to the contract resolvers. This will remove the duplication of tracking code that is present in the resolvers.

@joostjager joostjager force-pushed the nursery branch 7 times, most recently from 5497605 to 37780ed Compare September 13, 2018 13:19
Previously IncubateOutputs was a sequence of independent actions.
The construct to incubate all outputs of a commit tx in one single
call was not used anymore. This commit splits IncubateOutput into
logical functions.
@joostjager
Copy link
Copy Markdown
Contributor Author

All code in this pr is either merged or superseded by the sweeper development. Closing.

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.

2 participants