Skip to content

Commit a489fbf

Browse files
authored
Merge pull request #462 from tnull/2025-02-upgrade-to-ldk-0.2
2 parents 65f49af + 80ac9f3 commit a489fbf

33 files changed

+708
-957
lines changed

.github/workflows/kotlin.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ jobs:
3939
- name: Generate Kotlin JVM
4040
run: ./scripts/uniffi_bindgen_generate_kotlin.sh
4141

42-
- name: Install `bindgen-cli`
43-
run: cargo install --force bindgen-cli
44-
4542
- name: Generate Kotlin Android
4643
run: ./scripts/uniffi_bindgen_generate_kotlin_android.sh
4744

Cargo.toml

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,57 @@ panic = 'abort' # Abort on panic
2828
default = []
2929

3030
[dependencies]
31-
lightning = { version = "0.1.0", features = ["std"] }
32-
lightning-types = { version = "0.2.0" }
33-
lightning-invoice = { version = "0.33.0", features = ["std"] }
34-
lightning-net-tokio = { version = "0.1.0" }
35-
lightning-persister = { version = "0.1.0" }
36-
lightning-background-processor = { version = "0.1.0", features = ["futures"] }
37-
lightning-rapid-gossip-sync = { version = "0.1.0" }
38-
lightning-block-sync = { version = "0.1.0", features = ["rpc-client", "rest-client", "tokio"] }
39-
lightning-transaction-sync = { version = "0.1.0", features = ["esplora-async-https", "time", "electrum"] }
40-
lightning-liquidity = { version = "0.1.0", features = ["std"] }
31+
#lightning = { version = "0.1.0", features = ["std"] }
32+
#lightning-types = { version = "0.2.0" }
33+
#lightning-invoice = { version = "0.33.0", features = ["std"] }
34+
#lightning-net-tokio = { version = "0.1.0" }
35+
#lightning-persister = { version = "0.1.0" }
36+
#lightning-background-processor = { version = "0.1.0" }
37+
#lightning-rapid-gossip-sync = { version = "0.1.0" }
38+
#lightning-block-sync = { version = "0.1.0", features = ["rest-client", "rpc-client", "tokio"] }
39+
#lightning-transaction-sync = { version = "0.1.0", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
40+
#lightning-liquidity = { version = "0.1.0", features = ["std"] }
41+
#lightning-macros = { version = "0.1.0" }
4142

4243
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
4344
#lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
4445
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
4546
#lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
4647
#lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
47-
#lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["futures"] }
48+
#lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
4849
#lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
49-
#lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["rpc-client", "tokio"] }
50-
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["esplora-async-https", "electrum", "time"] }
50+
#lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["rest-client", "rpc-client", "tokio"] }
51+
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["esplora-async-https", "electrum-rustls-ring", "time"] }
5152
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
53+
#lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
54+
55+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab", features = ["std"] }
56+
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab" }
57+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab", features = ["std"] }
58+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab" }
59+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab" }
60+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab" }
61+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab" }
62+
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab", features = ["rest-client", "rpc-client", "tokio"] }
63+
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab", features = ["esplora-async-https", "electrum-rustls-ring", "time"] }
64+
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab" }
65+
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab" }
5266

5367
#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
5468
#lightning-types = { path = "../rust-lightning/lightning-types" }
5569
#lightning-invoice = { path = "../rust-lightning/lightning-invoice", features = ["std"] }
5670
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
5771
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
58-
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor", features = ["futures"] }
72+
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
5973
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
60-
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client", "tokio"] }
61-
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "electrum", "time"] }
74+
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rest-client", "rpc-client", "tokio"] }
75+
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "electrum-rustls-ring", "time"] }
6276
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity", features = ["std"] }
77+
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
6378

6479
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
6580
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
66-
bdk_electrum = { version = "0.23.0", default-features = false, features = ["use-rustls"]}
81+
bdk_electrum = { version = "0.23.0", default-features = false, features = ["use-rustls-ring"]}
6782
bdk_wallet = { version = "2.0.0", default-features = false, features = ["std", "keys-bip39"]}
6883

6984
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
@@ -78,12 +93,7 @@ rand = "0.8.5"
7893
chrono = { version = "0.4", default-features = false, features = ["clock"] }
7994
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
8095
esplora-client = { version = "0.12", default-features = false, features = ["tokio", "async-https-rustls"] }
81-
82-
# FIXME: This was introduced to decouple the `bdk_esplora` and
83-
# `lightning-transaction-sync` APIs. We should drop it as part of the upgrade
84-
# to LDK 0.2.
85-
esplora-client_0_11 = { package = "esplora-client", version = "0.11", default-features = false, features = ["tokio", "async-https-rustls"] }
86-
electrum-client = { version = "0.24.0", default-features = true }
96+
electrum-client = { version = "0.24.0", default-features = false, features = ["proxy", "use-rustls-ring"] }
8797
libc = "0.2"
8898
uniffi = { version = "0.28.3", features = ["build"], optional = true }
8999
serde = { version = "1.0.210", default-features = false, features = ["std", "derive"] }
@@ -97,8 +107,9 @@ prost = { version = "0.11.6", default-features = false}
97107
winapi = { version = "0.3", features = ["winbase"] }
98108

99109
[dev-dependencies]
100-
lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
110+
#lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
101111
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
112+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "4e32d85249359d8ef8ece97d89848e40154363ab", features = ["std", "_test_utils"] }
102113
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
103114
proptest = "1.0.0"
104115
regex = "1.5.6"

bindings/ldk_node.udl

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dictionary Config {
1212
sequence<PublicKey> trusted_peers_0conf;
1313
u64 probing_liquidity_limit_multiplier;
1414
AnchorChannelsConfig? anchor_channels_config;
15-
SendingParameters? sending_parameters;
15+
RouteParametersConfig? route_parameters;
1616
};
1717

1818
dictionary AnchorChannelsConfig {
@@ -167,13 +167,13 @@ interface Bolt11InvoiceDescription {
167167

168168
interface Bolt11Payment {
169169
[Throws=NodeError]
170-
PaymentId send([ByRef]Bolt11Invoice invoice, SendingParameters? sending_parameters);
170+
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
171171
[Throws=NodeError]
172-
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, SendingParameters? sending_parameters);
172+
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
173173
[Throws=NodeError]
174-
void send_probes([ByRef]Bolt11Invoice invoice);
174+
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
175175
[Throws=NodeError]
176-
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
176+
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
177177
[Throws=NodeError]
178178
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
179179
[Throws=NodeError]
@@ -213,13 +213,13 @@ interface Bolt12Payment {
213213

214214
interface SpontaneousPayment {
215215
[Throws=NodeError]
216-
PaymentId send(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters);
216+
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
217217
[Throws=NodeError]
218-
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters, sequence<CustomTlvRecord> custom_tlvs);
218+
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
219219
[Throws=NodeError]
220-
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, SendingParameters? sending_parameters);
220+
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
221221
[Throws=NodeError]
222-
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, SendingParameters? sending_parameters);
222+
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
223223
[Throws=NodeError]
224224
void send_probes(u64 amount_msat, PublicKey node_id);
225225
};
@@ -254,7 +254,7 @@ interface LSPS1Liquidity {
254254
[Throws=NodeError]
255255
LSPS1OrderStatus request_channel(u64 lsp_balance_sat, u64 client_balance_sat, u32 channel_expiry_blocks, boolean announce_channel);
256256
[Throws=NodeError]
257-
LSPS1OrderStatus check_order_status(OrderId order_id);
257+
LSPS1OrderStatus check_order_status(LSPS1OrderId order_id);
258258
};
259259

260260
[Error]
@@ -392,7 +392,7 @@ enum PaymentFailureReason {
392392
[Enum]
393393
interface ClosureReason {
394394
CounterpartyForceClosed(UntrustedString peer_msg);
395-
HolderForceClosed(boolean? broadcasted_latest_txn);
395+
HolderForceClosed(boolean? broadcasted_latest_txn, string message);
396396
LegacyCooperativeClosure();
397397
CounterpartyInitiatedCooperativeClosure();
398398
LocallyInitiatedCooperativeClosure();
@@ -402,8 +402,9 @@ interface ClosureReason {
402402
DisconnectedPeer();
403403
OutdatedChannelManager();
404404
CounterpartyCoopClosedUnfundedChannel();
405+
LocallyCoopClosedUnfundedChannel();
405406
FundingBatchClosure();
406-
HTLCsTimedOut();
407+
HTLCsTimedOut( PaymentHash? payment_hash );
407408
PeerFeerateTooLow(u32 peer_feerate_sat_per_kw, u32 required_feerate_sat_per_kw);
408409
};
409410

@@ -456,11 +457,11 @@ dictionary PaymentDetails {
456457
u64 latest_update_timestamp;
457458
};
458459

459-
dictionary SendingParameters {
460-
MaxTotalRoutingFeeLimit? max_total_routing_fee_msat;
461-
u32? max_total_cltv_expiry_delta;
462-
u8? max_path_count;
463-
u8? max_channel_saturation_power_of_half;
460+
dictionary RouteParametersConfig {
461+
u64? max_total_routing_fee_msat;
462+
u32 max_total_cltv_expiry_delta;
463+
u8 max_path_count;
464+
u8 max_channel_saturation_power_of_half;
464465
};
465466

466467
dictionary CustomTlvRecord {
@@ -469,13 +470,13 @@ dictionary CustomTlvRecord {
469470
};
470471

471472
dictionary LSPS1OrderStatus {
472-
OrderId order_id;
473-
OrderParameters order_params;
474-
PaymentInfo payment_options;
475-
ChannelOrderInfo? channel_state;
473+
LSPS1OrderId order_id;
474+
LSPS1OrderParams order_params;
475+
LSPS1PaymentInfo payment_options;
476+
LSPS1ChannelInfo? channel_state;
476477
};
477478

478-
dictionary OrderParameters {
479+
dictionary LSPS1OrderParams {
479480
u64 lsp_balance_sat;
480481
u64 client_balance_sat;
481482
u16 required_channel_confirmations;
@@ -485,22 +486,22 @@ dictionary OrderParameters {
485486
boolean announce_channel;
486487
};
487488

488-
dictionary PaymentInfo {
489-
Bolt11PaymentInfo? bolt11;
490-
OnchainPaymentInfo? onchain;
489+
dictionary LSPS1PaymentInfo {
490+
LSPS1Bolt11PaymentInfo? bolt11;
491+
LSPS1OnchainPaymentInfo? onchain;
491492
};
492493

493-
dictionary Bolt11PaymentInfo {
494-
PaymentState state;
495-
DateTime expires_at;
494+
dictionary LSPS1Bolt11PaymentInfo {
495+
LSPS1PaymentState state;
496+
LSPSDateTime expires_at;
496497
u64 fee_total_sat;
497498
u64 order_total_sat;
498499
Bolt11Invoice invoice;
499500
};
500501

501-
dictionary OnchainPaymentInfo {
502-
PaymentState state;
503-
DateTime expires_at;
502+
dictionary LSPS1OnchainPaymentInfo {
503+
LSPS1PaymentState state;
504+
LSPSDateTime expires_at;
504505
u64 fee_total_sat;
505506
u64 order_total_sat;
506507
Address address;
@@ -509,24 +510,18 @@ dictionary OnchainPaymentInfo {
509510
Address? refund_onchain_address;
510511
};
511512

512-
dictionary ChannelOrderInfo {
513-
DateTime funded_at;
513+
dictionary LSPS1ChannelInfo {
514+
LSPSDateTime funded_at;
514515
OutPoint funding_outpoint;
515-
DateTime expires_at;
516+
LSPSDateTime expires_at;
516517
};
517518

518-
enum PaymentState {
519+
enum LSPS1PaymentState {
519520
"ExpectPayment",
520521
"Paid",
521522
"Refunded",
522523
};
523524

524-
[Enum]
525-
interface MaxTotalRoutingFeeLimit {
526-
None ();
527-
Some ( u64 amount_msat );
528-
};
529-
530525
[NonExhaustive]
531526
enum Network {
532527
"Bitcoin",
@@ -861,7 +856,7 @@ typedef string UntrustedString;
861856
typedef string NodeAlias;
862857

863858
[Custom]
864-
typedef string OrderId;
859+
typedef string LSPS1OrderId;
865860

866861
[Custom]
867-
typedef string DateTime;
862+
typedef string LSPSDateTime;

src/balance.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
use crate::sweep::value_from_descriptor;
9-
108
use lightning::chain::channelmonitor::Balance as LdkBalance;
119
use lightning::chain::channelmonitor::BalanceSource;
1210
use lightning::ln::types::ChannelId;
11+
use lightning::sign::SpendableOutputDescriptor;
1312
use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};
1413

1514
use lightning_types::payment::{PaymentHash, PaymentPreimage};
1615

1716
use bitcoin::secp256k1::PublicKey;
18-
use bitcoin::{BlockHash, Txid};
17+
use bitcoin::{Amount, BlockHash, Txid};
1918

2019
/// Details of the known available balances returned by [`Node::list_balances`].
2120
///
@@ -385,3 +384,11 @@ impl PendingSweepBalance {
385384
}
386385
}
387386
}
387+
388+
fn value_from_descriptor(descriptor: &SpendableOutputDescriptor) -> Amount {
389+
match &descriptor {
390+
SpendableOutputDescriptor::StaticOutput { output, .. } => output.value,
391+
SpendableOutputDescriptor::DelayedPaymentOutput(output) => output.output.value,
392+
SpendableOutputDescriptor::StaticPaymentOutput(output) => output.output.value,
393+
}
394+
}

0 commit comments

Comments
 (0)