From 678119951c5b3460d24da64d0f2d755ef4f198e6 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 30 Mar 2021 13:44:17 -0400 Subject: [PATCH] Post-async refactor cleanup --- src/bitcoind_client.rs | 77 ------------------------------------------ src/cli.rs | 2 -- src/convert.rs | 12 +++---- src/main.rs | 18 +--------- 4 files changed, 5 insertions(+), 104 deletions(-) diff --git a/src/bitcoind_client.rs b/src/bitcoind_client.rs index 48d54f8..58510ae 100644 --- a/src/bitcoind_client.rs +++ b/src/bitcoind_client.rs @@ -153,19 +153,6 @@ impl BitcoindClient { fees.get(&Target::HighPriority) .unwrap() .store(high_prio_estimate, Ordering::Release); - // match fees.get(Target::Background) { - // Some(fee) => fee.store(background_estimate, Ordering::Release), - // None => - // } - // if let Some(fee) = background_estimate.feerate { - // fees.get("background").unwrap().store(fee, Ordering::Release); - // } - // if let Some(fee) = normal_estimate.feerate { - // fees.get("normal").unwrap().store(fee, Ordering::Release); - // } - // if let Some(fee) = high_prio_estimate.feerate { - // fees.get("high_prio").unwrap().store(fee, Ordering::Release); - // } tokio::time::sleep(Duration::from_secs(60)).await; } }); @@ -235,43 +222,6 @@ impl FeeEstimator for BitcoindClient { self.fees.get(&Target::HighPriority).unwrap().load(Ordering::Acquire) } } - // self.fees.g - // 253 - // match confirmation_target { - // ConfirmationTarget::Background => - // } - // let mut rpc = self.bitcoind_rpc_client.lock().unwrap(); - - // let (conf_target, estimate_mode, default) = match confirmation_target { - // ConfirmationTarget::Background => (144, "ECONOMICAL", 253), - // ConfirmationTarget::Normal => (18, "ECONOMICAL", 20000), - // ConfirmationTarget::HighPriority => (6, "CONSERVATIVE", 50000), - // }; - - // // This function may be called from a tokio runtime, or not. So we need to check before - // // making the call to avoid the error "cannot run a tokio runtime from within a tokio runtime". - // let conf_target_json = serde_json::json!(conf_target); - // let estimate_mode_json = serde_json::json!(estimate_mode); - // let resp = match Handle::try_current() { - // Ok(_) => tokio::task::block_in_place(|| { - // runtime - // .block_on(rpc.call_method::( - // "estimatesmartfee", - // &vec![conf_target_json, estimate_mode_json], - // )) - // .unwrap() - // }), - // _ => runtime - // .block_on(rpc.call_method::( - // "estimatesmartfee", - // &vec![conf_target_json, estimate_mode_json], - // )) - // .unwrap(), - // }; - // if resp.errored { - // return default; - // } - // resp.feerate.unwrap() } } @@ -283,32 +233,5 @@ impl BroadcasterInterface for BitcoindClient { let mut rpc = bitcoind_rpc_client.lock().await; rpc.call_method::("sendrawtransaction", &vec![tx_serialized]).await.unwrap(); }); - // let bitcoind_rpc_client = self.bitcoind_rpc_client.clone(); - // tokio::spawn(async move { - // let rpc = bitcoind_rpc_client.lock().await; - // rpc.call_method:: - // }); - // let mut rpc = self.bitcoind_rpc_client.lock().unwrap(); - // let runtime = self.runtime.lock().unwrap(); - - // let tx_serialized = serde_json::json!(encode::serialize_hex(tx)); - // // This function may be called from a tokio runtime, or not. So we need to check before - // // making the call to avoid the error "cannot run a tokio runtime from within a tokio runtime". - // match Handle::try_current() { - // Ok(_) => { - // tokio::task::block_in_place(|| { - // runtime - // .block_on( - // rpc.call_method::("sendrawtransaction", &vec![tx_serialized]), - // ) - // .unwrap(); - // }); - // } - // _ => { - // runtime - // .block_on(rpc.call_method::("sendrawtransaction", &vec![tx_serialized])) - // .unwrap(); - // } - // } } } diff --git a/src/cli.rs b/src/cli.rs index 56c788f..9589211 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -156,7 +156,6 @@ pub(crate) async fn poll_for_user_input( continue; }; - // let private_channel = match words.next().as_ref().map(String::as_str) { let announce_channel = match words.next() { Some("--public") | Some("--public=true") => true, Some("--public=false") => false, @@ -577,7 +576,6 @@ fn get_invoice( Some(info) => info, None => continue, }; - println!("VMW: adding routehop, info.fee base: {}", forwarding_info.fee_base_msat); invoice = invoice.route(vec![lightning_invoice::RouteHop { pubkey: channel.remote_network_id, short_channel_id, diff --git a/src/convert.rs b/src/convert.rs index 06677bc..7dbd8cc 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -52,7 +52,6 @@ impl TryInto for JsonResponse { pub struct FeeResponse { pub feerate: Option, - // pub errors: Array, pub errored: bool, } @@ -62,13 +61,10 @@ impl TryInto for JsonResponse { let errored = !self.0["errors"].is_null(); Ok(FeeResponse { errored, - feerate: match self.0["feerate"].as_f64() { - Some(fee) => Some((fee * 100_000_000.0).round() as u32), - None => None - } - // true => None, - // // The feerate from bitcoind is in BTC/kb, and we want satoshis/kb. - // false => Some((self.0["feerate"].as_f64().unwrap() * 100_000_000.0).round() as u32), + feerate: match self.0["feerate"].as_f64() { + Some(fee) => Some((fee * 100_000_000.0).round() as u32), + None => None, + }, }) } } diff --git a/src/main.rs b/src/main.rs index 8c5793a..ab95086 100644 --- a/src/main.rs +++ b/src/main.rs @@ -237,7 +237,6 @@ async fn handle_ldk_events( tokio::spawn(async move { let min = time_forwardable.as_secs(); let seconds_to_sleep = thread_rng().gen_range(min, min * 5); - // thread::sleep(Duration::new(seconds_to_sleep, 0)); tokio::time::sleep(Duration::from_secs(seconds_to_sleep)).await; forwarding_channel_manager.process_pending_htlc_forwards(); }); @@ -277,7 +276,7 @@ pub async fn main() { fs::create_dir_all(ldk_data_dir.clone()).unwrap(); // Initialize our bitcoind client. - let mut bitcoind_client = match BitcoindClient::new( + let bitcoind_client = match BitcoindClient::new( args.bitcoind_rpc_host.clone(), args.bitcoind_rpc_port, args.bitcoind_rpc_username.clone(), @@ -291,7 +290,6 @@ pub async fn main() { return; } }; - // let mut bitcoind_rpc_client = bitcoind_client.get_new_rpc_client().unwrap(); // ## Setup // Step 1: Initialize the FeeEstimator @@ -421,7 +419,6 @@ pub async fn main() { } chain_tip = Some( init::synchronize_listeners( - // &mut bitcoind_rpc_client, &mut bitcoind_client.deref(), args.network, &mut cache, @@ -482,21 +479,16 @@ pub async fn main() { // Step 17: Connect and Disconnect Blocks if chain_tip.is_none() { - // chain_tip = Some(init::validate_best_block_header(&mut bitcoind_client).await.unwrap()); chain_tip = Some(init::validate_best_block_header(&mut bitcoind_client.deref()).await.unwrap()); - // chain_tip = Some(init::validate_best_block_header(&mut bitcoind_rpc_client).await.unwrap()); } let channel_manager_listener = channel_manager.clone(); let chain_monitor_listener = chain_monitor.clone(); let bitcoind_block_source = bitcoind_client.clone(); let network = args.network; tokio::spawn(async move { - // let chain_poller = poll::ChainPoller::new(&mut bitcoind_client, network); let mut derefed = bitcoind_block_source.deref(); - // let chain_poller = poll::ChainPoller::new(&mut bitcoind_block_source.deref(), network); let chain_poller = poll::ChainPoller::new(&mut derefed, network); - // let chain_poller = poll::ChainPoller::new(&mut bitcoind_rpc_client, network); let chain_listener = (chain_monitor_listener, channel_manager_listener); let mut spv_client = SpvClient::new(chain_tip.unwrap(), chain_poller, &mut cache, &chain_listener); @@ -533,21 +525,13 @@ pub async fn main() { let payment_info: PaymentInfoStorage = Arc::new(Mutex::new(HashMap::new())); let payment_info_for_events = payment_info.clone(); let network = args.network; - // let bitcoind = BitcoindClient::new( - // args.bitcoind_rpc_host.clone(), - // args.bitcoind_rpc_port, - // args.bitcoind_rpc_username.clone(), - // args.bitcoind_rpc_password.clone(), - // ).await.unwrap(); 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_client.clone(), bitcoind_rpc, - // bitcoind, keys_manager_listener, payment_info_for_events, network, -- 2.30.2