Skip to content

multi: add watchtower client RPC subserver#3184

Merged
Roasbeef merged 12 commits intolightningnetwork:masterfrom
wpaulino:wtclient-subserver
Jul 31, 2019
Merged

multi: add watchtower client RPC subserver#3184
Roasbeef merged 12 commits intolightningnetwork:masterfrom
wpaulino:wtclient-subserver

Conversation

@wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Jun 11, 2019

In this PR, we introduce a new RPC subserver: WatchtowerClientRPC. So far, this RPC subserver allows us to interact with the daemon's backing watchtower client at runtime. Certain changes were needed for the wtclient.TowerClient and wtclient.DB interfaces in order to provide the functionality required by the RPC subserver.

@wpaulino wpaulino requested a review from cfromknecht June 14, 2019 20:19
@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour P2 should be fixed if one has time rpc Related to the RPC interface watchtower labels Jun 18, 2019
@Roasbeef Roasbeef requested a review from valentinewallace July 2, 2019 00:01
@wpaulino wpaulino added this to the 0.7.1 milestone Jul 2, 2019
@wpaulino wpaulino added the v0.7.1 label Jul 2, 2019
@Roasbeef Roasbeef requested review from Roasbeef and removed request for valentinewallace July 9, 2019 23:26
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.

did an initial pass, looks solid so far! tested on my node and was able to modify towers and get info about towers+sessions

@wpaulino wpaulino requested a review from cfromknecht July 11, 2019 00:51
@wpaulino wpaulino requested a review from cfromknecht July 12, 2019 01:48
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.

@wpaulino latest changes look solid! no major comments apart form maybe keeping the existing wtclient.private-tower-uris in the config to maintain backcompat for the point release, and removing fully in next major release

@wpaulino wpaulino removed this from the 0.7.1 milestone Jul 23, 2019
@wpaulino wpaulino removed the v0.7.1 label Jul 23, 2019
@wpaulino wpaulino added this to the 0.8 milestone Jul 23, 2019
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 💰

@Roasbeef Roasbeef added the v0.8 label Jul 30, 2019
Copy link
Member

Choose a reason for hiding this comment

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

Out of the scope of this PR, so just reflecting, but it seems that we can remove much of the code in this mock tower, if we abstracted the storage backend from the actual tower DB a bit. So in this case, the business logic would be shared across the regular and the mock, with the only difference being storage in a map vs actually on disk.

Each time we modify the behavior of the actual tower DB, we must also take care to ensure that this is also updated, and implements the actual behavior perfectly (ideally). This adds an additional cost/diff to modifying this area of the codebase, as we essentially need two maintain the logic of two structs that do the same thing.

Copy link
Member

Choose a reason for hiding this comment

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

The mock DB had it place during initial development as we wanted to flesh out the biz logic without being burdened with actual DB details such as bucket structure, serialization, etc. However at this point, I don't see a good reason for it to exists in its current state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In other parts of the codebase we have mock DBs for unit tests to speed them up, but doesn't seem like there's something to gain here given that the tests still run with the actual bolt implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

the db tests run both mock and boltdb implementations to assert they have identical behavior. all of the other packages use the mockdb to speed them up

Copy link
Member

Choose a reason for hiding this comment

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

This would be nice, as otherwise, the same macaroon (atm) that can add/remove towers is also able to do things like send coins on chain. On the other-hand, one could argue that being able to remove towers is possibly move dangerous than sending coins on chain...

I think we can leave this out for now, and leave the time from now until the first 0.8 release candidate to mull things over.

wpaulino added 6 commits July 30, 2019 15:13
The state updates that are pending to be acked by the tower are already
loaded within newSessionQueue.
This currently takes O(N) time as there does not exist an index of
active client sessions for each watchtower within the client's database.
This index is likely to be added in the future.
These operations are currently unused, but will be integrated into the
TowerClient at a later point as future preparation for the
WatchtowerClient RPC subserver, which will allow users to add, remove,
and list the watchtowers currntly in use.
wpaulino added 6 commits July 30, 2019 15:18
In this commit, we extend the wtclient.Client interface with the
following methods:

  * AddTower
  * RemoveTower
  * RegisteredTowers
  * LookupTower
  * Stats

Care has been taken to ensure that any in-memory state updates are
_only_ performed after a successful database update.

These methods are currently unused, but they serve as a dependency for
the upcoming WatchtowerClient RPC subserver.
We do this as a convenience for WatchtowerClient users so that they do
not need to re-add towers upon restarts. We ensure not to re-add towers
that have been previously removed by determining whether it has any
lingering active sessions.
With the introduction of the WatchtowerClient RPC subserver, the lnd
configuration flag to specify private watchtowers for the client is no
longer needed and can lead to confusion upon users. Therefore, we remove
the flag completely, and only rely on the watchtower client being active
through a new --wtclient.active flag.
…didates

Doing so allows us to load balance sessions better amongst all of the
tower candidates.
@wpaulino wpaulino requested a review from Roasbeef July 30, 2019 22:19
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🌊

Gave this a spin on my testnet nodes, was able to modify the set of towers it was connected to w/o any issue!

@Roasbeef Roasbeef merged commit 8c9c4b5 into lightningnetwork:master Jul 31, 2019
@wpaulino wpaulino deleted the wtclient-subserver branch July 31, 2019 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvements to existing features / behaviour P2 should be fixed if one has time rpc Related to the RPC interface watchtower

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants