Skip to content

Commit 3f1c842

Browse files
authored
Merge pull request #358 from tnull/2024-08-upgrade-to-LDK-0.0.124-BDK-1.0
2 parents 58188b8 + d0de144 commit 3f1c842

31 files changed

+1439
-481
lines changed

Cargo.toml

+20-18
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ panic = 'abort' # Abort on panic
2828
default = []
2929

3030
[dependencies]
31-
lightning = { version = "0.0.123", features = ["std"] }
32-
lightning-invoice = { version = "0.31.0" }
33-
lightning-net-tokio = { version = "0.0.123" }
34-
lightning-persister = { version = "0.0.123" }
35-
lightning-background-processor = { version = "0.0.123", features = ["futures"] }
36-
lightning-rapid-gossip-sync = { version = "0.0.123" }
37-
lightning-transaction-sync = { version = "0.0.123", features = ["esplora-async-https", "time"] }
38-
lightning-liquidity = { version = "=0.1.0-alpha.4", features = ["std"] }
31+
lightning = { version = "0.0.124", features = ["std"] }
32+
lightning-invoice = { version = "0.32.0" }
33+
lightning-net-tokio = { version = "0.0.124" }
34+
lightning-persister = { version = "0.0.124" }
35+
lightning-background-processor = { version = "0.0.124", features = ["futures"] }
36+
lightning-rapid-gossip-sync = { version = "0.0.124" }
37+
lightning-transaction-sync = { version = "0.0.124", features = ["esplora-async-https", "time"] }
38+
lightning-liquidity = { version = "0.1.0-alpha.5", features = ["std"] }
3939

4040
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std"] }
4141
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
@@ -55,18 +55,20 @@ lightning-liquidity = { version = "=0.1.0-alpha.4", features = ["std"] }
5555
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }
5656
#lightning-liquidity = { path = "../lightning-liquidity", features = ["std"] }
5757

58-
bdk = { version = "0.29.0", default-features = false, features = ["std", "async-interface", "use-esplora-async", "sqlite-bundled", "keys-bip39"]}
58+
bdk_chain = { version = "=0.19.0", default-features = false, features = ["std"] }
59+
bdk_esplora = { version = "=0.18.0", default-features = false, features = ["async-https-rustls"]}
60+
bdk_wallet = { version = "=1.0.0-beta.4", default-features = false, features = ["std", "keys-bip39"]}
5961

6062
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
6163
rusqlite = { version = "0.28.0", features = ["bundled"] }
62-
bitcoin = "0.30.2"
64+
bitcoin = "0.32.2"
6365
bip39 = "2.0.0"
64-
bip21 = { version = "0.3.1", features = ["std"], default-features = false }
66+
bip21 = { version = "0.5", features = ["std"], default-features = false }
6567

6668
rand = "0.8.5"
6769
chrono = { version = "0.4", default-features = false, features = ["clock"] }
68-
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync" ] }
69-
esplora-client = { version = "0.6", default-features = false }
70+
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
71+
esplora-client = { version = "0.9", default-features = false }
7072
libc = "0.2"
7173
uniffi = { version = "0.26.0", features = ["build"], optional = true }
7274

@@ -78,18 +80,18 @@ prost = { version = "0.11.6", default-features = false}
7880
winapi = { version = "0.3", features = ["winbase"] }
7981

8082
[dev-dependencies]
81-
lightning = { version = "0.0.123", features = ["std", "_test_utils"] }
83+
lightning = { version = "0.0.124", features = ["std", "_test_utils"] }
8284
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
83-
electrum-client = { version = "0.15.1", default-features = true }
84-
bitcoincore-rpc = { version = "0.17.0", default-features = false }
85+
electrum-client = { version = "0.21.0", default-features = true }
86+
bitcoincore-rpc = { version = "0.19.0", default-features = false }
8587
proptest = "1.0.0"
8688
regex = "1.5.6"
8789

8890
[target.'cfg(not(no_download))'.dev-dependencies]
89-
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
91+
electrsd = { version = "0.29.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
9092

9193
[target.'cfg(no_download)'.dev-dependencies]
92-
electrsd = { version = "0.26.0", features = ["legacy"] }
94+
electrsd = { version = "0.29.0", features = ["legacy"] }
9395

9496
[target.'cfg(cln_test)'.dev-dependencies]
9597
clightningrpc = { version = "0.3.0-beta.8", default-features = false }

bindings/ldk_node.udl

+62-14
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ interface Node {
7979
[Throws=NodeError]
8080
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
8181
[Throws=NodeError]
82-
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
82+
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
8383
[Throws=NodeError]
8484
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
8585
[Throws=NodeError]
@@ -92,7 +92,6 @@ interface Node {
9292
sequence<PeerDetails> list_peers();
9393
sequence<ChannelDetails> list_channels();
9494
NetworkGraph network_graph();
95-
[Throws=NodeError]
9695
string sign_message([ByRef]sequence<u8> msg);
9796
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
9897
};
@@ -130,9 +129,9 @@ interface Bolt12Payment {
130129
[Throws=NodeError]
131130
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note);
132131
[Throws=NodeError]
133-
Offer receive(u64 amount_msat, [ByRef]string description, u64? quantity);
132+
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
134133
[Throws=NodeError]
135-
Offer receive_variable_amount([ByRef]string description);
134+
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
136135
[Throws=NodeError]
137136
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
138137
[Throws=NodeError]
@@ -183,7 +182,6 @@ enum NodeError {
183182
"WalletOperationFailed",
184183
"WalletOperationTimeout",
185184
"OnchainTxSigningFailed",
186-
"MessageSigningFailed",
187185
"TxSyncFailed",
188186
"TxSyncTimeout",
189187
"GossipUpdateFailed",
@@ -251,7 +249,7 @@ enum BuildError {
251249
[Enum]
252250
interface Event {
253251
PaymentSuccessful(PaymentId? payment_id, PaymentHash payment_hash, u64? fee_paid_msat);
254-
PaymentFailed(PaymentId? payment_id, PaymentHash payment_hash, PaymentFailureReason? reason);
252+
PaymentFailed(PaymentId? payment_id, PaymentHash? payment_hash, PaymentFailureReason? reason);
255253
PaymentReceived(PaymentId? payment_id, PaymentHash payment_hash, u64 amount_msat);
256254
PaymentClaimable(PaymentId payment_id, PaymentHash payment_hash, u64 claimable_amount_msat, u32? claim_deadline);
257255
ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo);
@@ -266,12 +264,15 @@ enum PaymentFailureReason {
266264
"PaymentExpired",
267265
"RouteNotFound",
268266
"UnexpectedError",
267+
"UnknownRequiredFeatures",
268+
"InvoiceRequestExpired",
269+
"InvoiceRequestRejected",
269270
};
270271

271272
[Enum]
272273
interface ClosureReason {
273274
CounterpartyForceClosed(UntrustedString peer_msg);
274-
HolderForceClosed();
275+
HolderForceClosed(boolean? broadcasted_latest_txn);
275276
LegacyCooperativeClosure();
276277
CounterpartyInitiatedCooperativeClosure();
277278
LocallyInitiatedCooperativeClosure();
@@ -283,6 +284,7 @@ interface ClosureReason {
283284
CounterpartyCoopClosedUnfundedChannel();
284285
FundingBatchClosure();
285286
HTLCsTimedOut();
287+
PeerFeerateTooLow(u32 peer_feerate_sat_per_kw, u32 required_feerate_sat_per_kw);
286288
};
287289

288290
[Enum]
@@ -368,7 +370,7 @@ dictionary ChannelDetails {
368370
boolean is_outbound;
369371
boolean is_channel_ready;
370372
boolean is_usable;
371-
boolean is_public;
373+
boolean is_announced;
372374
u16? cltv_expiry_delta;
373375
u64 counterparty_unspendable_punishment_reserve;
374376
u64? counterparty_outbound_htlc_minimum_msat;
@@ -393,12 +395,58 @@ dictionary PeerDetails {
393395

394396
[Enum]
395397
interface LightningBalance {
396-
ClaimableOnChannelClose ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
397-
ClaimableAwaitingConfirmations ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 confirmation_height );
398-
ContentiousClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 timeout_height, PaymentHash payment_hash, PaymentPreimage payment_preimage );
399-
MaybeTimeoutClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 claimable_height, PaymentHash payment_hash);
400-
MaybePreimageClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 expiry_height, PaymentHash payment_hash);
401-
CounterpartyRevokedOutputClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
398+
ClaimableOnChannelClose (
399+
ChannelId channel_id,
400+
PublicKey counterparty_node_id,
401+
u64 amount_satoshis,
402+
u64 transaction_fee_satoshis,
403+
u64 outbound_payment_htlc_rounded_msat,
404+
u64 outbound_forwarded_htlc_rounded_msat,
405+
u64 inbound_claiming_htlc_rounded_msat,
406+
u64 inbound_htlc_rounded_msat
407+
);
408+
ClaimableAwaitingConfirmations (
409+
ChannelId channel_id,
410+
PublicKey counterparty_node_id,
411+
u64 amount_satoshis,
412+
u32 confirmation_height,
413+
BalanceSource source
414+
);
415+
ContentiousClaimable (
416+
ChannelId channel_id,
417+
PublicKey counterparty_node_id,
418+
u64 amount_satoshis,
419+
u32 timeout_height,
420+
PaymentHash payment_hash,
421+
PaymentPreimage payment_preimage
422+
);
423+
MaybeTimeoutClaimableHTLC (
424+
ChannelId channel_id,
425+
PublicKey counterparty_node_id,
426+
u64 amount_satoshis,
427+
u32 claimable_height,
428+
PaymentHash payment_hash,
429+
boolean outbound_payment
430+
);
431+
MaybePreimageClaimableHTLC (
432+
ChannelId channel_id,
433+
PublicKey counterparty_node_id,
434+
u64 amount_satoshis,
435+
u32 expiry_height,
436+
PaymentHash payment_hash
437+
);
438+
CounterpartyRevokedOutputClaimable (
439+
ChannelId channel_id,
440+
PublicKey counterparty_node_id,
441+
u64 amount_satoshis
442+
);
443+
};
444+
445+
enum BalanceSource {
446+
"HolderForceClosed",
447+
"CounterpartyForceClosed",
448+
"CoopClose",
449+
"Htlc",
402450
};
403451

404452
[Enum]

src/balance.rs

+84-16
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
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_satoshis_from_descriptor;
8+
use crate::sweep::value_from_descriptor;
99

1010
use lightning::chain::channelmonitor::Balance as LdkBalance;
11-
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
11+
use lightning::chain::channelmonitor::BalanceSource;
12+
use lightning::ln::types::ChannelId;
13+
use lightning::ln::{PaymentHash, PaymentPreimage};
1214
use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};
1315

1416
use bitcoin::secp256k1::PublicKey;
@@ -80,6 +82,49 @@ pub enum LightningBalance {
8082
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
8183
/// required to do so.
8284
amount_satoshis: u64,
85+
/// The transaction fee we pay for the closing commitment transaction. This amount is not
86+
/// included in the `amount_satoshis` value.
87+
///
88+
/// Note that if this channel is inbound (and thus our counterparty pays the commitment
89+
/// transaction fee) this value will be zero. For channels created prior to LDK Node 0.4
90+
/// the channel is always treated as outbound (and thus this value is never zero).
91+
transaction_fee_satoshis: u64,
92+
/// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
93+
/// from us and are related to a payment which was sent by us. This is the sum of the
94+
/// millisatoshis part of all HTLCs which are otherwise represented by
95+
/// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
96+
/// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag set, as well as
97+
/// any dust HTLCs which would otherwise be represented the same.
98+
///
99+
/// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
100+
outbound_payment_htlc_rounded_msat: u64,
101+
/// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
102+
/// from us and are related to a forwarded HTLC. This is the sum of the millisatoshis part
103+
/// of all HTLCs which are otherwise represented by
104+
/// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
105+
/// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag *not* set, as
106+
/// well as any dust HTLCs which would otherwise be represented the same.
107+
///
108+
/// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
109+
outbound_forwarded_htlc_rounded_msat: u64,
110+
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
111+
/// to us and for which we know the preimage. This is the sum of the millisatoshis part of
112+
/// all HTLCs which would be represented by [`LightningBalance::ContentiousClaimable`] on
113+
/// channel close, but whose current value is included in `amount_satoshis`, as well as any
114+
/// dust HTLCs which would otherwise be represented the same.
115+
///
116+
/// This amount (rounded up to a whole satoshi value) will not be included in the counterparty's
117+
/// `amount_satoshis`.
118+
inbound_claiming_htlc_rounded_msat: u64,
119+
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
120+
/// to us and for which we do not know the preimage. This is the sum of the millisatoshis
121+
/// part of all HTLCs which would be represented by
122+
/// [`LightningBalance::MaybePreimageClaimableHTLC`] on channel close, as well as any dust
123+
/// HTLCs which would otherwise be represented the same.
124+
///
125+
/// This amount (rounded up to a whole satoshi value) will not be included in the
126+
/// counterparty's `amount_satoshis`.
127+
inbound_htlc_rounded_msat: u64,
83128
},
84129
/// The channel has been closed, and the given balance is ours but awaiting confirmations until
85130
/// we consider it spendable.
@@ -96,6 +141,8 @@ pub enum LightningBalance {
96141
///
97142
/// [`Event::SpendableOutputs`]: lightning::events::Event::SpendableOutputs
98143
confirmation_height: u32,
144+
/// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
145+
source: BalanceSource,
99146
},
100147
/// The channel has been closed, and the given balance should be ours but awaiting spending
101148
/// transaction confirmation. If the spending transaction does not confirm in time, it is
@@ -136,6 +183,8 @@ pub enum LightningBalance {
136183
claimable_height: u32,
137184
/// The payment hash whose preimage our counterparty needs to claim this HTLC.
138185
payment_hash: PaymentHash,
186+
/// Indicates whether this HTLC represents a payment which was sent outbound from us.
187+
outbound_payment: bool,
139188
},
140189
/// HTLCs which we received from our counterparty which are claimable with a preimage which we
141190
/// do not currently have. This will only be claimable if we receive the preimage from the node
@@ -174,16 +223,33 @@ impl LightningBalance {
174223
channel_id: ChannelId, counterparty_node_id: PublicKey, balance: LdkBalance,
175224
) -> Self {
176225
match balance {
177-
LdkBalance::ClaimableOnChannelClose { amount_satoshis } => {
178-
Self::ClaimableOnChannelClose { channel_id, counterparty_node_id, amount_satoshis }
226+
LdkBalance::ClaimableOnChannelClose {
227+
amount_satoshis,
228+
transaction_fee_satoshis,
229+
outbound_payment_htlc_rounded_msat,
230+
outbound_forwarded_htlc_rounded_msat,
231+
inbound_claiming_htlc_rounded_msat,
232+
inbound_htlc_rounded_msat,
233+
} => Self::ClaimableOnChannelClose {
234+
channel_id,
235+
counterparty_node_id,
236+
amount_satoshis,
237+
transaction_fee_satoshis,
238+
outbound_payment_htlc_rounded_msat,
239+
outbound_forwarded_htlc_rounded_msat,
240+
inbound_claiming_htlc_rounded_msat,
241+
inbound_htlc_rounded_msat,
179242
},
180-
LdkBalance::ClaimableAwaitingConfirmations { amount_satoshis, confirmation_height } => {
181-
Self::ClaimableAwaitingConfirmations {
182-
channel_id,
183-
counterparty_node_id,
184-
amount_satoshis,
185-
confirmation_height,
186-
}
243+
LdkBalance::ClaimableAwaitingConfirmations {
244+
amount_satoshis,
245+
confirmation_height,
246+
source,
247+
} => Self::ClaimableAwaitingConfirmations {
248+
channel_id,
249+
counterparty_node_id,
250+
amount_satoshis,
251+
confirmation_height,
252+
source,
187253
},
188254
LdkBalance::ContentiousClaimable {
189255
amount_satoshis,
@@ -202,12 +268,14 @@ impl LightningBalance {
202268
amount_satoshis,
203269
claimable_height,
204270
payment_hash,
271+
outbound_payment,
205272
} => Self::MaybeTimeoutClaimableHTLC {
206273
channel_id,
207274
counterparty_node_id,
208275
amount_satoshis,
209276
claimable_height,
210277
payment_hash,
278+
outbound_payment,
211279
},
212280
LdkBalance::MaybePreimageClaimableHTLC {
213281
amount_satoshis,
@@ -278,7 +346,7 @@ impl PendingSweepBalance {
278346
match output_info.status {
279347
OutputSpendStatus::PendingInitialBroadcast { .. } => {
280348
let channel_id = output_info.channel_id;
281-
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
349+
let amount_satoshis = value_from_descriptor(&output_info.descriptor).to_sat();
282350
Self::PendingBroadcast { channel_id, amount_satoshis }
283351
},
284352
OutputSpendStatus::PendingFirstConfirmation {
@@ -287,8 +355,8 @@ impl PendingSweepBalance {
287355
..
288356
} => {
289357
let channel_id = output_info.channel_id;
290-
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
291-
let latest_spending_txid = latest_spending_tx.txid();
358+
let amount_satoshis = value_from_descriptor(&output_info.descriptor).to_sat();
359+
let latest_spending_txid = latest_spending_tx.compute_txid();
292360
Self::BroadcastAwaitingConfirmation {
293361
channel_id,
294362
latest_broadcast_height,
@@ -303,8 +371,8 @@ impl PendingSweepBalance {
303371
..
304372
} => {
305373
let channel_id = output_info.channel_id;
306-
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
307-
let latest_spending_txid = latest_spending_tx.txid();
374+
let amount_satoshis = value_from_descriptor(&output_info.descriptor).to_sat();
375+
let latest_spending_txid = latest_spending_tx.compute_txid();
308376
Self::AwaitingThresholdConfirmations {
309377
channel_id,
310378
latest_spending_txid,

0 commit comments

Comments
 (0)