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