Skip to content
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

[htlcnotifier 4/4]: lnrpc: Add HTLC Event Subscription #3848

Merged

Conversation

carlaKC
Copy link
Collaborator

@carlaKC carlaKC commented Dec 17, 2019

This PR is change 4 of 4 proposed to add a htlc event notifier to lnd.
1: #3843
2: #3844
3: #3781
4: This PR

This PR adds a htlcnotifier subscription to routerrpc:

  • We can either present wire message + detail separately (current approach), or combine them into one error code (I think this isn't great for adding more details, permutations go up).

Fixes #3420

@carlaKC carlaKC changed the title lnrpc: Add HTLC Event Subscription [htlcnotifier 4/4]: lnrpc: Add HTLC Event Subscription Dec 17, 2019
@carlaKC carlaKC added HTLC rpc Related to the RPC interface labels Dec 17, 2019
@carlaKC carlaKC marked this pull request as ready for review December 17, 2019 21:30
@Roasbeef Roasbeef added this to the 0.10.0 milestone Jan 14, 2020
@Roasbeef Roasbeef added the v0.10 label Jan 17, 2020
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch from aff9bb4 to a8cdea4 Compare February 6, 2020 19:01
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch 3 times, most recently from 5edad82 to 680aaae Compare February 12, 2020 11:06
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch 6 times, most recently from 62ea380 to 8988ee8 Compare February 21, 2020 10:04
@carlaKC carlaKC requested review from joostjager and cfromknecht and removed request for halseth February 26, 2020 21:08
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch from 54b1e9b to 4403e4c Compare March 9, 2020 09:07
@carlaKC carlaKC requested a review from joostjager March 9, 2020 09:07
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch 2 times, most recently from a89412e to b7f9e46 Compare March 10, 2020 08:24
@carlaKC
Copy link
Collaborator Author

carlaKC commented Mar 10, 2020

Rebased to address some merge conflicts, ready for a look @cfromknecht @joostjager :)

Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

Only a few questions about quitting left.

Tested using https://github.com/carlaKC/lndwrap to monitor a three node network. Looks good 👍

@@ -167,6 +170,7 @@ func (s *Server) Start() error {
//
// NOTE: This is part of the lnrpc.SubServer interface.
func (s *Server) Stop() error {
close(s.quit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need a waitgroup too, to wait for completion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Offline discussion about this, no reason for subscriptions not to be wait grouped (I thought there could be some grpc magic in the background). Added wait group for routerrpc subserver + trackPayment.

Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to add sync.Once here? o/w calling Stop() multiple times will panic

lnrpc/routerrpc/router_server.go Show resolved Hide resolved
lnrpc/routerrpc/router.proto Outdated Show resolved Hide resolved
lnrpc/routerrpc/router.proto Show resolved Hide resolved
lnrpc/routerrpc/router_server.go Show resolved Hide resolved
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch from b7f9e46 to f6b5b32 Compare March 10, 2020 18:19
@carlaKC carlaKC requested a review from joostjager March 10, 2020 18:55
@@ -449,6 +454,9 @@ func (s *Server) trackPayment(paymentHash lntypes.Hash,
}
}

s.wg.Add(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Still this feels a bit strange. Normally we add to the waitgroup right before we start the goroutine. In this case, grpc started the goroutine already, so are we too late here? I don't know the answer really, but maybe it doesn't make sense after all to do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On the router server level, adding this wait group means that we don't consider the server to be stopped before all the subscriptions have received the quit signal. So I think that adds something, although all the other subservers are shutting down fine without it, so also unsure.


// The amount of the outgoing htlc.
uint64 outgoing_amt_msat = 4;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason for not exposing payment hash? perhaps i'm just forgetting something that was already decided on this front

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah we discussed it in the previous notifier PRs, wanted to force people towards identifying htlcs by incoming/outgoing circuit keys rather than payment hash, since it's not a unique identifier. If it's there, chances are people with use it as a uuid. It's specifically a concern here since forwards need to be matched with settles/fails, and doing so with payment hash could go very wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, i think that's a reasonable assumption 👍

lnrpc/routerrpc/subscribe_events.go Outdated Show resolved Hide resolved
lnrpc/routerrpc/router_server.go Outdated Show resolved Hide resolved
@@ -167,6 +170,7 @@ func (s *Server) Start() error {
//
// NOTE: This is part of the lnrpc.SubServer interface.
func (s *Server) Stop() error {
close(s.quit)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to add sync.Once here? o/w calling Stop() multiple times will panic

Add SubscribeHtlcEvents to RouterBackend in preparation for the
addition of a HtlcNotifier stream.
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch from f6b5b32 to 891a9fd Compare March 13, 2020 07:41
@carlaKC carlaKC force-pushed the htlcnotifier-3-addhtlcnotifierrpc branch from 891a9fd to 0a5b918 Compare March 13, 2020 07:54
@carlaKC
Copy link
Collaborator Author

carlaKC commented Mar 13, 2020

@joostjager re-requesting to make sure approval still stands. Removed wait group (see comment) and converted timestamps to ns.

@joostjager
Copy link
Contributor

Yes approval still stands.

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

LGTM 🏄‍♂️


// The amount of the outgoing htlc.
uint64 outgoing_amt_msat = 4;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, i think that's a reasonable assumption 👍

@cfromknecht cfromknecht merged commit b6a0bfc into lightningnetwork:master Mar 17, 2020
@carlaKC
Copy link
Collaborator Author

carlaKC commented Mar 20, 2020

it seems like this file is missing make rpc-format...

Last push build, so must have missed the travis build check merge in some werid order. Fixed in #4105.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HTLC rpc Related to the RPC interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

htlcswitch+rpcserver: add new streaming ForwardingEvent API
5 participants