Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ldk v0.0.118 #163

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitcoin-rpc-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
54 changes: 48 additions & 6 deletions bitcoin-rpc-provider/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<ConfirmationTarget, AtomicU32> = 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 }
Expand Down Expand Up @@ -378,19 +401,35 @@ fn poll_for_fee_estimates(
fees: Arc<HashMap<ConfirmationTarget, AtomicU32>>,
) {
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);
}
};
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);
}
Expand All @@ -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);
Tibo-lg marked this conversation as resolved.
Show resolved Hide resolved
}
Err(e) => {
error!("Error querying fee estimate: {}", e);
Expand Down
3 changes: 1 addition & 2 deletions bitcoin-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ pub fn from_hex(hex: &str, target: &mut [u8]) -> Result<usize, ()> {
/// Transforms an hex string to a Vec<u8>.
/// Panics if the string is not valid hex.
pub fn str_to_hex(hex_str: &str) -> Vec<u8> {
let mut hex = Vec::<u8>::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
}
Expand Down
2 changes: 1 addition & 1 deletion dlc-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion dlc-manager/src/conversion_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion dlc-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 1 addition & 4 deletions dlc-manager/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion dlc-messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion dlc-sled-storage-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion dlc-trie/src/multi_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ mod tests {
}

fn variable_len_test_cases() -> Vec<VariableLengthTestCase> {
let black_list = vec![5, 7];
let black_list = [5, 7];
let mut test_cases = test_cases()
.into_iter()
.enumerate()
Expand Down
4 changes: 2 additions & 2 deletions electrs-blockchain-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
24 changes: 20 additions & 4 deletions electrs-blockchain-provider/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::max;
use std::collections::HashMap;
use std::str::FromStr;
use std::sync::atomic::{AtomicU32, Ordering};
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["."]
2 changes: 1 addition & 1 deletion mocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
4 changes: 2 additions & 2 deletions sample/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions sample/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct OracleConfig {
#[derive(Debug)]
pub struct NetworkConfig {
pub peer_listening_port: u16,
pub announced_listen_addr: Option<NetAddress>,
pub announced_listen_addr: Option<SocketAddress>,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -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,
}),
Expand Down
2 changes: 1 addition & 1 deletion simple-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
4 changes: 2 additions & 2 deletions simple-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -275,7 +276,6 @@ where
self.storage.upsert_utxo(&updated)?;
}
res.push(org.clone());

}
Ok(res)
}
Expand Down
Loading