Skip to content

Commit

Permalink
Merge pull request #426 from tnull/2025-01-upgrade-bdk-ldk
Browse files Browse the repository at this point in the history
Update BDK to 1.0.0 and LDK to 0.1.0
  • Loading branch information
tnull authored Jan 16, 2025
2 parents ec00e5c + c39bfba commit 03c4ab0
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 163 deletions.
58 changes: 32 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,42 @@ panic = 'abort' # Abort on panic
default = []

[dependencies]
lightning = { version = "0.0.125", features = ["std"] }
lightning-invoice = { version = "0.32.0" }
lightning-net-tokio = { version = "0.0.125" }
lightning-persister = { version = "0.0.125" }
lightning-background-processor = { version = "0.0.125", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.125" }
lightning-block-sync = { version = "0.0.125", features = ["rpc-client", "tokio"] }
lightning-transaction-sync = { version = "0.0.125", features = ["esplora-async-https", "time"] }
lightning-liquidity = { version = "0.1.0-alpha.6", 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" }
#lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
#lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
#lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["futures"] }
#lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["esplora-async"] }
#lightning-liquidity = { git = "https://github.com/lightningdevkit/lightning-liquidity", branch="main", features = ["std"] }
lightning = { version = "0.1.0", features = ["std"] }
lightning-types = { version = "0.2.0" }
lightning-invoice = { version = "0.33.0", features = ["std"] }
lightning-net-tokio = { version = "0.1.0" }
lightning-persister = { version = "0.1.0" }
lightning-background-processor = { version = "0.1.0", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.1.0" }
lightning-block-sync = { version = "0.1.0", features = ["rpc-client", "tokio"] }
lightning-transaction-sync = { version = "0.1.0", features = ["esplora-async-https", "time"] }
lightning-liquidity = { version = "0.1.0", features = ["std"] }

#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
#lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
#lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["futures"] }
#lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["rpc-client", "tokio"] }
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["esplora-async-https", "time"] }
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }

#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
#lightning-types = { path = "../rust-lightning/lightning-types" }
#lightning-invoice = { path = "../rust-lightning/lightning-invoice", features = ["std"] }
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor", features = ["futures"] }
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }
#lightning-liquidity = { path = "../lightning-liquidity", features = ["std"] }
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client", "tokio"] }
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "time"] }
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity", features = ["std"] }

bdk_chain = { version = "=0.19.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "=0.18.0", default-features = false, features = ["async-https-rustls"]}
bdk_wallet = { version = "=1.0.0-beta.4", default-features = false, features = ["std", "keys-bip39"]}
bdk_chain = { version = "0.21.1", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.20.1", default-features = false, features = ["async-https-rustls", "tokio"]}
bdk_wallet = { version = "1.0.0", default-features = false, features = ["std", "keys-bip39"]}

reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
rusqlite = { version = "0.31.0", features = ["bundled"] }
Expand All @@ -70,7 +75,7 @@ base64 = { version = "0.22.1", default-features = false, features = ["std"] }
rand = "0.8.5"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
esplora-client = { version = "0.9", default-features = false }
esplora-client = { version = "0.11", default-features = false, features = ["tokio", "async-https-rustls"] }
libc = "0.2"
uniffi = { version = "0.27.3", features = ["build"], optional = true }
serde = { version = "1.0.210", default-features = false, features = ["std", "derive"] }
Expand All @@ -83,8 +88,9 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { version = "0.0.125", features = ["std", "_test_utils"] }
lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
electrum-client = { version = "0.21.0", default-features = true }
bitcoincore-rpc = { version = "0.19.0", default-features = false }
proptest = "1.0.0"
Expand Down
4 changes: 3 additions & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ interface Event {
PaymentFailed(PaymentId? payment_id, PaymentHash? payment_hash, PaymentFailureReason? reason);
PaymentReceived(PaymentId? payment_id, PaymentHash payment_hash, u64 amount_msat, sequence<CustomTlvRecord> custom_records);
PaymentClaimable(PaymentId payment_id, PaymentHash payment_hash, u64 claimable_amount_msat, u32? claim_deadline, sequence<CustomTlvRecord> custom_records);
PaymentForwarded(ChannelId prev_channel_id, ChannelId next_channel_id, UserChannelId? prev_user_channel_id, UserChannelId? next_user_channel_id, u64? total_fee_earned_msat, u64? skimmed_fee_msat, boolean claim_from_onchain_tx, u64? outbound_amount_forwarded_msat);
PaymentForwarded(ChannelId prev_channel_id, ChannelId next_channel_id, UserChannelId?
prev_user_channel_id, UserChannelId? next_user_channel_id, PublicKey? prev_node_id, PublicKey? next_node_id, u64? total_fee_earned_msat, u64? skimmed_fee_msat, boolean claim_from_onchain_tx, u64? outbound_amount_forwarded_msat);
ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo);
ChannelReady(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id);
ChannelClosed(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id, ClosureReason? reason);
Expand All @@ -296,6 +297,7 @@ enum PaymentFailureReason {
"UnknownRequiredFeatures",
"InvoiceRequestExpired",
"InvoiceRequestRejected",
"BlindedPathCreationFailed",
};

[Enum]
Expand Down
3 changes: 2 additions & 1 deletion src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use crate::sweep::value_from_descriptor;
use lightning::chain::channelmonitor::Balance as LdkBalance;
use lightning::chain::channelmonitor::BalanceSource;
use lightning::ln::types::ChannelId;
use lightning::ln::{PaymentHash, PaymentPreimage};
use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};

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

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

Expand Down
17 changes: 11 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ fn build_with_store_internal(
));

// Read ChannelMonitor state from store
let mut channel_monitors = match read_channel_monitors(
let channel_monitors = match read_channel_monitors(
Arc::clone(&kv_store),
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Expand Down Expand Up @@ -936,6 +936,9 @@ fn build_with_store_internal(
100;
}

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

// Initialize the ChannelManager
let channel_manager = {
if let Ok(res) = kv_store.read(
Expand All @@ -945,7 +948,7 @@ fn build_with_store_internal(
) {
let mut reader = Cursor::new(res);
let channel_monitor_references =
channel_monitors.iter_mut().map(|(_, chanmon)| chanmon).collect();
channel_monitors.iter().map(|(_, chanmon)| chanmon).collect();
let read_args = ChannelManagerReadArgs::new(
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Expand All @@ -954,6 +957,7 @@ fn build_with_store_internal(
Arc::clone(&chain_monitor),
Arc::clone(&tx_broadcaster),
Arc::clone(&router),
Arc::clone(&message_router),
Arc::clone(&logger),
user_config,
channel_monitor_references,
Expand All @@ -978,6 +982,7 @@ fn build_with_store_internal(
Arc::clone(&chain_monitor),
Arc::clone(&tx_broadcaster),
Arc::clone(&router),
Arc::clone(&message_router),
Arc::clone(&logger),
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Expand All @@ -1000,18 +1005,17 @@ fn build_with_store_internal(
})?;
}

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(
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&logger),
Arc::clone(&channel_manager),
Arc::new(message_router),
message_router,
Arc::clone(&channel_manager),
IgnoringMessageHandler {},
IgnoringMessageHandler {},
IgnoringMessageHandler {},
));
let ephemeral_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();

Expand Down Expand Up @@ -1055,7 +1059,8 @@ fn build_with_store_internal(
let liquidity_source = liquidity_source_config.as_ref().and_then(|lsc| {
lsc.lsps2_service.as_ref().map(|(address, node_id, token)| {
let lsps2_client_config = Some(LSPS2ClientConfig {});
let liquidity_client_config = Some(LiquidityClientConfig { lsps2_client_config });
let liquidity_client_config =
Some(LiquidityClientConfig { lsps1_client_config: None, lsps2_client_config });
let liquidity_manager = Arc::new(LiquidityManager::new(
Arc::clone(&keys_manager),
Arc::clone(&channel_manager),
Expand Down
5 changes: 1 addition & 4 deletions src/chain/bitcoind_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ impl BitcoindRpcClient {
let rpc_credentials =
BASE64_STANDARD.encode(format!("{}:{}", rpc_user.clone(), rpc_password.clone()));

let rpc_client = Arc::new(
RpcClient::new(&rpc_credentials, http_endpoint)
.expect("RpcClient::new is actually infallible"),
);
let rpc_client = Arc::new(RpcClient::new(&rpc_credentials, http_endpoint));

let latest_mempool_timestamp = AtomicU64::new(0);

Expand Down
16 changes: 5 additions & 11 deletions src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,18 +787,12 @@ impl ChainSource {
for target in confirmation_targets {
let num_blocks = get_num_block_defaults_for_target(target);

// Convert the retrieved fee rate and fall back to 1 sat/vb if we fail or it
// yields less than that. This is mostly necessary to continue on
// `signet`/`regtest` where we might not get estimates (or bogus values).
let converted_estimate_sat_vb =
esplora_client::convert_fee_rate(num_blocks, estimates.clone()).map_err(
|e| {
log_error!(
logger,
"Failed to convert fee rate estimates for {:?}: {}",
target,
e
);
Error::FeerateEstimationUpdateFailed
},
)?;
esplora_client::convert_fee_rate(num_blocks, estimates.clone())
.map_or(1.0, |converted| converted.max(1.0));

let fee_rate =
FeeRate::from_sat_per_kwu((converted_estimate_sat_vb * 250.0) as u64);
Expand Down
23 changes: 21 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ use lightning::events::{Event as LdkEvent, PaymentFailureReason};
use lightning::impl_writeable_tlv_based_enum;
use lightning::ln::channelmanager::PaymentId;
use lightning::ln::types::ChannelId;
use lightning::ln::{PaymentHash, PaymentPreimage};
use lightning::routing::gossip::NodeId;
use lightning::util::errors::APIError;
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};

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

use lightning_liquidity::lsps2::utils::compute_opening_fee;

use bitcoin::blockdata::locktime::absolute::LockTime;
Expand Down Expand Up @@ -120,6 +121,16 @@ pub enum Event {
/// This will be `None` if the payment was settled via an on-chain transaction. See the
/// caveat described for the `total_fee_earned_msat` field.
next_user_channel_id: Option<UserChannelId>,
/// The node id of the previous node.
///
/// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
/// versions prior to v0.5.
prev_node_id: Option<PublicKey>,
/// The node id of the next node.
///
/// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
/// versions prior to v0.5.
next_node_id: Option<PublicKey>,
/// The total fee, in milli-satoshis, which was earned as a result of the payment.
///
/// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
Expand Down Expand Up @@ -257,7 +268,9 @@ impl_writeable_tlv_based_enum!(Event,
},
(7, PaymentForwarded) => {
(0, prev_channel_id, required),
(1, prev_node_id, option),
(2, next_channel_id, required),
(3, next_node_id, option),
(4, prev_user_channel_id, option),
(6, next_user_channel_id, option),
(8, total_fee_earned_msat, option),
Expand Down Expand Up @@ -550,6 +563,7 @@ where
claim_deadline,
onion_fields,
counterparty_skimmed_fee_msat,
payment_id: _,
} => {
let payment_id = PaymentId(payment_hash.0);
if let Some(info) = self.payment_store.get(&payment_id) {
Expand Down Expand Up @@ -812,6 +826,7 @@ where
htlcs: _,
sender_intended_total_msat: _,
onion_fields,
payment_id: _,
} => {
let payment_id = PaymentId(payment_hash.0);
log_info!(
Expand Down Expand Up @@ -1025,7 +1040,7 @@ where
counterparty_node_id,
funding_satoshis,
channel_type,
push_msat: _,
channel_negotiation_type: _,
is_announced: _,
params: _,
} => {
Expand Down Expand Up @@ -1139,6 +1154,8 @@ where
next_channel_id,
prev_user_channel_id,
next_user_channel_id,
prev_node_id,
next_node_id,
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
Expand All @@ -1149,6 +1166,8 @@ where
next_channel_id: next_channel_id.expect("next_channel_id expected for events generated by LDK versions greater than 0.0.107."),
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
next_user_channel_id: next_user_channel_id.map(UserChannelId),
prev_node_id,
next_node_id,
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
Expand Down
3 changes: 1 addition & 2 deletions src/io/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use lightning::ln::functional_test_utils::{
};
use lightning::util::persist::{read_channel_monitors, KVStore, KVSTORE_NAMESPACE_KEY_MAX_LEN};

use lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
use lightning::events::ClosureReason;
use lightning::util::test_utils;
use lightning::{check_added_monitors, check_closed_broadcast, check_closed_event};
Expand Down Expand Up @@ -186,5 +185,5 @@ pub(crate) fn do_test_store<K: KVStore>(store_0: &K, store_1: &K) {
check_added_monitors!(nodes[1], 1);

// Make sure everything is persisted as expected after close.
check_persisted_data!(CLOSED_CHANNEL_UPDATE_ID);
check_persisted_data!(11);
}
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub use bip39;
pub use bitcoin;
pub use lightning;
pub use lightning_invoice;
pub use lightning_types;
pub use vss_client;

pub use balance::{BalanceDetails, LightningBalance, PendingSweepBalance};
Expand Down Expand Up @@ -823,7 +824,6 @@ impl Node {
Arc::clone(&self.runtime),
Arc::clone(&self.channel_manager),
Arc::clone(&self.connection_manager),
Arc::clone(&self.keys_manager),
self.liquidity_source.clone(),
Arc::clone(&self.payment_store),
Arc::clone(&self.peer_store),
Expand All @@ -841,7 +841,6 @@ impl Node {
Arc::clone(&self.runtime),
Arc::clone(&self.channel_manager),
Arc::clone(&self.connection_manager),
Arc::clone(&self.keys_manager),
self.liquidity_source.clone(),
Arc::clone(&self.payment_store),
Arc::clone(&self.peer_store),
Expand Down
Loading

0 comments on commit 03c4ab0

Please sign in to comment.