Skip to content

Add Payment Hash to a subset of htlc events #7309

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ziggie1984
Copy link
Collaborator

@ziggie1984 ziggie1984 commented Jan 11, 2023

Change Description

This PR adds the payment hash to the htlc events Forward, ForwardFail, Settle and Linkfail and fixes #7165.

I intentionally decided to not include it in the FinalHtlcEvent because it would have broken a lot of compatibility with existing code and from my perspective I see no benefit introducing them there.

Based on Jesse's Code who introduced the router-rpc tests in #6335, I created additional Testcases for the SubscribeHtlcEvents server feature.

I did not find it reasonable to add itests for this functionality because there are already tests on the unit-test level in the htlcswitch package, but open for other opinions.

Steps to Test

For the unit tests you can test it by doing:

make unit pkg=htlcswitch

For the router grpc-server you can do:

make unit pkg=lnrpc/routerrpc log="info" case=TestSubscribeHtlcEvents

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

@yyforyongyu
Copy link
Member

I cannot really find a suitable unit/integration test where we test this htlc streaming method thats why for testing purposes I included an lncli command to test the new message on regtest.

Yeah the unit test for HtlcNotifier is missing, something we def want to patch. For itest, if search SubscribeHtlcEvents, there are multiple usages, for instance testHtlcErrorPropagation.

I found it reasonable to only include the the payment_hash in events where it actually makes sense to use it. Events like SubscribedEvent and FinalHtlcEvent where intentionally not included.

Make sense.

Does it make sense to include the lncli subscribehtlcs for general usage, for now consider it experimental for testing purposes only

I'd imagine the use case for this endpoint would not be inside a terminal, so I guess not(not sure tho).

@ziggie1984
Copy link
Collaborator Author

Thank you :) Now I can continue my work

@ziggie1984 ziggie1984 force-pushed the payment-hash-subscribehtlc-events branch 4 times, most recently from 7580729 to 3156254 Compare January 16, 2023 15:42
@ziggie1984
Copy link
Collaborator Author

I found the unit-tests, so I changed my initial commit.

@ziggie1984 ziggie1984 force-pushed the payment-hash-subscribehtlc-events branch 3 times, most recently from a544fac to 24430e6 Compare January 18, 2023 12:20
Adds the payment hash to the particular set of htlc notifiers
(Forward, ForwardFail, Settle, LinkFail). Also unit tests are
adapted according to the introduced changes.
@ziggie1984 ziggie1984 force-pushed the payment-hash-subscribehtlc-events branch 2 times, most recently from 5b19198 to ce3a579 Compare January 18, 2023 12:46
@ziggie1984
Copy link
Collaborator Author

Testing the gprc stream of htlcs I found an error when not populating the Linkerror in the LinkFail event, though I did not change the behaviour, so asking for your opinion how to handle this.

Also in the htlcswitch package, I had to add the function newPayHash, because the unit tests reveiled that sometimes the payment circuit during a failevent is nil, maybe just returning the payment hash is not the cleanest solution here. I marked the relavant code parts in further comments


// newPayHash returns the payment hash for the package provided.
func newPayHash(pkt *htlcPacket) lntypes.Hash {
// In case the circuit is nil a zero payment hash is returned to satisfy
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add the zero payment hash here, because some unit tests failed because the circuit was sometimes nil.

if err != nil {
t.Fatalf("failed sending htlc event to server: %s", err)
}
// Make sure the LinkError is populated otherwise the test fails.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment speaks for itself, though this is the part where the test will fail if we just pass the empty LinkFailEvent

@ziggie1984 ziggie1984 marked this pull request as ready for review January 18, 2023 13:02
@ziggie1984 ziggie1984 force-pushed the payment-hash-subscribehtlc-events branch from ce3a579 to f433790 Compare January 19, 2023 18:47
Adds the payment hash to a particular set of htlc events
(Forwards, ForwardFails, Settle, LinkFail) of the grpc stream.

In addition the grpc tests for the routerrpc package are adapted
for the subscribehtlcevents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: give payment hash in subscribehtlcevents
2 participants