From da42ad245f1325eac5e5d3d5745d4699bd109680 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 30 Jan 2019 09:05:01 +0100 Subject: [PATCH] funding: cap the max_htlc value at channel capacity We are not longer validating the max_value_in_flight field set by the remote peer, so it is not always less than the channel capacity anymore. We therefore make sure to cap it before advertising it. --- fundingmanager.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index b5127c0f..50519116 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -2111,10 +2111,12 @@ func (f *fundingManager) addToRouterGraph(completeChan *channeldb.OpenChannel, // We'll obtain the max HTLC value we can forward in our direction, as // we'll use this value within our ChannelUpdate. This value must be <= - // channel capacity and <= the maximum in-flight msats set by the peer, so - // we default to max in-flight msats as this value will always be <= - // channel capacity. + // channel capacity and <= the maximum in-flight msats set by the peer. fwdMaxHTLC := completeChan.LocalChanCfg.MaxPendingAmount + capacityMSat := lnwire.NewMSatFromSatoshis(completeChan.Capacity) + if fwdMaxHTLC > capacityMSat { + fwdMaxHTLC = capacityMSat + } ann, err := f.newChanAnnouncement( f.cfg.IDKey, completeChan.IdentityPub, @@ -2285,12 +2287,15 @@ func (f *fundingManager) annAfterSixConfs(completeChan *channeldb.OpenChannel, // HTLC it deems economically relevant. fwdMinHTLC := completeChan.LocalChanCfg.MinHTLC - // We'll obtain the max HTLC value we can forward in our direction, as - // we'll use this value within our ChannelUpdate. This value must be <= - // channel capacity and <= the maximum in-flight msats set by the peer, - // so we default to max in-flight msats as this value will always be <= - // channel capacity. + // We'll obtain the max HTLC value we can forward in our + // direction, as we'll use this value within our ChannelUpdate. + // This value must be <= channel capacity and <= the maximum + // in-flight msats set by the peer. fwdMaxHTLC := completeChan.LocalChanCfg.MaxPendingAmount + capacityMSat := lnwire.NewMSatFromSatoshis(completeChan.Capacity) + if fwdMaxHTLC > capacityMSat { + fwdMaxHTLC = capacityMSat + } // Create and broadcast the proofs required to make this channel // public and usable for other nodes for routing.