-
Notifications
You must be signed in to change notification settings - Fork 2.3k
lnwallet+htlcswitch: make Switch dust-aware #5770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7d16e58
0b24603
0ce6194
3897baf
702b3a3
25a0fe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |
|
|
||
| "github.com/btcsuite/btcd/wire" | ||
| "github.com/btcsuite/btclog" | ||
| "github.com/btcsuite/btcutil" | ||
| "github.com/davecgh/go-spew/spew" | ||
| "github.com/go-errors/errors" | ||
| "github.com/lightningnetwork/lnd/build" | ||
|
|
@@ -1929,6 +1930,10 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { | |
| "error receiving fee update: %v", err) | ||
| return | ||
| } | ||
|
|
||
| // Update the mailbox's feerate as well. | ||
| l.mailBox.SetFeeRate(fee) | ||
|
Crypt-iQ marked this conversation as resolved.
Outdated
|
||
|
|
||
| case *lnwire.Error: | ||
| // Error received from remote, MUST fail channel, but should | ||
| // only print the contents of the error message if all | ||
|
|
@@ -2192,6 +2197,64 @@ func (l *channelLink) MayAddOutgoingHtlc() error { | |
| return l.channel.MayAddOutgoingHtlc() | ||
| } | ||
|
|
||
| // getDustSum is a wrapper method that calls the underlying channel's dust sum | ||
| // method. | ||
| // | ||
| // NOTE: Part of the dustHandler interface. | ||
| func (l *channelLink) getDustSum(remote bool) lnwire.MilliSatoshi { | ||
| return l.channel.GetDustSum(remote) | ||
| } | ||
|
|
||
| // getFeeRate is a wrapper method that retrieves the underlying channel's | ||
| // feerate. | ||
| // | ||
| // NOTE: Part of the dustHandler interface. | ||
| func (l *channelLink) getFeeRate() chainfee.SatPerKWeight { | ||
| return l.channel.CommitFeeRate() | ||
| } | ||
|
|
||
| // getDustClosure returns a closure that can be used by the switch or mailbox | ||
| // to evaluate whether a given HTLC is dust. | ||
| // | ||
| // NOTE: Part of the dustHandler interface. | ||
| func (l *channelLink) getDustClosure() dustClosure { | ||
| localDustLimit := l.channel.State().LocalChanCfg.DustLimit | ||
| remoteDustLimit := l.channel.State().RemoteChanCfg.DustLimit | ||
| chanType := l.channel.State().ChanType | ||
|
|
||
| return dustHelper(chanType, localDustLimit, remoteDustLimit) | ||
| } | ||
|
|
||
| // dustClosure is a function that evaluates whether an HTLC is dust. It returns | ||
| // true if the HTLC is dust. It takes in a feerate, a boolean denoting whether | ||
| // the HTLC is incoming (i.e. one that the remote sent), a boolean denoting | ||
| // whether to evaluate on the local or remote commit, and finally an HTLC | ||
| // amount to test. | ||
| type dustClosure func(chainfee.SatPerKWeight, bool, bool, btcutil.Amount) bool | ||
|
carlaKC marked this conversation as resolved.
Outdated
|
||
|
|
||
| // dustHelper is used to construct the dustClosure. | ||
| func dustHelper(chantype channeldb.ChannelType, localDustLimit, | ||
| remoteDustLimit btcutil.Amount) dustClosure { | ||
|
|
||
| isDust := func(feerate chainfee.SatPerKWeight, incoming, | ||
| localCommit bool, amt btcutil.Amount) bool { | ||
|
|
||
| if localCommit { | ||
| return lnwallet.HtlcIsDust( | ||
| chantype, incoming, true, feerate, amt, | ||
| localDustLimit, | ||
| ) | ||
| } | ||
|
|
||
| return lnwallet.HtlcIsDust( | ||
| chantype, incoming, false, feerate, amt, | ||
| remoteDustLimit, | ||
| ) | ||
| } | ||
|
|
||
| return isDust | ||
| } | ||
|
|
||
| // AttachMailBox updates the current mailbox used by this link, and hooks up | ||
| // the mailbox's message and packet outboxes to the link's upstream and | ||
| // downstream chans, respectively. | ||
|
|
@@ -2201,6 +2264,14 @@ func (l *channelLink) AttachMailBox(mailbox MailBox) { | |
| l.upstream = mailbox.MessageOutBox() | ||
| l.downstream = mailbox.PacketOutBox() | ||
| l.Unlock() | ||
|
|
||
| // Set the mailbox's fee rate. This may be refreshing a feerate that was | ||
| // never committed. | ||
| l.mailBox.SetFeeRate(l.getFeeRate()) | ||
|
|
||
| // Also set the mailbox's dust closure so that it can query whether HTLC's | ||
| // are dust given the current feerate. | ||
| l.mailBox.SetDustClosure(l.getDustClosure()) | ||
| } | ||
|
|
||
| // UpdateForwardingPolicy updates the forwarding policy for the target | ||
|
|
@@ -2501,6 +2572,10 @@ func (l *channelLink) updateChannelFee(feePerKw chainfee.SatPerKWeight) error { | |
| return err | ||
| } | ||
|
|
||
| // The fee passed the channel's validation checks, so we update the | ||
| // mailbox feerate. | ||
| l.mailBox.SetFeeRate(feePerKw) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a problem if we set fee rate here but then fail to send the new fee rate through to our peer?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assumption I made here is that Typing this out, I realize that the mailbox could have an outdated feerate:
Could add another method to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, agree it's not worth the extra code, maybe just drop a comment on the mailbox
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment added |
||
|
|
||
| // We'll then attempt to send a new UpdateFee message, and also lock it | ||
| // in immediately by triggering a commitment update. | ||
| msg := lnwire.NewUpdateFee(l.ChanID(), uint32(feePerKw)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.