From 1760fe30db09db99db6b6134afd4a96b2b230f71 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 12 Aug 2020 15:45:48 -0700 Subject: [PATCH] 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. --- fundingmanager.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index e6a53dc0b..c2343b8f2 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -124,6 +124,7 @@ type reservationWithCtx struct { remoteCsvDelay uint16 remoteMinHtlc lnwire.MilliSatoshi remoteMaxValue lnwire.MilliSatoshi + remoteMaxHtlcs uint16 updateMtx sync.RWMutex lastUpdated time.Time @@ -1411,6 +1412,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) { remoteCsvDelay: remoteCsvDelay, remoteMinHtlc: minHtlc, remoteMaxValue: remoteMaxValue, + remoteMaxHtlcs: maxHtlcs, err: make(chan error, 1), peer: fmsg.peer, } @@ -1560,7 +1562,6 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) { // here so we can properly commit their accepted constraints to the // reservation. 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 // contribution. At this point, we can process their contribution which @@ -1574,7 +1575,7 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) { MaxPendingAmount: resCtx.remoteMaxValue, ChanReserve: chanReserve, MinHTLC: resCtx.remoteMinHtlc, - MaxAcceptedHtlcs: maxHtlcs, + MaxAcceptedHtlcs: resCtx.remoteMaxHtlcs, CsvDelay: resCtx.remoteCsvDelay, }, MultiSigKey: keychain.KeyDescriptor{ @@ -3267,6 +3268,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { remoteCsvDelay: remoteCsvDelay, remoteMinHtlc: minHtlcIn, remoteMaxValue: maxValue, + remoteMaxHtlcs: maxHtlcs, reservation: reservation, peer: msg.peer, updates: msg.updates,