From 3e4f920ad130ef5cdf7a00c8b00c03041c9723f5 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 10 Sep 2024 15:06:12 +0200 Subject: [PATCH] tapchannel: add chan reserve check on PaymentBandwidth method --- tapchannel/aux_traffic_shaper.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tapchannel/aux_traffic_shaper.go b/tapchannel/aux_traffic_shaper.go index 08b7b82e0..1e9c1e7e4 100644 --- a/tapchannel/aux_traffic_shaper.go +++ b/tapchannel/aux_traffic_shaper.go @@ -140,6 +140,19 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob, return linkBandwidth, nil } + htlcAmountMSat := lnwire.NewMSatFromSatoshis(DefaultOnChainHtlcAmount) + + // Todo: grab actual channel reserve + chanReserve := lnwire.MilliSatoshi(0) + + // Check if the current link bandwidth can afford sending our default + // htlc amount without dipping into the channel reserve. If it goes + // below the reserve, we report zero bandwdith as we cannot push the + // htlc amount. + if linkBandwidth-htlcAmountMSat <= chanReserve { + return 0, nil + } + commitment, err := cmsg.DecodeCommitment(commitmentBytes) if err != nil { return 0, fmt.Errorf("error decoding commitment blob: %w", err)