-
Notifications
You must be signed in to change notification settings - Fork 130
Add Postgres database #863
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
Open
benthecarman
wants to merge
2
commits into
lightningdevkit:main
Choose a base branch
from
benthecarman:postgres
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: CI Checks - PostgreSQL Integration Tests | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build-and-test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:latest | ||
| ports: | ||
| - 5432:5432 | ||
| env: | ||
| POSTGRES_DB: postgres | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres | ||
| options: >- | ||
| --health-cmd pg_isready | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
| - name: Install Rust stable toolchain | ||
| run: | | ||
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable | ||
| - name: Run PostgreSQL store tests | ||
| env: | ||
| TEST_POSTGRES_URL: "host=localhost user=postgres password=postgres" | ||
| run: cargo test --features postgres io::postgres_store | ||
| - name: Run PostgreSQL integration tests | ||
| env: | ||
| TEST_POSTGRES_URL: "host=localhost user=postgres password=postgres" | ||
| run: | | ||
| RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test --features postgres --test integration_tests_postgres | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,9 @@ use crate::entropy::NodeEntropy; | |
| use crate::event::EventQueue; | ||
| use crate::fee_estimator::OnchainFeeEstimator; | ||
| use crate::gossip::GossipSource; | ||
| #[cfg(feature = "sqlite")] | ||
| use crate::io; | ||
| #[cfg(feature = "sqlite")] | ||
| use crate::io::sqlite_store::SqliteStore; | ||
| use crate::io::utils::{ | ||
| read_event_queue, read_external_pathfinding_scores_from_cache, read_network_graph, | ||
|
|
@@ -61,7 +64,7 @@ use crate::io::utils::{ | |
| }; | ||
| use crate::io::vss_store::VssStoreBuilder; | ||
| use crate::io::{ | ||
| self, PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE, | ||
| PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE, | ||
| PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, | ||
| PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE, | ||
| }; | ||
|
|
@@ -616,6 +619,7 @@ impl NodeBuilder { | |
|
|
||
| /// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options | ||
| /// previously configured. | ||
| #[cfg(feature = "sqlite")] | ||
| pub fn build(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> { | ||
| let storage_dir_path = self.config.storage_dir_path.clone(); | ||
| fs::create_dir_all(storage_dir_path.clone()) | ||
|
|
@@ -629,6 +633,24 @@ impl NodeBuilder { | |
| self.build_with_store(node_entropy, kv_store) | ||
| } | ||
|
|
||
| /// Builds a [`Node`] instance with a [PostgreSQL] backend and according to the options | ||
| /// previously configured. | ||
| /// | ||
| /// Connects to the PostgreSQL database at the given `connection_string`. | ||
| /// The given `kv_table_name` will be used or default to | ||
| /// [`DEFAULT_KV_TABLE_NAME`](crate::io::postgres_store::DEFAULT_KV_TABLE_NAME). | ||
| /// | ||
| /// [PostgreSQL]: https://www.postgresql.org | ||
| #[cfg(feature = "postgres")] | ||
| pub fn build_with_postgres_store( | ||
| &self, node_entropy: NodeEntropy, connection_string: &str, kv_table_name: Option<String>, | ||
| ) -> Result<Node, BuildError> { | ||
| let kv_store = | ||
| crate::io::postgres_store::PostgresStore::new(connection_string, kv_table_name) | ||
| .map_err(|_| BuildError::KVStoreSetupFailed)?; | ||
| self.build_with_store(node_entropy, kv_store) | ||
| } | ||
|
|
||
| /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options | ||
| /// previously configured. | ||
| pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> { | ||
|
|
@@ -1083,10 +1105,27 @@ impl ArcedNodeBuilder { | |
|
|
||
| /// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options | ||
| /// previously configured. | ||
| #[cfg(feature = "sqlite")] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we suddenly introduce features? We so far held off and meant to do that in a dedicated PR at some point for this or next release. Is it necessary to make Postgres work? |
||
| pub fn build(&self, node_entropy: Arc<NodeEntropy>) -> Result<Arc<Node>, BuildError> { | ||
| self.inner.read().unwrap().build(*node_entropy).map(Arc::new) | ||
| } | ||
|
|
||
| /// Builds a [`Node`] instance with a [PostgreSQL] backend and according to the options | ||
| /// previously configured. | ||
| /// | ||
| /// [PostgreSQL]: https://www.postgresql.org | ||
| #[cfg(feature = "postgres")] | ||
| pub fn build_with_postgres_store( | ||
| &self, node_entropy: Arc<NodeEntropy>, connection_string: String, | ||
| kv_table_name: Option<String>, | ||
| ) -> Result<Arc<Node>, BuildError> { | ||
| self.inner | ||
| .read() | ||
| .unwrap() | ||
| .build_with_postgres_store(*node_entropy, &connection_string, kv_table_name) | ||
| .map(Arc::new) | ||
| } | ||
|
|
||
| /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options | ||
| /// previously configured. | ||
| pub fn build_with_fs_store( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // This file is Copyright its original authors, visible in version control history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
| // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or | ||
| // http://opensource.org/licenses/MIT>, at your option. You may not use this file except in | ||
| // accordance with one or both of these licenses. | ||
|
|
||
| use lightning::io; | ||
| use tokio_postgres::Client; | ||
|
|
||
| pub(super) async fn migrate_schema( | ||
| _client: &Client, _kv_table_name: &str, from_version: u16, to_version: u16, | ||
| ) -> io::Result<()> { | ||
| assert!(from_version < to_version); | ||
| // Future migrations go here, e.g.: | ||
| // if from_version == 1 && to_version >= 2 { | ||
| // migrate_v1_to_v2(client, kv_table_name).await?; | ||
| // from_version = 2; | ||
| // } | ||
| Ok(()) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think there are newer action versions available? Cf #861.