Commit Graph

94 Commits

Author SHA1 Message Date
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
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
Carsten Otto
378478eb1a multi: fix typos and grammar issues in comments [skip ci] 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
Elle Mouton
3ac3b6a90d
watchtower: refactor getClientSession helper funcs
Small refactor to some of the tower client db helper functions in order
to simplify upcoming commits.
2022-10-13 14:35:03 +02:00
Elle Mouton
ecd2eb965a
watchtower: make use of the new tower-to-session index
In this commit, the towerID-to-sessionID index added in the previous
commit is put to use in order to make session lookup more efficient in
certain places. In the process, 2 TODO's are also removed from the code.
2022-10-13 11:30:27 +02:00
Elle Mouton
354a3b16bd
watchtower/wtdb: add new towerID-to-sessionID index
This commit adds a new towerID-to-sessionID index to the wtclient DB.
The commit also contains the necessary migration required in order to
build the index for an existing client.
This index will greatly improve the lookup of sessions for a given tower
ID.
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
e150bb83d1
watchtower/wtdb: check tower exists on session create
Before creating a new session, first check that the TowerID that the
ClientSession is referencing refers to an existing tower. This is done
to prevent the situation where RemoveTower is called right before
CreateClientSession is called which would, before this commit, lead to
the session being created with a tower ID that does not refer to any
existing tower.
2022-10-13 11:30:26 +02:00
Elle Mouton
5dabf7cb3e
watchtower/wtdb: update tests to use require package
In this commit, all the tests in the wtdb package are updated in order
to make use of the `require` package where appropriate.
2022-10-13 11:30:26 +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
Eng Zer Jun
6d00cdea45
watchtower/wtdb: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 09:03:06 +08: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
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
ErikEk
d5463818a8 bbolt sync-freelist ignored 2021-09-27 06:49:56 +01:00
Oliver Gugger
75531455da
multi: make watchtower client/server DBs remote compatible
The final database that needs to be made remote compatible is the
watchtower server and client database.
They are handled a bit differently because both of them are not always
active, only when specifically turned on in the config.
2021-08-04 14:55:53 +02:00
Andras Banki-Horvath
14c851c8fc
kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
Yong
582b164c46
kvdb: add timeout options for bbolt (#4787)
* mod: bump btcwallet version to accept db timeout

* btcwallet: add DBTimeOut in config

* kvdb: add database timeout option for bbolt

This commit adds a DBTimeout option in bbolt config. The relevant
functions walletdb.Open/Create are updated to use this config. In
addition, the bolt compacter also applies the new timeout option.

* channeldb: add DBTimeout in db options

This commit adds the DBTimeout option for channeldb. A new unit
test file is created to test the default options. In addition,
the params used in kvdb.Create inside channeldb_test is updated
with a DefaultDBTimeout value.

* contractcourt+routing: use DBTimeout in kvdb

This commit touches multiple test files in contractcourt and routing.
The call of function kvdb.Create and kvdb.Open are now updated with
the new param DBTimeout, using the default value kvdb.DefaultDBTimeout.

* lncfg: add DBTimeout option in db config

The DBTimeout option is added to db config. A new unit test is
added to check the default DB config is created as expected.

* migration: add DBTimeout param in kvdb.Create/kvdb.Open

* keychain: update tests to use DBTimeout param

* htlcswitch+chainreg: add DBTimeout option

* macaroons: support DBTimeout config in creation

This commit adds the DBTimeout during the creation of macaroons.db.
The usage of kvdb.Create and kvdb.Open in its tests are updated with
a timeout value using kvdb.DefaultDBTimeout.

* walletunlocker: add dbTimeout option in UnlockerService

This commit adds a new param, dbTimeout, during the creation of
UnlockerService. This param is then passed to wallet.NewLoader
inside various service calls, specifying a timeout value to be
used when opening the bbolt. In addition, the macaroonService
is also called with this dbTimeout param.

* watchtower/wtdb: add dbTimeout param during creation

This commit adds the dbTimeout param for the creation of both
watchtower.db and wtclient.db.

* multi: add db timeout param for walletdb.Create

This commit adds the db timeout param for the function call
walletdb.Create. It touches only the test files found in chainntnfs,
lnwallet, and routing.

* lnd: pass DBTimeout config to relevant services

This commit enables lnd to pass the DBTimeout config to the following
services/config/functions,
  - chainControlConfig
  - walletunlocker
  - wallet.NewLoader
  - macaroons
  - watchtower
In addition, the usage of wallet.Create is updated too.

* sample-config: add dbtimeout option
2020-12-07 15:31:49 -08:00
Conner Fromknecht
6b4df04950
wtclient_tests: remove expErr param from nextKeyIndex
This command cannot fail (apart from commit errors) so the linter
complained that the argument was always nil.
2020-12-01 16:55:24 -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
Conner Fromknecht
b9f031b3e3
Merge pull request #4746 from wpaulino/tower-last-addr
watchtower: prevent removal of last tower addr
2020-11-11 09:27:54 -08:00
Andras Banki-Horvath
d89f51d1d0
multi: add reset closure to kvdb.Update
Similarly as with kvdb.View this commits adds a reset closure to the
kvdb.Update call in order to be able to reset external state if the
underlying db backend needs to retry the transaction.
2020-11-05 17:57:12 +01:00
Andras Banki-Horvath
2a358327f4
multi: add reset closure to kvdb.View
This commit adds a reset() closure to the kvdb.View function which will
be called before each retry (including the first) of the view
transaction. The reset() closure can be used to reset external state
(eg slices or maps) where the view closure puts intermediate results.
2020-11-05 17:57:12 +01:00
Wilmer Paulino
d3157bcaf8
watchtower: prevent removal of last tower addr
This addresses a potential panic when a tower has one of its candidate
sessions chosen, but its only reachable address was removed by a
user-initiated RPC before the fact.
2020-11-04 15:43:18 -08:00
Conner Fromknecht
455ddfebdb
multi: rename: ReadBucket to RBucket 2020-05-26 18:21:08 -07:00
Conner Fromknecht
d0d2ca403d
multi: rename ReadTx to RTx 2020-05-26 18:20:37 -07:00
Oliver Gugger
f97e7b9951
watchtower: use ECDH interface for watchtower session 2020-05-20 09:06:57 +02:00
Oliver Gugger
b0cb110e86
watchtower: rename SessionPrivKey to SessionKeyECDH 2020-05-20 09:05:15 +02:00
Olaoluwa Osuntokun
557b930c5f
watchtower: convert to use new kvdb abstraction 2020-03-18 19:35:01 -07:00
Olaoluwa Osuntokun
777ed104a3
chainfee: create new chainfee package extracting fees from lnwallet
In this commit, we create a new chainfee package, that houses all fee
related functionality used within the codebase. The creation of this new
package furthers our long-term goal of extracting functionality from the
bloated `lnwallet` package into new distinct packages. Additionally,
this new packages resolves a class of import cycle that could arise if a
new package that was imported by something in `lnwallet` wanted to use
the existing fee related functions in the prior `lnwallet` package.
2019-10-31 16:41:57 -07:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02:00
Johan T. Halseth
21baa7bf18
multi: fix linter errors 2019-08-07 10:53:10 +02:00
Olaoluwa Osuntokun
8c9c4b52e8
Merge pull request #3184 from wpaulino/wtclient-subserver
multi: add watchtower client RPC subserver
2019-07-30 17:26:22 -07:00
Wilmer Paulino
359b2049b6
watchtower: load persisted towers upon TowerClient creation
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.
2019-07-30 15:18:17 -07:00
Wilmer Paulino
1d73a6564f
watchtower: extend client databse with CRUD operations for towers
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.
2019-07-30 15:13:23 -07:00
Wilmer Paulino
56d66c80a1
watchtower: extend client db to filter sessions for a specific tower
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.
2019-07-30 15:13:22 -07:00