@@ -121,7 +121,7 @@ func (s *AuxTrafficShaper) HandleTraffic(_ lnwire.ShortChannelID,
121121// called first.
122122func (s * AuxTrafficShaper ) PaymentBandwidth (htlcBlob ,
123123 commitmentBlob lfn.Option [tlv.Blob ],
124- linkBandwidth lnwire.MilliSatoshi ) (lnwire.MilliSatoshi , error ) {
124+ linkBandwidth , htlcAmt lnwire.MilliSatoshi ) (lnwire.MilliSatoshi , error ) {
125125
126126 // If the commitment or HTLC blob is not set, we don't have any
127127 // information about the channel and cannot determine the available
@@ -140,6 +140,35 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
140140 return linkBandwidth , nil
141141 }
142142
143+ // Get the minimum HTLC amount, which is just above dust.
144+ minHtlcAmt := lnwire .NewMSatFromSatoshis (DefaultOnChainHtlcAmount )
145+
146+ // LND calls this hook twice. Once to see if the overall budget of the
147+ // node is enough, and then during pathfinding to actually see if
148+ // there's enough balance in the channel to make the payment attempt.
149+ //
150+ // When doing the overall balance check, we don't know what the actual
151+ // htlcAmt is in satoshis, so a value of 0 will be passed here. Let's at
152+ // least check if we can afford the min amount above dust. If the actual
153+ // htlc amount ends up being greater when calling this method during
154+ // pathfinding, we will still check it below.
155+
156+ // If the passed htlcAmt is below dust, then assume the dust amount. At
157+ // this point we know we are sending assets, so we cannot anchor them to
158+ // dust amounts. Dust HTLCs are added to the fees and aren't
159+ // materialized in an on-chain output, so we wouldn't have anything
160+ // to anchor the asset commitment to.
161+ if htlcAmt < minHtlcAmt {
162+ htlcAmt = minHtlcAmt
163+ }
164+
165+ // Check if the current link bandwidth can afford sending out the htlc
166+ // amount without dipping into the channel reserve. If it goes below the
167+ // reserve, we report zero bandwdith as we cannot push the htlc amount.
168+ if linkBandwidth < htlcAmt {
169+ return 0 , nil
170+ }
171+
143172 commitment , err := cmsg .DecodeCommitment (commitmentBytes )
144173 if err != nil {
145174 return 0 , fmt .Errorf ("error decoding commitment blob: %w" , err )
0 commit comments