diff --git a/bitcoin-rpc-provider/Cargo.toml b/bitcoin-rpc-provider/Cargo.toml index e7926592..3d6bff11 100644 --- a/bitcoin-rpc-provider/Cargo.toml +++ b/bitcoin-rpc-provider/Cargo.toml @@ -9,7 +9,7 @@ bitcoin = {version = "0.29.2"} bitcoincore-rpc = {version = "0.16.0"} bitcoincore-rpc-json = {version = "0.16.0"} dlc-manager = {path = "../dlc-manager"} -lightning = {version = "0.0.116"} +lightning = { version = "0.0.118" } log = "0.4.14" rust-bitcoin-coin-selection = { version = "0.1.0", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", rev = "405451929568422f7df809e35d6ad8f36fccce90", features = ["rand"] } simple-wallet = {path = "../simple-wallet"} diff --git a/bitcoin-rpc-provider/src/lib.rs b/bitcoin-rpc-provider/src/lib.rs index 13e7c9ca..112a4b00 100644 --- a/bitcoin-rpc-provider/src/lib.rs +++ b/bitcoin-rpc-provider/src/lib.rs @@ -1,5 +1,6 @@ //! # Bitcoin rpc provider +use std::cmp::max; use std::collections::HashMap; use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::{Arc, Mutex}; @@ -101,9 +102,31 @@ impl BitcoinCoreProvider { pub fn new_from_rpc_client(rpc_client: Client) -> Self { let client = Arc::new(Mutex::new(rpc_client)); let mut fees: HashMap = HashMap::new(); - fees.insert(ConfirmationTarget::Background, AtomicU32::new(MIN_FEERATE)); - fees.insert(ConfirmationTarget::Normal, AtomicU32::new(2000)); - fees.insert(ConfirmationTarget::HighPriority, AtomicU32::new(5000)); + fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000)); + fees.insert( + ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee, + AtomicU32::new(25 * 250), + ); + fees.insert( + ConfirmationTarget::MinAllowedAnchorChannelRemoteFee, + AtomicU32::new(MIN_FEERATE), + ); + fees.insert( + ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee, + AtomicU32::new(MIN_FEERATE), + ); + fees.insert( + ConfirmationTarget::AnchorChannelFee, + AtomicU32::new(MIN_FEERATE), + ); + fees.insert( + ConfirmationTarget::NonAnchorChannelFee, + AtomicU32::new(2000), + ); + fees.insert( + ConfirmationTarget::ChannelCloseMinimum, + AtomicU32::new(MIN_FEERATE), + ); let fees = Arc::new(fees); poll_for_fee_estimates(client.clone(), fees.clone()); BitcoinCoreProvider { client, fees } @@ -378,11 +401,27 @@ fn poll_for_fee_estimates( fees: Arc>, ) { std::thread::spawn(move || loop { + match query_fee_estimate(&client, 1008, EstimateMode::Economical) { + Ok(fee_rate) => { + fees.get(&ConfirmationTarget::MinAllowedAnchorChannelRemoteFee) + .unwrap() + .store(fee_rate, Ordering::Release); + } + Err(e) => { + error!("Error querying fee estimate: {}", e); + } + }; match query_fee_estimate(&client, 144, EstimateMode::Economical) { Ok(fee_rate) => { - fees.get(&ConfirmationTarget::Background) + fees.get(&ConfirmationTarget::AnchorChannelFee) + .unwrap() + .store(fee_rate, Ordering::Release); + fees.get(&ConfirmationTarget::ChannelCloseMinimum) .unwrap() .store(fee_rate, Ordering::Release); + fees.get(&ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee) + .unwrap() + .store(fee_rate - 250, Ordering::Release); } Err(e) => { error!("Error querying fee estimate: {}", e); @@ -390,7 +429,7 @@ fn poll_for_fee_estimates( }; match query_fee_estimate(&client, 18, EstimateMode::Conservative) { Ok(fee_rate) => { - fees.get(&ConfirmationTarget::Normal) + fees.get(&ConfirmationTarget::NonAnchorChannelFee) .unwrap() .store(fee_rate, Ordering::Release); } @@ -400,9 +439,12 @@ fn poll_for_fee_estimates( }; match query_fee_estimate(&client, 6, EstimateMode::Conservative) { Ok(fee_rate) => { - fees.get(&ConfirmationTarget::HighPriority) + fees.get(&ConfirmationTarget::OnChainSweep) .unwrap() .store(fee_rate, Ordering::Release); + fees.get(&ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee) + .unwrap() + .store(max(25 * 250, fee_rate * 10), Ordering::Release); } Err(e) => { error!("Error querying fee estimate: {}", e); diff --git a/bitcoin-test-utils/src/lib.rs b/bitcoin-test-utils/src/lib.rs index d79cfaf1..165a54d2 100644 --- a/bitcoin-test-utils/src/lib.rs +++ b/bitcoin-test-utils/src/lib.rs @@ -42,8 +42,7 @@ pub fn from_hex(hex: &str, target: &mut [u8]) -> Result { /// Transforms an hex string to a Vec. /// Panics if the string is not valid hex. pub fn str_to_hex(hex_str: &str) -> Vec { - let mut hex = Vec::::new(); - hex.resize(hex_str.len() / 2, 0); + let mut hex = vec![0; hex_str.len() / 2]; from_hex(hex_str, &mut hex).unwrap(); hex } diff --git a/dlc-manager/Cargo.toml b/dlc-manager/Cargo.toml index 58a98fa9..4ada9f89 100644 --- a/dlc-manager/Cargo.toml +++ b/dlc-manager/Cargo.toml @@ -21,7 +21,7 @@ bitcoin = { version = "0.29.2", default-features = false } dlc = { version = "0.4.0", default-features = false, path = "../dlc" } dlc-messages = { version = "0.4.0", default-features = false, path = "../dlc-messages" } dlc-trie = { version = "0.4.0", default-features = false, path = "../dlc-trie" } -lightning = { version = "0.0.116", default-features = false, features = ["grind_signatures"] } +lightning = { version = "0.0.118", default-features = false, features = ["grind_signatures"] } log = "0.4.14" rand_chacha = {version = "0.3.1", optional = true} secp256k1-zkp = {version = "0.7.0"} diff --git a/dlc-manager/src/conversion_utils.rs b/dlc-manager/src/conversion_utils.rs index 51625090..af998c39 100644 --- a/dlc-manager/src/conversion_utils.rs +++ b/dlc-manager/src/conversion_utils.rs @@ -53,7 +53,7 @@ impl fmt::Display for Error { } } -#[cfg(not(feature = "no-std"))] +#[cfg(feature = "std")] impl std::error::Error for Error { fn cause(&self) -> Option<&dyn std::error::Error> { match *self { diff --git a/dlc-manager/src/manager.rs b/dlc-manager/src/manager.rs index 0d98cec5..b4486674 100644 --- a/dlc-manager/src/manager.rs +++ b/dlc-manager/src/manager.rs @@ -1991,7 +1991,7 @@ where }; let fee_rate_per_vb: u64 = (self.fee_estimator.get_est_sat_per_1000_weight( - lightning::chain::chaininterface::ConfirmationTarget::HighPriority, + lightning::chain::chaininterface::ConfirmationTarget::OnChainSweep, ) / 250) .into(); diff --git a/dlc-manager/tests/test_utils.rs b/dlc-manager/tests/test_utils.rs index cf90edd1..57ce74a9 100644 --- a/dlc-manager/tests/test_utils.rs +++ b/dlc-manager/tests/test_utils.rs @@ -547,10 +547,7 @@ pub fn get_enum_and_numerical_test_params( }; TestParams { - oracles: enum_oracles - .into_iter() - .chain(numerical_oracles.into_iter()) - .collect(), + oracles: enum_oracles.into_iter().chain(numerical_oracles).collect(), contract_input, } } diff --git a/dlc-messages/Cargo.toml b/dlc-messages/Cargo.toml index e58c9055..1dd34713 100644 --- a/dlc-messages/Cargo.toml +++ b/dlc-messages/Cargo.toml @@ -16,7 +16,7 @@ use-serde = ["serde", "secp256k1-zkp/use-serde"] [dependencies] bitcoin = { version = "0.29.2", default-features = false } dlc = { version = "0.4.0", path = "../dlc", default-features = false } -lightning = { version = "0.0.116", default-features = false } +lightning = { version = "0.0.118", default-features = false } secp256k1-zkp = {version = "0.7.0"} serde = {version = "1.0", features = ["derive"], optional = true} diff --git a/dlc-sled-storage-provider/Cargo.toml b/dlc-sled-storage-provider/Cargo.toml index 87ef5cbc..dfb073ed 100644 --- a/dlc-sled-storage-provider/Cargo.toml +++ b/dlc-sled-storage-provider/Cargo.toml @@ -14,7 +14,7 @@ wallet = ["bitcoin", "secp256k1-zkp", "simple-wallet", "lightning"] [dependencies] bitcoin = {version = "0.29", optional = true} dlc-manager = {path = "../dlc-manager"} -lightning = {version = "0.0.116", optional = true} +lightning = {version = "0.0.118", optional = true} secp256k1-zkp = {version = "0.7", optional = true} simple-wallet = {path = "../simple-wallet", optional = true} sled = "0.34" diff --git a/dlc-trie/src/multi_oracle.rs b/dlc-trie/src/multi_oracle.rs index 66dc4293..7b6620db 100644 --- a/dlc-trie/src/multi_oracle.rs +++ b/dlc-trie/src/multi_oracle.rs @@ -800,7 +800,7 @@ mod tests { } fn variable_len_test_cases() -> Vec { - let black_list = vec![5, 7]; + let black_list = [5, 7]; let mut test_cases = test_cases() .into_iter() .enumerate() diff --git a/electrs-blockchain-provider/Cargo.toml b/electrs-blockchain-provider/Cargo.toml index 9b91cdf2..a3c762a9 100644 --- a/electrs-blockchain-provider/Cargo.toml +++ b/electrs-blockchain-provider/Cargo.toml @@ -9,8 +9,8 @@ version = "0.1.0" bitcoin = {version = "0.29"} bitcoin-test-utils = {path = "../bitcoin-test-utils"} dlc-manager = {path = "../dlc-manager"} -lightning = {version = "0.0.116"} -lightning-block-sync = {version = "0.0.116"} +lightning = {version = "0.0.118"} +lightning-block-sync = {version = "0.0.118"} reqwest = {version = "0.11", features = ["blocking", "json"]} serde = {version = "*", features = ["derive"]} simple-wallet = {path = "../simple-wallet"} diff --git a/electrs-blockchain-provider/src/lib.rs b/electrs-blockchain-provider/src/lib.rs index fe317619..210224a1 100644 --- a/electrs-blockchain-provider/src/lib.rs +++ b/electrs-blockchain-provider/src/lib.rs @@ -1,3 +1,4 @@ +use std::cmp::max; use std::collections::HashMap; use std::str::FromStr; use std::sync::atomic::{AtomicU32, Ordering}; @@ -206,26 +207,41 @@ impl simple_wallet::WalletBlockchainProvider for ElectrsBlockchainProvider { impl FeeEstimator for ElectrsBlockchainProvider { fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 { let est = match confirmation_target { - ConfirmationTarget::MempoolMinimum => self + ConfirmationTarget::MinAllowedAnchorChannelRemoteFee => self .fees .get(&Target::Minimum) .unwrap() .load(Ordering::Acquire), - ConfirmationTarget::Background => self + ConfirmationTarget::AnchorChannelFee | ConfirmationTarget::ChannelCloseMinimum => self .fees .get(&Target::Background) .unwrap() .load(Ordering::Acquire), - ConfirmationTarget::Normal => self + ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => { + self.fees + .get(&Target::Background) + .unwrap() + .load(Ordering::Acquire) + - 250 + } + ConfirmationTarget::NonAnchorChannelFee => self .fees .get(&Target::Normal) .unwrap() .load(Ordering::Acquire), - ConfirmationTarget::HighPriority => self + ConfirmationTarget::OnChainSweep => self .fees .get(&Target::HighPriority) .unwrap() .load(Ordering::Acquire), + ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => { + let high = self + .fees + .get(&Target::HighPriority) + .unwrap() + .load(Ordering::Acquire); + max(25 * 250, high * 10) + } }; u32::max(est, MIN_FEERATE) } diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index c14827ea..0cb58780 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -10,7 +10,7 @@ cargo-fuzz = true [dependencies] dlc-messages = {path = "../dlc-messages"} honggfuzz = "0.5" -lightning = {version = "0.0.116" } +lightning = {version = "0.0.118" } [workspace] members = ["."] diff --git a/mocks/Cargo.toml b/mocks/Cargo.toml index 220638eb..e113b1a4 100644 --- a/mocks/Cargo.toml +++ b/mocks/Cargo.toml @@ -9,6 +9,6 @@ bitcoin = "0.29" dlc = {path = "../dlc"} dlc-manager = {path = "../dlc-manager"} dlc-messages = {path = "../dlc-messages"} -lightning = {version = "0.0.116"} +lightning = {version = "0.0.118"} secp256k1-zkp = {version = "0.7.0", features = ["bitcoin_hashes", "global-context", "rand", "rand-std"]} simple-wallet = {path = "../simple-wallet"} diff --git a/sample/Cargo.toml b/sample/Cargo.toml index f1d96905..bde07bf1 100644 --- a/sample/Cargo.toml +++ b/sample/Cargo.toml @@ -12,8 +12,8 @@ dlc-manager = {path = "../dlc-manager", features = ["use-serde", "parallel"]} dlc-messages = {path = "../dlc-messages"} dlc-sled-storage-provider = {path = "../dlc-sled-storage-provider"} futures = "0.3" -lightning = {version = "0.0.116"} -lightning-net-tokio = {version = "0.0.116" } +lightning = {version = "0.0.118"} +lightning-net-tokio = {version = "0.0.118" } p2pd-oracle-client = {path = "../p2pd-oracle-client"} serde = "1.0" serde_json = "1.0" diff --git a/sample/src/cli.rs b/sample/src/cli.rs index 0740f0b2..367fb689 100644 --- a/sample/src/cli.rs +++ b/sample/src/cli.rs @@ -12,7 +12,7 @@ use dlc_manager::contract::Contract; use dlc_manager::Storage; use dlc_messages::Message as DlcMessage; use hex_utils::{hex_str, to_slice}; -use lightning::ln::msgs::NetAddress; +use lightning::ln::msgs::SocketAddress; use serde::Deserialize; use serde_json::Value; use std::convert::TryInto; @@ -44,7 +44,7 @@ pub struct OracleConfig { #[derive(Debug)] pub struct NetworkConfig { pub peer_listening_port: u16, - pub announced_listen_addr: Option, + pub announced_listen_addr: Option, } #[derive(Debug, Deserialize)] @@ -76,13 +76,13 @@ where { let buf = announced_listen_addr .as_str() - .expect("Error parsing announcedListeAddr"); + .expect("Error parsing announcedListenAddr"); match IpAddr::from_str(buf) { - Ok(IpAddr::V4(a)) => Some(NetAddress::IPv4 { + Ok(IpAddr::V4(a)) => Some(SocketAddress::TcpIpV4 { addr: a.octets(), port: peer_listening_port, }), - Ok(IpAddr::V6(a)) => Some(NetAddress::IPv6 { + Ok(IpAddr::V6(a)) => Some(SocketAddress::TcpIpV6 { addr: a.octets(), port: peer_listening_port, }), diff --git a/simple-wallet/Cargo.toml b/simple-wallet/Cargo.toml index bf7c3309..748cd965 100644 --- a/simple-wallet/Cargo.toml +++ b/simple-wallet/Cargo.toml @@ -9,7 +9,7 @@ version = "0.1.0" bitcoin = "0.29" dlc = {path = "../dlc"} dlc-manager = {path = "../dlc-manager"} -lightning = {version = "0.0.116"} +lightning = {version = "0.0.118"} bdk = {version = "0.28.0"} secp256k1-zkp = {version = "0.7.0"} diff --git a/simple-wallet/src/lib.rs b/simple-wallet/src/lib.rs index 401cd19b..3f835866 100644 --- a/simple-wallet/src/lib.rs +++ b/simple-wallet/src/lib.rs @@ -149,7 +149,8 @@ where let weight = (tx.weight() + tx.input.len() * (74 + 33)) as u64; let fee_rate = self .blockchain - .get_est_sat_per_1000_weight(ConfirmationTarget::Normal) as u64; + .get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee) + as u64; let fee = (weight * fee_rate) / 1000; tx.output[0].value -= fee; @@ -275,7 +276,6 @@ where self.storage.upsert_utxo(&updated)?; } res.push(org.clone()); - } Ok(res) }