Skip to content

Commit

Permalink
Update to LDK 0.1-beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Jan 10, 2025
1 parent 3676248 commit 0bc73c3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 53 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lightning = { version = "0.0.125", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.125", features = [ "rpc-client", "tokio" ] }
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 = { version = "0.1.0-beta1", features = ["dnssec"] }
lightning-block-sync = { version = "0.1.0-beta1", features = [ "rpc-client", "tokio" ] }
lightning-invoice = { version = "0.33.0-beta1" }
lightning-net-tokio = { version = "0.1.0-beta1" }
lightning-persister = { version = "0.1.0-beta1" }
lightning-background-processor = { version = "0.1.0-beta1", features = [ "futures" ] }
lightning-rapid-gossip-sync = { version = "0.1.0-beta1" }

base64 = "0.13.0"
bitcoin = "0.32"
Expand Down
4 changes: 2 additions & 2 deletions src/bitcoind_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl BitcoindClient {
let http_endpoint = HttpEndpoint::for_host(host.clone()).with_port(port);
let rpc_credentials =
base64::encode(format!("{}:{}", rpc_user.clone(), rpc_password.clone()));
let bitcoind_rpc_client = RpcClient::new(&rpc_credentials, http_endpoint)?;
let bitcoind_rpc_client = RpcClient::new(&rpc_credentials, http_endpoint);
let _dummy = bitcoind_rpc_client
.call_method::<BlockchainInfo>("getblockchaininfo", &vec![])
.await
Expand Down Expand Up @@ -226,7 +226,7 @@ impl BitcoindClient {
});
}

pub fn get_new_rpc_client(&self) -> std::io::Result<RpcClient> {
pub fn get_new_rpc_client(&self) -> RpcClient {
let http_endpoint = HttpEndpoint::for_host(self.host.clone()).with_port(self.port);
let rpc_credentials =
base64::encode(format!("{}:{}", self.rpc_user.clone(), self.rpc_password.clone()));
Expand Down
9 changes: 3 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bitcoin::network::Network;
use bitcoin::secp256k1::PublicKey;
use lightning::chain::channelmonitor::Balance;
use lightning::ln::bolt11_payment::payment_parameters_from_invoice;
use lightning::ln::bolt11_payment::payment_parameters_from_zero_amount_invoice;
use lightning::ln::bolt11_payment::payment_parameters_from_variable_amount_invoice;
use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
use lightning::ln::invoice_utils as utils;
use lightning::ln::msgs::SocketAddress;
Expand Down Expand Up @@ -746,7 +746,7 @@ fn send_payment(
invoice.amount_milli_satoshis().is_none() || invoice.amount_milli_satoshis() == Some(0);
let pay_params_opt = if zero_amt_invoice {
if let Some(amt_msat) = required_amount_msat {
payment_parameters_from_zero_amount_invoice(invoice, amt_msat)
payment_parameters_from_variable_amount_invoice(invoice, amt_msat)
} else {
println!("Need an amount for the given 0-value invoice");
print!("> ");
Expand Down Expand Up @@ -826,7 +826,7 @@ fn keysend<E: EntropySource>(
},
);
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
match channel_manager.send_spontaneous_payment_with_retry(
match channel_manager.send_spontaneous_payment(
Some(payment_preimage),
RecipientOnionFields::spontaneous_empty(),
payment_id,
Expand Down Expand Up @@ -859,9 +859,6 @@ fn get_invoice(
};
let invoice = match utils::create_invoice_from_channelmanager(
channel_manager,
keys_manager,
logger,
currency,
Some(amt_msat),
"ldk-tutorial-node".to_string(),
expiry_secs,
Expand Down
10 changes: 5 additions & 5 deletions src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use bitcoin::secp256k1::PublicKey;
use bitcoin::Network;
use chrono::Utc;
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringDecayParameters};
use lightning::util::hash_tables::{HashMap, new_hash_map};
use lightning::util::logger::{Logger, Record};
use lightning::util::ser::{Readable, ReadableArgs};
use std::collections::HashMap;
use std::fs;
use std::fs::File;
use std::io::{BufRead, BufReader, Write};
Expand Down Expand Up @@ -58,9 +58,9 @@ pub(crate) fn persist_channel_peer(path: &Path, peer_info: &str) -> std::io::Res
pub(crate) fn read_channel_peer_data(
path: &Path,
) -> Result<HashMap<PublicKey, SocketAddr>, std::io::Error> {
let mut peer_data = HashMap::new();
let mut peer_data = new_hash_map();
if !Path::new(&path).exists() {
return Ok(HashMap::new());
return Ok(new_hash_map());
}
let file = File::open(path)?;
let reader = BufReader::new(file);
Expand Down Expand Up @@ -92,7 +92,7 @@ pub(crate) fn read_inbound_payment_info(path: &Path) -> InboundPaymentInfoStorag
return info;
}
}
InboundPaymentInfoStorage { payments: HashMap::new() }
InboundPaymentInfoStorage { payments: new_hash_map() }
}

pub(crate) fn read_outbound_payment_info(path: &Path) -> OutboundPaymentInfoStorage {
Expand All @@ -101,7 +101,7 @@ pub(crate) fn read_outbound_payment_info(path: &Path) -> OutboundPaymentInfoStor
return info;
}
}
OutboundPaymentInfoStorage { payments: HashMap::new() }
OutboundPaymentInfoStorage { payments: new_hash_map() }
}

pub(crate) fn read_scorer(
Expand Down
54 changes: 21 additions & 33 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use lightning::routing::router::DefaultRouter;
use lightning::routing::scoring::ProbabilisticScoringFeeParameters;
use lightning::sign::{EntropySource, InMemorySigner, KeysManager};
use lightning::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::util::hash_tables::hash_map::Entry;
use lightning::util::hash_tables::HashMap;
use lightning::util::config::UserConfig;
use lightning::util::persist::{
self, KVStore, MonitorUpdatingPersister, OUTPUT_SWEEPER_PERSISTENCE_KEY,
Expand All @@ -49,8 +51,7 @@ use lightning_block_sync::UnboundedCache;
use lightning_net_tokio::SocketDescriptor;
use lightning_persister::fs_store::FilesystemStore;
use rand::{thread_rng, Rng};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::collections::HashMap as StdHashMap;
use std::convert::TryInto;
use std::fmt;
use std::fs;
Expand Down Expand Up @@ -158,7 +159,7 @@ pub(crate) type PeerManager = SimpleArcPeerManager<
ChainMonitor,
BitcoindClient,
BitcoindClient,
GossipVerifier,
Arc<GossipVerifier>,
FilesystemLogger,
>;

Expand Down Expand Up @@ -219,7 +220,7 @@ async fn handle_ldk_events(
)
.expect("Lightning funding tx should always be to a SegWit output")
.to_address();
let mut outputs = vec![HashMap::with_capacity(1)];
let mut outputs = vec![StdHashMap::new()];
outputs[0].insert(addr, channel_value_satoshis as f64 / 100_000_000.0);
let raw_tx = bitcoind_client.create_raw_transaction(outputs).await;

Expand All @@ -246,17 +247,7 @@ async fn handle_ldk_events(
Event::FundingTxBroadcastSafe { .. } => {
// We don't use the manual broadcasting feature, so this event should never be seen.
},
Event::PaymentClaimable {
payment_hash,
purpose,
amount_msat,
receiver_node_id: _,
via_channel_id: _,
via_user_channel_id: _,
claim_deadline: _,
onion_fields: _,
counterparty_skimmed_fee_msat: _,
} => {
Event::PaymentClaimable { payment_hash, purpose, amount_msat, .. } => {
println!(
"\nEVENT: received payment from payment hash {} of {} millisatoshis",
payment_hash, amount_msat,
Expand Down Expand Up @@ -402,9 +393,7 @@ async fn handle_ldk_events(
total_fee_earned_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
skimmed_fee_msat: _,
prev_user_channel_id: _,
next_user_channel_id: _,
..
} => {
let read_only_network_graph = network_graph.read_only();
let nodes = read_only_network_graph.nodes();
Expand Down Expand Up @@ -497,14 +486,7 @@ async fn handle_ldk_events(
print!("> ");
std::io::stdout().flush().unwrap();
},
Event::ChannelClosed {
channel_id,
reason,
user_channel_id: _,
counterparty_node_id,
channel_capacity_sats: _,
channel_funding_txo: _,
} => {
Event::ChannelClosed { channel_id, reason, counterparty_node_id, .. } => {
println!(
"\nEVENT: Channel {} with counterparty {} closed due to: {:?}",
channel_id,
Expand Down Expand Up @@ -688,7 +670,7 @@ async fn start_ldk() {
Arc::clone(&logger),
)));

// Step 10: Create Router
// Step 10: Create Routers
let scoring_fee_params = ProbabilisticScoringFeeParameters::default();
let router = Arc::new(DefaultRouter::new(
network_graph.clone(),
Expand All @@ -698,6 +680,9 @@ async fn start_ldk() {
scoring_fee_params,
));

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

// Step 11: Initialize the ChannelManager
let mut user_config = UserConfig::default();
user_config.channel_handshake_limits.force_announced_channel_preference = false;
Expand All @@ -706,9 +691,9 @@ async fn start_ldk() {
let mut restarting_node = true;
let (channel_manager_blockhash, channel_manager) = {
if let Ok(f) = fs::File::open(format!("{}/manager", ldk_data_dir.clone())) {
let mut channel_monitor_mut_references = Vec::new();
for (_, channel_monitor) in channelmonitors.iter_mut() {
channel_monitor_mut_references.push(channel_monitor);
let mut channel_monitor_references = Vec::new();
for (_, channel_monitor) in channelmonitors.iter() {
channel_monitor_references.push(channel_monitor);
}
let read_args = ChannelManagerReadArgs::new(
keys_manager.clone(),
Expand All @@ -718,9 +703,10 @@ async fn start_ldk() {
chain_monitor.clone(),
broadcaster.clone(),
router,
Arc::clone(&message_router),
logger.clone(),
user_config,
channel_monitor_mut_references,
channel_monitor_references,
);
<(BlockHash, ChannelManager)>::read(&mut BufReader::new(f), read_args).unwrap()
} else {
Expand All @@ -736,6 +722,7 @@ async fn start_ldk() {
chain_monitor.clone(),
broadcaster.clone(),
router,
Arc::clone(&message_router),
logger.clone(),
keys_manager.clone(),
keys_manager.clone(),
Expand Down Expand Up @@ -842,7 +829,8 @@ async fn start_ldk() {
Arc::clone(&keys_manager),
Arc::clone(&logger),
Arc::clone(&channel_manager),
Arc::new(DefaultMessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager))),
Arc::clone(&message_router),
Arc::clone(&channel_manager),
Arc::clone(&channel_manager),
Arc::clone(&channel_manager),
IgnoringMessageHandler {},
Expand Down Expand Up @@ -871,7 +859,7 @@ async fn start_ldk() {
Arc::clone(&gossip_sync),
Arc::clone(&peer_manager),
);
gossip_sync.add_utxo_lookup(Some(utxo_lookup));
gossip_sync.add_utxo_lookup(Some(Arc::new(utxo_lookup)));

// ## Running LDK
// Step 17: Initialize networking
Expand Down

0 comments on commit 0bc73c3

Please sign in to comment.