Skip to content

Commit 8699320

Browse files
committed
Drop futures dependency from lightning-block-sync
Some how I'd understood that `futures` had reasonable MSRV guarantees (e.g. at least Debian stable), but apparently that isn't actually the case, as they bumped it to upgrade to syn (with apparently no actual features or bugfixes added as a result?) with no minor version bump or any available alternative (unlike Tokio, which does LTS releases). Luckily its relatively easy to just drop the `futures` dependency - it means a new connection for each request, which is annoying, but certainly not the end of the world, and its easier than trying to deal with pinning `futures`. See rust-lang/futures-rs#2733
1 parent 783e818 commit 8699320

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

lightning-block-sync/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ rpc-client = [ "serde_json", "chunked_transfer" ]
2020
[dependencies]
2121
bitcoin = "0.29.0"
2222
lightning = { version = "0.0.114", path = "../lightning" }
23-
futures-util = { version = "0.3" }
2423
tokio = { version = "1.0", features = [ "io-util", "net", "time" ], optional = true }
2524
serde_json = { version = "1.0", optional = true }
2625
chunked_transfer = { version = "1.4", optional = true }

lightning-block-sync/src/rest.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,29 @@ use crate::http::{BinaryResponse, HttpEndpoint, HttpClient, JsonResponse};
77
use bitcoin::hash_types::BlockHash;
88
use bitcoin::hashes::hex::ToHex;
99

10-
use futures_util::lock::Mutex;
11-
1210
use std::convert::TryFrom;
1311
use std::convert::TryInto;
1412

1513
/// A simple REST client for requesting resources using HTTP `GET`.
1614
pub struct RestClient {
1715
endpoint: HttpEndpoint,
18-
client: Mutex<HttpClient>,
1916
}
2017

2118
impl RestClient {
2219
/// Creates a new REST client connected to the given endpoint.
2320
///
2421
/// The endpoint should contain the REST path component (e.g., http://127.0.0.1:8332/rest).
2522
pub fn new(endpoint: HttpEndpoint) -> std::io::Result<Self> {
26-
let client = Mutex::new(HttpClient::connect(&endpoint)?);
27-
Ok(Self { endpoint, client })
23+
Ok(Self { endpoint })
2824
}
2925

3026
/// Requests a resource encoded in `F` format and interpreted as type `T`.
3127
pub async fn request_resource<F, T>(&self, resource_path: &str) -> std::io::Result<T>
3228
where F: TryFrom<Vec<u8>, Error = std::io::Error> + TryInto<T, Error = std::io::Error> {
3329
let host = format!("{}:{}", self.endpoint.host(), self.endpoint.port());
3430
let uri = format!("{}/{}", self.endpoint.path().trim_end_matches("/"), resource_path);
35-
self.client.lock().await.get::<F>(&uri, &host).await?.try_into()
31+
let client = HttpClient::connect(&self.endpoint)?;
32+
client.get::<F>(&uri, &host).await?.try_into()
3633
}
3734
}
3835

lightning-block-sync/src/rpc.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ impl Error for RpcError {}
4141
pub struct RpcClient {
4242
basic_auth: String,
4343
endpoint: HttpEndpoint,
44-
client: Mutex<HttpClient>,
4544
id: AtomicUsize,
4645
}
4746

@@ -50,11 +49,9 @@ impl RpcClient {
5049
/// credentials should be a base64 encoding of a user name and password joined by a colon, as is
5150
/// required for HTTP basic access authentication.
5251
pub fn new(credentials: &str, endpoint: HttpEndpoint) -> std::io::Result<Self> {
53-
let client = Mutex::new(HttpClient::connect(&endpoint)?);
5452
Ok(Self {
5553
basic_auth: "Basic ".to_string() + credentials,
5654
endpoint,
57-
client,
5855
id: AtomicUsize::new(0),
5956
})
6057
}
@@ -73,7 +70,8 @@ impl RpcClient {
7370
"id": &self.id.fetch_add(1, Ordering::AcqRel).to_string()
7471
});
7572

76-
let mut response = match self.client.lock().await.post::<JsonResponse>(&uri, &host, &self.basic_auth, content).await {
73+
let client = HttpClient::connect(&self.endpoint)?;
74+
let mut response = match client.post::<JsonResponse>(&uri, &host, &self.basic_auth, content).await {
7775
Ok(JsonResponse(response)) => response,
7876
Err(e) if e.kind() == std::io::ErrorKind::Other => {
7977
match e.get_ref().unwrap().downcast_ref::<HttpError>() {

0 commit comments

Comments
 (0)