lnwallet+funding: enable AnchorsZeroFeeHtlcTx commit type if both nodes support

We assume the legacy anchor type is no longer advertised by us.
This commit is contained in:
Johan T. Halseth 2020-12-07 14:22:07 +01:00
parent 0b9bec7804
commit 1923d40843
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 31 additions and 31 deletions

@ -1137,20 +1137,21 @@ func (f *fundingManager) ProcessFundingMsg(msg lnwire.Message, peer lnpeer.Peer)
func commitmentType(localFeatures, func commitmentType(localFeatures,
remoteFeatures *lnwire.FeatureVector) lnwallet.CommitmentType { remoteFeatures *lnwire.FeatureVector) lnwallet.CommitmentType {
// If both peers are signalling support for anchor commitments, this // If both peers are signalling support for anchor commitments with
// implicitly mean we'll create the channel of this type. Note that // zero-fee HTLC transactions, we'll use this type.
// this also enables tweakless commitments, as anchor commitments are localZeroFee := localFeatures.HasFeature(
// always tweakless. lnwire.AnchorsZeroFeeHtlcTxOptional,
localAnchors := localFeatures.HasFeature(
lnwire.AnchorsOptional,
) )
remoteAnchors := remoteFeatures.HasFeature( remoteZeroFee := remoteFeatures.HasFeature(
lnwire.AnchorsOptional, lnwire.AnchorsZeroFeeHtlcTxOptional,
) )
if localAnchors && remoteAnchors { if localZeroFee && remoteZeroFee {
return lnwallet.CommitmentTypeAnchors 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( localTweakless := localFeatures.HasFeature(
lnwire.StaticRemoteKeyOptional, 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 // responding side of a single funder workflow, we don't commit any
// funds to the channel ourselves. // funds to the channel ourselves.
// //
// Before we init the channel, we'll also check to see if we've // Before we init the channel, we'll also check to see what commitment
// negotiated the new tweakless commitment format. This is only the // format we can use with this peer. This is dependent on *both* us and
// case if *both* us and the remote peer are signaling the proper // the remote peer are signaling the proper feature bit.
// feature bit.
commitType := commitmentType( commitType := commitmentType(
peer.LocalFeatures(), peer.RemoteFeatures(), peer.LocalFeatures(), peer.RemoteFeatures(),
) )
@ -3116,7 +3116,6 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
case chainreg.LitecoinChain: case chainreg.LitecoinChain:
ourDustLimit = chainreg.DefaultLitecoinDustLimit ourDustLimit = chainreg.DefaultLitecoinDustLimit
} }
fndgLog.Infof("Initiating fundingRequest(local_amt=%v "+ fndgLog.Infof("Initiating fundingRequest(local_amt=%v "+
"(subtract_fees=%v), push_amt=%v, chain_hash=%v, peer=%x, "+ "(subtract_fees=%v), push_amt=%v, chain_hash=%v, peer=%x, "+
"dust_limit=%v, min_confs=%v)", localAmt, msg.subtractFees, "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 // wallet doesn't have enough funds to commit to this channel, then the
// request will fail, and be aborted. // request will fail, and be aborted.
// //
// Before we init the channel, we'll also check to see if we've // Before we init the channel, we'll also check to see what commitment
// negotiated the new tweakless commitment format. This is only the // format we can use with this peer. This is dependent on *both* us and
// case if *both* us and the remote peer are signaling the proper // the remote peer are signaling the proper feature bit.
// feature bit.
commitType := commitmentType( commitType := commitmentType(
msg.peer.LocalFeatures(), msg.peer.RemoteFeatures(), msg.peer.LocalFeatures(), msg.peer.RemoteFeatures(),
) )

@ -28,10 +28,11 @@ const (
// to_remote key is static. // to_remote key is static.
CommitmentTypeTweakless CommitmentTypeTweakless
// CommitmentTypeAnchors is a commitment type that is tweakless, and // CommitmentTypeAnchorsZeroFeeHtlcTx is a commitment type that is an
// has extra anchor ouputs in order to bump the fee of the commitment // extension of the outdated CommitmentTypeAnchors, which in addition
// transaction. // requires second-level HTLC transactions to be signed using a
CommitmentTypeAnchors // zero-fee.
CommitmentTypeAnchorsZeroFeeHtlcTx
) )
// String returns the name of the CommitmentType. // String returns the name of the CommitmentType.
@ -41,8 +42,8 @@ func (c CommitmentType) String() string {
return "legacy" return "legacy"
case CommitmentTypeTweakless: case CommitmentTypeTweakless:
return "tweakless" return "tweakless"
case CommitmentTypeAnchors: case CommitmentTypeAnchorsZeroFeeHtlcTx:
return "anchors" return "anchors-zero-fee-second-level"
default: default:
return "invalid" return "invalid"
} }
@ -182,7 +183,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
// Based on the channel type, we determine the initial commit weight // Based on the channel type, we determine the initial commit weight
// and fee. // and fee.
commitWeight := int64(input.CommitWeight) commitWeight := int64(input.CommitWeight)
if commitType == CommitmentTypeAnchors { if commitType == CommitmentTypeAnchorsZeroFeeHtlcTx {
commitWeight = input.AnchorCommitWeight commitWeight = input.AnchorCommitWeight
} }
commitFee := commitFeePerKw.FeeForWeight(commitWeight) commitFee := commitFeePerKw.FeeForWeight(commitWeight)
@ -195,7 +196,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
// The total fee paid by the initiator will be the commitment fee in // The total fee paid by the initiator will be the commitment fee in
// addition to the two anchor outputs. // addition to the two anchor outputs.
feeMSat := lnwire.NewMSatFromSatoshis(commitFee) feeMSat := lnwire.NewMSatFromSatoshis(commitFee)
if commitType == CommitmentTypeAnchors { if commitType == CommitmentTypeAnchorsZeroFeeHtlcTx {
feeMSat += 2 * lnwire.NewMSatFromSatoshis(anchorSize) feeMSat += 2 * lnwire.NewMSatFromSatoshis(anchorSize)
} }
@ -280,8 +281,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
// Both the tweakless type and the anchor type is tweakless, // Both the tweakless type and the anchor type is tweakless,
// hence set the bit. // hence set the bit.
if commitType == CommitmentTypeTweakless || if commitType == CommitmentTypeTweakless ||
commitType == CommitmentTypeAnchors { commitType == CommitmentTypeAnchorsZeroFeeHtlcTx {
chanType |= channeldb.SingleFunderTweaklessBit chanType |= channeldb.SingleFunderTweaklessBit
} else { } else {
chanType |= channeldb.SingleFunderBit chanType |= channeldb.SingleFunderBit
@ -315,9 +315,11 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
chanType |= channeldb.DualFunderBit chanType |= channeldb.DualFunderBit
} }
// We are adding anchor outputs to our commitment. // We are adding anchor outputs to our commitment. We only support this
if commitType == CommitmentTypeAnchors { // in combination with zero-fee second-levels HTLCs.
if commitType == CommitmentTypeAnchorsZeroFeeHtlcTx {
chanType |= channeldb.AnchorOutputsBit chanType |= channeldb.AnchorOutputsBit
chanType |= channeldb.ZeroHtlcTxFeeBit
} }
// If the channel is meant to be frozen, then we'll set the frozen bit // If the channel is meant to be frozen, then we'll set the frozen bit