Skip to content

Commit a2040b3

Browse files
committed
WIP: Upgrade to ldk-node 0.7
1 parent 1d54b47 commit a2040b3

14 files changed

Lines changed: 382 additions & 267 deletions

File tree

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/benthecarman/bitcoin-payment-instructions.git", branch = "orange-fork", features = ["http"] }
20-
lightning = { git = "https://github.com/tnull/rust-lightning", branch = "2025-08-bump-electrum-client-0.1" }
21-
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", branch = "2025-08-bump-electrum-client-0.1" }
19+
bitcoin-payment-instructions = { git = "https://github.com/benthecarman/bitcoin-payment-instructions.git", branch = "orange-fork2", features = ["http"] }
20+
lightning = { version = "0.2.0-beta1" }
21+
lightning-invoice = { version = "0.34.0-beta1" }
2222

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

orange-sdk/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,24 @@ _cashu-tests = ["_test-utils", "cdk-ldk-node", "cdk/mint", "cdk-sqlite", "cdk-ax
1818
[dependencies]
1919
graduated-rebalancer = { path = "../graduated-rebalancer", version = "0.1.0" }
2020

21-
ldk-node = { git = "https://github.com/benthecarman/ldk-node.git", branch = "esplora-auth" }
21+
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", rev = "dd519080318ba099280b4353fb6335c587a67cbd" }
22+
lightning-macros = "0.2.0-beta1"
2223
bitcoin-payment-instructions = { workspace = true }
2324
chrono = { version = "0.4", default-features = false }
2425
rand = { version = "0.8.5", optional = true }
2526
reqwest = { version = "0.12.23", default-features = false, features = ["rustls-tls"] }
2627
breez-sdk-spark = { git = "https://github.com/breez/spark-sdk.git", rev = "1c3dd78a40ae50a88d743110a79fa4a95d93d932", default-features = false, features = ["rustls-tls"], optional = true }
2728
tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "sync"] }
2829
uuid = { version = "1.0", default-features = false, optional = true }
29-
cdk = { git = "https://github.com/benthecarman/cdk.git", rev = "39c1206a4a1dda2adc1f3e23628136ef645f6c6b", default-features = false, features = ["wallet"], optional = true }
30+
cdk = { git = "https://github.com/benthecarman/cdk.git", rev = "0d7c1b2b9b73964e497763c4a315133db83d1c53", default-features = false, features = ["wallet"], optional = true }
3031
serde_json = { version = "1.0", optional = true }
3132
async-trait = "0.1"
3233
log = "0.4.28"
3334

3435
corepc-node = { version = "0.8.0", features = ["29_0", "download"], optional = true }
35-
cdk-ldk-node = { git = "https://github.com/benthecarman/cdk.git", rev = "39c1206a4a1dda2adc1f3e23628136ef645f6c6b", optional = true }
36-
cdk-sqlite = { git = "https://github.com/benthecarman/cdk.git", rev = "39c1206a4a1dda2adc1f3e23628136ef645f6c6b", optional = true }
37-
cdk-axum = { git = "https://github.com/benthecarman/cdk.git", rev = "39c1206a4a1dda2adc1f3e23628136ef645f6c6b", optional = true }
36+
cdk-ldk-node = { git = "https://github.com/benthecarman/cdk.git", rev = "0d7c1b2b9b73964e497763c4a315133db83d1c53", optional = true }
37+
cdk-sqlite = { git = "https://github.com/benthecarman/cdk.git", rev = "0d7c1b2b9b73964e497763c4a315133db83d1c53", optional = true }
38+
cdk-axum = { git = "https://github.com/benthecarman/cdk.git", rev = "0d7c1b2b9b73964e497763c4a315133db83d1c53", optional = true }
3839
axum = { version = "0.8.1", optional = true }
3940

4041
uniffi = { version = "0.29", features = ["cli", "tokio"], optional = true }

orange-sdk/src/event.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use ldk_node::bitcoin::{OutPoint, Txid};
66
use ldk_node::lightning::events::{ClosureReason, PaymentFailureReason};
77
use ldk_node::lightning::ln::types::ChannelId;
88
use ldk_node::lightning::util::logger::Logger as _;
9-
use ldk_node::lightning::util::persist::KVStore;
9+
use ldk_node::lightning::util::persist::KVStoreSync;
1010
use ldk_node::lightning::util::ser::{Writeable, Writer};
1111
use ldk_node::lightning::{impl_writeable_tlv_based_enum, log_debug, log_error, log_warn};
1212
use ldk_node::lightning_types::payment::{PaymentHash, PaymentPreimage};
1313
use ldk_node::payment::{ConfirmationStatus, PaymentKind};
14-
use ldk_node::{CustomTlvRecord, UserChannelId};
14+
use ldk_node::{CustomTlvRecord, DynStore, UserChannelId};
1515

1616
use std::collections::VecDeque;
1717
use std::sync::{Arc, Condvar, Mutex};
@@ -191,12 +191,12 @@ pub struct EventQueue {
191191
queue: Arc<Mutex<VecDeque<Event>>>,
192192
waker: Arc<Mutex<Option<Waker>>>,
193193
notifier: Condvar,
194-
kv_store: Arc<dyn KVStore + Send + Sync>,
194+
kv_store: Arc<DynStore>,
195195
logger: Arc<Logger>,
196196
}
197197

198198
impl EventQueue {
199-
pub(crate) fn new(kv_store: Arc<dyn KVStore + Send + Sync>, logger: Arc<Logger>) -> Self {
199+
pub(crate) fn new(kv_store: Arc<DynStore>, logger: Arc<Logger>) -> Self {
200200
let queue = Arc::new(Mutex::new(VecDeque::new()));
201201
let waker = Arc::new(Mutex::new(None));
202202
let notifier = Condvar::new();
@@ -251,24 +251,24 @@ impl EventQueue {
251251
&self, locked_queue: &VecDeque<Event>,
252252
) -> Result<(), ldk_node::lightning::io::Error> {
253253
let data = EventQueueSerWrapper(locked_queue).encode();
254-
self.kv_store
255-
.write(
254+
KVStoreSync::write(
255+
self.kv_store.as_ref(),
256+
EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE,
257+
EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE,
258+
EVENT_QUEUE_PERSISTENCE_KEY,
259+
data,
260+
)
261+
.map_err(|e| {
262+
log_error!(
263+
self.logger.as_ref(),
264+
"Write for key {}/{}/{} failed due to: {}",
256265
EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE,
257266
EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE,
258267
EVENT_QUEUE_PERSISTENCE_KEY,
259-
&data,
260-
)
261-
.map_err(|e| {
262-
log_error!(
263-
self.logger.as_ref(),
264-
"Write for key {}/{}/{} failed due to: {}",
265-
EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE,
266-
EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE,
267-
EVENT_QUEUE_PERSISTENCE_KEY,
268-
e
269-
);
270268
e
271-
})?;
269+
);
270+
e
271+
})?;
272272
Ok(())
273273
}
274274
}
@@ -316,7 +316,7 @@ pub(crate) struct LdkEventHandler {
316316
}
317317

318318
impl LdkEventHandler {
319-
pub(crate) fn handle_ldk_node_event(&self, event: ldk_node::Event) {
319+
pub(crate) async fn handle_ldk_node_event(&self, event: ldk_node::Event) {
320320
match event {
321321
ldk_node::Event::PaymentSuccessful {
322322
payment_id,

orange-sdk/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ use ldk_node::bitcoin::secp256k1::PublicKey;
3636
use ldk_node::io::sqlite_store::SqliteStore;
3737
use ldk_node::lightning::ln::msgs::SocketAddress;
3838
use ldk_node::lightning::util::logger::Logger as _;
39-
use ldk_node::lightning::util::persist::KVStore;
4039
use ldk_node::lightning::{log_debug, log_error, log_info, log_trace, log_warn};
4140
use ldk_node::lightning_invoice::Bolt11Invoice;
4241
use ldk_node::payment::PaymentKind;
43-
use ldk_node::{BuildError, ChannelDetails, NodeError};
42+
use ldk_node::{BuildError, ChannelDetails, DynStore, NodeError};
4443

4544
use tokio::runtime::Runtime;
4645

@@ -125,7 +124,7 @@ struct WalletImpl {
125124
/// Metadata store for tracking transactions.
126125
tx_metadata: TxMetadataStore,
127126
/// Key-value store for persistent storage.
128-
store: Arc<dyn KVStore + Send + Sync>,
127+
store: Arc<DynStore>,
129128
/// Logger for logging wallet operations.
130129
logger: Arc<Logger>,
131130
/// The Tokio runtime for asynchronous operations.
@@ -532,15 +531,15 @@ impl Wallet {
532531

533532
log_info!(logger, "Initializing orange on network: {network}");
534533

535-
let store: Arc<dyn KVStore + Send + Sync> = match &config.storage_config {
534+
let store: Arc<DynStore> = match &config.storage_config {
536535
StorageConfig::LocalSQLite(path) => {
537536
Arc::new(SqliteStore::new(path.into(), Some("orange.sqlite".to_owned()), None)?)
538537
},
539538
};
540539

541540
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
542541

543-
let tx_metadata = TxMetadataStore::new(Arc::clone(&store));
542+
let tx_metadata = TxMetadataStore::new(Arc::clone(&store)).await;
544543

545544
let trusted: Arc<Box<DynTrustedWalletInterface>> = match &config.extra_config {
546545
#[cfg(feature = "spark")]
@@ -650,7 +649,7 @@ impl Wallet {
650649

651650
/// Sets whether the wallet should automatically rebalance from trusted/onchain to lightning.
652651
pub fn set_rebalance_enabled(&self, value: bool) {
653-
store::set_rebalance_enabled(self.inner.store.as_ref(), value);
652+
store::set_rebalance_enabled(self.inner.store.as_ref(), value)
654653
}
655654

656655
/// Whether the wallet should automatically rebalance from trusted/onchain to lightning.
@@ -1027,7 +1026,8 @@ impl Wallet {
10271026
pub async fn parse_payment_instructions(
10281027
&self, instructions: &str,
10291028
) -> Result<PaymentInstructions, instructions::ParseError> {
1030-
PaymentInstructions::parse(instructions, self.inner.network, &HTTPHrnResolver, true).await
1029+
PaymentInstructions::parse(instructions, self.inner.network, &HTTPHrnResolver::new(), true)
1030+
.await
10311031
}
10321032

10331033
/*/// Verifies instructions which allow us to claim funds given as:
@@ -1156,7 +1156,8 @@ impl Wallet {
11561156

11571157
let methods = match &instructions.instructions {
11581158
PaymentInstructions::ConfigurableAmount(conf) => {
1159-
let res = conf.clone().set_amount(instructions.amount, &HTTPHrnResolver).await;
1159+
let res =
1160+
conf.clone().set_amount(instructions.amount, &HTTPHrnResolver::new()).await;
11601161
let fixed_instr = res.map_err(|e| {
11611162
log_error!(
11621163
self.inner.logger,
@@ -1270,8 +1271,8 @@ impl Wallet {
12701271
/// Authenticates the user via [LNURL-auth] for the given LNURL string.
12711272
///
12721273
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
1273-
pub fn lnurl_auth(&self, lnurl: &str) -> Result<(), WalletError> {
1274-
self.inner.ln_wallet.inner.ldk_node.lnurl_auth(lnurl)?;
1274+
pub fn lnurl_auth(&self, _lnurl: &str) -> Result<(), WalletError> {
1275+
// todo wait for merge, self.inner.ln_wallet.inner.ldk_node.lnurl_auth(lnurl)?;
12751276
Ok(())
12761277
}
12771278

orange-sdk/src/lightning_wallet.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ use bitcoin_payment_instructions::amount::Amount;
1010
use ldk_node::bitcoin::base64::Engine;
1111
use ldk_node::bitcoin::base64::prelude::BASE64_STANDARD;
1212
use ldk_node::bitcoin::secp256k1::PublicKey;
13-
use ldk_node::bitcoin::{Address, Network, Script};
13+
use ldk_node::bitcoin::{Address, Network};
1414
use ldk_node::lightning::ln::channelmanager::PaymentId;
1515
use ldk_node::lightning::ln::msgs::SocketAddress;
1616
use ldk_node::lightning::util::logger::Logger as _;
1717
use ldk_node::lightning::util::persist::KVStore;
1818
use ldk_node::lightning::{log_debug, log_error, log_info};
1919
use ldk_node::lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};
2020
use ldk_node::payment::{PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus};
21-
use ldk_node::{NodeError, UserChannelId, lightning};
21+
use ldk_node::{DynStore, NodeError, UserChannelId, lightning};
2222

2323
use graduated_rebalancer::{LightningBalance, ReceivedLightningPayment};
2424

@@ -52,7 +52,7 @@ const DEFAULT_INVOICE_EXPIRY_SECS: u32 = 86_400; // 24 hours
5252

5353
impl LightningWallet {
5454
pub(super) async fn init(
55-
runtime: Arc<Runtime>, config: WalletConfig, store: Arc<dyn KVStore + Sync + Send>,
55+
runtime: Arc<Runtime>, config: WalletConfig, store: Arc<DynStore>,
5656
event_queue: Arc<EventQueue>, tx_metadata: TxMetadataStore, logger: Arc<Logger>,
5757
) -> Result<Self, InitFailure> {
5858
log_info!(logger, "Creating LDK node...");
@@ -148,12 +148,14 @@ impl LightningWallet {
148148
InitFailure::LdkNodeStartFailure(NodeError::InvalidUri)
149149
})?;
150150

151-
store.write(
151+
KVStore::write(
152+
store.as_ref(),
152153
lightning::util::persist::SCORER_PERSISTENCE_PRIMARY_NAMESPACE,
153154
lightning::util::persist::SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
154155
lightning::util::persist::SCORER_PERSISTENCE_KEY,
155-
bytes.as_ref(),
156-
)?;
156+
bytes.to_vec(),
157+
)
158+
.await?;
157159
}
158160

159161
let ldk_node = Arc::new(builder.build_with_store(Arc::clone(&store))?);
@@ -175,13 +177,13 @@ impl LightningWallet {
175177
lsp_socket_addr,
176178
});
177179

178-
inner.ldk_node.start_with_runtime(Arc::clone(&runtime))?;
180+
inner.ldk_node.start()?;
179181

180182
runtime.spawn(async move {
181183
loop {
182184
let event = ev_handler.ldk_node.next_event_async().await;
183185
log_debug!(ev_handler.logger, "Got ldk-node event {:?}", event);
184-
ev_handler.handle_ldk_node_event(event);
186+
ev_handler.handle_ldk_node_event(event).await;
185187
}
186188
});
187189

@@ -295,18 +297,20 @@ impl LightningWallet {
295297
let bal = self.inner.ldk_node.list_balances().spendable_onchain_balance_sats;
296298

297299
// need a dummy p2wsh address to estimate the fee, p2wsh is used for LN channels
298-
let fake_addr = Address::p2wsh(Script::new(), self.inner.ldk_node.config().network);
299-
300-
let fee = self
301-
.inner
302-
.ldk_node
303-
.onchain_payment()
304-
.estimate_send_all_to_address(&fake_addr, true, None)?;
300+
// let fake_addr = Address::p2wsh(Script::new(), self.inner.ldk_node.config().network);
301+
//
302+
// let fee = self
303+
// .inner
304+
// .ldk_node
305+
// .onchain_payment()
306+
// .estimate_send_all_to_address(&fake_addr, true, None)?;
307+
// todo get real fee
308+
let fee = 1000;
305309

306310
let id = self.inner.ldk_node.open_channel(
307311
self.inner.lsp_node_id,
308312
self.inner.lsp_socket_addr.clone(),
309-
bal - fee.to_sat(),
313+
bal - fee,
310314
None,
311315
None,
312316
)?;

orange-sdk/src/rebalancer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::trusted_wallet::DynTrustedWalletInterface;
88
use crate::{Event, EventQueue, PaymentType, Tunables, store};
99
use bitcoin_payment_instructions::amount::Amount;
1010
use graduated_rebalancer::{RebalanceTrigger, RebalancerEvent, TriggerParams};
11+
use ldk_node::DynStore;
1112
use ldk_node::lightning::util::logger::Logger as _;
12-
use ldk_node::lightning::util::persist::KVStore;
1313
use ldk_node::lightning::{log_error, log_info, log_warn};
1414
use ldk_node::payment::{ConfirmationStatus, PaymentDirection, PaymentKind, PaymentStatus};
1515
use std::cmp;
@@ -29,7 +29,7 @@ pub(crate) struct OrangeTrigger {
2929
/// The event handler for processing wallet events.
3030
event_queue: Arc<EventQueue>,
3131
/// Key-value store for persistent storage.
32-
store: Arc<dyn KVStore + Send + Sync>,
32+
store: Arc<DynStore>,
3333
/// Time of the last on-chain sync, used to determine when to trigger rebalances.
3434
onchain_sync_time: AtomicU64,
3535
/// Logger for logging events and errors.
@@ -41,7 +41,7 @@ impl OrangeTrigger {
4141
pub(crate) fn new(
4242
ln_wallet: Arc<LightningWallet>, trusted: Arc<Box<DynTrustedWalletInterface>>,
4343
tunables: Tunables, tx_metadata: TxMetadataStore, event_queue: Arc<EventQueue>,
44-
store: Arc<dyn KVStore + Send + Sync>, logger: Arc<Logger>,
44+
store: Arc<DynStore>, logger: Arc<Logger>,
4545
) -> Self {
4646
let start =
4747
ln_wallet.inner.ldk_node.status().latest_onchain_wallet_sync_timestamp.unwrap_or(0);

0 commit comments

Comments
 (0)