fundingmanager: preserve remote MinHtlc during funding flow
This commit fixes a bug within the funding manager, where we would use the wrong min_htlc_value parameter. Instead of attributing the custom passed value for MinHtlc to the remote's constraints, we would add it to our own constraints.
This commit is contained in:
parent
cbfba79f46
commit
ca0b4cb8c5
@ -79,8 +79,11 @@ type reservationWithCtx struct {
|
|||||||
reservation *lnwallet.ChannelReservation
|
reservation *lnwallet.ChannelReservation
|
||||||
peerAddress *lnwire.NetAddress
|
peerAddress *lnwire.NetAddress
|
||||||
|
|
||||||
chanAmt btcutil.Amount
|
chanAmt btcutil.Amount
|
||||||
|
|
||||||
|
// Constraints we require for the remote.
|
||||||
remoteCsvDelay uint16
|
remoteCsvDelay uint16
|
||||||
|
remoteMinHtlc lnwire.MilliSatoshi
|
||||||
|
|
||||||
updateMtx sync.RWMutex
|
updateMtx sync.RWMutex
|
||||||
lastUpdated time.Time
|
lastUpdated time.Time
|
||||||
@ -1006,7 +1009,6 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reservation.RegisterMinHTLC(f.cfg.DefaultRoutingPolicy.MinHTLC)
|
|
||||||
|
|
||||||
fndgLog.Infof("Requiring %v confirmations for pendingChan(%x): "+
|
fndgLog.Infof("Requiring %v confirmations for pendingChan(%x): "+
|
||||||
"amt=%v, push_amt=%v", numConfsReq, fmsg.msg.PendingChannelID,
|
"amt=%v, push_amt=%v", numConfsReq, fmsg.msg.PendingChannelID,
|
||||||
@ -1016,6 +1018,12 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
// delay we require given the total amount of funds within the channel.
|
// delay we require given the total amount of funds within the channel.
|
||||||
remoteCsvDelay := f.cfg.RequiredRemoteDelay(amt)
|
remoteCsvDelay := f.cfg.RequiredRemoteDelay(amt)
|
||||||
|
|
||||||
|
// We'll also generate our required constraints for the remote party,
|
||||||
|
chanReserve := f.cfg.RequiredRemoteChanReserve(amt)
|
||||||
|
maxValue := f.cfg.RequiredRemoteMaxValue(amt)
|
||||||
|
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(amt)
|
||||||
|
minHtlc := f.cfg.DefaultRoutingPolicy.MinHTLC
|
||||||
|
|
||||||
// Once the reservation has been created successfully, we add it to
|
// Once the reservation has been created successfully, we add it to
|
||||||
// this peer's map of pending reservations to track this particular
|
// this peer's map of pending reservations to track this particular
|
||||||
// reservation until either abort or completion.
|
// reservation until either abort or completion.
|
||||||
@ -1027,6 +1035,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
reservation: reservation,
|
reservation: reservation,
|
||||||
chanAmt: amt,
|
chanAmt: amt,
|
||||||
remoteCsvDelay: remoteCsvDelay,
|
remoteCsvDelay: remoteCsvDelay,
|
||||||
|
remoteMinHtlc: minHtlc,
|
||||||
err: make(chan error, 1),
|
err: make(chan error, 1),
|
||||||
peerAddress: fmsg.peerAddress,
|
peerAddress: fmsg.peerAddress,
|
||||||
}
|
}
|
||||||
@ -1036,11 +1045,6 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
// Update the timestamp once the fundingOpenMsg has been handled.
|
// Update the timestamp once the fundingOpenMsg has been handled.
|
||||||
defer resCtx.updateTimestamp()
|
defer resCtx.updateTimestamp()
|
||||||
|
|
||||||
// We'll also generate our required constraints for the remote party,
|
|
||||||
chanReserve := f.cfg.RequiredRemoteChanReserve(amt)
|
|
||||||
maxValue := f.cfg.RequiredRemoteMaxValue(amt)
|
|
||||||
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(amt)
|
|
||||||
|
|
||||||
// With our parameters set, we'll now process their contribution so we
|
// With our parameters set, we'll now process their contribution so we
|
||||||
// can move the funding workflow ahead.
|
// can move the funding workflow ahead.
|
||||||
remoteContribution := &lnwallet.ChannelContribution{
|
remoteContribution := &lnwallet.ChannelContribution{
|
||||||
@ -1051,7 +1055,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
DustLimit: msg.DustLimit,
|
DustLimit: msg.DustLimit,
|
||||||
MaxPendingAmount: maxValue,
|
MaxPendingAmount: maxValue,
|
||||||
ChanReserve: chanReserve,
|
ChanReserve: chanReserve,
|
||||||
MinHTLC: msg.HtlcMinimum,
|
MinHTLC: minHtlc,
|
||||||
MaxAcceptedHtlcs: maxHtlcs,
|
MaxAcceptedHtlcs: maxHtlcs,
|
||||||
},
|
},
|
||||||
CsvDelay: remoteCsvDelay,
|
CsvDelay: remoteCsvDelay,
|
||||||
@ -1094,7 +1098,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
MaxValueInFlight: maxValue,
|
MaxValueInFlight: maxValue,
|
||||||
ChannelReserve: chanReserve,
|
ChannelReserve: chanReserve,
|
||||||
MinAcceptDepth: uint32(numConfsReq),
|
MinAcceptDepth: uint32(numConfsReq),
|
||||||
HtlcMinimum: ourContribution.MinHTLC,
|
HtlcMinimum: minHtlc,
|
||||||
CsvDelay: remoteCsvDelay,
|
CsvDelay: remoteCsvDelay,
|
||||||
MaxAcceptedHTLCs: maxHtlcs,
|
MaxAcceptedHTLCs: maxHtlcs,
|
||||||
FundingKey: ourContribution.MultiSigKey.PubKey,
|
FundingKey: ourContribution.MultiSigKey.PubKey,
|
||||||
@ -1178,7 +1182,7 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
|
|||||||
DustLimit: msg.DustLimit,
|
DustLimit: msg.DustLimit,
|
||||||
MaxPendingAmount: maxValue,
|
MaxPendingAmount: maxValue,
|
||||||
ChanReserve: chanReserve,
|
ChanReserve: chanReserve,
|
||||||
MinHTLC: msg.HtlcMinimum,
|
MinHTLC: resCtx.remoteMinHtlc,
|
||||||
MaxAcceptedHtlcs: maxHtlcs,
|
MaxAcceptedHtlcs: maxHtlcs,
|
||||||
},
|
},
|
||||||
CsvDelay: resCtx.remoteCsvDelay,
|
CsvDelay: resCtx.remoteCsvDelay,
|
||||||
@ -2547,6 +2551,11 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
remoteCsvDelay = f.cfg.RequiredRemoteDelay(capacity)
|
remoteCsvDelay = f.cfg.RequiredRemoteDelay(capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no minimum HTLC value was specified, use the default one.
|
||||||
|
if minHtlc == 0 {
|
||||||
|
minHtlc = f.cfg.DefaultRoutingPolicy.MinHTLC
|
||||||
|
}
|
||||||
|
|
||||||
// If a pending channel map for this peer isn't already created, then
|
// If a pending channel map for this peer isn't already created, then
|
||||||
// we create one, ultimately allowing us to track this pending
|
// we create one, ultimately allowing us to track this pending
|
||||||
// reservation within the target peer.
|
// reservation within the target peer.
|
||||||
@ -2559,6 +2568,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
resCtx := &reservationWithCtx{
|
resCtx := &reservationWithCtx{
|
||||||
chanAmt: capacity,
|
chanAmt: capacity,
|
||||||
remoteCsvDelay: remoteCsvDelay,
|
remoteCsvDelay: remoteCsvDelay,
|
||||||
|
remoteMinHtlc: minHtlc,
|
||||||
reservation: reservation,
|
reservation: reservation,
|
||||||
peerAddress: msg.peerAddress,
|
peerAddress: msg.peerAddress,
|
||||||
updates: msg.updates,
|
updates: msg.updates,
|
||||||
@ -2570,14 +2580,8 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
// Update the timestamp once the initFundingMsg has been handled.
|
// Update the timestamp once the initFundingMsg has been handled.
|
||||||
defer resCtx.updateTimestamp()
|
defer resCtx.updateTimestamp()
|
||||||
|
|
||||||
// If no minimum HTLC value was specified, use the default one.
|
|
||||||
if minHtlc == 0 {
|
|
||||||
minHtlc = f.cfg.DefaultRoutingPolicy.MinHTLC
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once the reservation has been created, and indexed, queue a funding
|
// Once the reservation has been created, and indexed, queue a funding
|
||||||
// request to the remote peer, kicking off the funding workflow.
|
// request to the remote peer, kicking off the funding workflow.
|
||||||
reservation.RegisterMinHTLC(minHtlc)
|
|
||||||
ourContribution := reservation.OurContribution()
|
ourContribution := reservation.OurContribution()
|
||||||
|
|
||||||
// Finally, we'll use the current value of the channels and our default
|
// Finally, we'll use the current value of the channels and our default
|
||||||
@ -2598,7 +2602,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
DustLimit: ourContribution.DustLimit,
|
DustLimit: ourContribution.DustLimit,
|
||||||
MaxValueInFlight: maxValue,
|
MaxValueInFlight: maxValue,
|
||||||
ChannelReserve: chanReserve,
|
ChannelReserve: chanReserve,
|
||||||
HtlcMinimum: ourContribution.MinHTLC,
|
HtlcMinimum: minHtlc,
|
||||||
FeePerKiloWeight: uint32(commitFeePerKw),
|
FeePerKiloWeight: uint32(commitFeePerKw),
|
||||||
CsvDelay: remoteCsvDelay,
|
CsvDelay: remoteCsvDelay,
|
||||||
MaxAcceptedHTLCs: maxHtlcs,
|
MaxAcceptedHTLCs: maxHtlcs,
|
||||||
|
Loading…
Reference in New Issue
Block a user