Skip to content

Commit 1877d05

Browse files
committed
htlcswitch: extend ChannelLink iface with dustHandler iface
This allows the Switch to determine the dust exposure of a certain channel and allows the link to set the dust limits for its mailbox.
1 parent ec66696 commit 1877d05

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

htlcswitch/interfaces.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ type packetHandler interface {
5757
handleLocalAddPacket(*htlcPacket) error
5858
}
5959

60+
// dustHandler is an interface used exclusively by the Switch to evaluate
61+
// whether a link has too much dust exposure.
62+
type dustHandler interface {
63+
// getDustSum returns the dust sum on either the local or remote
64+
// commitment.
65+
getDustSum(remote bool) lnwire.MilliSatoshi
66+
67+
// getDustLimits returns the underlying channel's dust limits.
68+
getDustLimits() (lnwire.MilliSatoshi, lnwire.MilliSatoshi)
69+
}
70+
6071
// ChannelUpdateHandler is an interface that provides methods that allow
6172
// sending lnwire.Message to the underlying link as well as querying state.
6273
type ChannelUpdateHandler interface {
@@ -122,6 +133,9 @@ type ChannelLink interface {
122133
// Embed the ChannelUpdateHandler interface.
123134
ChannelUpdateHandler
124135

136+
// Embed the dustHandler interface.
137+
dustHandler
138+
125139
// ChannelPoint returns the channel outpoint for the channel link.
126140
ChannelPoint() *wire.OutPoint
127141

htlcswitch/link.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,29 @@ func (l *channelLink) MayAddOutgoingHtlc() error {
21922192
return l.channel.MayAddOutgoingHtlc()
21932193
}
21942194

2195+
// getDustSum is a wrapper method that calls the underlying channel's dust sum
2196+
// method.
2197+
//
2198+
// NOTE: Part of the dustHandler interface.
2199+
func (l *channelLink) getDustSum(remote bool) lnwire.MilliSatoshi {
2200+
return l.channel.GetDustSum(remote)
2201+
}
2202+
2203+
// getDustLimits returns the local and remote dust limits.
2204+
//
2205+
// NOTE: Part of the dustHandler interface.
2206+
func (l *channelLink) getDustLimits() (lnwire.MilliSatoshi,
2207+
lnwire.MilliSatoshi) {
2208+
2209+
localDustLimit := l.channel.State().LocalChanCfg.DustLimit
2210+
remoteDustLimit := l.channel.State().RemoteChanCfg.DustLimit
2211+
2212+
localMsat := lnwire.NewMSatFromSatoshis(localDustLimit)
2213+
remoteMsat := lnwire.NewMSatFromSatoshis(remoteDustLimit)
2214+
2215+
return localMsat, remoteMsat
2216+
}
2217+
21952218
// AttachMailBox updates the current mailbox used by this link, and hooks up
21962219
// the mailbox's message and packet outboxes to the link's upstream and
21972220
// downstream chans, respectively.
@@ -2200,6 +2223,11 @@ func (l *channelLink) AttachMailBox(mailbox MailBox) {
22002223
l.mailBox = mailbox
22012224
l.upstream = mailbox.MessageOutBox()
22022225
l.downstream = mailbox.PacketOutBox()
2226+
2227+
// Set the mailbox's DustLimit variables if they are not already set.
2228+
local, remote := l.getDustLimits()
2229+
l.mailBox.SetDustLimits(local, remote)
2230+
22032231
l.Unlock()
22042232
}
22052233

htlcswitch/mock.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,16 @@ func (f *mockChannelLink) handleLocalAddPacket(pkt *htlcPacket) error {
716716
return nil
717717
}
718718

719+
func (f *mockChannelLink) getDustSum(remote bool) lnwire.MilliSatoshi {
720+
return 0
721+
}
722+
723+
func (f *mockChannelLink) getDustLimits() (lnwire.MilliSatoshi,
724+
lnwire.MilliSatoshi) {
725+
726+
return 0, 0
727+
}
728+
719729
func (f *mockChannelLink) HandleChannelUpdate(lnwire.Message) {
720730
}
721731

0 commit comments

Comments
 (0)