Skip to content
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
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ jobs:

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

- name: Cache package-enabled Esplora
id: cache-esplora
uses: actions/cache@v4
with:
path: bin/electrs-${{ runner.os }}-${{ runner.arch }}
key: electrs-submit-package-8c06d801-${{ runner.os }}-${{ runner.arch }}

- name: Build package-enabled Esplora
if: steps.cache-esplora.outputs.cache-hit != 'true'
run: |
./scripts/build_package_esplora.sh "bin/electrs-${{ runner.os }}-${{ runner.arch }}"

- name: Configure package-enabled Esplora
run: echo "ELECTRS_EXE=$(pwd)/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"

- name: Check formatting
run: cargo fmt --check

Expand Down Expand Up @@ -62,5 +77,20 @@ jobs:

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

- name: Cache package-enabled Esplora
id: cache-esplora
uses: actions/cache@v4
with:
path: bin/electrs-${{ runner.os }}-${{ runner.arch }}
key: electrs-submit-package-8c06d801-${{ runner.os }}-${{ runner.arch }}

- name: Build package-enabled Esplora
if: steps.cache-esplora.outputs.cache-hit != 'true'
run: |
./scripts/build_package_esplora.sh "bin/electrs-${{ runner.os }}-${{ runner.arch }}"

- name: Configure package-enabled Esplora
run: echo "ELECTRS_EXE=$(pwd)/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"

- name: Run cashu tests
run: cargo test --features _cashu-tests -- --test-threads=2 --nocapture
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = 'abort' # Abort on panic

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

[profile.release]
panic = "abort"
Expand Down
4 changes: 2 additions & 2 deletions orange-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _cashu-tests = ["_test-utils", "cdk-ldk-node", "cdk/mint", "cdk-sqlite", "cdk-ax
[dependencies]
graduated-rebalancer = { path = "../graduated-rebalancer", version = "0.1.0" }

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

corepc-node = { version = "0.10.1", features = ["29_0", "download"], optional = true }
electrsd = { version = "0.36.1", default-features = false, features = ["esplora_a33e97e1", "corepc-node_29_0"], optional = true }
electrsd = { version = "0.36.1", default-features = false, features = ["legacy", "corepc-node_29_0"], optional = true }
cdk-ldk-node = { version = "0.16.0", optional = true }
cdk-sqlite = { version = "0.16.0", optional = true }
cdk-axum = { version = "0.16.0", optional = true }
Expand Down
52 changes: 45 additions & 7 deletions orange-sdk/src/dyn_store.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
//! Object-safe wrapper around ldk-node's async `KVStore` trait.
//! Object-safe wrapper around ldk-node's async `PaginatedKVStore` trait.
//!
//! `lightning`'s `KVStore` returns `impl Future` from its methods, which makes the trait not
//! object-safe — orange-sdk can't share a backend across components as `Arc<dyn KVStore>`.
//!
//! This module defines `DynStore`, an object-safe trait covering the kv methods (returning
//! boxed futures), with a blanket impl over any concrete type that implements `KVStore`. The
//! whole crate stores backends as `Arc<dyn DynStore>`; conversion to a value ldk-node accepts
//! happens at the call site through a thin newtype that delegates back to `DynStore`.
//! boxed futures), with a blanket impl over any concrete type that implements
//! `PaginatedKVStore`. The whole crate stores backends as `Arc<dyn DynStore>`; conversion to a
//! value ldk-node accepts happens at the call site through a thin newtype that delegates back to
//! `DynStore`.

use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;

use ldk_node::lightning::io;
use ldk_node::lightning::util::persist::KVStore;
use ldk_node::lightning::util::persist::{
KVStore, PageToken, PaginatedKVStore, PaginatedListResponse,
};
use tokio::task::JoinSet;

/// Matches the connection capacity used by the VSS HTTP client. Keeping the
Expand All @@ -38,11 +41,15 @@ pub(crate) trait DynStore: Send + Sync + 'static {
fn list_async(
&self, primary_namespace: &str, secondary_namespace: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + Send + 'static>>;

fn list_paginated_async(
&self, primary_namespace: &str, secondary_namespace: &str, page_token: Option<PageToken>,
) -> Pin<Box<dyn Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static>>;
}

impl<T> DynStore for T
where
T: KVStore + Send + Sync + 'static,
T: PaginatedKVStore + Send + Sync + 'static,
{
fn read_async(
&self, p: &str, s: &str, k: &str,
Expand All @@ -67,6 +74,12 @@ where
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + Send + 'static>> {
Box::pin(<T as KVStore>::list(self, p, s))
}

fn list_paginated_async(
&self, p: &str, s: &str, page_token: Option<PageToken>,
) -> Pin<Box<dyn Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static>> {
Box::pin(<T as PaginatedKVStore>::list_paginated(self, p, s, page_token))
}
}

// Make `dyn DynStore` itself implement `KVStore` so the same handle orange-sdk shares
Expand Down Expand Up @@ -96,8 +109,16 @@ impl KVStore for dyn DynStore {
}
}

impl PaginatedKVStore for dyn DynStore {
fn list_paginated(
&self, p: &str, s: &str, page_token: Option<PageToken>,
) -> impl Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static {
self.list_paginated_async(p, s, page_token)
}
}

/// Cloneable handle wrapping `Arc<dyn DynStore>` that satisfies ldk-node's
/// `KVStore + Send + Sync + 'static` bound on `build_with_store`. The trait impl just
/// `PaginatedKVStore + Send + Sync + 'static` bound on `build_with_store`. The trait impl just
/// forwards to the underlying `dyn DynStore`.
#[derive(Clone)]
pub(crate) struct LdkNodeStore(pub(crate) Arc<dyn DynStore>);
Expand Down Expand Up @@ -125,6 +146,14 @@ impl KVStore for LdkNodeStore {
}
}

impl PaginatedKVStore for LdkNodeStore {
fn list_paginated(
&self, p: &str, s: &str, page_token: Option<PageToken>,
) -> impl Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static {
self.0.list_paginated_async(p, s, page_token)
}
}

/// Reads a set of keys concurrently while preserving the input order.
///
/// Storage formats expose record collections as a list followed by individual
Expand Down Expand Up @@ -242,6 +271,15 @@ mod tests {
}
}

impl PaginatedKVStore for ControlledStore {
fn list_paginated(
&self, _primary_namespace: &str, _secondary_namespace: &str,
_page_token: Option<PageToken>,
) -> impl Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static {
ready(Ok(PaginatedListResponse { keys: Vec::new(), next_page_token: None }))
}
}

#[tokio::test]
async fn bounded_reads_limit_concurrency_and_preserve_order() {
let (entered, mut entered_rx) = mpsc::unbounded_channel();
Expand Down
2 changes: 1 addition & 1 deletion orange-sdk/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ impl LdkEventHandler {
.add_event(Event::ChannelClosed {
channel_id,
user_channel_id,
counterparty_node_id: counterparty_node_id.unwrap(), // safe
counterparty_node_id,
reason,
})
.await
Expand Down
7 changes: 6 additions & 1 deletion orange-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,7 @@ mod tests {
let kind = PaymentKind::Onchain {
txid: Txid::from_byte_array([42; 32]),
status: ConfirmationStatus::Unconfirmed,
tx_type: None,
};

assert!(should_surface_lightning_payment_without_metadata(TxStatus::Pending, &kind));
Expand All @@ -1787,7 +1788,11 @@ mod tests {
let txid = Txid::from_byte_array([42; 32]);
let payment = PaymentDetails {
id: LightningPaymentId([24; 32]),
kind: PaymentKind::Onchain { txid, status: ConfirmationStatus::Unconfirmed },
kind: PaymentKind::Onchain {
txid,
status: ConfirmationStatus::Unconfirmed,
tx_type: None,
},
amount_msat: Some(123_000),
fee_paid_msat: None,
direction: PaymentDirection::Inbound,
Expand Down
12 changes: 7 additions & 5 deletions orange-sdk/src/lightning_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ impl LightningWallet {
log_info!(logger, "Creating LDK node...");
let anchor_channels_config = ldk_node::config::AnchorChannelsConfig {
trusted_peers_no_reserve: vec![config.lsp.1],
enable_zero_fee_commitments: true,
..Default::default()
};
let ldk_node_config = ldk_node::config::Config {
anchor_channels_config: Some(anchor_channels_config),
..Default::default()
};
let ldk_node_config =
ldk_node::config::Config { anchor_channels_config, ..Default::default() };
let mut builder = ldk_node::Builder::from_config(ldk_node_config);
builder.set_network(config.network);
let node_entropy = config.seed.to_node_entropy();
Expand Down Expand Up @@ -113,6 +112,7 @@ impl LightningWallet {
fee_rate_cache_update_interval_secs: 30,
}),
timeouts_config: SyncTimeoutsConfig::default(),
..Default::default()
}
} else {
ldk_node::config::EsploraSyncConfig::default()
Expand Down Expand Up @@ -151,14 +151,15 @@ impl LightningWallet {
lightning_wallet_sync_interval_secs: 2,
fee_rate_cache_update_interval_secs: 30,
}),
..Default::default()
})
} else {
None
};
builder.set_chain_source_electrum(url, sync_config)
},
ChainSource::BitcoindRPC { host, port, user, password } => {
builder.set_chain_source_bitcoind_rpc(host, port, user, password)
builder.set_chain_source_bitcoind_rpc(host, port, user, password, None)
},
};

Expand Down Expand Up @@ -353,6 +354,7 @@ impl LightningWallet {
kind: PaymentKind::Onchain {
txid: funding_txo.txid,
status: ConfirmationStatus::Unconfirmed, // todo how do we update this?
tx_type: None,
},
amount_msat: Some(amount_sats * 1_000),
fee_paid_msat: Some(69), // todo get real fee
Expand Down
2 changes: 1 addition & 1 deletion orange-sdk/src/rebalancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl RebalanceTrigger for OrangeTrigger {
for payment in new_recvs {
let payment_id = PaymentId::SelfCustodial(payment.id.0);
let (txid, status) = match payment.kind {
PaymentKind::Onchain { txid, status } => (txid, status),
PaymentKind::Onchain { txid, status, .. } => (txid, status),
_ => continue,
};
let event = Event::OnchainPaymentReceived {
Expand Down
11 changes: 11 additions & 0 deletions orange-sdk/src/trusted_wallet/cashu/cashu_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ mod tests {
use cdk::Amount;
use cdk::nuts::Proof;
use cdk::secret::Secret;
use ldk_node::lightning::util::persist::{PageToken, PaginatedKVStore, PaginatedListResponse};
use std::future::ready;
use std::sync::Mutex as StdMutex;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -1364,6 +1365,16 @@ mod tests {
}
}

impl PaginatedKVStore for ProofTestStore {
fn list_paginated(
&self, _primary_namespace: &str, _secondary_namespace: &str,
_page_token: Option<PageToken>,
) -> impl std::future::Future<Output = Result<PaginatedListResponse, io::Error>> + Send + 'static
{
ready(Ok(PaginatedListResponse { keys: Vec::new(), next_page_token: None }))
}
}

fn proof_info(secret: &str, amount: u64) -> ProofInfo {
let proof = Proof::new(
Amount::from(amount),
Expand Down
5 changes: 4 additions & 1 deletion orange-sdk/src/trusted_wallet/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ impl DummyTrustedWallet {
uuid: Uuid, lsp: Arc<Node>, bitcoind: Arc<Bitcoind>, tx_metadata: TxMetadataStore,
event_queue: Arc<EventQueue>, rt: Arc<Runtime>,
) -> Self {
let mut builder = ldk_node::Builder::new();
let mut config = ldk_node::config::Config::default();
config.anchor_channels_config.enable_zero_fee_commitments = true;
let mut builder = ldk_node::Builder::from_config(config);
builder.set_network(Network::Regtest);
let mut seed: [u8; 64] = [0; 64];
rand::thread_rng().fill_bytes(&mut seed);
Expand All @@ -65,6 +67,7 @@ impl DummyTrustedWallet {
bitcoind.params.rpc_socket.port(),
cookie.user,
cookie.password,
None,
);

let tmp = temp_dir().join(format!("orange-test-{uuid}/dummy-ldk"));
Expand Down
5 changes: 5 additions & 0 deletions orange-sdk/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ async fn test_receive_to_ln() {
let third_party = Arc::clone(&params.third_party);

let recv_amt = open_channel_from_lsp(&wallet, Arc::clone(&third_party)).await;
let channel = wallet.channels().into_iter().next().expect("expected a JIT channel");
assert_eq!(
channel.feerate_sat_per_1000_weight, 0,
"JIT channel should use zero-fee commitments"
);

let txs = wallet.list_transactions().await.unwrap();
assert_eq!(txs.len(), 1);
Expand Down
Loading
Loading