Commit Graph

198 Commits

Author SHA1 Message Date
Elle Mouton
660f1f361e
watchtower/wtclient: prep client for taproot towers 2024-01-19 15:33:06 +02:00
Elle Mouton
1daec3e890
wtclient: use the new filter options to fix the demo'd bug
In this commit, we use the newly added session listing options to ensure
that we only see a session as exhausted if it does not have any un-acked
updates on disk. This fixes the bug previously demonstrated.
2024-01-12 08:25:28 +02:00
Elle Mouton
776f2a026c
wtdb: supply commited update count to PostEvaluateFilterFn
In this commit, we adjust the PostEvaluateFilterFn to also take in a
count representing the number of committed updates (ie, persisted
un-acked updates) that the session has. This will be made use of in an
upcoming commit.
2024-01-12 08:23:02 +02:00
Elle Mouton
bdf9ec1423
wtclient: demonstrate "tower has un-acked updates" bug
This commit adds a test to demonstrate an edge case that can result in
the "tower has un-acked updates" error being thrown when a user is
attempting to remove a tower. This will be fixed in an upcoming commit.
2024-01-11 15:13:02 +02:00
Elle Mouton
154e9fafec
watchtower: convert JusticeKit to interface
In this commit, we convert the `JusticeKit` struct to an interface.
Then, we add two implementations of that interface:
1) The `legacyJusticeKit` which implements all the methods of
   `JusticeKit`
2) The `anchorJusticKit` which wraps the `legacyJusticeKit` and just
   re-implements the `ToRemoteOutputSpendInfo` method since.
2024-01-04 14:37:42 +02:00
Elle Mouton
204ca6cb0f
watchtower: introduce CommitmentType
In this commit a new enum, CommitmentType, is introduced and initially
there are 3 CommitmentTypes: Legacy, LegacyTweakless and Anchor.

Then, various methods are added to `CommitmentType`. This allows us to
remove a bunch of "if-else" chains from the `wtclient` and `lookout`
code. This will also make things easier to extend when a new commitment
type (like Taproot) is added.
2024-01-04 14:37:42 +02:00
Elle Mouton
e800aacff4
wtclient+server: unexport and rename TowerClient
Rename and unexport the `TowerClient` struct to `client` and rename the
`TowerClientManager` interface to `ClientManager`.
2023-11-28 11:01:51 +02:00
Elle Mouton
fcfdf699e3
multi: move BackupState and RegisterChannel to Manager
This commit moves over the last two methods, `RegisterChannel` and
`BackupState` from the `Client` to the `Manager` interface. With this
change, we no longer need to pass around the individual clients around
and now only need to pass the manager around.

To do this change, all the goroutines that handle channel closes,
closable sessions needed to be moved to the Manager and so a large part
of this commit is just moving this code from the TowerClient to the
Manager.
2023-11-28 10:59:40 +02:00
Elle Mouton
ab2f781b4a
wtclient+lnrpc: move Policy to Manager 2023-11-28 09:54:03 +02:00
Elle Mouton
4e51bf3a3f
wtclient+lnrpc: move LookupTower to Manager 2023-11-28 09:54:02 +02:00
Elle Mouton
0b3d751e33
wtclient+lnrpc: move RegisteredTowers to Manager
Move the `RegisteredTowers` method from the `Client` to the `Manager`
interface.
2023-11-28 09:54:02 +02:00
Elle Mouton
4348f2062a
wtclient+lnrpc: move Stats to Manager
Move the `Stats` method from the `Client` to the `Manager` interface.
2023-11-28 09:54:02 +02:00
Elle Mouton
f38b5cf258
lnrpc+wtclient: refactor ClientStats
This commit removes the mutex from ClientStats and instead puts that in
clientStats which wraps ClientStats with a mutex. This is so that the
tower client interface can return a ClientStats struct without worrying
about copying a mutex.
2023-11-28 09:54:02 +02:00
Elle Mouton
a5e7d35af2
wtclient+lnrpc: move RemoveTower to Manager
Simiarly to the previous commit, this commit moves the RemoveTower
method from the Client to the TowerClientManager interface. The manager
handles any DB related handling. The manager will first attempt to
remove the tower from the in-memory state of each client and then will
attempt to remove the tower from the DB. If the removal from the DB
fails, the manager will re-add the tower to the in-memory state of each
client.
2023-11-28 09:54:02 +02:00
Elle Mouton
a44bf381c4
multi: move AddTower to Tower Client Manager
In this commit we move the AddTower method from the Client interface to
the TowerClientManager interface. The wtclientrpc is updated to call the
`AddTower` method of the Manager instead of calling the `AddTower`
method of each individual client. The TowerClient now is also only
concerned with adding a new tower (or new tower address) to its
in-memory state; the tower Manager will handle adding the tower to the
DB.
2023-11-28 09:54:02 +02:00
Elle Mouton
2abc422aac
watchtower+server: let manager Start & Stop the clients
In this commit, the `Stop` and `Start` methods are removed from the
`Client` interface and instead added to the new `Manager`. Callers now
only need to call the Manager to start or stop the clients instead of
needing to call stop/start on each individual client.
2023-11-28 09:54:01 +02:00
Elle Mouton
ab0375e0c1
wtclient+server: introduce tower client Manager
Introduce a wtclient `Manager` which handles tower clients. It indexes
clients by the policy used. The policy field is thus removed from the
`Config` struct which configures the Manager and is instead added to a
new `towerClientCfg` which configures a specific client managed by the
manager. For now, only the `NewClient` method is added to the Manager.
It can be used to construct a new `TowerClient`. The Manager currently
does notthing with the clients added to it.
2023-11-28 09:51:15 +02:00
Elle Mouton
fee94ae5af
watchtower: start using the new channel max heights
This commit also adds tests for the DB changes made in the previous
commit since we can now read the new field with the FetchChanInfos
method.

The commit following this one does the backfill migration.
2023-11-27 20:01:17 +02:00
Michael Rooke
78d9996620
trivial: Fix spelling errors
- Fixes some spelling in code comments and a couple of function names
2023-09-21 22:35:33 -04:00
Elle Mouton
2a9339805e
watchtower: account for rogue updates
In this commit, we introduce the concept of a rogue update. An update is
rogue if we need to ACK it but we have already deleted all the data for
the associated channel due to the channel being closed. In this case, we
now no longer error out and instead keep count of how many rogue updates
a session has backed-up.
2023-09-14 10:33:02 +02:00
Elle Mouton
adb87dcfb8
wtclient: demo un-acked update of closed channel bug
This commit adds a new test to the tower client to demonstrate a bug
that can happen if a channel is closed while an update for it has yet to
be acked by the tower server. This will be fixed in an upcomming commit.
2023-09-14 10:28:56 +02:00
Elle Mouton
ff0d8fc619
watchtower: completely remove the mock tower client DB
Remove the use of the mock tower client DB and use the actual bbolt DB
everywhere instead.
2023-09-13 12:21:04 +02:00
Elle Mouton
f889c9b1cc
watchtower: use bbolt db instead of mock DB for client tests
The watchtower client test framework currently uses a mock version of
the tower client DB. This can lead to bugs if the mock DB works slightly
differently to the actual bbolt DB. So this commit ensures that we only
use the bbolt db for the tower client tests. We also increment the
`waitTime` used in the tests a bit to account for the slightly longer DB
read and write times. Doing this switch resulted in one bug being
caught: we were not removing sessions from the in-memory set on deletion
of the session and so that is fixed here too.
2023-09-13 12:13:22 +02:00
Olaoluwa Osuntokun
b368e476c5
lnwire: update Sig to support both ECDSA and schnorr sigs
In this commit, we update the Sig type to support ECDSA and schnorr
signatures. We need to do this as the HTLC signatures will become
schnorr sigs for taproot channels. The current spec draft opts to
overload this field since both the sigs are actually 64 bytes in length.
The only consideration with this move is that callers need to "coerce" a
sig to the proper type if they need schnorr signatures.
2023-08-22 16:29:19 -07:00
Elle Mouton
3ea67983b5
wtclient: replay un-acked updates onto pipeline
In this commit, the bugs demonstrated in prior commits are fixed. In the
case where an session has persisted a CommittedUpdate and the tower is
being removed, the session will now replay that update on to the main
task pipeline so that it can be backed up using a different session.
2023-07-18 16:28:27 +02:00
Elle Mouton
c432899bf9
watchtower: add DeleteCommittedUpdate DB method
Add a new DeleteCommittedUpdate method to the wtdb In preparation for an
upcoming commit that will replay committed updates from one session to
another.
2023-07-18 16:28:27 +02:00
Elle Mouton
cfb81c00a6
wtclient: tower with unacked updates cant be removed after restart
This commit demonstrates that if a session has persisted committed
updates and the client is restarted _after_ these committed updates have
been persisted, then removing the tower will fail.
2023-07-18 16:28:27 +02:00
Elle Mouton
af1506bff1
wtclient: demo "tower has unacked updates" bug
In this commit, we demonstrate the situation where a client has
persisted CommittedUpdates but has not yet recieved Acks for them from
the tower. If this happens and the client attempts to remove the tower,
it will with the "tower has unacked updates" error.
2023-07-18 16:28:26 +02:00
Elle Mouton
552ef4bf81
wtclient: replay pending tasks on sessionQueue stop
This commit does a few things:
- First, it gives the sessionQueue access to the TowerClient task
  pipeline so that it can replay backup tasks onto the pipeline on Stop.
- Given that the above is done, the ForceQuit functionality of the
  sessionQueue and TowerClient can be removed.
- The bug demonstrated in a prior commit is now fixed due to the above
  changes.
2023-07-18 16:28:26 +02:00
Elle Mouton
449d6b5500
wtclient: fix handleStaleTower comment 2023-07-18 14:27:14 +02:00
Elle Mouton
25c4d3f1f7
wtclient: make sessionQueueSet thread safe
In preparation for an upcoming commit where multiple threads will have
access to the TowerClient sessionQueueSet, we turn it into a thread safe
struct.
2023-07-18 14:27:04 +02:00
Elle Mouton
c4fec3ebc9
wtclient: show that bound tasks are not replayed
This commit demonstrates a bug. It shows that if backup tasks have been
bound to a session with a tower (ie, the tasks are in the session's
pendingQueue) and then the tower is removed and a new one is added, then
the tasks from the pendingQueue are _not_ replayed to the session with
the new tower. Instead, they are silently lost. This will be fixed in an
upcoming commit.
2023-07-18 14:26:51 +02:00
Elle Mouton
feb35e65d8
wtclient: show that a client can switch towers
This commit adds a new watchtower client test to demonstrate that a
client is able to successfully switch to a new tower and continue
backing up updates to that new tower.
2023-07-18 14:26:35 +02:00
Elle Mouton
d8af5fcc92
wtclient: ensure that waitForUpdates has no race condition on timeout
Enforce that the fail timeout in `waitForUpdates` is greater than the
ping timeout.
2023-07-18 14:25:58 +02:00
Elle Mouton
d979f59331
wtclient: move server specific methods to serverHarness 2023-07-18 14:15:46 +02:00
Elle Mouton
2ed5788de3
wtclient: separate server from testHarness
In this commit, a serverHarness is added to the test framework. This
will allow us to create more mock servers appart from the main server.
2023-07-18 14:15:26 +02:00
Oliver Gugger
56dba2df03
multi: update linter, fix new issues 2023-06-13 11:58:33 +02:00
Matt Morehouse
f53c8d6e91
wtclient: AddressIterator fuzz test
Test AddressIterator for the absence of panics, nil addresses, and empty
lists.

This fuzz test finds https://github.com/lightningnetwork/lnd/issues/7552
in seconds. No other panics found after 300+ CPU-hours of fuzzing.
2023-06-01 08:46:45 -05:00
Elle Mouton
8abe2f89e1
watchtower: use a stable blob identifier
In this commit, we add an Identifier method to the blob.Type struct
which returns a unique identifier for a given blob type. This identifier
is then used for initialising the disk overflow queue of the given
client.
2023-05-18 15:17:22 +02:00
Elle Mouton
db145bfd8e
wtclient: check un-checked errors
Some errors are not checked during startup and shutdown of the tower
client. These are checked now.
2023-05-18 15:13:24 +02:00
Elle Mouton
56cd825695
watchtower: replace taskpipeline with disk overflow queue 2023-05-16 10:57:50 +02:00
Elle Mouton
e91fe50878
watchtower/wtclient: generic disk overflow queue
In this commit, a new generic DiskOverflowQueue implementation is added.
This allows a user to specify a maximum number of items that the queue
can hold in-memory. Any new items will then overflow to disk. The
producer and consumer of the queue items will interact with the queue
just like a normal in-memory queue.
2023-05-16 10:57:50 +02:00
Elle Mouton
66f6bf3955
watchtower/wtmock: add in-memory impl of Queue
This commit adds an in-memory implementation of the Queue interface.
This can be used for tests.
2023-05-16 10:57:49 +02:00
Elle Mouton
01e2f10797
wtclient: demo that in-mem updates are lost
This commit adds a test to the wtclient. The test demonstrates that if a
client tries to back up states while it has no active sessions with a
server then those updates are accumlated in memory and lost on restart.
This will be fixed in upcoming commits.
2023-05-16 10:57:49 +02:00
Elle Mouton
08cde98869
wtclient: add mutex locking in perUpdate
Lock the `backupMu` when accessing `c.chanCommitHeights` in the `New`
function. It is not strictly necessary right now but good to add it so
that there is no accidental oversight if the `perUpdate` method is ever
extracted and reused in future.
2023-04-24 13:15:40 +02:00
Elle Mouton
65dc20f2cc
wtclient: let task pipeline only carry wtdb.BackupID
Since the retrubution info of a backup task is now only constructed at
the time that the task is being bound to a session, the in-memory queue
only needs to carry the BackupID of the task.
2023-04-24 13:15:40 +02:00
Elle Mouton
2371bbf09a
wtclient: only fetch retribution info when needed.
Only construct the retribution info at the time that the backup task is
being bound to a session.
2023-04-24 13:15:40 +02:00
Elle Mouton
458ac32146
multi: build retribution info in TowerClient
Since the TowerClient now has a callback that it can use to retrieve the
retribution for a certain channel and commit height, let it use this
call back instead of requiring the info to be passed to it through
BackupState.
2023-04-24 13:15:40 +02:00
Elle Mouton
530a8cae5d
wtclient: lint the package
This commit fixes some lints in the wtclient package. This is done so
that upcoming logic changes are easier to parse.
2023-04-24 13:15:40 +02:00
Elle Mouton
85ec38f447
multi: pass BuildBreachRetribution callback to tower client
In this commit, a new BuildBreachRetribution callback is added to the
tower client's Config struct. The main LND server provides the client
with an implementation of the callback.
2023-04-24 13:15:40 +02:00