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

channeldb+lnd: eliminate direct graph access via *channeldb.DB pointer, enable custom graph db implementations #6294

Open
3 tasks
Roasbeef opened this issue Feb 24, 2022 · 2 comments
Labels
database Related to the database/storage of LND graph intermediate Issues suitable for developers moderately familiar with the codebase and LN refactoring

Comments

@Roasbeef
Copy link
Member

Roasbeef commented Feb 24, 2022

During the 0.14 cycle, we did a lot of refactoring to extract much of the internal sub-system initialization from the main() function in lng.go. This was a necessary step along the road to enabling things like the new remote signer operating mode, which from the PoV of lnd is just the same existing wallet/signing interfaces used. In this operating mode, lnd isn't explicitly aware that it's actually speaking with a signer over the RPC interface. This interaction is enabled by the fact that our internal wallet/signing interface closely mirrors the wallet/signing sub-servers.

In a similar vein, if we start to surface more storage-level interfaces as part of the DatabaseBuilder abstraction, then we enable users to pass in custom implementations of app-specific storage engines like the invoice registry or channel graph.

One easy win here on the road to creating more performance optimized storage implementations for various sub-systems is abstracting away usage of the "channel graph" across the codebase. Today most of the time, the graph is interact with via a direct *channeldb.DB pointer. If we add a layer of indirection here with another interface, then it enables more advanced lnd operating modes like having a fleet of nodes share the same channel graph (no need for them all to download it again once a new node is added to the cluster, etc). Ignoring some of the database concurrency control implications for a second, this would allow new nodes which are part of shared infrastructure to more instantly be initialized, as they don't need to sync the graph from the p2p network. This also serves to de-duplicate information that can safely be shared across related lnd nodes.

Steps to Completion

@Roasbeef Roasbeef added intermediate Issues suitable for developers moderately familiar with the codebase and LN database Related to the database/storage of LND graph refactoring labels Feb 24, 2022
@Roasbeef
Copy link
Member Author

Example of the new architectures that this would indirectly enable: #6262 (comment)

@starius
Copy link
Collaborator

starius commented Jan 8, 2024

I propose to add high level storage interfaces exchanging data in structured types rather than bytes (repository pattern).

Currently the primary storage interface is key-value which is bbolt-like. Data types in the KV interface are already serialized. Some disadvantages of KV approach to storage interface were noted in #6176 (comment)
Many packages use kvdb package directly and encode/decode data types themselves. I propose to "hide" kvdb from high level packages. High level code could pass structs to methods of repositories, which could encode/decode and call kvdb. Alternative implementation may call something else instead of kvdb.

If all parts of DatabaseInstances become high level interfaces, it will simplify the following things:

  • native SQL storage implementations
  • optimized graph database shared between multiple nodes
  • separate process / microservice for storage

Transition from KV to high level interfaces can be done in an incremental way and it is an internal code change, not requiring database migration; the KV implementation could expose new methods with high level types instead of []byte.

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 graph intermediate Issues suitable for developers moderately familiar with the codebase and LN refactoring
Projects
None yet
Development

No branches or pull requests

2 participants