Commit Graph

133 Commits

Author SHA1 Message Date
Elle Mouton
2b08d3443f
watchtowers: add thread safe min-heap
In this commit, a thread-safe min-heap is implemented. It will carry
sessionCloseItems which carry a sessionID and a block height at which
the session should be closed.
2023-03-20 16:51:32 +02:00
Elle Mouton
16008c0032
watchtower: handle channel closures
Add a channel-close handler that waits for channel close events and
marks channels as closed in the tower client DB.
2023-03-20 16:51:25 +02:00
Elle Mouton
41e36c7ec7
watchtower: add wtclient.ClientSession constructor 2023-03-20 10:46:53 +02:00
Elle Mouton
0ed5c750c8
watchtower: add GetTower to tower iterator
Add a GetTower method to the tower iterator.
2023-03-20 10:46:53 +02:00
Elle Mouton
e432261dab
watchtower: add DeleteSession method
Add a DeleteSession method to the tower client DB. This can be used to
delete a closable session along with any references to the session.
2023-03-20 10:46:52 +02:00
Elle Mouton
3577c829d3
watchtower: add ListClosableSessions method
This commit adds a new ListClosableSessions method to the tower client
DB. This method will return a map of sessionIDs to block heights. The
IDs belong to sessions that are considered closable and the block
heights are the block height at which the last associated channel for
the session was closed in.
2023-03-20 10:46:52 +02:00
Elle Mouton
571966440c
watchtower: add MarkChannelClosed db method
This commit adds a `MarkChannelClosed` method to the tower client DB.
This function can be called when a channel is closed and it will
check the channel's associated sessions to see if any of them are
"closable". Any closable sessions are added to a new
`cClosableSessionsBkt` bucket so that they can be evaluated in future.
Note that only the logic for this function is added in this commit and
it is not yet called.
2023-03-20 10:46:52 +02:00
Elle Mouton
a3050ed213
watchtower: add GetClientSession func to DB
This commit adds a new `GetClientSession` method to the tower client DB
which can be used to fetch a session by its ID from the DB.
2023-03-20 10:46:52 +02:00
Elle Mouton
c1be420696
watchtower: make use of the new ClientSessionFilterFn option
In this commit, the wtclient starts making use of the new
ClientSessionFilterFn to do any session filtering instead of doing it in
memory.
2023-03-16 14:59:08 +02:00
Elle Mouton
40ac82e439
watchtower: add ClientSessionFilterFn to session requests
In this commit, a new ClientSessionFilterFn parameter is added to the
DB's ListClientSession method which can be used to allow the caller to
specify a filter function for filtering sessions read from the DB.
Currently all filtering of sessions are done after the sessions have
been read from the DB, so adding this option should provide some
efficiency.
2023-03-16 14:59:08 +02:00
Elle Mouton
c3a2368f46
multi: migrate towers to use RangeIndex for AckedUpdates
In this commit, a migration is done that takes all the AckedUpdates of
all sessions and stores them in the RangeIndex pattern instead and
deletes the session's old AckedUpdates bucket. All the logic in the code
is also updates in order to write and read from this new structure.
2023-01-11 13:59:03 +02:00
Oliver Gugger
55b53555e9
multi: improve readability of goroutine defers
This commit fixes the readability of some of the defer calls in
goroutines by making sure the defer stands out properly.
2022-11-21 13:54:24 +01:00
Elle Mouton
3ff5abc9e3
watchtower: allow removal during session negotiation
In this commit, the bug demonstrated in the previous commit is fixed.
The locking capabilities of the AddressIterator are used to lock
addresses if they are being used for session negotiation. So now, when a
request comes through to remove a tower address then a check is first
done to ensure that the address is not currently in use. If it is not,
then the request can go through.
2022-10-20 15:46:56 +02:00
Elle Mouton
b2039f245e
watchtower: demo cant remove tower during negotiation bug
In this commit, a new test is added to demonstrate that an error is
thrown if a user attempts to remove a tower during session negotiation
even if no current negotiation is taking place with the tower.
2022-10-20 15:46:55 +02:00
Elle Mouton
8a7329b988
watchtower: make use of the new AddressIterator
This commit upgrades the wtclient package to make use of the new
`AddressIterator`. It does so by first creating new `Tower` and
`ClientSession` types. The new `Tower` type has an `AddressIterator`
instead of a list of addresses. The `ClientSession` type contains a
`Tower`.
2022-10-20 15:46:52 +02:00
Elle Mouton
7924542500
watchtower: add AddressIterator and tests
In this commit, a new AddressIterator type is added. It is a type that
can be used to iterate over a list of addresses. It strictly disallows
the list of addresses it holds to be empty. It also allows callers to
place locks on certain addresses in order to prevent other callers from
removing the addresses in question from the iterator.
2022-10-20 15:46:03 +02:00
Elle Mouton
5bc8ee48fc
watchtower: demo that client cant update tower address
In this commit, a test is added to demonstrate that if a client tries to
update the address of a tower for an active tower session, then this new
address will not be used until the client restarts. This is a bug that
will be fixed in a future commit.
2022-10-20 11:32:08 +02:00
Elle Mouton
60f58b7812
watchtower: simplify the newHarness test function 2022-10-19 18:49:18 +02:00
Elle Mouton
4828fd902d
wtclient: allow multiplie callback dial functions
This commit is a step towards prepping the watchtower client test
harness to be able to handle the case where the client connects to
multiple mock servers.
2022-10-19 18:49:18 +02:00
Elle Mouton
ab4d4a19be
watchtower/wtclient: upgrade pkg to use require
Upgrade all the tests in the wtclient package to make use of the
`require` package.
2022-10-19 18:49:17 +02:00
Elle Mouton
d29a55bbb5
watchtower: make use of t.Cleanup funcs in tests
Make use of the t.Cleanup helper function to clean up watchtower client
tests instead of relying on defer calls.
2022-10-19 18:39:26 +02:00
Carsten Otto
378478eb1a multi: fix typos and grammar issues in comments [skip ci] 2022-10-17 09:40:22 +02:00
Carsten Otto
2a56f602db wtclient: fix documentation [skip ci]
the implementation also returns exhausted sessions
2022-10-17 09:40:22 +02:00
Elle Mouton
75e5339217
watchtower: remove CommittedUpdates from ClientSession
In this commit, the new ListClientSession functional options and new
FetchSessionCommittedUpdates function are utilised in order to allow us
to completely remove the CommittedUpdates member from the ClientSession
struct.
2022-10-13 14:41:26 +02:00
Elle Mouton
fe3d9174ea
watchtower: add FetchSessionCommittedUpdates func to DB
In this commit, a new tower client db function is added that can be used
to fetch all the committed updates for a given session ID. This is done
in preparation for an upcoming commit where the CommittedUpdates will be
removed from the ClientSession struct.
2022-10-13 14:39:23 +02:00
Elle Mouton
15858cae1c
watchtower+lnrpc: remove AckedUpdates from ClientSession struct
In this commit, we start making use of the new ListClientSession
functional options added in the previous commit. We use the functional
options in order to calculate the max commit heights per channel on the
construction of the tower client. We also use the options to count the
total number of acked and committed updates. With this commit, we are
also able to completely remove the AckedUpdates member of the
ClientSession since it is no longer used anywhere in the code.
2022-10-13 14:36:33 +02:00
Elle Mouton
40e0ebf417
watchtower: add ListClientSessions functional options
This commit adds functional options to the ListClientSessions call that
can be used to perform a variety of extra operations during the DB
query. These functional options are not yet used in this commit.
2022-10-13 14:35:34 +02:00
Oliver Gugger
707546e2f0
Merge pull request #6972 from ellemouton/wtclientTowerDb
watchtower: add towerID-to-sessionID index
2022-10-13 13:09:12 +02:00
Eng Zer Jun
228f1e36c4
watchtower: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:47:04 +08:00
Elle Mouton
105c44df9b
watchtower: use more efficient session query on startup
In this commit, the functions used to fetch candidate sessions and
towers on creation of the watchtower Client are changed to make use of
the more efficient lookup functions. Previously, all sessions were
listed from the DB and then these were used to collect the active
towers which in certain situations lead to some users getting the
"tower not found" error on start up. With this commit, we instead first
list all Towers in the DB and then we fetch the sessions for each of
those towers.
2022-10-13 11:30:27 +02:00
Elle Mouton
c60ecaccbf
watchtower: always populate Tower in ClientSession
In this commit, we make sure to always populate the Tower member of a
ClientSession. This is done for consistency.
2022-10-13 11:30:27 +02:00
Elle Mouton
f815c88ee4
watchtower: fix formatting
In order to make upcoming commits in the PR easier to parse, this commit
makes some basic formatting changes to some of the watchtower files.
2022-10-13 11:30:22 +02:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
Olaoluwa Osuntokun
dc16f5df53
watchtower: uses P2TR for sweep, delivery, and reward addresses
In this commit, we modify the watch tower to use P2TR addrs for just
about anything sweep related.

One eye sore in this diff are the changes to
`backup_task_internal_test.go`. All the values are hard coded, and now
either differ by a value of 48, or needed to be modified to account for
the new assumptions propagated to rewards values and fees.
2022-08-11 17:26:13 -07:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
yyforyongyu
953767961e
multi: use txid instead of tx in BreachRetribution
This commit replaces the field `BreachTransaction` with `BreachTxHash`
as there's no need to pass that large raw transaction.
2022-04-20 01:18:14 +08:00
Oliver Gugger
f130eddb92
multi: use prev output fetcher where possible 2022-03-24 18:02:37 +01:00
Oliver Gugger
72c9582b85
multi: bump btcd to taproot aware version 2022-03-24 15:00:25 +01:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
yyforyongyu
1ad6bbfbc2
multi: add logs when subservers are starting
Also unified the log messages.
2022-02-11 21:17:03 +08:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
eugene
fdcd726f9a
multi: replace DefaultDustLimit with script-specific DustLimitForSize
This commit updates call-sites to use the proper dust limits for
various script types. This also updates the default dust limit used
in the funding flow to be 354 satoshis instead of 573 satoshis.
2021-09-29 13:33:10 -04:00
Wilmer Paulino
7517243d6d
wtclient: decrement pending tasks stats upon accepted task
We'd never decrement the number of pending backups upon a watchtower
accepting one, making it confusing for users to determine whether their
backups have actually been accepted. Along the way, we also rename
NumTasksReceived to NumTasksPending to better reflect its purpose.
2021-04-14 17:18:25 -07:00
Conner Fromknecht
e0e57642b6
wtclient/client: fix missed prefix log 2021-01-04 08:33:34 -08:00
Conner Fromknecht
1d3535582b
wtclient/seseion_queue: add prefix logging 2021-01-04 08:32:34 -08:00
Conner Fromknecht
de09b8d9bd
wtclient/session_negotiator: add prefix logging 2021-01-04 08:32:34 -08:00
Conner Fromknecht
505901d7b8
wtclient/task_pipeline: add prefix logging 2021-01-04 08:32:31 -08:00
Conner Fromknecht
9bd73c0a85
wtdb+wtclient: segregate session-key-index reservations by blob-type
This commit introduces a change in the key format used to reserve/lookup
session-key-indexes. Currently the reservations are stored under the
tower id, however this creates issues when multiple clients are using
the same database since only one reservation is permitted per tower.

We fix this by appending the blob type to the session-key-index locator.
This allows multiple clients to reserve keys for the same tower, but
still limits each client to one outstanding reservation. The changes are
made in a way such that we fall back to the legacy format if the a
reservation under the new format is not found, but only if the blob type
matches blob.TypeAltruistCommit, which is so far the only actively
deployed blob type.
2020-12-01 16:24:16 -08:00
Olaoluwa Osuntokun
94f8311667
Merge pull request #4782 from cfromknecht/anchor-wtserver
watchtower: anchor channel support
2020-11-30 17:49:32 -08:00
Conner Fromknecht
1f86526250
wtclient: add backoff in negotiation when createSession() fails
Currently if the tower hangs up during session negotiation there is no
backoff applied. We add backoff here to avoid excessive CPU/network
utilization during unexpected failures.
2020-11-30 13:08:18 -08:00