Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to LDK v0.0.123-beta #243

Merged
merged 2 commits into from
Apr 25, 2024
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
20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ panic = 'abort' # Abort on panic
default = []

[dependencies]
lightning = { version = "0.0.121", features = ["std"] }
lightning-invoice = { version = "0.29.0" }
lightning-net-tokio = { version = "0.0.121" }
lightning-persister = { version = "0.0.121" }
lightning-background-processor = { version = "0.0.121", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.121" }
lightning-transaction-sync = { version = "0.0.121", features = ["esplora-async-https", "time"] }
lightning-liquidity = { version = "0.1.0-alpha.1", features = ["std"] }
lightning = { version = "0.0.123-beta", features = ["std"] }
lightning-invoice = { version = "0.31.0-beta" }
lightning-net-tokio = { version = "0.0.123-beta" }
lightning-persister = { version = "0.0.123-beta" }
lightning-background-processor = { version = "0.0.123-beta", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.123-beta" }
lightning-transaction-sync = { version = "0.0.123-beta", features = ["esplora-async-https", "time"] }
#lightning-liquidity = { version = "0.1.0-alpha.1", features = ["std"] }

lightning-liquidity = { git = "https://github.com/tnull/lightning-liquidity", rev = "abf7088c0e03221c0f122e797f34802c9e99a3d4", features = ["std"] }

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

[dev-dependencies]
lightning = { version = "0.0.121", features = ["std", "_test_utils"] }
lightning = { version = "0.0.123-beta", features = ["std", "_test_utils"] }
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
electrum-client = { version = "0.15.1", default-features = true }
bitcoincore-rpc = { version = "0.17.0", default-features = false }
Expand Down
23 changes: 13 additions & 10 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,19 @@ enum PaymentFailureReason {

[Enum]
interface ClosureReason {
CounterpartyForceClosed ( UntrustedString peer_msg );
HolderForceClosed ();
CooperativeClosure ();
CommitmentTxConfirmed ();
FundingTimedOut ();
ProcessingError ( string err );
DisconnectedPeer ();
OutdatedChannelManager ();
CounterpartyCoopClosedUnfundedChannel ();
FundingBatchClosure ();
CounterpartyForceClosed(UntrustedString peer_msg);
HolderForceClosed();
LegacyCooperativeClosure();
CounterpartyInitiatedCooperativeClosure();
LocallyInitiatedCooperativeClosure();
CommitmentTxConfirmed();
FundingTimedOut();
ProcessingError(string err);
DisconnectedPeer();
OutdatedChannelManager();
CounterpartyCoopClosedUnfundedChannel();
FundingBatchClosure();
HTLCsTimedOut();
};

enum PaymentDirection {
Expand Down
82 changes: 41 additions & 41 deletions src/balance.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::sweep::value_satoshis_from_descriptor;

use lightning::chain::channelmonitor::Balance as LdkBalance;
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};

use bitcoin::secp256k1::PublicKey;
use bitcoin::{BlockHash, Txid};

use crate::sweep::SpendableOutputInfo;

/// Details of the known available balances returned by [`Node::list_balances`].
///
/// [`Node::list_balances`]: crate::Node::list_balances
Expand Down Expand Up @@ -258,46 +259,45 @@ pub enum PendingSweepBalance {
}

impl PendingSweepBalance {
pub(crate) fn from_tracked_spendable_output(output_info: SpendableOutputInfo) -> Self {
if let Some(confirmation_hash) = output_info.confirmation_hash {
debug_assert!(output_info.confirmation_height.is_some());
debug_assert!(output_info.latest_spending_tx.is_some());
let channel_id = output_info.channel_id;
let confirmation_height = output_info
.confirmation_height
.expect("Height must be set if the output is confirmed");
let latest_spending_txid = output_info
.latest_spending_tx
.as_ref()
.expect("Spending tx must be set if the output is confirmed")
.txid();
let amount_satoshis = output_info.value_satoshis();
Self::AwaitingThresholdConfirmations {
channel_id,
latest_spending_txid,
confirmation_hash,
confirmation_height,
amount_satoshis,
}
} else if let Some(latest_broadcast_height) = output_info.latest_broadcast_height {
debug_assert!(output_info.latest_spending_tx.is_some());
let channel_id = output_info.channel_id;
let latest_spending_txid = output_info
.latest_spending_tx
.as_ref()
.expect("Spending tx must be set if the spend was broadcast")
.txid();
let amount_satoshis = output_info.value_satoshis();
Self::BroadcastAwaitingConfirmation {
channel_id,
pub(crate) fn from_tracked_spendable_output(output_info: TrackedSpendableOutput) -> Self {
match output_info.status {
OutputSpendStatus::PendingInitialBroadcast { .. } => {
let channel_id = output_info.channel_id;
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
Self::PendingBroadcast { channel_id, amount_satoshis }
},
OutputSpendStatus::PendingFirstConfirmation {
latest_broadcast_height,
latest_spending_txid,
amount_satoshis,
}
} else {
let channel_id = output_info.channel_id;
let amount_satoshis = output_info.value_satoshis();
Self::PendingBroadcast { channel_id, amount_satoshis }
latest_spending_tx,
..
} => {
let channel_id = output_info.channel_id;
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
let latest_spending_txid = latest_spending_tx.txid();
Self::BroadcastAwaitingConfirmation {
channel_id,
latest_broadcast_height,
latest_spending_txid,
amount_satoshis,
}
},
OutputSpendStatus::PendingThresholdConfirmations {
latest_spending_tx,
confirmation_height,
confirmation_hash,
..
} => {
let channel_id = output_info.channel_id;
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
let latest_spending_txid = latest_spending_tx.txid();
Self::AwaitingThresholdConfirmations {
channel_id,
latest_spending_txid,
confirmation_hash,
confirmation_height,
amount_satoshis,
}
},
}
}
}
75 changes: 50 additions & 25 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use crate::gossip::GossipSource;
use crate::io;
use crate::io::sqlite_store::SqliteStore;
use crate::liquidity::LiquiditySource;
use crate::logger::{log_error, FilesystemLogger, Logger};
use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
use crate::message_handler::NodeCustomMessageHandler;
use crate::payment_store::PaymentStore;
use crate::peer_store::PeerStore;
use crate::sweep::OutputSweeper;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
ChainMonitor, ChannelManager, GossipSync, KeysManager, MessageRouter, NetworkGraph,
OnionMessenger, PeerManager,
};
use crate::wallet::Wallet;
Expand All @@ -37,6 +36,7 @@ use lightning::util::persist::{
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
};
use lightning::util::ser::ReadableArgs;
use lightning::util::sweep::OutputSweeper;

use lightning_persister::fs_store::FilesystemStore;

Expand Down Expand Up @@ -664,7 +664,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
let router = Arc::new(DefaultRouter::new(
Arc::clone(&network_graph),
Arc::clone(&logger),
keys_manager.get_secure_random_bytes(),
Arc::clone(&keys_manager),
Arc::clone(&scorer),
scoring_fee_params,
));
Expand Down Expand Up @@ -776,12 +776,15 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
})?;
}

let message_router = MessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager));

// Initialize the PeerManager
let onion_messenger: Arc<OnionMessenger> = Arc::new(OnionMessenger::new(
let onion_messenger: Arc<OnionMessenger<K>> = Arc::new(OnionMessenger::new(
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&logger),
Arc::new(FakeMessageRouter {}),
Arc::clone(&channel_manager),
Arc::new(message_router),
IgnoringMessageHandler {},
IgnoringMessageHandler {},
));
Expand Down Expand Up @@ -892,6 +895,47 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(

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

let output_sweeper = match io::utils::read_output_sweeper(
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
Arc::clone(&tx_sync),
Arc::clone(&keys_manager),
Arc::clone(&kv_store),
Arc::clone(&logger),
) {
Ok(output_sweeper) => Arc::new(output_sweeper),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(OutputSweeper::new(
channel_manager.current_best_block(),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
Some(Arc::clone(&tx_sync)),
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&kv_store),
Arc::clone(&logger),
))
} else {
return Err(BuildError::ReadFailed);
}
},
};

match io::utils::migrate_deprecated_spendable_outputs(
Arc::clone(&output_sweeper),
Arc::clone(&kv_store),
Arc::clone(&logger),
) {
Ok(()) => {
log_info!(logger, "Successfully migrated OutputSweeper data.");
},
Err(e) => {
log_error!(logger, "Failed to migrate OutputSweeper data: {}", e);
return Err(BuildError::ReadFailed);
},
}

// Init payment info storage
let payment_store = match io::utils::read_payments(Arc::clone(&kv_store), Arc::clone(&logger)) {
Ok(payments) => {
Expand Down Expand Up @@ -925,25 +969,6 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
},
};

let best_block = channel_manager.current_best_block();
let output_sweeper =
match io::utils::read_spendable_outputs(Arc::clone(&kv_store), Arc::clone(&logger)) {
Ok(outputs) => Arc::new(OutputSweeper::new(
outputs,
Arc::clone(&wallet),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
Arc::clone(&keys_manager),
Arc::clone(&kv_store),
best_block,
Some(Arc::clone(&tx_sync)),
Arc::clone(&logger),
)),
Err(_) => {
return Err(BuildError::ReadFailed);
},
};

let (stop_sender, _) = tokio::sync::watch::channel(());

let is_listening = Arc::new(AtomicBool::new(false));
Expand Down
Loading
Loading