-
Notifications
You must be signed in to change notification settings - Fork 2.2k
htlcswitch: exit early if no adds are in the fwd pkg #9911
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
htlcswitch: exit early if no adds are in the fwd pkg #9911
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would always record a HTLC two times in the decayed log (batch-replay bucket) protection
When there are no Adds it's a noop?
I actually verified on my local node and HTLC will be persisted 2 times in the batch-reply log, here is the flow: Line 3761 in 4a7cd00
We start the batch_replay tx here: lnd/htlcswitch/hop/iterator.go Line 756 in 4a7cd00
it persist the empty batch in the batch-reply here: lnd/htlcswitch/hop/iterator.go Line 831 in 4a7cd00
which happens here: and writes it eventually here: Line 407 in 4a7cd00
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually verified on my local node and HTLC will be persisted 2 times in the batch-reply log, here is the flow:
Nice analysis! I'm wondering why would call processRemoteAdds
with empty ADDs?
func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg) { | ||
// Exit early if there are no adds to process. | ||
if len(fwdPkg.Adds) == 0 { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a log here since it's unexpected to have empty Adds
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not unexpeted tho, every HTLC will eventually be resolved and then the fwd has only Fail/Settles no ADDs, I can add a trace if you want ? In case no other HTLC is added while the first one is Removed.
FWD PKG 1 => adds the invoming HTLC onto the Channel
FWD PKG 2 => resolves the HTLC via an FAIL/Settle and has 0 ADDs in the single HTLC flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah right - we sort just move the empty check into the methods, so they are always called.
a7219c0
to
d82b1b8
Compare
This lead to the case that we would always record a HTLC two times in the decayed log protection which is not necessary in the first place.
d82b1b8
to
6feed32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM🙏
func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg) { | ||
// Exit early if there are no adds to process. | ||
if len(fwdPkg.Adds) == 0 { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah right - we sort just move the empty check into the methods, so they are always called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ☃️
This lead to the case that we would always record a HTLC
two times in the decayed log (batch-replay bucket) protection which is not necessary
in the first place.
We already do it for the settle/fail package:
lnd/htlcswitch/link.go
Lines 3626 to 3628 in 4a7cd00