Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cnct: anchor output sweeping and fee bumping #3758

Merged
merged 17 commits into from
Mar 18, 2020

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented Nov 25, 2019

LND supports an experimental commitment format that produces anchor outputs (#3829, lightning/bolts#688). Anchor outputs allow users to increase the fee of their commitment txes after they've been published. It allows timely confirmation even if the miner fee of the commitment tx itself is insufficient.

This PR adds the functionality required to do so. When the commitment tx isn't confirming, the BumpFee rpc can be used to increase the fee of the total package. Anchor outpoints that are available can be discovered via the PendingChannels and PendingSweeps rpcs.

To make the experience more friendly towards users, a composite lncli command bumpclosefee is added.

For channels in the waiting_close_channels stage, this command can be used as follows:

lncli wallet bumpclosefee 2b66cf489298b5b4a9305127413e4124e385588178e4b0fc4cec2d28c277b17d:0 --sat_per_byte 15

Notes:

  • lnd needs to be built with the walletrpc subserver enabled.
  • The channel that is closed needs to be an anchor channel. Anchor channels are created automatically with OpenChannel when both sides run lnd with --protocol.anchors
  • The anchor commitment format is experimental. It doesn't have the reliability track record of the regular commitment format and therefore carries more risk. There is also still a chance of breaking changes in future releases. In that case, lnd will most likely require anchor channels to be closed before upgrading.

Important implementation changes made:

  • Keeping certain anchor inputs in separate sweep transactions always. When the commitment transaction hasn't confirmed yet, we don't know which of the three versions (local, remote, remote pending) will confirm. We attempt to sweep all three anchors, but batching those together would always create an invalid tx.
  • A dedicated bucket for sweeping at the minimum fee rate. Anchor outputs are very small and if they would be batched in a higher fee rate bucket, they are unlikely to be economical.
  • Try to sweep anchors before and after commit confirms
  • Report status of anchor sweep

@joostjager joostjager force-pushed the anchor-output-poc-joost branch 5 times, most recently from 3a906e6 to bb94988 Compare December 2, 2019 11:28
@joostjager joostjager force-pushed the anchor-output-poc-joost branch 2 times, most recently from 79e8375 to 6df6c0e Compare December 3, 2019 10:32
@halseth halseth added the anchors label Dec 5, 2019
@joostjager joostjager force-pushed the anchor-output-poc-joost branch 4 times, most recently from 338b1f2 to 7f4ecde Compare December 12, 2019 12:38
@joostjager joostjager force-pushed the anchor-output-poc-joost branch 4 times, most recently from ef5d3c6 to f4ac679 Compare January 7, 2020 16:20
@Roasbeef Roasbeef added the v0.10 label Jan 14, 2020
@joostjager joostjager mentioned this pull request Jan 14, 2020
@joostjager joostjager force-pushed the anchor-output-poc-joost branch 5 times, most recently from aaac70c to bec3316 Compare January 24, 2020 11:32
@joostjager joostjager force-pushed the anchor-output-poc-joost branch 3 times, most recently from e6c5a18 to c72e852 Compare January 27, 2020 10:33
@joostjager joostjager force-pushed the anchor-output-poc-joost branch 2 times, most recently from cf266e3 to 8c9717c Compare February 12, 2020 09:03
joostjager and others added 4 commits March 17, 2020 14:19
Co-authored-by: Joost Jager <joost.jager@gmail.com>
Exclusive group is a static property that doesn't need to be updated.
Requiring the exclusive group to be passed into UpdateParams creates a
burden for the caller to make sure they supply the existing group.

This change will be beneficial for users that bump anchor sweeps that
have exclusive groups set.
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Great work, LGTM ✅ Only non-blockinng comments.

contractcourt/channel_arbitrator.go Show resolved Hide resolved
input/size.go Show resolved Hide resolved
contractcourt/anchor_resolver.go Show resolved Hide resolved
contractcourt/anchor_resolver.go Show resolved Hide resolved
contractcourt/anchor_resolver.go Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
Prior to this change, the trigger height for closed channels was set to
the current best block height. As this height is in some cases used as a
height hint, the spend may have been missed.
Allows unit testing of the channel arbitrator with fewer dependencies.
This is a preparation for the addition of anchor sweeping.
Relay fee is needed later to sweep anchors at the minimum fee rate.
@joostjager
Copy link
Contributor Author

joostjager commented Mar 17, 2020

Need to fix restore_from_backup_file_anchors itest after rebase

@joostjager joostjager force-pushed the anchor-output-poc-joost branch 2 times, most recently from b01923b to afc5023 Compare March 18, 2020 08:08
Start anchor sweep attempts immediately after the commitment transaction
has been published. This makes the anchor known to the sweeper and
allows the user to bump the fee on it to get their commitment
transaction confirmed in case the fee committed too is insufficient for
timely confirmation.
Preparation for the anchor resolver which does not have persistent
state.
Preparation for anchor resolver. The recovered anchor amount should
still be included in the pending channel report even after it has been
resolved.

This also fixes an existing bug that in some cases caused the recovered
amount from an htlc resolver not to be included in the total.
Sweeping anchors and being able to bump the fee was already added in a
previous commit. This commit extends anchor sweeping with an anchor
resolver object that becomes active after the commitment tx confirms.
At that point, the anchors do not serve the purpose of getting the
commitment tranaction confirmed anymore. It is however still possible to
reclaim some of their value if using a low fee rate.
To make it easier to determine which pending sweep to bump in order to
get your anchor commitment tx confirmed.
This command allows users to easily bump the fee on their unconfirmed
closing transactions.
@joostjager
Copy link
Contributor Author

Anchors itest failure fixed as part of 'cnct: pre-confirmation anchor sweep'

@joostjager joostjager merged commit e2052f7 into lightningnetwork:master Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants