-
Notifications
You must be signed in to change notification settings - Fork 2.2k
lnrpc: add HtlcIndex to ForwardingEvents #9813
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
lnrpc: add HtlcIndex to ForwardingEvents #9813
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 (
|
f4c5fd9
to
009584f
Compare
Thanks for the PR. |
Thanks for the heads up. I will check how this was handled before in previous PRs. For now, I will change this to a draft. |
009584f
to
cb09e8c
Compare
cb09e8c
to
a775db2
Compare
Thanks again for the early feedback, @guggero. I thought about writing a migration script or handling the EOF error, but I decided to handle the EOF error when decoding the events (Let me know if a migration is preferred instead). Also, does it make sense to set a default value of "0" when returning older event logs?. This means if you execute |
Definitely looks better now, thanks for the update. I think because |
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.
Thanks for the PR!
For forwarding events we need to have both incoming and outgoing htlc index.
A migration would be nice, tho I don't think it's possible since we cannot get the htlc index info. Alternative to fn.Option
, we can use a tlv record instead, sth like tlv.BigSizeT
to save the space since for a busy node the logs can be huge.
We should also update the RPC docs, and release docs to mention this behavior.
rpcserver.go
Outdated
@@ -8060,6 +8060,7 @@ func (r *rpcServer) ForwardingHistory(ctx context.Context, | |||
FeeMsat: uint64(feeMsat), | |||
AmtInMsat: uint64(amtInMsat), | |||
AmtOutMsat: uint64(amtOutMsat), | |||
HtlcIndex: event.HtlcIndex, |
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 also update the test here to check the change,
lnd/itest/lnd_multi-hop-payments_test.go
Lines 183 to 184 in 3707b1f
fwdingHistory := dave.RPC.ForwardingHistory(nil) | |
require.Len(ht, fwdingHistory.ForwardingEvents, numPayments) |
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.
Updated to check for the change 👍
a6343fe
to
5b070cb
Compare
Now using |
Thanks for the review @yyforyongyu. The ....
// IncomingHtlcID is the ID of the incoming HTLC in the payment circuit.
// If the HTLC ID is not set, the value will be nil.
IncomingHtlcID tlv.OptionalRecordT[tlv.TlvType0, tlv.BigSizeT[uint64]]
// OutgoingHtlcID is the ID of the outgoing HTLC in the payment circuit.
// If the HTLC ID is not set, the value will be nil.
OutgoingHtlcID tlv.OptionalRecordT[tlv.TlvType0, tlv.BigSizeT[uint64]]
... and then checking if the indices are set in the encode and decode functions? |
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.
Changes looking good! My main comment is to provide more detailed docs, and minor suggestion on the tests.
The tlv is quite new to me, but I've done some research on it, and I want to clarify something.
Yeah sth like that, I've played a bit locally without the optional record, here's the diff. Previously I was concerned about the size of the records, but since each TLV record requires extra 2 bytes to store the type and length info, plus one byte to store the total length of the TLV records, in this specific case, it would require extra 5 bytes. If the value stored is less than 0xffffffff
(roughly 4.3 billion), then each htlc index takes 5 bytes, so a total of 5*2 + 5 = 15 bytes, which takes one byte less than two uint64
.
However I don't think it's necessary to use TLV here now, as I'm looking forward to sunset the forwarding log bucket and relying on revocation log only one day - the latter plus the channel commitments gives us enough info to construct the forwarding events on the fly, maybe a simple query would be sufficient once we've done SQLizing the channeldb.
Also not requesting for changes, but just give you my thoughts on the most proper way of handling adding new fields, for this specific case,
- add new fields, without the
fn.Option
. - define a flag, sth like
NoHtlcIndexValue = math.MaxUint64
. - create a migration to migrate all forwarding events using this flag.
- at the RPC level, check the index value, and only set the optional field there if the value is not the above flag value.
This way we can avoid all the if-else branches and catching EOF in our serializer/deserializer, tho there's a bit more work to create the migration.
channeldb/forwarding_log.go
Outdated
return err | ||
} | ||
|
||
// Then we write the optional HTLC IDs if they are set. |
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.
To be more defensive - I would return an error here if f.IncomingHtlcID.IsNone()
to make it clear that they are mandatory.
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.
Makes sense since new events now should always have them. Now returning an error if the fields are not set.
@@ -213,6 +214,17 @@ func testMultiHopPayments(ht *lntest.HarnessTest) { | |||
require.Equal(ht, aliceAlias, event.PeerAliasOut) | |||
} | |||
|
|||
// Verify HTLC IDs are not nil and unique across all forwarding events. |
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.
Nice addition! I think we can make this test more rigorous by asserting the htlc ids are exactly [0, 1, 2, 3, 4]
.
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 tried using require.Equal
to compare the htlc indices strictly, the itest passed locally but all failed in the CI
, seems it's a bit hard to track the exact indices.
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 the events order is not guaranteed, so we'll need to collect the indices in a map and compare them after the iteration.
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.
Now comparing the indices
90b2f24
to
f06a99c
Compare
Thanks again for the review @yyforyongyu 👍.
Added more details to the doc, giving more context to this change.
Thanks for the information. I will certainly keep this in mind! |
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🌹 (Need to squash that fixup commit before merging ofc)
@@ -213,6 +214,17 @@ func testMultiHopPayments(ht *lntest.HarnessTest) { | |||
require.Equal(ht, aliceAlias, event.PeerAliasOut) | |||
} | |||
|
|||
// Verify HTLC IDs are not nil and unique across all forwarding events. |
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 the events order is not guaranteed, so we'll need to collect the indices in a map and compare them after the iteration.
It will be squashed (used fixup because the contribution guide says it's preferable) |
The doc mentions "auto squash the fix up commits on rebase". Which is something the PR author needs to do before merge, upon request by the reviewers, which is what @yyforyongyu meant. |
f105265
to
1a7298d
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.
Very nice! Looks good, just two ideas/requests.
In this commit we add htlcindex field to the forwardingevent struct, which is persisted alongside the other event fields.
In this commit we update the returned message for fwdinghistory to include the htlcindex for all forwarded htlcs.
1a7298d
to
ccf3a28
Compare
@@ -78,14 +81,44 @@ type ForwardingEvent struct { | |||
// AmtOut is the amount of the outgoing HTLC. Subtracting the incoming | |||
// amount from this gives the total fees for this payment circuit. | |||
AmtOut lnwire.MilliSatoshi | |||
|
|||
// IncomingHtlcID is the ID of the incoming HTLC in the payment circuit. | |||
// If this is not set, the value will be nil. This field is added in |
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 do not understand this comment, this value cannot be nil, it is of type fn.Option.
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.
probably you meant in lnrpc.ForwardingEvent
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 do not understand this comment, this value cannot be nil, it is of type fn.Option.
Since fn.Option
represents a value that may or may not be present, I thought I could refer to it as nil when the value isn't present?. But I think if you find it confusing then many would too, which means I should've framed this better.
IncomingHtlcID fn.Option[uint64] | ||
|
||
// OutgoingHtlcID is the ID of the outgoing HTLC in the payment circuit. | ||
// If this is not set, the value will be nil. This field is added in |
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.
same here
Change Description
Fixes #9656
This PR adds incoming and outgoing HTLC indices fields to the
ForwardingEvent
to improve HTLC tracking and reconciliation.When creating forwarding events, the HTLC indices fields are populated using the incoming and outgoing HTLCId from the payment circuit.
Steps to Test
lncli fwdinghistory
Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.