-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[anchors] zero-fee HTLC secondlevel transactions #4840
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
Changes from all commits
abefa93
d5cd986
0b9bec7
1923d40
c92c064
d69a1a6
64659e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1137,20 +1137,21 @@ func (f *fundingManager) ProcessFundingMsg(msg lnwire.Message, peer lnpeer.Peer) | |
| func commitmentType(localFeatures, | ||
| remoteFeatures *lnwire.FeatureVector) lnwallet.CommitmentType { | ||
|
|
||
| // If both peers are signalling support for anchor commitments, this | ||
| // implicitly mean we'll create the channel of this type. Note that | ||
| // this also enables tweakless commitments, as anchor commitments are | ||
| // always tweakless. | ||
| localAnchors := localFeatures.HasFeature( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| lnwire.AnchorsOptional, | ||
| // If both peers are signalling support for anchor commitments with | ||
| // zero-fee HTLC transactions, we'll use this type. | ||
| localZeroFee := localFeatures.HasFeature( | ||
| lnwire.AnchorsZeroFeeHtlcTxOptional, | ||
| ) | ||
| remoteAnchors := remoteFeatures.HasFeature( | ||
| lnwire.AnchorsOptional, | ||
| remoteZeroFee := remoteFeatures.HasFeature( | ||
| lnwire.AnchorsZeroFeeHtlcTxOptional, | ||
| ) | ||
| if localAnchors && remoteAnchors { | ||
| return lnwallet.CommitmentTypeAnchors | ||
| if localZeroFee && remoteZeroFee { | ||
| return lnwallet.CommitmentTypeAnchorsZeroFeeHtlcTx | ||
| } | ||
|
|
||
| // Since we don't want to support the "legacy" anchor type, we will | ||
| // fall back to static remote key if the nodes don't support the zero | ||
| // fee HTLC tx anchor type. | ||
| localTweakless := localFeatures.HasFeature( | ||
| lnwire.StaticRemoteKeyOptional, | ||
| ) | ||
|
|
@@ -1306,10 +1307,9 @@ func (f *fundingManager) handleFundingOpen(peer lnpeer.Peer, | |
| // responding side of a single funder workflow, we don't commit any | ||
| // funds to the channel ourselves. | ||
| // | ||
| // Before we init the channel, we'll also check to see if we've | ||
| // negotiated the new tweakless commitment format. This is only the | ||
| // case if *both* us and the remote peer are signaling the proper | ||
| // feature bit. | ||
| // Before we init the channel, we'll also check to see what commitment | ||
| // format we can use with this peer. This is dependent on *both* us and | ||
| // the remote peer are signaling the proper feature bit. | ||
| commitType := commitmentType( | ||
| peer.LocalFeatures(), peer.RemoteFeatures(), | ||
| ) | ||
|
|
@@ -3116,7 +3116,6 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { | |
| case chainreg.LitecoinChain: | ||
| ourDustLimit = chainreg.DefaultLitecoinDustLimit | ||
| } | ||
|
|
||
| fndgLog.Infof("Initiating fundingRequest(local_amt=%v "+ | ||
| "(subtract_fees=%v), push_amt=%v, chain_hash=%v, peer=%x, "+ | ||
| "dust_limit=%v, min_confs=%v)", localAmt, msg.subtractFees, | ||
|
|
@@ -3185,10 +3184,9 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { | |
| // wallet doesn't have enough funds to commit to this channel, then the | ||
| // request will fail, and be aborted. | ||
| // | ||
| // Before we init the channel, we'll also check to see if we've | ||
| // negotiated the new tweakless commitment format. This is only the | ||
| // case if *both* us and the remote peer are signaling the proper | ||
| // feature bit. | ||
| // Before we init the channel, we'll also check to see what commitment | ||
| // format we can use with this peer. This is dependent on *both* us and | ||
| // the remote peer are signaling the proper feature bit. | ||
| commitType := commitmentType( | ||
| msg.peer.LocalFeatures(), msg.peer.RemoteFeatures(), | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // +build !rpctest | ||
|
|
||
| package lncfg | ||
|
|
||
| // ProtocolOptions is a struct that we use to be able to test backwards | ||
|
|
@@ -17,10 +19,20 @@ type ProtocolOptions struct { | |
| // (channels larger than 0.16 BTC) channels, which is the opposite of | ||
| // mini. | ||
| WumboChans bool `long:"wumbo-channels" description:"if set, then lnd will create and accept requests for channels larger chan 0.16 BTC"` | ||
|
|
||
| // NoAnchors should be set if we don't want to support opening or accepting | ||
| // channels having the anchor commitment type. | ||
| NoAnchors bool `long:"no-anchors" description:"disable support for anchor commitments"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure how specific we want to be here, but does it make sense to clarify that this is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think users interacting with this flag don't have to know about the difference. |
||
| } | ||
|
|
||
| // Wumbo returns true if lnd should permit the creation and acceptance of wumbo | ||
| // channels. | ||
| func (l *ProtocolOptions) Wumbo() bool { | ||
| return l.WumboChans | ||
| } | ||
|
|
||
| // NoAnchorCommitments returns true if we have disabled support for the anchor | ||
| // commitment type. | ||
| func (l *ProtocolOptions) NoAnchorCommitments() bool { | ||
| return l.NoAnchors | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // +build rpctest | ||
|
|
||
| package lncfg | ||
|
|
||
| // ProtocolOptions is a struct that we use to be able to test backwards | ||
| // compatibility of protocol additions, while defaulting to the latest within | ||
| // lnd, or to enable experimental protocol changes. | ||
| type ProtocolOptions struct { | ||
| // LegacyProtocol is a sub-config that houses all the legacy protocol | ||
| // options. These are mostly used for integration tests as most modern | ||
| // nodes shuld always run with them on by default. | ||
| LegacyProtocol `group:"legacy" namespace:"legacy"` | ||
|
|
||
| // ExperimentalProtocol is a sub-config that houses any experimental | ||
| // protocol features that also require a build-tag to activate. | ||
| ExperimentalProtocol | ||
|
|
||
| // WumboChans should be set if we want to enable support for wumbo | ||
| // (channels larger than 0.16 BTC) channels, which is the opposite of | ||
| // mini. | ||
| WumboChans bool `long:"wumbo-channels" description:"if set, then lnd will create and accept requests for channels larger chan 0.16 BTC"` | ||
|
|
||
| // Anchors enables anchor commitments. | ||
| // TODO(halseth): transition itests to anchors instead! | ||
| Anchors bool `long:"anchors" description:"enable support for anchor commitments"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this was
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So there's two different versions of the config now: one for the itests, and the one for the rest. This commit makes the default one have anchor on, while the itest one it's off by default. |
||
| } | ||
|
|
||
| // Wumbo returns true if lnd should permit the creation and acceptance of wumbo | ||
| // channels. | ||
| func (l *ProtocolOptions) Wumbo() bool { | ||
| return l.WumboChans | ||
| } | ||
|
|
||
| // NoAnchorCommitments returns true if we have disabled support for the anchor | ||
| // commitment type. | ||
| func (l *ProtocolOptions) NoAnchorCommitments() bool { | ||
| return !l.Anchors | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,6 +278,12 @@ func CommitWeight(chanType channeldb.ChannelType) int64 { | |
| func HtlcTimeoutFee(chanType channeldb.ChannelType, | ||
| feePerKw chainfee.SatPerKWeight) btcutil.Amount { | ||
|
|
||
| // For zero-fee HTLC channels, this will always be zero, regardless of | ||
| // feerate. | ||
| if chanType.ZeroHtlcTxFee() { | ||
| return 0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EZ 😎 Could also instead have the param be passed in (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer zero, since that mitigates the fee leak completely. |
||
| } | ||
|
|
||
| if chanType.HasAnchors() { | ||
| return feePerKw.FeeForWeight(input.HtlcTimeoutWeightConfirmed) | ||
| } | ||
|
|
@@ -290,6 +296,12 @@ func HtlcTimeoutFee(chanType channeldb.ChannelType, | |
| func HtlcSuccessFee(chanType channeldb.ChannelType, | ||
| feePerKw chainfee.SatPerKWeight) btcutil.Amount { | ||
|
|
||
| // For zero-fee HTLC channels, this will always be zero, regardless of | ||
| // feerate. | ||
| if chanType.ZeroHtlcTxFee() { | ||
| return 0 | ||
| } | ||
|
|
||
| if chanType.HasAnchors() { | ||
| return feePerKw.FeeForWeight(input.HtlcSuccessWeightConfirmed) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.