htlcswitch: update TestChannelLinkBandwidthConsistencyOverflow to account for HTLC fees
This commit is contained in:
parent
3e00b2a0a9
commit
fceec1306d
@ -1610,16 +1610,24 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
coreLink = aliceLink.(*channelLink)
|
coreLink = aliceLink.(*channelLink)
|
||||||
|
defaultCommitFee = coreLink.channel.StateSnapshot().CommitFee
|
||||||
aliceStartingBandwidth = aliceLink.Bandwidth()
|
aliceStartingBandwidth = aliceLink.Bandwidth()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
estimator := &lnwallet.StaticFeeEstimator{
|
||||||
|
FeeRate: 24,
|
||||||
|
Confirmation: 6,
|
||||||
|
}
|
||||||
|
feePerKw := btcutil.Amount(estimator.EstimateFeePerWeight(1) * 1000)
|
||||||
|
|
||||||
addLinkHTLC := func(amt lnwire.MilliSatoshi) [32]byte {
|
addLinkHTLC := func(amt lnwire.MilliSatoshi) [32]byte {
|
||||||
invoice, htlc, err := generatePayment(amt, amt, 5, mockBlob)
|
invoice, htlc, err := generatePayment(amt, amt, 5, mockBlob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create payment: %v", err)
|
t.Fatalf("unable to create payment: %v", err)
|
||||||
}
|
}
|
||||||
addPkt := htlcPacket{
|
addPkt := htlcPacket{
|
||||||
htlc: htlc,
|
htlc: htlc,
|
||||||
|
amount: amt,
|
||||||
}
|
}
|
||||||
aliceLink.HandleSwitchPacket(&addPkt)
|
aliceLink.HandleSwitchPacket(&addPkt)
|
||||||
|
|
||||||
@ -1640,8 +1648,13 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
|
|||||||
totalHtlcAmt += htlcAmt
|
totalHtlcAmt += htlcAmt
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Second * 1)
|
||||||
expectedBandwidth := aliceStartingBandwidth - totalHtlcAmt
|
commitWeight := lnwallet.CommitWeight + lnwallet.HtlcWeight*numHTLCs
|
||||||
|
htlcFee := lnwire.NewMSatFromSatoshis(
|
||||||
|
btcutil.Amount((int64(feePerKw) * commitWeight) / 1000),
|
||||||
|
)
|
||||||
|
expectedBandwidth := aliceStartingBandwidth - totalHtlcAmt - htlcFee
|
||||||
|
expectedBandwidth += lnwire.NewMSatFromSatoshis(defaultCommitFee)
|
||||||
assertLinkBandwidth(t, aliceLink, expectedBandwidth)
|
assertLinkBandwidth(t, aliceLink, expectedBandwidth)
|
||||||
|
|
||||||
// The overflow queue should be empty at this point, as the commitment
|
// The overflow queue should be empty at this point, as the commitment
|
||||||
@ -1653,7 +1666,7 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
|
|||||||
|
|
||||||
// At this point, the commitment transaction should now be fully
|
// At this point, the commitment transaction should now be fully
|
||||||
// saturated. We'll continue adding HTLC's, and asserting that the
|
// saturated. We'll continue adding HTLC's, and asserting that the
|
||||||
// bandwidth account is done properly.
|
// bandwidth accounting is done properly.
|
||||||
const numOverFlowHTLCs = 20
|
const numOverFlowHTLCs = 20
|
||||||
for i := 0; i < numOverFlowHTLCs; i++ {
|
for i := 0; i < numOverFlowHTLCs; i++ {
|
||||||
preImage := addLinkHTLC(htlcAmt)
|
preImage := addLinkHTLC(htlcAmt)
|
||||||
@ -1662,12 +1675,10 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
|
|||||||
totalHtlcAmt += htlcAmt
|
totalHtlcAmt += htlcAmt
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Second * 2)
|
||||||
expectedBandwidth = aliceStartingBandwidth - totalHtlcAmt
|
expectedBandwidth -= (numOverFlowHTLCs * htlcAmt)
|
||||||
assertLinkBandwidth(t, aliceLink, expectedBandwidth)
|
assertLinkBandwidth(t, aliceLink, expectedBandwidth)
|
||||||
|
|
||||||
aliceEndBandwidth := aliceLink.Bandwidth()
|
|
||||||
|
|
||||||
// With the extra HTLC's added, the overflow queue should now be
|
// With the extra HTLC's added, the overflow queue should now be
|
||||||
// populated with our 10 additional HTLC's.
|
// populated with our 10 additional HTLC's.
|
||||||
if coreLink.overflowQueue.Length() != numOverFlowHTLCs {
|
if coreLink.overflowQueue.Length() != numOverFlowHTLCs {
|
||||||
@ -1688,13 +1699,15 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
|
|||||||
|
|
||||||
aliceLink.HandleChannelUpdate(htlcSettle)
|
aliceLink.HandleChannelUpdate(htlcSettle)
|
||||||
time.Sleep(time.Millisecond * 50)
|
time.Sleep(time.Millisecond * 50)
|
||||||
assertLinkBandwidth(t, aliceLink, aliceEndBandwidth)
|
|
||||||
|
|
||||||
// As we're not actually initiating a full state update, we'll
|
// As we're not actually initiating a full state update, we'll
|
||||||
// trigger a free-slot signal manually here.
|
// trigger a free-slot signal manually here.
|
||||||
coreLink.overflowQueue.SignalFreeSlot()
|
coreLink.overflowQueue.SignalFreeSlot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * 200)
|
||||||
|
assertLinkBandwidth(t, aliceLink, expectedBandwidth)
|
||||||
|
|
||||||
// Finally, at this point, the queue itself should be fully empty. As
|
// Finally, at this point, the queue itself should be fully empty. As
|
||||||
// enough slots have been drained from the commitment transaction to
|
// enough slots have been drained from the commitment transaction to
|
||||||
// allocate the queue items to.
|
// allocate the queue items to.
|
||||||
|
Loading…
Reference in New Issue
Block a user