-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
etcd: enable full remote database support #5484
Conversation
4980273
to
90e6ef2
Compare
There was a problem hiding this 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!
90e6ef2
to
097fddd
Compare
I noticed one thing while running the postgres Line 653 in c733c13
This leads to a failure for the subsequent rpc call when validating the macaroon. |
a028369
to
6fe0160
Compare
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. |
There was a problem hiding this 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!
There's still something off with the itests it seems. We may need another round later on. |
9bb3538
to
a3b6120
Compare
There was a problem hiding this 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.
983307c
to
ba2c7c9
Compare
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.
9887a9c
to
70b1c57
Compare
There was a problem hiding this 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!
70b1c57
to
66ed64d
Compare
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 toetcd
, with an appropriate sub namespace added to the key path.