Commit Graph

133 Commits

Author SHA1 Message Date
Elle Mouton
23602e017e
multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
yyforyongyu
b6049ff94b
multi: add NewLogClosure in lnutils to avoid repetition
And replaces all usage of `logClosure` with `lnutils.LogClosure`.
2024-07-25 21:25:23 +08:00
ffranr
cd566eb097
multi: fix fmt.Errorf error wrapping
Refactor fmt.Errorf usage to correctly wrap errors instead of using
non-wrapping format verbs.
2024-02-27 11:13:40 +00:00
Elle Mouton
05c03400a9
wtdb: add TerminateSession method 2024-02-20 14:44:11 +02:00
Elle Mouton
41582c0b8b
wtdb: create and remove tower should no longer change session status 2024-02-20 14:44:11 +02:00
Elle Mouton
cbf08940ca
wtdb: let DeleteCommitedUpdates move session to terminal
In this commit, we adjust the DeleteCommitmentUpdate method so that it
marks a session as Terminal (if there are updates to delete) since once
we have deleted a commitment update from a session - the session is no
longer useable.
2024-02-20 14:44:11 +02:00
Elle Mouton
5cb8c8df7e
wtdb: rename CSessionInactive to CSessionTerminal
Since we will now change this to mean that the session should not ever
be activated again.
2024-02-20 14:44:11 +02:00
Elle Mouton
4548e72f79
wtdb: add a DeactivateTower method
This new method sets the tower's status to inactive so that it is not
loaded at startup as a candidate tower. We also ensure that a tower's
status is set to active if the CreateTower is called when the tower
already exists.
2024-02-20 09:02:36 +02:00
Elle Mouton
0bb1816fff
watchtower: add filter function to ListTowers
And then only load active towers on client start up.
2024-02-20 08:58:46 +02:00
Elle Mouton
ffd355c6c4
wtdb: add TowerStatus to Tower
This is added as a TLV record meaning that all the towers currently on
disk that don't have this new field will be seen as Active.
2024-02-20 08:58:46 +02:00
Elle Mouton
1ae802812c
watchtower: update DeleteCommittedUpdate to delete all
This commit updates the DeleteCommittedUpdate DB method to delete all of
a given session's committed updates instead of just one at a time. The
reason for this is that in an upcoming commit, we will introduce a
"Terminal" session state - once we have deleted a committed update for a
session it should be considered "Terminal" and there is never a case
where we would only want to delete one committed update and not the
rest. So we want these two actions (deleting committed updates of a
session and setting it's status to terminal) to be atomic.
2024-02-20 08:58:45 +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
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
4131ced707
wtdb/migration8: migrate channel max heights 2023-11-27 20:01:17 +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
Elle Mouton
01ba2661db
watchtower/wtdb: start populating channel max commitment
In this commit, a new key, cChanMaxCommitmentHeight, is added to the
channel details bucket. This key will hold the highest commitment number
that the tower has been handed for this channel. In this commit, we
start writing to it in the two places where a backup is first persisted
in the tower client db: 1) CommitUpdate and 2) in the Queue's `addItem`
method. The logic for both 1 & 2 is tested in the next commit which adds
a DB helper that allows us to read the new field.

A follow up commit will do a migration to back-fill the new field.
2023-11-27 20:01:17 +02:00
Elle Mouton
273b934f62
wtdb+lnrpc: return correct NumAckedUpdates from wtclientrpc 2023-09-14 10:33:04 +02: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
c33cd0ea38
wtdb: refactor getRangesWriteBucket
A pure refactor commit that passes the required buckets to the
`getRangesWriteBucket` instead of re-fetching them.
2023-09-14 10:30:00 +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
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
Oliver Gugger
56dba2df03
multi: update linter, fix new issues 2023-06-13 11:58:33 +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
5cc7438d33
watchtower/wtdb: add bolt db impl of Queue
This commit adds a new generic DiskQueueDB type which is an
bbolt implementation of the Queue interface.
2023-05-16 10:57:49 +02:00
Elle Mouton
a946715b7e
watchtower/wtdb: add a generic Queue interface 2023-05-16 10:57:49 +02:00
Elle Mouton
24016c35c7
watchtower: add forceNext to NextSessionKeyIndex
This commit adds a forceNext boolean parameter to NextSessionKeyIndex.
Setting this param to true will force the index to cycle over 1000 key
indices before returning the new key.
2023-03-31 12:04:57 +02:00
Elle Mouton
49cd23725a
watchtower: add PostEvaluateFilterFn call-back option
This commit adds a new PostEvaluateFilterFn call-back option to
`wtdb.ClientSessionListCfg`. This call-back is run _after_ all the other
evaluation call-backs in `wtdb.ClientSessionListCfg` and is only used to
determine if the session should be included in the returned list or not.
2023-03-20 20:14:01 +02:00
Elle Mouton
7bc86ca42e
watchtower: add PreEvaluateFilterFn callback
In this commit, a PreEvaluateFilterFn option is added to the
wtdb.ClientSessionListCfg and it is used instead of a separate
ClientSessionFilterFn parameter. This neatens quiet a few function
signatures.
2023-03-20 20:14:01 +02:00
Elle Mouton
d840761cc4
watchtower: dont load closed channel details
In this commit, the FetchChanSummaries method is adapted to skip loading
any channel summaries if the channel has been marked as closed.
2023-03-20 16:51:51 +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
5283e2c341
watchtower/wtdb: remove unnecessary tower load 2023-03-20 10:46:52 +02:00
Elle Mouton
ee0353dd24
watchtower: build channel to sessionIDs index
In this commit, a migration is added that adds an index from channel to
sessionIDs (using the DB-assigned session IDs). This will make it easier
in future to know which sessions have updates for which channels.
2023-03-20 10:46:52 +02:00
Elle Mouton
b16df45076
watchtower: add sessionID index
In this commit, a new session-ID index is added to the tower client db
with the help of a migration. This index holds a mapping from a
db-assigned-ID (a uint64 encoded using BigSize encoding) to real session
ID (33 bytes). This mapping will help us save space in future when
persisting references to sessions.
2023-03-20 10:46:52 +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
f6ef3db6ea
watchtower/wtdb: add tower-to-session index entry for all towers
In this commit, a small migration is added to the watchtower client DB
to ensure that there is an entry in the towerID-to-sessionID index for
all towers in the db regardless of if they have sessions or not. This is
required as a follow up to migration 1 since that migration only created
entries in the index for towers that had associated sessions which would
lead to "tower not found" errors on start up.
2023-03-08 11:00:40 +02:00
Elle Mouton
33b7b9221a
channeldb+wtdb: fix migration function name lint
Rename the ApplyMigrationWithDb function to ApplyMigrationWithDB to make
the linter happy.
2023-02-16 07:51:49 +02:00
Oliver Gugger
d960fcd68a
multi: remove gomnd disable directives 2023-01-17 19:43:26 +01: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
Elle Mouton
50ad10666c
watchtower/wtdb: add migration code for AckedUpdates
In this commit, the code for migration 4 is added. This migration takes
all the existing session acked updates and migrates them to be stored in
the RangeIndex form instead. Note that this migration is not activated
in this commit. This is done in a follow up commit in order to keep this
one smaller.
2023-01-11 13:59:03 +02:00
Elle Mouton
870a91a1e8
watchtower/wtdb: add ability for a multi-tx db migration
In this commit, we add the ability to add a wtdb version migration that
does not get given a transaction but rather a whole db object. This will
be useful for migrations that are best done in multiple transaction in
order to use less RAM.
2023-01-11 13:59:03 +02:00
Elle Mouton
0f6229d9e6
watchtower: convert helpers to methods
In preparation for an upcoming commit where some helper functions will
need access to the ClientDB's ackedRangeIndex member, this commit
converts those helper functions into methods on the ClientDB struct.
2023-01-11 13:59:02 +02:00
Elle Mouton
e2ae563304
watchtower: add in-mem acked range index to ClientDB
In this commit, an RangeIndex set is added to the ClientDB along with
getter methods that can be used to populate this in-memory set from the
DB.
2023-01-11 13:59:02 +02:00
Elle Mouton
4ea6c7d2ae
watchtower: refactor putClientSessionBody
Refactor the putClientSessionBody to take in a session sub-bucket rather
than the top-level session bucket. This is mainly to make an upcoming
commit diff easier to parse.
2023-01-11 13:59:02 +02:00
Elle Mouton
25afc8ad90
watchtower: add RangeIndex and tests
In this commit, a new concept called a RangeIndex is introduced. It
provides an efficient way to keep track of numbers added to a set by
keeping track of various ranges instead of individual numbers.

Notably, it also provides a way to map the contents & diffs applied to
the in memory RangeIndex (which uses a sorted array structure) to a
persisted KV structure.
2023-01-11 13:46:55 +02:00
Elle Mouton
fdba28ab7d
watchtower: add channelID index
In this commit, a new channel-ID index is added to the tower client db
with the help of a migration. This index holds a mapping from a
db-assigned-ID (a uint64 encoded using BigSize encoding) to real channel
ID (32 bytes). This mapping will help us save space in future when
persisting references to channels.
2023-01-11 13:46:55 +02:00
Elle Mouton
d03047f313
watchtower: migrate channel summaries
In this commit a migration of the tower client db is done. The migration
creates a new top-level cChanDetailsBkt bucket and for each channel
found in the old cChanSummaryBkt bucket, it creates a new sub-bucket. In
the subbucket, the ClientChanSummary is then stored under the
cChannelSummary key. The reason for this migration is that it will be
useful in future when we want to store more easily accessible data under
a specific client ID.
2023-01-11 13:46:55 +02:00
Elle Mouton
4ab8c57eae
watchtower: make better use of getChanSummary
Small refactor just to make the upcoming commit easier to parse. In
this commit, we make better use of the getChanSummary helper function.
2023-01-11 13:46:54 +02:00