fundingmanager: cache remote-max-htlcs in res context

Currenlty the maxHtlcs value is recomputed after receiving
accept_channel. This works when the derivation is deterministic, howver
we now allow the user to manually override this value from open_channel.
As such, we must retain the chosen value in memory throughout the
funding process, otherwise the initiator would revert to the
deterministic derivation and the two endpoints will disagree on the
correct max-htlcs value in their view of the other's policy.
This commit is contained in:
Conner Fromknecht 2020-08-12 15:45:48 -07:00
parent ef69537c7f
commit 1760fe30db
No known key found for this signature in database
GPG key ID: E7D737B67FA592C7

View file

@ -124,6 +124,7 @@ type reservationWithCtx struct {
remoteCsvDelay uint16 remoteCsvDelay uint16
remoteMinHtlc lnwire.MilliSatoshi remoteMinHtlc lnwire.MilliSatoshi
remoteMaxValue lnwire.MilliSatoshi remoteMaxValue lnwire.MilliSatoshi
remoteMaxHtlcs uint16
updateMtx sync.RWMutex updateMtx sync.RWMutex
lastUpdated time.Time lastUpdated time.Time
@ -1411,6 +1412,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
remoteCsvDelay: remoteCsvDelay, remoteCsvDelay: remoteCsvDelay,
remoteMinHtlc: minHtlc, remoteMinHtlc: minHtlc,
remoteMaxValue: remoteMaxValue, remoteMaxValue: remoteMaxValue,
remoteMaxHtlcs: maxHtlcs,
err: make(chan error, 1), err: make(chan error, 1),
peer: fmsg.peer, peer: fmsg.peer,
} }
@ -1560,7 +1562,6 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
// here so we can properly commit their accepted constraints to the // here so we can properly commit their accepted constraints to the
// reservation. // reservation.
chanReserve := f.cfg.RequiredRemoteChanReserve(resCtx.chanAmt, msg.DustLimit) chanReserve := f.cfg.RequiredRemoteChanReserve(resCtx.chanAmt, msg.DustLimit)
maxHtlcs := f.cfg.RequiredRemoteMaxHTLCs(resCtx.chanAmt)
// The remote node has responded with their portion of the channel // The remote node has responded with their portion of the channel
// contribution. At this point, we can process their contribution which // contribution. At this point, we can process their contribution which
@ -1574,7 +1575,7 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
MaxPendingAmount: resCtx.remoteMaxValue, MaxPendingAmount: resCtx.remoteMaxValue,
ChanReserve: chanReserve, ChanReserve: chanReserve,
MinHTLC: resCtx.remoteMinHtlc, MinHTLC: resCtx.remoteMinHtlc,
MaxAcceptedHtlcs: maxHtlcs, MaxAcceptedHtlcs: resCtx.remoteMaxHtlcs,
CsvDelay: resCtx.remoteCsvDelay, CsvDelay: resCtx.remoteCsvDelay,
}, },
MultiSigKey: keychain.KeyDescriptor{ MultiSigKey: keychain.KeyDescriptor{
@ -3267,6 +3268,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
remoteCsvDelay: remoteCsvDelay, remoteCsvDelay: remoteCsvDelay,
remoteMinHtlc: minHtlcIn, remoteMinHtlc: minHtlcIn,
remoteMaxValue: maxValue, remoteMaxValue: maxValue,
remoteMaxHtlcs: maxHtlcs,
reservation: reservation, reservation: reservation,
peer: msg.peer, peer: msg.peer,
updates: msg.updates, updates: msg.updates,