From 7e84892c21821a851bec0daa35264ec3b9d90d67 Mon Sep 17 00:00:00 2001 From: nsa Date: Wed, 29 Nov 2017 14:26:48 +0100 Subject: [PATCH] htlcswitch: account for channel reserve in Bandwidth --- htlcswitch/link.go | 3 ++- htlcswitch/test_utils.go | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 4f4e0b52..4c94b44d 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -1264,8 +1264,9 @@ func (l *channelLink) Bandwidth() lnwire.MilliSatoshi { // TODO(roasbeef): subtract reserve channelBandwidth := l.channel.AvailableBalance() overflowBandwidth := l.overflowQueue.TotalHtlcAmount() + reserve := lnwire.NewMSatFromSatoshis(l.channel.GetReserve()) - return channelBandwidth - overflowBandwidth + return channelBandwidth - overflowBandwidth - reserve } // policyUpdate is a message sent to a channel link when an outside sub-system diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 7595a6d7..23a9776c 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -97,11 +97,27 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte, bobKeyPriv, bobKeyPub := btcec.PrivKeyFromBytes(btcec.S256(), bobPrivKey) channelCapacity := aliceAmount + bobAmount - aliceDustLimit := btcutil.Amount(200) - bobDustLimit := btcutil.Amount(800) csvTimeoutAlice := uint32(5) csvTimeoutBob := uint32(4) + aliceConstraints := &channeldb.ChannelConstraints{ + DustLimit: btcutil.Amount(200), + MaxPendingAmount: lnwire.NewMSatFromSatoshis( + channelCapacity), + ChanReserve: 0, + MinHTLC: 0, + MaxAcceptedHtlcs: lnwallet.MaxHTLCNumber / 2, + } + + bobConstraints := &channeldb.ChannelConstraints{ + DustLimit: btcutil.Amount(800), + MaxPendingAmount: lnwire.NewMSatFromSatoshis( + channelCapacity), + ChanReserve: 0, + MinHTLC: 0, + MaxAcceptedHtlcs: lnwallet.MaxHTLCNumber / 2, + } + var hash [sha256.Size]byte randomSeed, err := generateRandomBytes(sha256.Size) if err != nil { @@ -116,9 +132,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte, fundingTxIn := wire.NewTxIn(prevOut, nil, nil) aliceCfg := channeldb.ChannelConfig{ - ChannelConstraints: channeldb.ChannelConstraints{ - DustLimit: aliceDustLimit, - }, + ChannelConstraints: *aliceConstraints, CsvDelay: uint16(csvTimeoutAlice), MultiSigKey: aliceKeyPub, RevocationBasePoint: aliceKeyPub, @@ -127,9 +141,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte, HtlcBasePoint: aliceKeyPub, } bobCfg := channeldb.ChannelConfig{ - ChannelConstraints: channeldb.ChannelConstraints{ - DustLimit: bobDustLimit, - }, + ChannelConstraints: *bobConstraints, CsvDelay: uint16(csvTimeoutBob), MultiSigKey: bobKeyPub, RevocationBasePoint: bobKeyPub,