Skip to content

Support HTTPS Esplora endpoints in lightning-transaction-sync via new feature #2085

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,21 @@ jobs:
cd lightning-transaction-sync
cargo build --verbose --color always --features esplora-blocking
cargo build --verbose --color always --features esplora-async
cargo build --verbose --color always --features esplora-async-https
- name: Build transaction sync clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
if: "matrix.build-tx-sync && matrix.coverage"
run: |
cd lightning-transaction-sync
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async-https
- name: Test transaction sync clients on Rust ${{ matrix.toolchain }} with features
if: "matrix.build-tx-sync"
run: |
cd lightning-transaction-sync
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
- name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
if: "matrix.toolchain == 'stable'"
shell: bash # Default on Winblows is powershell
Expand Down
2 changes: 2 additions & 0 deletions lightning-transaction-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = []
esplora-async = ["async-interface", "esplora-client/async", "futures"]
esplora-async-https = ["esplora-async", "reqwest/rustls-tls"]
esplora-blocking = ["esplora-client/blocking"]
async-interface = []

Expand All @@ -25,6 +26,7 @@ bitcoin = { version = "0.29.0", default-features = false }
bdk-macros = "0.6"
futures = { version = "0.3", optional = true }
esplora-client = { version = "0.3.0", default-features = false, optional = true }
reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }

[dev-dependencies]
lightning = { version = "0.0.114", path = "../lightning", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion lightning-transaction-sync/src/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::{TxSyncError, InternalError};
use crate::common::{SyncState, FilterQueue, ConfirmedTx};

use lightning::util::logger::Logger;
use lightning::{log_error, log_given_level, log_info, log_internal, log_debug, log_trace};
use lightning::{log_error, log_info, log_debug, log_trace};
use lightning::chain::WatchedOutput;
use lightning::chain::{Confirm, Filter};

Expand Down
5 changes: 3 additions & 2 deletions lightning-transaction-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//!
//! ## Features and Backend Support
//!
//!- `esplora_blocking` enables syncing against an Esplora backend based on a blocking client.
//!- `esplora_async` enables syncing against an Esplora backend based on an async client.
//!- `esplora-blocking` enables syncing against an Esplora backend based on a blocking client.
//!- `esplora-async` enables syncing against an Esplora backend based on an async client.
//!- `esplora-async-https` enables the async Esplora client with support for HTTPS.
//!
//! ## Version Compatibility
//!
Expand Down
17 changes: 17 additions & 0 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,20 @@ async fn test_esplora_syncs() {
_ => panic!("Unexpected event"),
}
}

#[tokio::test]
#[cfg(any(feature = "esplora-async-https", feature = "esplora-blocking"))]
async fn test_esplora_connects_to_public_server() {
let mut logger = TestLogger {};
let esplora_url = "https://blockstream.info/api".to_string();
let tx_sync = EsploraSyncClient::new(esplora_url, &mut logger);
let confirmable = TestConfirmable::new();

// Check we connect and pick up on new best blocks
assert_eq!(confirmable.best_block.lock().unwrap().1, 0);
#[cfg(feature = "esplora-async-https")]
tx_sync.sync(vec![&confirmable]).await.unwrap();
#[cfg(feature = "esplora-blocking")]
tx_sync.sync(vec![&confirmable]).unwrap();
assert_ne!(confirmable.best_block.lock().unwrap().1, 0);
}