mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
lnwallet: fix bug with funding channels with 50/50 balances
This commit fixes a prior bug in the wallet triggered by the creation of a channel using the single funder workflow, but pushing exactly *half* of the channel over to the other side. The prior logic to determine who the initiator would result in a disagreement over who created the channel initially. This wouldn’t manifest until the channel was attempted to be closed cooperatively. As both side disagreed about who created the channel they would apply the closing fee to different outputs, thereby creating mismatched closing transaction. The signature would fail to validate as the closer will create a different transaction from that of the responder. This commit fixes the issue by properly detecting who initially created the channel.
This commit is contained in:
parent
f82d957c90
commit
e60f40b845
1 changed files with 13 additions and 24 deletions
|
@ -146,6 +146,7 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcut
|
||||||
var (
|
var (
|
||||||
ourBalance btcutil.Amount
|
ourBalance btcutil.Amount
|
||||||
theirBalance btcutil.Amount
|
theirBalance btcutil.Amount
|
||||||
|
initiator bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// If we're the responder to a single-funder reservation, then we have
|
// If we're the responder to a single-funder reservation, then we have
|
||||||
|
@ -154,6 +155,7 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcut
|
||||||
if fundingAmt == 0 {
|
if fundingAmt == 0 {
|
||||||
ourBalance = pushSat
|
ourBalance = pushSat
|
||||||
theirBalance = capacity - commitFee - pushSat
|
theirBalance = capacity - commitFee - pushSat
|
||||||
|
initiator = false
|
||||||
} else {
|
} else {
|
||||||
// TODO(roasbeef): need to rework fee structure in general and
|
// TODO(roasbeef): need to rework fee structure in general and
|
||||||
// also when we "unlock" dual funder within the daemon
|
// also when we "unlock" dual funder within the daemon
|
||||||
|
@ -172,34 +174,21 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcut
|
||||||
}
|
}
|
||||||
|
|
||||||
theirBalance = capacity - fundingAmt - commitFee + pushSat
|
theirBalance = capacity - fundingAmt - commitFee + pushSat
|
||||||
|
initiator = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// Next we'll set the channel type based on what we can ascertain about
|
||||||
initiator bool
|
// the balances/push amount within the channel.
|
||||||
chanType channeldb.ChannelType
|
var chanType channeldb.ChannelType
|
||||||
)
|
|
||||||
switch {
|
|
||||||
// If our balance is zero, or we're being pushed our entire balance in
|
|
||||||
// the first state, then we're the responder to a single funder
|
|
||||||
// channel workflow.
|
|
||||||
case pushSat != 0 && ourBalance-pushSat == 0:
|
|
||||||
fallthrough
|
|
||||||
case ourBalance == 0:
|
|
||||||
initiator = false
|
|
||||||
chanType = channeldb.SingleFunder
|
|
||||||
|
|
||||||
// If their balance is zero, or being pushed entirely to them, then
|
// If either of the balances are zero at this point, or we have a
|
||||||
// we're the initiator to a single funder channel workflow.
|
// non-zero push amt (there's no pushing for dual funder), then this is
|
||||||
case pushSat != 0 && theirBalance-pushSat == 0:
|
// a single-funder channel.
|
||||||
fallthrough
|
if ourBalance == 0 || theirBalance == 0 || pushSat != 0 {
|
||||||
case theirBalance == 0:
|
|
||||||
initiator = true
|
|
||||||
chanType = channeldb.SingleFunder
|
chanType = channeldb.SingleFunder
|
||||||
|
} else {
|
||||||
// Otherwise, if both sides are starting out with a non-zero balance,
|
// Otherwise, this is a dual funder channel, and no side is
|
||||||
// then neither of us is technically the "initiator" and this is a dual
|
// technically the "initiator"
|
||||||
// funder channel.
|
|
||||||
default:
|
|
||||||
initiator = false
|
initiator = false
|
||||||
chanType = channeldb.DualFunder
|
chanType = channeldb.DualFunder
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue