Skip to content

Commit 9be82cc

Browse files
authored
Merge pull request #243 from tnull/2024-02-upgrade-to-LDK-v0.0.122
Upgrade to LDK v0.0.123-beta
2 parents 71b1d3c + 4564ec1 commit 9be82cc

File tree

12 files changed

+360
-647
lines changed

12 files changed

+360
-647
lines changed

Cargo.toml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ panic = 'abort' # Abort on panic
2828
default = []
2929

3030
[dependencies]
31-
lightning = { version = "0.0.121", features = ["std"] }
32-
lightning-invoice = { version = "0.29.0" }
33-
lightning-net-tokio = { version = "0.0.121" }
34-
lightning-persister = { version = "0.0.121" }
35-
lightning-background-processor = { version = "0.0.121", features = ["futures"] }
36-
lightning-rapid-gossip-sync = { version = "0.0.121" }
37-
lightning-transaction-sync = { version = "0.0.121", features = ["esplora-async-https", "time"] }
38-
lightning-liquidity = { version = "0.1.0-alpha.1", features = ["std"] }
31+
lightning = { version = "0.0.123-beta", features = ["std"] }
32+
lightning-invoice = { version = "0.31.0-beta" }
33+
lightning-net-tokio = { version = "0.0.123-beta" }
34+
lightning-persister = { version = "0.0.123-beta" }
35+
lightning-background-processor = { version = "0.0.123-beta", features = ["futures"] }
36+
lightning-rapid-gossip-sync = { version = "0.0.123-beta" }
37+
lightning-transaction-sync = { version = "0.0.123-beta", features = ["esplora-async-https", "time"] }
38+
#lightning-liquidity = { version = "0.1.0-alpha.1", features = ["std"] }
39+
40+
lightning-liquidity = { git = "https://github.com/tnull/lightning-liquidity", rev = "abf7088c0e03221c0f122e797f34802c9e99a3d4", features = ["std"] }
3941

4042
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std"] }
4143
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
@@ -78,7 +80,7 @@ prost = { version = "0.11.6", default-features = false}
7880
winapi = { version = "0.3", features = ["winbase"] }
7981

8082
[dev-dependencies]
81-
lightning = { version = "0.0.121", features = ["std", "_test_utils"] }
83+
lightning = { version = "0.0.123-beta", features = ["std", "_test_utils"] }
8284
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
8385
electrum-client = { version = "0.15.1", default-features = true }
8486
bitcoincore-rpc = { version = "0.17.0", default-features = false }

bindings/ldk_node.udl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,19 @@ enum PaymentFailureReason {
190190

191191
[Enum]
192192
interface ClosureReason {
193-
CounterpartyForceClosed ( UntrustedString peer_msg );
194-
HolderForceClosed ();
195-
CooperativeClosure ();
196-
CommitmentTxConfirmed ();
197-
FundingTimedOut ();
198-
ProcessingError ( string err );
199-
DisconnectedPeer ();
200-
OutdatedChannelManager ();
201-
CounterpartyCoopClosedUnfundedChannel ();
202-
FundingBatchClosure ();
193+
CounterpartyForceClosed(UntrustedString peer_msg);
194+
HolderForceClosed();
195+
LegacyCooperativeClosure();
196+
CounterpartyInitiatedCooperativeClosure();
197+
LocallyInitiatedCooperativeClosure();
198+
CommitmentTxConfirmed();
199+
FundingTimedOut();
200+
ProcessingError(string err);
201+
DisconnectedPeer();
202+
OutdatedChannelManager();
203+
CounterpartyCoopClosedUnfundedChannel();
204+
FundingBatchClosure();
205+
HTLCsTimedOut();
203206
};
204207

205208
enum PaymentDirection {

src/balance.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
use crate::sweep::value_satoshis_from_descriptor;
2+
13
use lightning::chain::channelmonitor::Balance as LdkBalance;
24
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
5+
use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};
36

47
use bitcoin::secp256k1::PublicKey;
58
use bitcoin::{BlockHash, Txid};
69

7-
use crate::sweep::SpendableOutputInfo;
8-
910
/// Details of the known available balances returned by [`Node::list_balances`].
1011
///
1112
/// [`Node::list_balances`]: crate::Node::list_balances
@@ -258,46 +259,45 @@ pub enum PendingSweepBalance {
258259
}
259260

260261
impl PendingSweepBalance {
261-
pub(crate) fn from_tracked_spendable_output(output_info: SpendableOutputInfo) -> Self {
262-
if let Some(confirmation_hash) = output_info.confirmation_hash {
263-
debug_assert!(output_info.confirmation_height.is_some());
264-
debug_assert!(output_info.latest_spending_tx.is_some());
265-
let channel_id = output_info.channel_id;
266-
let confirmation_height = output_info
267-
.confirmation_height
268-
.expect("Height must be set if the output is confirmed");
269-
let latest_spending_txid = output_info
270-
.latest_spending_tx
271-
.as_ref()
272-
.expect("Spending tx must be set if the output is confirmed")
273-
.txid();
274-
let amount_satoshis = output_info.value_satoshis();
275-
Self::AwaitingThresholdConfirmations {
276-
channel_id,
277-
latest_spending_txid,
278-
confirmation_hash,
279-
confirmation_height,
280-
amount_satoshis,
281-
}
282-
} else if let Some(latest_broadcast_height) = output_info.latest_broadcast_height {
283-
debug_assert!(output_info.latest_spending_tx.is_some());
284-
let channel_id = output_info.channel_id;
285-
let latest_spending_txid = output_info
286-
.latest_spending_tx
287-
.as_ref()
288-
.expect("Spending tx must be set if the spend was broadcast")
289-
.txid();
290-
let amount_satoshis = output_info.value_satoshis();
291-
Self::BroadcastAwaitingConfirmation {
292-
channel_id,
262+
pub(crate) fn from_tracked_spendable_output(output_info: TrackedSpendableOutput) -> Self {
263+
match output_info.status {
264+
OutputSpendStatus::PendingInitialBroadcast { .. } => {
265+
let channel_id = output_info.channel_id;
266+
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
267+
Self::PendingBroadcast { channel_id, amount_satoshis }
268+
},
269+
OutputSpendStatus::PendingFirstConfirmation {
293270
latest_broadcast_height,
294-
latest_spending_txid,
295-
amount_satoshis,
296-
}
297-
} else {
298-
let channel_id = output_info.channel_id;
299-
let amount_satoshis = output_info.value_satoshis();
300-
Self::PendingBroadcast { channel_id, amount_satoshis }
271+
latest_spending_tx,
272+
..
273+
} => {
274+
let channel_id = output_info.channel_id;
275+
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
276+
let latest_spending_txid = latest_spending_tx.txid();
277+
Self::BroadcastAwaitingConfirmation {
278+
channel_id,
279+
latest_broadcast_height,
280+
latest_spending_txid,
281+
amount_satoshis,
282+
}
283+
},
284+
OutputSpendStatus::PendingThresholdConfirmations {
285+
latest_spending_tx,
286+
confirmation_height,
287+
confirmation_hash,
288+
..
289+
} => {
290+
let channel_id = output_info.channel_id;
291+
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
292+
let latest_spending_txid = latest_spending_tx.txid();
293+
Self::AwaitingThresholdConfirmations {
294+
channel_id,
295+
latest_spending_txid,
296+
confirmation_hash,
297+
confirmation_height,
298+
amount_satoshis,
299+
}
300+
},
301301
}
302302
}
303303
}

src/builder.rs

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use crate::gossip::GossipSource;
88
use crate::io;
99
use crate::io::sqlite_store::SqliteStore;
1010
use crate::liquidity::LiquiditySource;
11-
use crate::logger::{log_error, FilesystemLogger, Logger};
11+
use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
1212
use crate::message_handler::NodeCustomMessageHandler;
1313
use crate::payment_store::PaymentStore;
1414
use crate::peer_store::PeerStore;
15-
use crate::sweep::OutputSweeper;
1615
use crate::tx_broadcaster::TransactionBroadcaster;
1716
use crate::types::{
18-
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
17+
ChainMonitor, ChannelManager, GossipSync, KeysManager, MessageRouter, NetworkGraph,
1918
OnionMessenger, PeerManager,
2019
};
2120
use crate::wallet::Wallet;
@@ -37,6 +36,7 @@ use lightning::util::persist::{
3736
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
3837
};
3938
use lightning::util::ser::ReadableArgs;
39+
use lightning::util::sweep::OutputSweeper;
4040

4141
use lightning_persister::fs_store::FilesystemStore;
4242

@@ -664,7 +664,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
664664
let router = Arc::new(DefaultRouter::new(
665665
Arc::clone(&network_graph),
666666
Arc::clone(&logger),
667-
keys_manager.get_secure_random_bytes(),
667+
Arc::clone(&keys_manager),
668668
Arc::clone(&scorer),
669669
scoring_fee_params,
670670
));
@@ -776,12 +776,15 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
776776
})?;
777777
}
778778

779+
let message_router = MessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager));
780+
779781
// Initialize the PeerManager
780-
let onion_messenger: Arc<OnionMessenger> = Arc::new(OnionMessenger::new(
782+
let onion_messenger: Arc<OnionMessenger<K>> = Arc::new(OnionMessenger::new(
781783
Arc::clone(&keys_manager),
782784
Arc::clone(&keys_manager),
783785
Arc::clone(&logger),
784-
Arc::new(FakeMessageRouter {}),
786+
Arc::clone(&channel_manager),
787+
Arc::new(message_router),
785788
IgnoringMessageHandler {},
786789
IgnoringMessageHandler {},
787790
));
@@ -892,6 +895,47 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
892895

893896
liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::clone(&peer_manager)));
894897

898+
let output_sweeper = match io::utils::read_output_sweeper(
899+
Arc::clone(&tx_broadcaster),
900+
Arc::clone(&fee_estimator),
901+
Arc::clone(&tx_sync),
902+
Arc::clone(&keys_manager),
903+
Arc::clone(&kv_store),
904+
Arc::clone(&logger),
905+
) {
906+
Ok(output_sweeper) => Arc::new(output_sweeper),
907+
Err(e) => {
908+
if e.kind() == std::io::ErrorKind::NotFound {
909+
Arc::new(OutputSweeper::new(
910+
channel_manager.current_best_block(),
911+
Arc::clone(&tx_broadcaster),
912+
Arc::clone(&fee_estimator),
913+
Some(Arc::clone(&tx_sync)),
914+
Arc::clone(&keys_manager),
915+
Arc::clone(&keys_manager),
916+
Arc::clone(&kv_store),
917+
Arc::clone(&logger),
918+
))
919+
} else {
920+
return Err(BuildError::ReadFailed);
921+
}
922+
},
923+
};
924+
925+
match io::utils::migrate_deprecated_spendable_outputs(
926+
Arc::clone(&output_sweeper),
927+
Arc::clone(&kv_store),
928+
Arc::clone(&logger),
929+
) {
930+
Ok(()) => {
931+
log_info!(logger, "Successfully migrated OutputSweeper data.");
932+
},
933+
Err(e) => {
934+
log_error!(logger, "Failed to migrate OutputSweeper data: {}", e);
935+
return Err(BuildError::ReadFailed);
936+
},
937+
}
938+
895939
// Init payment info storage
896940
let payment_store = match io::utils::read_payments(Arc::clone(&kv_store), Arc::clone(&logger)) {
897941
Ok(payments) => {
@@ -925,25 +969,6 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
925969
},
926970
};
927971

928-
let best_block = channel_manager.current_best_block();
929-
let output_sweeper =
930-
match io::utils::read_spendable_outputs(Arc::clone(&kv_store), Arc::clone(&logger)) {
931-
Ok(outputs) => Arc::new(OutputSweeper::new(
932-
outputs,
933-
Arc::clone(&wallet),
934-
Arc::clone(&tx_broadcaster),
935-
Arc::clone(&fee_estimator),
936-
Arc::clone(&keys_manager),
937-
Arc::clone(&kv_store),
938-
best_block,
939-
Some(Arc::clone(&tx_sync)),
940-
Arc::clone(&logger),
941-
)),
942-
Err(_) => {
943-
return Err(BuildError::ReadFailed);
944-
},
945-
};
946-
947972
let (stop_sender, _) = tokio::sync::watch::channel(());
948973

949974
let is_listening = Arc::new(AtomicBool::new(false));

0 commit comments

Comments
 (0)