[[package]]
name = "lightning"
version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=6fcac8bc65ed6d372e0b8c367e9934c754f99ff3#6fcac8bc65ed6d372e0b8c367e9934c754f99ff3"
+source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=3d51b11fe99c9d6a41b0d662efdf5693d9600552#3d51b11fe99c9d6a41b0d662efdf5693d9600552"
dependencies = [
"bitcoin",
]
[[package]]
name = "lightning-background-processor"
version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=6fcac8bc65ed6d372e0b8c367e9934c754f99ff3#6fcac8bc65ed6d372e0b8c367e9934c754f99ff3"
+source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=3d51b11fe99c9d6a41b0d662efdf5693d9600552#3d51b11fe99c9d6a41b0d662efdf5693d9600552"
dependencies = [
"bitcoin",
"lightning",
[[package]]
name = "lightning-block-sync"
version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=6fcac8bc65ed6d372e0b8c367e9934c754f99ff3#6fcac8bc65ed6d372e0b8c367e9934c754f99ff3"
+source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=3d51b11fe99c9d6a41b0d662efdf5693d9600552#3d51b11fe99c9d6a41b0d662efdf5693d9600552"
dependencies = [
"bitcoin",
"chunked_transfer",
[[package]]
name = "lightning-net-tokio"
version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=6fcac8bc65ed6d372e0b8c367e9934c754f99ff3#6fcac8bc65ed6d372e0b8c367e9934c754f99ff3"
+source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=3d51b11fe99c9d6a41b0d662efdf5693d9600552#3d51b11fe99c9d6a41b0d662efdf5693d9600552"
dependencies = [
"bitcoin",
"lightning",
[[package]]
name = "lightning-persister"
version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=6fcac8bc65ed6d372e0b8c367e9934c754f99ff3#6fcac8bc65ed6d372e0b8c367e9934c754f99ff3"
+source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=3d51b11fe99c9d6a41b0d662efdf5693d9600552#3d51b11fe99c9d6a41b0d662efdf5693d9600552"
dependencies = [
"bitcoin",
"libc",
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" }
+lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "3d51b11fe99c9d6a41b0d662efdf5693d9600552" }
# lightning-background-processor = { path = "../rust-lightning/background-processor" }
base64 = "0.13.0"
bitcoin = "0.26"
bitcoin-bech32 = "0.7"
bech32 = "0.7"
hex = "0.3"
-lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" }
+lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "3d51b11fe99c9d6a41b0d662efdf5693d9600552" }
# lightning = { path = "../rust-lightning/lightning" }
-lightning-block-sync = { git = "https://github.com/rust-bitcoin/rust-lightning", features = ["rpc-client"], rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" }
+lightning-block-sync = { git = "https://github.com/rust-bitcoin/rust-lightning", features = ["rpc-client"], rev = "3d51b11fe99c9d6a41b0d662efdf5693d9600552" }
# lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client"] }
lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning-invoice", rev = "aa3a57b9dca5205fa25fa333a2db165d7e77b3b0" }
-lightning-net-tokio = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" }
+lightning-net-tokio = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "3d51b11fe99c9d6a41b0d662efdf5693d9600552" }
# lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
-lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" }
+lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "3d51b11fe99c9d6a41b0d662efdf5693d9600552" }
# lightning-persister = { path = "../rust-lightning/lightning-persister" }
time = "0.2"
rand = "0.4"
use crate::cli;
-use bitcoin::hashes::hex::FromHex;
use bitcoin::secp256k1::key::PublicKey;
-use bitcoin::{BlockHash, Txid};
-use lightning::chain::channelmonitor::ChannelMonitor;
-use lightning::chain::keysinterface::{InMemorySigner, KeysManager};
-use lightning::chain::transaction::OutPoint;
use lightning::util::logger::{Logger, Record};
-use lightning::util::ser::{ReadableArgs, Writer};
+use lightning::util::ser::Writer;
use std::collections::HashMap;
use std::fs;
use std::fs::File;
-// use std::io::{BufRead, BufReader, Cursor, Write};
-use std::io::{BufRead, BufReader, Cursor};
+use std::io::{BufRead, BufReader};
use std::net::SocketAddr;
use std::path::Path;
-use std::sync::Arc;
use time::OffsetDateTime;
pub(crate) struct FilesystemLogger {
}
Ok(peer_data)
}
-
-pub(crate) fn read_channelmonitors(
- path: String, keys_manager: Arc<KeysManager>,
-) -> Result<HashMap<OutPoint, (BlockHash, ChannelMonitor<InMemorySigner>)>, std::io::Error> {
- if !Path::new(&path).exists() {
- return Ok(HashMap::new());
- }
- let mut outpoint_to_channelmonitor = HashMap::new();
- for file_option in fs::read_dir(path).unwrap() {
- let file = file_option.unwrap();
- let owned_file_name = file.file_name();
- let filename = owned_file_name.to_str();
- if !filename.is_some() || !filename.unwrap().is_ascii() || filename.unwrap().len() < 65 {
- return Err(std::io::Error::new(
- std::io::ErrorKind::Other,
- "Invalid ChannelMonitor file name",
- ));
- }
-
- let txid = Txid::from_hex(filename.unwrap().split_at(64).0);
- if txid.is_err() {
- return Err(std::io::Error::new(
- std::io::ErrorKind::Other,
- "Invalid tx ID in filename",
- ));
- }
-
- let index = filename.unwrap().split_at(65).1.split('.').next().unwrap().parse();
- if index.is_err() {
- return Err(std::io::Error::new(
- std::io::ErrorKind::Other,
- "Invalid tx index in filename",
- ));
- }
-
- let contents = fs::read(&file.path())?;
-
- if let Ok((blockhash, channel_monitor)) =
- <(BlockHash, ChannelMonitor<InMemorySigner>)>::read(
- &mut Cursor::new(&contents),
- &*keys_manager,
- ) {
- outpoint_to_channelmonitor.insert(
- OutPoint { txid: txid.unwrap(), index: index.unwrap() },
- (blockhash, channel_monitor),
- );
- } else {
- return Err(std::io::Error::new(
- std::io::ErrorKind::Other,
- "Failed to deserialize ChannelMonitor",
- ));
- }
- }
- Ok(outpoint_to_channelmonitor)
-}
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
use lightning::chain::chainmonitor;
use lightning::chain::keysinterface::{InMemorySigner, KeysInterface, KeysManager};
-use lightning::chain::transaction::OutPoint;
use lightning::chain::Filter;
use lightning::chain::Watch;
use lightning::ln::channelmanager;
SimpleArcChannelManager<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;
async fn handle_ldk_events(
- peer_manager: Arc<PeerManager>, channel_manager: Arc<ChannelManager>,
- chain_monitor: Arc<ChainMonitor>, bitcoind_client: Arc<BitcoindClient>,
- keys_manager: Arc<KeysManager>, payment_storage: PaymentInfoStorage, network: Network,
+ channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>,
+ bitcoind_client: Arc<BitcoindClient>, keys_manager: Arc<KeysManager>,
+ payment_storage: PaymentInfoStorage, network: Network,
) {
- let mut pending_txs: HashMap<OutPoint, Transaction> = HashMap::new();
loop {
- peer_manager.process_events();
let loop_channel_manager = channel_manager.clone();
let mut events = channel_manager.get_and_clear_pending_events();
events.append(&mut chain_monitor.get_and_clear_pending_events());
assert_eq!(signed_tx.complete, true);
let final_tx: Transaction =
encode::deserialize(&hex_utils::to_vec(&signed_tx.hex).unwrap()).unwrap();
- let outpoint = OutPoint {
- txid: final_tx.txid(),
- index: if change_output_position == 0 { 1 } else { 0 },
- };
// Give the funding transaction back to LDK for opening the channel.
loop_channel_manager
- .funding_transaction_generated(&temporary_channel_id, outpoint);
- pending_txs.insert(outpoint, final_tx);
+ .funding_transaction_generated(&temporary_channel_id, final_tx)
+ .unwrap();
}
Event::FundingBroadcastSafe { funding_txo, .. } => {
- let funding_tx = pending_txs.remove(&funding_txo).unwrap();
- bitcoind_client.broadcast_transaction(&funding_tx);
- println!("\nEVENT: broadcasted funding transaction");
- print!("> ");
- io::stdout().flush().unwrap();
- }
Event::PaymentReceived { payment_hash, payment_secret, amt: amt_msat } => {
let mut payments = payment_storage.lock().unwrap();
if let Some((Some(preimage), _, _, _)) = payments.get(&payment_hash) {
let keys_manager = Arc::new(KeysManager::new(&keys_seed, cur.as_secs(), cur.subsec_nanos()));
// Step 7: Read ChannelMonitor state from disk
- let monitors_path = format!("{}/monitors", ldk_data_dir.clone());
- let mut outpoint_to_channelmonitor =
- disk::read_channelmonitors(monitors_path.to_string(), keys_manager.clone()).unwrap();
+ let mut channelmonitors = persister.read_channelmonitors(keys_manager.clone()).unwrap();
// Step 9: Initialize the ChannelManager
let user_config = UserConfig::default();
let (channel_manager_blockhash, mut channel_manager) = {
if let Ok(mut f) = fs::File::open(format!("{}/manager", ldk_data_dir.clone())) {
let mut channel_monitor_mut_references = Vec::new();
- for (_, channel_monitor) in outpoint_to_channelmonitor.iter_mut() {
- channel_monitor_mut_references.push(&mut channel_monitor.1);
+ for (_, channel_monitor) in channelmonitors.iter_mut() {
+ channel_monitor_mut_references.push(channel_monitor);
}
let read_args = ChannelManagerReadArgs::new(
keys_manager.clone(),
let mut chain_listeners =
vec![(channel_manager_blockhash, &mut channel_manager as &mut dyn chain::Listen)];
- for (outpoint, blockhash_and_monitor) in outpoint_to_channelmonitor.drain() {
- let blockhash = blockhash_and_monitor.0;
- let channel_monitor = blockhash_and_monitor.1;
+ for (blockhash, channel_monitor) in channelmonitors.drain(..) {
+ let outpoint = channel_monitor.get_funding_txo().0;
chain_listener_channel_monitors.push((
blockhash,
(channel_monitor, broadcaster.clone(), fee_estimator.clone(), logger.clone()),
BackgroundProcessor::start(
persist_channel_manager_callback,
channel_manager.clone(),
+ peer_manager.clone(),
logger.clone(),
);
});
// Step 15: Initialize LDK Event Handling
- let peer_manager_event_listener = peer_manager.clone();
let channel_manager_event_listener = channel_manager.clone();
let chain_monitor_event_listener = chain_monitor.clone();
let keys_manager_listener = keys_manager.clone();
let bitcoind_rpc = bitcoind_client.clone();
tokio::spawn(async move {
handle_ldk_events(
- peer_manager_event_listener,
channel_manager_event_listener,
chain_monitor_event_listener,
bitcoind_rpc,