Skip to content

Commit 808cec4

Browse files
committed
Add transaction sync crate
This crate provides utilities for syncing LDK via the transaction-based `Confirm` interface. The initial implementation facilitates synchronization with an Esplora backend server.
1 parent de2acc0 commit 808cec4

File tree

6 files changed

+482
-1
lines changed

6 files changed

+482
-1
lines changed

.github/workflows/build.yml

+22-1
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,52 @@ jobs:
2121
build-net-tokio: true
2222
build-no-std: true
2323
build-futures: true
24+
build-tx-sync: true
2425
- toolchain: stable
2526
platform: macos-latest
2627
build-net-tokio: true
2728
build-no-std: true
2829
build-futures: true
30+
build-tx-sync: true
2931
- toolchain: beta
3032
platform: macos-latest
3133
build-net-tokio: true
3234
build-no-std: true
3335
build-futures: true
36+
build-tx-sync: true
3437
- toolchain: stable
3538
platform: windows-latest
3639
build-net-tokio: true
3740
build-no-std: true
3841
build-futures: true
42+
build-tx-sync: true
3943
- toolchain: beta
4044
platform: windows-latest
4145
build-net-tokio: true
4246
build-no-std: true
4347
build-futures: true
48+
build-tx-sync: true
4449
- toolchain: beta
4550
build-net-tokio: true
4651
build-no-std: true
4752
build-futures: true
53+
build-tx-sync: true
4854
- toolchain: 1.41.1
4955
build-no-std: false
5056
test-log-variants: true
5157
build-futures: false
58+
build-tx-sync: false
5259
- toolchain: 1.45.2
5360
build-net-old-tokio: true
5461
build-net-tokio: true
5562
build-no-std: false
5663
build-futures: true
64+
build-tx-sync: false
5765
coverage: true
5866
- toolchain: 1.47.0
5967
build-futures: true
6068
build-no-std: true
69+
build-tx-sync: false
6170
runs-on: ${{ matrix.platform }}
6271
steps:
6372
- name: Checkout source code
@@ -108,6 +117,18 @@ jobs:
108117
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
109118
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
110119
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
120+
- name: Build Transaction Sync Clients on Rust ${{ matrix.toolchain }} with features
121+
if: "matrix.build-tx-sync && !matrix.coverage"
122+
run: |
123+
cd lightning-transaction-sync
124+
cargo build --verbose --color always --features esplora-blocking
125+
cargo build --verbose --color always --features esplora-async
126+
- name: Build Transaction Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
127+
if: "matrix.build-tx-sync && matrix.coverage"
128+
run: |
129+
cd lightning-transaction-sync
130+
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking
131+
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async
111132
- name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
112133
if: "matrix.build-no-std"
113134
run: |
@@ -349,7 +370,7 @@ jobs:
349370
linting:
350371
runs-on: ubuntu-latest
351372
env:
352-
TOOLCHAIN: 1.47.0
373+
TOOLCHAIN: stable
353374
steps:
354375
- name: Checkout source code
355376
uses: actions/checkout@v3

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
members = [
44
"lightning",
55
"lightning-block-sync",
6+
"lightning-transaction-sync",
67
"lightning-invoice",
78
"lightning-net-tokio",
89
"lightning-persister",

lightning-transaction-sync/Cargo.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "lightning-transaction-sync"
3+
version = "0.0.112"
4+
authors = ["Elias Rohrer"]
5+
license = "MIT OR Apache-2.0"
6+
repository = "http://github.com/lightningdevkit/rust-lightning"
7+
description = """
8+
Utilities for syncing LDK via the transaction-based `Confirm` interface.
9+
"""
10+
edition = "2018"
11+
12+
[package.metadata.docs.rs]
13+
all-features = true
14+
rustdoc-args = ["--cfg", "docsrs"]
15+
16+
[features]
17+
default = ["esplora-blocking"]
18+
esplora-async = ["async-interface", "esplora-client/async", "tokio"]
19+
esplora-blocking = ["esplora-client/blocking"]
20+
async-interface = []
21+
22+
[dependencies]
23+
lightning = { version = "0.0.112", path = "../lightning" }
24+
bitcoin = "0.29.0"
25+
bdk-macros = "0.6"
26+
tokio = { version = "1.0", default-features = false, features = [], optional = true }
27+
esplora-client = { git = "https://github.com/tnull/rust-esplora-client", branch = "2022-10-get-merkle-block", default-features = false, optional = true }
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::fmt;
2+
3+
#[derive(Debug)]
4+
/// An error that possibly needs to be handled by the user.
5+
pub enum TxSyncError {
6+
/// A transaction sync failed.
7+
Failed,
8+
/// An inconsisteny was encounterd during transaction sync.
9+
Inconsistency,
10+
}
11+
12+
impl fmt::Display for TxSyncError {
13+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14+
match *self {
15+
Self::Failed => write!(f, "Failed to conduct transaction sync."),
16+
Self::Inconsistency => {
17+
write!(f, "Encountered an inconsisteny during transaction sync.")
18+
}
19+
}
20+
}
21+
}
22+
23+
impl std::error::Error for TxSyncError {}
24+
25+
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
26+
impl From<esplora_client::Error> for TxSyncError {
27+
fn from(_e: esplora_client::Error) -> Self {
28+
Self::Failed
29+
}
30+
}

0 commit comments

Comments
 (0)