Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcd: enable full remote database support #5484

Merged
merged 18 commits into from
Aug 4, 2021

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Jul 7, 2021

Depends on btcsuite/btcwallet#757.

This PR enables full remote database support when using an etcd database backend.
This means that everything that used to be in a bbolt database now gets written to etcd, with an appropriate sub namespace added to the key path.

@guggero guggero added database Related to the database/storage of LND etcd labels Jul 7, 2021
@guggero guggero added this to the v0.14.0 milestone Jul 7, 2021
lncfg/db.go Outdated Show resolved Hide resolved
lncfg/db.go Show resolved Hide resolved
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

Awesome work @guggero !! My main comment is whether we should also add interfaces by function in this PR and if we should also support testing of all these DBs with all backends. Other than that, LGTM!

kvdb/etcd/db.go Show resolved Hide resolved
chainreg/chainregistry.go Outdated Show resolved Hide resolved
lncfg/db.go Show resolved Hide resolved
lncfg/db.go Show resolved Hide resolved
lncfg/db.go Outdated Show resolved Hide resolved
htlcswitch/decayedlog.go Show resolved Hide resolved
lncfg/db.go Outdated Show resolved Hide resolved
watchtower/wtdb/client_db_test.go Show resolved Hide resolved
kvdb/etcd/config.go Show resolved Hide resolved
lncfg/db.go Outdated Show resolved Hide resolved
@joostjager
Copy link
Contributor

I noticed one thing while running the postgres stateless_init itest. In this test, the password is changed. But during the handling of this call, the macaroon service and the macaroon db connection is closed in

err = macaroonService.Close()
.

This leads to a failure for the subsequent rpc call when validating the macaroon.

@guggero guggero force-pushed the database-full-remote branch 3 times, most recently from a028369 to 6fe0160 Compare July 12, 2021 11:42
@guggero
Copy link
Collaborator Author

guggero commented Jul 12, 2021

I noticed one thing while running the postgres stateless_init itest. In this test, the password is changed.

I addressed this in the version I pushed last week. The macaroon service no longer closes the DB backend now (since it is also not responsible for creating it in the first place). If you still see this with the current version, please let me know.

@guggero guggero marked this pull request as ready for review July 12, 2021 11:54
lncfg/db.go Outdated Show resolved Hide resolved
lnd.go Outdated Show resolved Hide resolved
lnd.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

Changes LGTM barring Joost's comment on the migration. Great work Oliver!

lncfg/db.go Outdated Show resolved Hide resolved
@bhandras
Copy link
Collaborator

Changes LGTM barring Joost's comment on the migration. Great work Oliver!

There's still something off with the itests it seems. We may need another round later on.

@guggero guggero force-pushed the database-full-remote branch 3 times, most recently from 9bb3538 to a3b6120 Compare July 16, 2021 15:54
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

Looks good. Only comment is that the commit order is such that not every commit seems to be safe to run. For example the etcd namespacing is introduced after all data is already stored in the same etcd database in a previous commit.

lnd.go Show resolved Hide resolved
@guggero guggero force-pushed the database-full-remote branch 2 times, most recently from 983307c to ba2c7c9 Compare August 3, 2021 07:57
As a preparation to initialize more than just the channel database on
startup we introduce a new struct that holds a reference to each of our
database instances.
As a preparation to not have a local and remote version of the database
around anymore, we rename the variables into what their actual function
is. In case of the RPC server we even directly use the channel graph
instead of the DB instance. This should allow us to extract the channel
graph into its own, separate database (perhaps with better access
characteristics) in the future.
In order to separate our databases more clearly, we refactor the height
hint cache DB to use a kvdb backend instead of the channel DB instance
directly.
This commit gets rid of the concept of a local and remote database when
etcd is used. Instead the same backend is now used for both the
(previously renamed from local and remote DB) graph and channel state
databases.
This will make path finding extremely slow on etcd and will require
further optimizations and possibly a write-through cache for the graph
DB. But this is a requirement for making lnd itself fully stateless.
The macaroon root keys should also be stored to the remote database if a
replicated backend such as etcd is used.
This commit refactors the macaroons service and wallet unlocker to
accept a kvdb backend directly instead of creating the bolt instance
automatically.
The wallet and macaroon databases are the first files that are created
for a new node. When initializing those databases, the parent directory
is created if it does not exist.
With both of the databases now potentially being remote, that code that
creates the parent directory might never be executed and we need to do
that manually when parsing the configuration.
Otherwise we run into an error when we later try to create our default
macaroons in that folder and it doesn't exist.
Even though the sphinx router's persistent replay log is not crucial in
the operation of lnd as its state can be re-created by creating a new
brontide connection, we want to make lnd fully stateless and therefore
have the option of not storing any state on disk.
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.
To have all the database backend related code in one place, we finally
also move the initialization of the wallet DB loader option into the
GetBackends() method.
Since we're now storing the content of multiple previously distinct
database files in etcd, we want to properly namespace them as not to
provoke any key collisions. We append a sub namespace to the given
global namespace in order to still support multiple lnd nodes using the
same etcd database simultaneously.

Because the btcwallet code uses the legacy walletdb interface we must
assume it is not fully concurrency safe. Therefore we make sure only a
single writer can be active at any given time for the wallet DB backend
when using etcd.
Depends on btcsuite/btcwallet#757.
Pulls in the updated version of btcwallet and walletdb that have the DB
interface enhanced by their own View() and Update() methods with the
reset callback/closure supported out of the box. That way the global
package-level View() and Update() functions now become pure redirects.
With this commit we address some issues the linter picked up after
touching older code.
To make it easier to see what tranche a failed test was running in, we
add the tranche index to the test name. This corresponds to the number
in the .logs-tranche<index> folder name so the logs can be found much
quicker.
@guggero guggero force-pushed the database-full-remote branch 4 times, most recently from 9887a9c to 70b1c57 Compare August 4, 2021 16:37
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM, let's get this merged!

lntest/itest/test_harness.go Outdated Show resolved Hide resolved
@guggero guggero merged commit 4c010e8 into lightningnetwork:master Aug 4, 2021
@guggero guggero deleted the database-full-remote branch August 4, 2021 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Related to the database/storage of LND etcd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants