htlcswitch: respect minimum relay fee

When channels fee rates are being considered for an update, the minimum
relay fee should also be considered.
This commit is contained in:
Elle Mouton committed 2021-10-05 18:30:41 +02:00
1 parent 6712595618
commit f667683e6c
5 files changed
+317 -60

No files matched your search

+41 -7
View File
@@ -3744,6 +3744,7 @@ func TestShouldAdjustCommitFee(t *testing.T) {
tests := []struct {
netFee chainfee.SatPerKWeight
chanFee chainfee.SatPerKWeight
minRelayFee chainfee.SatPerKWeight
shouldAdjust bool
}{
@@ -3819,11 +3820,22 @@ func TestShouldAdjustCommitFee(t *testing.T) {
chanFee: 1000,
shouldAdjust: false,
},
// The network fee is higher than our commitment fee,
// hasn't yet crossed our activation threshold, but the
// current commitment fee is below the minimum relay fee and
// so the fee should be updated.
{
netFee: 1100,
chanFee: 1098,
minRelayFee: 1099,
shouldAdjust: true,
},
}
for i, test := range tests {
adjustedFee := shouldAdjustCommitFee(
test.netFee, test.chanFee,
test.netFee, test.chanFee, test.minRelayFee,
)
if adjustedFee && !test.shouldAdjust {
@@ -4009,6 +4021,13 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
{"bob", "alice", &lnwire.RevokeAndAck{}, false},
{"bob", "alice", &lnwire.CommitSig{}, false},
{"alice", "bob", &lnwire.RevokeAndAck{}, false},
// Third fee update.
{"alice", "bob", &lnwire.UpdateFee{}, false},
{"alice", "bob", &lnwire.CommitSig{}, false},
{"bob", "alice", &lnwire.RevokeAndAck{}, false},
{"bob", "alice", &lnwire.CommitSig{}, false},
{"alice", "bob", &lnwire.RevokeAndAck{}, false},
}
n.aliceServer.intersect(createInterceptorFunc("[alice] <-- [bob]",
"alice", messages, chanID, false))
@@ -4025,8 +4044,8 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
// triggerFeeUpdate is a helper closure to determine whether a fee
// update was triggered and completed properly.
triggerFeeUpdate := func(feeEstimate, newFeeRate chainfee.SatPerKWeight,
shouldUpdate bool) {
triggerFeeUpdate := func(feeEstimate, minRelayFee,
newFeeRate chainfee.SatPerKWeight, shouldUpdate bool) {
t.Helper()
@@ -4046,6 +4065,13 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
t.Fatalf("alice didn't query for the new network fee")
}
// We also send the min relay fee response to Alice.
select {
case n.feeEstimator.relayFee <- minRelayFee:
case <-time.After(time.Second * 5):
t.Fatalf("alice didn't query for the min relay fee")
}
// Record the fee rates after the links have processed the fee
// update and ensure they are correct based on whether a fee
// update should have been triggered.
@@ -4071,20 +4097,28 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
}, 10*time.Second, time.Second)
}
minRelayFee := startingFeeRate / 3
// Triggering the link to update the fee of the channel with the same
// fee rate should not send a fee update.
triggerFeeUpdate(startingFeeRate, startingFeeRate, false)
triggerFeeUpdate(startingFeeRate, minRelayFee, startingFeeRate, false)
// Triggering the link to update the fee of the channel with a much
// larger fee rate _should_ send a fee update.
newFeeRate := startingFeeRate * 3
triggerFeeUpdate(newFeeRate, newFeeRate, true)
triggerFeeUpdate(newFeeRate, minRelayFee, newFeeRate, true)
// Triggering the link to update the fee of the channel with a fee rate
// that exceeds its maximum fee allocation should result in a fee rate
// corresponding to the maximum fee allocation.
const maxFeeRate chainfee.SatPerKWeight = 207182320
triggerFeeUpdate(maxFeeRate+1, maxFeeRate, true)
const maxFeeRate chainfee.SatPerKWeight = 207180182
triggerFeeUpdate(maxFeeRate+1, minRelayFee, maxFeeRate, true)
// Triggering the link to update the fee of the channel with a fee rate
// that is below the current min relay fee rate should result in a fee
// rate corresponding to the minimum relay fee.
newFeeRate = minRelayFee / 2
triggerFeeUpdate(newFeeRate, minRelayFee, minRelayFee, true)
}
// TestChannelLinkAcceptDuplicatePayment tests that if a link receives an