Skip to content

Commit 5a540f6

Browse files
authored
Merge pull request #97 from lightningdevkit/0fc
Update ldk-node and enable zero-fee commitments
2 parents a283d74 + 915ec20 commit 5a540f6

13 files changed

Lines changed: 179 additions & 26 deletions

File tree

.github/workflows/tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ jobs:
3434

3535
- uses: Swatinem/rust-cache@v2.7.8
3636

37+
- name: Cache package-enabled Esplora
38+
id: cache-esplora
39+
uses: actions/cache@v4
40+
with:
41+
path: bin/electrs-${{ runner.os }}-${{ runner.arch }}
42+
key: electrs-submit-package-8c06d801-${{ runner.os }}-${{ runner.arch }}
43+
44+
- name: Build package-enabled Esplora
45+
if: steps.cache-esplora.outputs.cache-hit != 'true'
46+
run: |
47+
./scripts/build_package_esplora.sh "bin/electrs-${{ runner.os }}-${{ runner.arch }}"
48+
49+
- name: Configure package-enabled Esplora
50+
run: echo "ELECTRS_EXE=$(pwd)/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
51+
3752
- name: Check formatting
3853
run: cargo fmt --check
3954

@@ -62,5 +77,20 @@ jobs:
6277

6378
- uses: Swatinem/rust-cache@v2.7.8
6479

80+
- name: Cache package-enabled Esplora
81+
id: cache-esplora
82+
uses: actions/cache@v4
83+
with:
84+
path: bin/electrs-${{ runner.os }}-${{ runner.arch }}
85+
key: electrs-submit-package-8c06d801-${{ runner.os }}-${{ runner.arch }}
86+
87+
- name: Build package-enabled Esplora
88+
if: steps.cache-esplora.outputs.cache-hit != 'true'
89+
run: |
90+
./scripts/build_package_esplora.sh "bin/electrs-${{ runner.os }}-${{ runner.arch }}"
91+
92+
- name: Configure package-enabled Esplora
93+
run: echo "ELECTRS_EXE=$(pwd)/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
94+
6595
- name: Run cashu tests
6696
run: cargo test --features _cashu-tests -- --test-threads=2 --nocapture

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ codegen-units = 1 # Reduce number of codegen units to increase optimizations.
1616
panic = 'abort' # Abort on panic
1717

1818
[workspace.dependencies]
19-
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }
20-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
21-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
19+
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "0e430be98c09540624a68a68022ee0551e86d1be" }
20+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "506cb91f2e0fb87906188b79777bcf42595d3623" }
21+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "506cb91f2e0fb87906188b79777bcf42595d3623" }
2222

2323
[profile.release]
2424
panic = "abort"

orange-sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _cashu-tests = ["_test-utils", "cdk-ldk-node", "cdk/mint", "cdk-sqlite", "cdk-ax
2323
[dependencies]
2424
graduated-rebalancer = { path = "../graduated-rebalancer", version = "0.1.0" }
2525

26-
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node", rev = "8a5426044bdcae6369d7a847697c6143676e2df5" }
26+
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node", rev = "0cea34122767f0b86ebaf29c03f49eb38a85fc00" }
2727
lightning-macros = "0.2.0"
2828
bitcoin-payment-instructions = { workspace = true, features = ["http"] }
2929
chrono = { version = "0.4", default-features = false }
@@ -38,7 +38,7 @@ async-trait = "0.1"
3838
log = "0.4.28"
3939

4040
corepc-node = { version = "0.10.1", features = ["29_0", "download"], optional = true }
41-
electrsd = { version = "0.36.1", default-features = false, features = ["esplora_a33e97e1", "corepc-node_29_0"], optional = true }
41+
electrsd = { version = "0.36.1", default-features = false, features = ["legacy", "corepc-node_29_0"], optional = true }
4242
cdk-ldk-node = { version = "0.16.0", optional = true }
4343
cdk-sqlite = { version = "0.16.0", optional = true }
4444
cdk-axum = { version = "0.16.0", optional = true }

orange-sdk/src/dyn_store.rs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
//! Object-safe wrapper around ldk-node's async `KVStore` trait.
1+
//! Object-safe wrapper around ldk-node's async `PaginatedKVStore` trait.
22
//!
33
//! `lightning`'s `KVStore` returns `impl Future` from its methods, which makes the trait not
44
//! object-safe — orange-sdk can't share a backend across components as `Arc<dyn KVStore>`.
55
//!
66
//! This module defines `DynStore`, an object-safe trait covering the kv methods (returning
7-
//! boxed futures), with a blanket impl over any concrete type that implements `KVStore`. The
8-
//! whole crate stores backends as `Arc<dyn DynStore>`; conversion to a value ldk-node accepts
9-
//! happens at the call site through a thin newtype that delegates back to `DynStore`.
7+
//! boxed futures), with a blanket impl over any concrete type that implements
8+
//! `PaginatedKVStore`. The whole crate stores backends as `Arc<dyn DynStore>`; conversion to a
9+
//! value ldk-node accepts happens at the call site through a thin newtype that delegates back to
10+
//! `DynStore`.
1011
1112
use std::future::Future;
1213
use std::pin::Pin;
1314
use std::sync::Arc;
1415

1516
use ldk_node::lightning::io;
16-
use ldk_node::lightning::util::persist::KVStore;
17+
use ldk_node::lightning::util::persist::{
18+
KVStore, PageToken, PaginatedKVStore, PaginatedListResponse,
19+
};
1720
use tokio::task::JoinSet;
1821

1922
/// Matches the connection capacity used by the VSS HTTP client. Keeping the
@@ -38,11 +41,15 @@ pub(crate) trait DynStore: Send + Sync + 'static {
3841
fn list_async(
3942
&self, primary_namespace: &str, secondary_namespace: &str,
4043
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + Send + 'static>>;
44+
45+
fn list_paginated_async(
46+
&self, primary_namespace: &str, secondary_namespace: &str, page_token: Option<PageToken>,
47+
) -> Pin<Box<dyn Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static>>;
4148
}
4249

4350
impl<T> DynStore for T
4451
where
45-
T: KVStore + Send + Sync + 'static,
52+
T: PaginatedKVStore + Send + Sync + 'static,
4653
{
4754
fn read_async(
4855
&self, p: &str, s: &str, k: &str,
@@ -67,6 +74,12 @@ where
6774
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + Send + 'static>> {
6875
Box::pin(<T as KVStore>::list(self, p, s))
6976
}
77+
78+
fn list_paginated_async(
79+
&self, p: &str, s: &str, page_token: Option<PageToken>,
80+
) -> Pin<Box<dyn Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static>> {
81+
Box::pin(<T as PaginatedKVStore>::list_paginated(self, p, s, page_token))
82+
}
7083
}
7184

7285
// Make `dyn DynStore` itself implement `KVStore` so the same handle orange-sdk shares
@@ -96,8 +109,16 @@ impl KVStore for dyn DynStore {
96109
}
97110
}
98111

112+
impl PaginatedKVStore for dyn DynStore {
113+
fn list_paginated(
114+
&self, p: &str, s: &str, page_token: Option<PageToken>,
115+
) -> impl Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static {
116+
self.list_paginated_async(p, s, page_token)
117+
}
118+
}
119+
99120
/// Cloneable handle wrapping `Arc<dyn DynStore>` that satisfies ldk-node's
100-
/// `KVStore + Send + Sync + 'static` bound on `build_with_store`. The trait impl just
121+
/// `PaginatedKVStore + Send + Sync + 'static` bound on `build_with_store`. The trait impl just
101122
/// forwards to the underlying `dyn DynStore`.
102123
#[derive(Clone)]
103124
pub(crate) struct LdkNodeStore(pub(crate) Arc<dyn DynStore>);
@@ -125,6 +146,14 @@ impl KVStore for LdkNodeStore {
125146
}
126147
}
127148

149+
impl PaginatedKVStore for LdkNodeStore {
150+
fn list_paginated(
151+
&self, p: &str, s: &str, page_token: Option<PageToken>,
152+
) -> impl Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static {
153+
self.0.list_paginated_async(p, s, page_token)
154+
}
155+
}
156+
128157
/// Reads a set of keys concurrently while preserving the input order.
129158
///
130159
/// Storage formats expose record collections as a list followed by individual
@@ -242,6 +271,15 @@ mod tests {
242271
}
243272
}
244273

274+
impl PaginatedKVStore for ControlledStore {
275+
fn list_paginated(
276+
&self, _primary_namespace: &str, _secondary_namespace: &str,
277+
_page_token: Option<PageToken>,
278+
) -> impl Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static {
279+
ready(Ok(PaginatedListResponse { keys: Vec::new(), next_page_token: None }))
280+
}
281+
}
282+
245283
#[tokio::test]
246284
async fn bounded_reads_limit_concurrency_and_preserve_order() {
247285
let (entered, mut entered_rx) = mpsc::unbounded_channel();

orange-sdk/src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ impl LdkEventHandler {
648648
.add_event(Event::ChannelClosed {
649649
channel_id,
650650
user_channel_id,
651-
counterparty_node_id: counterparty_node_id.unwrap(), // safe
651+
counterparty_node_id,
652652
reason,
653653
})
654654
.await

orange-sdk/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,7 @@ mod tests {
17771777
let kind = PaymentKind::Onchain {
17781778
txid: Txid::from_byte_array([42; 32]),
17791779
status: ConfirmationStatus::Unconfirmed,
1780+
tx_type: None,
17801781
};
17811782

17821783
assert!(should_surface_lightning_payment_without_metadata(TxStatus::Pending, &kind));
@@ -1787,7 +1788,11 @@ mod tests {
17871788
let txid = Txid::from_byte_array([42; 32]);
17881789
let payment = PaymentDetails {
17891790
id: LightningPaymentId([24; 32]),
1790-
kind: PaymentKind::Onchain { txid, status: ConfirmationStatus::Unconfirmed },
1791+
kind: PaymentKind::Onchain {
1792+
txid,
1793+
status: ConfirmationStatus::Unconfirmed,
1794+
tx_type: None,
1795+
},
17911796
amount_msat: Some(123_000),
17921797
fee_paid_msat: None,
17931798
direction: PaymentDirection::Inbound,

orange-sdk/src/lightning_wallet.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ impl LightningWallet {
6565
log_info!(logger, "Creating LDK node...");
6666
let anchor_channels_config = ldk_node::config::AnchorChannelsConfig {
6767
trusted_peers_no_reserve: vec![config.lsp.1],
68+
enable_zero_fee_commitments: true,
6869
..Default::default()
6970
};
70-
let ldk_node_config = ldk_node::config::Config {
71-
anchor_channels_config: Some(anchor_channels_config),
72-
..Default::default()
73-
};
71+
let ldk_node_config =
72+
ldk_node::config::Config { anchor_channels_config, ..Default::default() };
7473
let mut builder = ldk_node::Builder::from_config(ldk_node_config);
7574
builder.set_network(config.network);
7675
let node_entropy = config.seed.to_node_entropy();
@@ -113,6 +112,7 @@ impl LightningWallet {
113112
fee_rate_cache_update_interval_secs: 30,
114113
}),
115114
timeouts_config: SyncTimeoutsConfig::default(),
115+
..Default::default()
116116
}
117117
} else {
118118
ldk_node::config::EsploraSyncConfig::default()
@@ -151,14 +151,15 @@ impl LightningWallet {
151151
lightning_wallet_sync_interval_secs: 2,
152152
fee_rate_cache_update_interval_secs: 30,
153153
}),
154+
..Default::default()
154155
})
155156
} else {
156157
None
157158
};
158159
builder.set_chain_source_electrum(url, sync_config)
159160
},
160161
ChainSource::BitcoindRPC { host, port, user, password } => {
161-
builder.set_chain_source_bitcoind_rpc(host, port, user, password)
162+
builder.set_chain_source_bitcoind_rpc(host, port, user, password, None)
162163
},
163164
};
164165

@@ -353,6 +354,7 @@ impl LightningWallet {
353354
kind: PaymentKind::Onchain {
354355
txid: funding_txo.txid,
355356
status: ConfirmationStatus::Unconfirmed, // todo how do we update this?
357+
tx_type: None,
356358
},
357359
amount_msat: Some(amount_sats * 1_000),
358360
fee_paid_msat: Some(69), // todo get real fee

orange-sdk/src/rebalancer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl RebalanceTrigger for OrangeTrigger {
176176
for payment in new_recvs {
177177
let payment_id = PaymentId::SelfCustodial(payment.id.0);
178178
let (txid, status) = match payment.kind {
179-
PaymentKind::Onchain { txid, status } => (txid, status),
179+
PaymentKind::Onchain { txid, status, .. } => (txid, status),
180180
_ => continue,
181181
};
182182
let event = Event::OnchainPaymentReceived {

orange-sdk/src/trusted_wallet/cashu/cashu_store.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ mod tests {
12921292
use cdk::Amount;
12931293
use cdk::nuts::Proof;
12941294
use cdk::secret::Secret;
1295+
use ldk_node::lightning::util::persist::{PageToken, PaginatedKVStore, PaginatedListResponse};
12951296
use std::future::ready;
12961297
use std::sync::Mutex as StdMutex;
12971298
use std::sync::atomic::{AtomicBool, Ordering};
@@ -1364,6 +1365,16 @@ mod tests {
13641365
}
13651366
}
13661367

1368+
impl PaginatedKVStore for ProofTestStore {
1369+
fn list_paginated(
1370+
&self, _primary_namespace: &str, _secondary_namespace: &str,
1371+
_page_token: Option<PageToken>,
1372+
) -> impl std::future::Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static
1373+
{
1374+
ready(Ok(PaginatedListResponse { keys: Vec::new(), next_page_token: None }))
1375+
}
1376+
}
1377+
13671378
fn proof_info(secret: &str, amount: u64) -> ProofInfo {
13681379
let proof = Proof::new(
13691380
Amount::from(amount),

orange-sdk/src/trusted_wallet/dummy.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ impl DummyTrustedWallet {
5252
uuid: Uuid, lsp: Arc<Node>, bitcoind: Arc<Bitcoind>, tx_metadata: TxMetadataStore,
5353
event_queue: Arc<EventQueue>, rt: Arc<Runtime>,
5454
) -> Self {
55-
let mut builder = ldk_node::Builder::new();
55+
let mut config = ldk_node::config::Config::default();
56+
config.anchor_channels_config.enable_zero_fee_commitments = true;
57+
let mut builder = ldk_node::Builder::from_config(config);
5658
builder.set_network(Network::Regtest);
5759
let mut seed: [u8; 64] = [0; 64];
5860
rand::thread_rng().fill_bytes(&mut seed);
@@ -65,6 +67,7 @@ impl DummyTrustedWallet {
6567
bitcoind.params.rpc_socket.port(),
6668
cookie.user,
6769
cookie.password,
70+
None,
6871
);
6972

7073
let tmp = temp_dir().join(format!("orange-test-{uuid}/dummy-ldk"));

0 commit comments

Comments
 (0)