multi: thread bandwidth check amount down to MayAddOutgoingHtlc
Pass htlc amount down to the channel so that we don't need to rely on minHtlc (and pad it when the channel sets a 0 min htlc). Update test to just check some sane values since we're no longer relying on minHtlc amount at all.
This commit is contained in:
13 files changed
+81
-39
No files matched your search
+13
-7
@@ -12,8 +12,13 @@ import (
|
||||
type bandwidthHints interface {
|
||||
// availableChanBandwidth returns the total available bandwidth for a
|
||||
// channel and a bool indicating whether the channel hint was found.
|
||||
// If the channel is unavailable, a zero amount is returned.
|
||||
availableChanBandwidth(channelID uint64) (lnwire.MilliSatoshi, bool)
|
||||
// The amount parameter is used to validate the outgoing htlc amount
|
||||
// that we wish to add to the channel against its flow restrictions. If
|
||||
// a zero amount is provided, the minimum htlc value for the channel
|
||||
// will be used. If the channel is unavailable, a zero amount is
|
||||
// returned.
|
||||
availableChanBandwidth(channelID uint64,
|
||||
amount lnwire.MilliSatoshi) (lnwire.MilliSatoshi, bool)
|
||||
}
|
||||
|
||||
// getLinkQuery is the function signature used to lookup a link.
|
||||
@@ -65,7 +70,8 @@ func newBandwidthManager(graph routingGraph, sourceNode route.Vertex,
|
||||
// available bandwidth. Note that this function assumes that the channel being
|
||||
// queried is one of our local channels, so any failure to retrieve the link
|
||||
// is interpreted as the link being offline.
|
||||
func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID) lnwire.MilliSatoshi {
|
||||
func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
||||
amount lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||
link, err := b.getLink(cid)
|
||||
if err != nil {
|
||||
// If the link isn't online, then we'll report that it has
|
||||
@@ -82,7 +88,7 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID) lnwire.MilliS
|
||||
|
||||
// If our link isn't currently in a state where it can add another
|
||||
// outgoing htlc, treat the link as unusable.
|
||||
if err := link.MayAddOutgoingHtlc(); err != nil {
|
||||
if err := link.MayAddOutgoingHtlc(amount); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -94,8 +100,8 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID) lnwire.MilliS
|
||||
// availableChanBandwidth returns the total available bandwidth for a channel
|
||||
// and a bool indicating whether the channel hint was found. If the channel is
|
||||
// unavailable, a zero amount is returned.
|
||||
func (b *bandwidthManager) availableChanBandwidth(channelID uint64) (
|
||||
lnwire.MilliSatoshi, bool) {
|
||||
func (b *bandwidthManager) availableChanBandwidth(channelID uint64,
|
||||
amount lnwire.MilliSatoshi) (lnwire.MilliSatoshi, bool) {
|
||||
|
||||
shortID := lnwire.NewShortChanIDFromInt(channelID)
|
||||
_, ok := b.localChans[shortID]
|
||||
@@ -103,5 +109,5 @@ func (b *bandwidthManager) availableChanBandwidth(channelID uint64) (
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return b.getBandwidth(shortID), true
|
||||
return b.getBandwidth(shortID, amount), true
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func TestBandwidthManager(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
bandwidth, found := m.availableChanBandwidth(
|
||||
testCase.channelID,
|
||||
testCase.channelID, 10,
|
||||
)
|
||||
require.Equal(t, testCase.expectedBandwidth, bandwidth)
|
||||
require.Equal(t, testCase.expectFound, found)
|
||||
|
||||
@@ -22,8 +22,8 @@ type mockBandwidthHints struct {
|
||||
hints map[uint64]lnwire.MilliSatoshi
|
||||
}
|
||||
|
||||
func (m *mockBandwidthHints) availableChanBandwidth(channelID uint64) (
|
||||
lnwire.MilliSatoshi, bool) {
|
||||
func (m *mockBandwidthHints) availableChanBandwidth(channelID uint64,
|
||||
_ lnwire.MilliSatoshi) (lnwire.MilliSatoshi, bool) {
|
||||
|
||||
if m.hints == nil {
|
||||
return 0, false
|
||||
|
||||
@@ -760,6 +760,6 @@ func (m *mockLink) EligibleToForward() bool {
|
||||
}
|
||||
|
||||
// MayAddOutgoingHtlc returns the error configured in our mock.
|
||||
func (m *mockLink) MayAddOutgoingHtlc() error {
|
||||
func (m *mockLink) MayAddOutgoingHtlc(_ lnwire.MilliSatoshi) error {
|
||||
return m.mayAddOutgoingErr
|
||||
}
|
||||
+3
-1
@@ -373,7 +373,9 @@ func getOutgoingBalance(node route.Vertex, outgoingChans map[uint64]struct{},
|
||||
}
|
||||
}
|
||||
|
||||
bandwidth, ok := bandwidthHints.availableChanBandwidth(chanID)
|
||||
bandwidth, ok := bandwidthHints.availableChanBandwidth(
|
||||
chanID, 0,
|
||||
)
|
||||
|
||||
// If the bandwidth is not available, use the channel capacity.
|
||||
// This can happen when a channel is added to the graph after
|
||||
|
||||
@@ -170,7 +170,7 @@ func (u *unifiedPolicy) getPolicyLocal(amt lnwire.MilliSatoshi,
|
||||
// channel. The bandwidth hint is expected to be
|
||||
// available.
|
||||
bandwidth, ok := bandwidthHints.availableChanBandwidth(
|
||||
edge.policy.ChannelID,
|
||||
edge.policy.ChannelID, amt,
|
||||
)
|
||||
if !ok {
|
||||
bandwidth = lnwire.MaxMilliSatoshi
|
||||
|
||||
Reference in new issue
Block a user