Skip to content

Commit 1293259

Browse files
authored
Merge pull request #500 from hashgraph/sr/deps
2 parents e632550 + 2cd0b92 commit 1293259

File tree

14 files changed

+643
-594
lines changed

14 files changed

+643
-594
lines changed

Cargo.lock

Lines changed: 449 additions & 422 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ mnemonic = []
2020
[dependencies]
2121
async-stream = "0.3.3"
2222
backoff = "0.4.0"
23-
ed25519-dalek = { version = "2.0.0-pre.0", features = ["rand_core"] }
24-
fraction = { version = "0.11.0", default-features = false }
23+
ed25519-dalek = { version = "2.0.0-rc.2", features = ["rand_core"] }
24+
fraction = { version = "0.13.0", default-features = false }
2525
futures-core = "0.3.21"
26-
futures-util = "0.3.21"
2726
hedera-proto = { path = "./protobufs", version = "0.6.0", features = [
2827
"time_0_3",
2928
"fraction",
@@ -33,35 +32,42 @@ hmac = "0.12.1"
3332
log = "0.4.17"
3433
num-bigint = "0.4.3"
3534
once_cell = "1.10.0"
36-
parking_lot = "0.12.0"
37-
pbkdf2 = { version = "0.11.0", default-features = false }
38-
pem-rfc7468 = { version = "0.6.0", features = ["std"] }
39-
prost = "0.11.0"
35+
pbkdf2 = { version = "0.12.0", default-features = false }
36+
pem-rfc7468 = { version = "0.7.0", features = ["std"] }
4037
rand = "0.8.5"
4138
sha2 = "0.10.2"
4239
sha3 = "0.10.2"
4340
thiserror = "1.0.31"
4441
time = "0.3.9"
45-
tokio = { version = "1.24.2", features = ["rt-multi-thread"] }
46-
tonic = "0.8.0"
47-
tinystr = "0.7.0"
42+
tokio = { version = "1.24.2", features = ["time"] }
43+
tonic = "0.9.0"
44+
tinystr = { version = "0.7.0", default-features = false }
4845
arc-swap = "1.6.0"
4946
rlp = "0.5.2"
50-
bytes = "1.2.1"
47+
bytes = { version = "1.2.1", default-features = false }
5148
pin-project-lite = "0.2.9"
5249

50+
[dependencies.futures-util]
51+
version = "0.3.21"
52+
default-features = false
53+
54+
[dependencies.prost]
55+
version = "0.11"
56+
default-features = false
57+
features = ["std"]
58+
5359
[dependencies.rust_decimal]
5460
version = "1.26.1"
5561
default-features = false
5662
features = ["std"]
5763

5864
[dependencies.k256]
59-
version = "0.12.0"
65+
version = "0.13.0"
6066
default-features = false
61-
features = ["arithmetic", "ecdsa", "pkcs8", "precomputed-tables", "std"]
67+
features = ["ecdsa", "precomputed-tables", "std"]
6268

6369
[dependencies.pkcs8]
64-
version = "0.9.0"
70+
version = "0.10.0"
6571
default_features = false
6672
features = ["encryption"]
6773

@@ -70,7 +76,15 @@ anyhow = "1.0.57"
7076
assert_matches = "1.5.0"
7177
clap = { version = "4.0.0", features = ["derive", "env"] }
7278
dotenvy = "0.15.5"
73-
env_logger = "0.10.0"
7479
expect-test = "1.4.0"
75-
hex-literal = "0.3.4"
76-
tokio = { version = "1.24.2", features = ["full"] }
80+
hex-literal = "0.4.0"
81+
parking_lot = "0.12.0"
82+
83+
[dev-dependencies.tokio]
84+
version = "1.24.2"
85+
features = ["rt-multi-thread", "macros"]
86+
87+
[dev-dependencies.env_logger]
88+
version = "0.10.0"
89+
default-features = false
90+
features = ["auto-color", "color", "humantime"]

protobufs/Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ version = "0.6.0"
99
[features]
1010

1111
[dependencies]
12-
fraction = { version = "0.11.0", optional = true }
13-
prost = "0.11.0"
12+
fraction = { version = "0.13.0", default-features = false, optional = true }
1413
prost-types = "0.11.0"
1514
time_0_3 = { version = "0.3.9", optional = true, package = "time" }
1615

16+
[dependencies.prost]
17+
version = "0.11"
18+
default-features = false
19+
features = ["std", "prost-derive"]
20+
1721
# todo: get the tonic devs to actually make `channel` usable without `transport` (it *should*, it's *documented* as such, but it just doesn't work).
1822
[dependencies.tonic]
19-
version = "0.8.0"
23+
version = "0.9.0"
2024

2125
[build-dependencies]
2226
anyhow = "1.0.55"
23-
tonic-build = "0.8.0"
27+
tonic-build = "0.9.0"

src/client/mirror_network.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use std::borrow::Cow;
2222
use std::time::Duration;
2323

24-
use parking_lot::RwLock;
24+
use once_cell::sync::OnceCell;
2525
use tonic::transport::{
2626
Channel,
2727
Endpoint,
@@ -35,7 +35,7 @@ pub(crate) const PREVIEWNET: &str = "hcs.previewnet.mirrornode.hedera.com:5600";
3535

3636
pub(crate) struct MirrorNetwork {
3737
addresses: Vec<Cow<'static, str>>,
38-
channel: RwLock<Option<Channel>>,
38+
channel: OnceCell<Channel>,
3939
}
4040

4141
impl MirrorNetwork {
@@ -58,30 +58,24 @@ impl MirrorNetwork {
5858
addresses.push(Cow::Borrowed(*address));
5959
}
6060

61-
Self { addresses, channel: RwLock::new(None) }
61+
Self { addresses, channel: OnceCell::new() }
6262
}
6363

6464
pub(crate) fn channel(&self) -> Channel {
65-
if let Some(channel) = &*self.channel.read_recursive() {
66-
return channel.clone();
67-
}
68-
69-
let mut slot = self.channel.write();
70-
71-
let endpoints = self.addresses.iter().map(|address| {
72-
let uri = format!("tcp://{address}");
73-
Endpoint::from_shared(uri)
74-
.unwrap()
75-
.keep_alive_timeout(Duration::from_secs(10))
76-
.keep_alive_while_idle(true)
77-
.tcp_keepalive(Some(Duration::from_secs(10)))
78-
.connect_timeout(Duration::from_secs(10))
79-
});
80-
81-
let channel = Channel::balance_list(endpoints);
82-
83-
*slot = Some(channel.clone());
84-
85-
channel
65+
self.channel
66+
.get_or_init(|| {
67+
let endpoints = self.addresses.iter().map(|address| {
68+
let uri = format!("tcp://{address}");
69+
Endpoint::from_shared(uri)
70+
.unwrap()
71+
.keep_alive_timeout(Duration::from_secs(10))
72+
.keep_alive_while_idle(true)
73+
.tcp_keepalive(Some(Duration::from_secs(10)))
74+
.connect_timeout(Duration::from_secs(10))
75+
});
76+
77+
Channel::balance_list(endpoints)
78+
})
79+
.clone()
8680
}
8781
}

src/client/network.rs

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::sync::atomic::{
2626
};
2727
use std::time::Duration;
2828

29-
use parking_lot::RwLock;
29+
use once_cell::sync::OnceCell;
3030
use time::OffsetDateTime;
3131
use tonic::transport::{
3232
Channel,
@@ -141,7 +141,7 @@ pub(crate) struct Network {
141141
map: HashMap<AccountId, usize>,
142142
nodes: Vec<AccountId>,
143143
addresses: Vec<Vec<Cow<'static, str>>>,
144-
channels: Vec<RwLock<Option<Channel>>>,
144+
channels: Vec<OnceCell<Channel>>,
145145
healthy: Vec<AtomicI64>,
146146
last_pinged: Vec<AtomicI64>,
147147
}
@@ -173,7 +173,7 @@ impl Network {
173173
map.insert(node_account_id, i);
174174
nodes.push(node_account_id);
175175
addresses.push(address.iter().map(|address| Cow::Borrowed(*address)).collect());
176-
channels.push(RwLock::new(None));
176+
channels.push(OnceCell::new());
177177
healthy.push(AtomicI64::new(0));
178178
last_pinged.push(AtomicI64::new(0));
179179
}
@@ -236,39 +236,23 @@ impl Network {
236236
pub(crate) fn channel(&self, index: usize) -> (AccountId, Channel) {
237237
let id = self.nodes[index];
238238

239-
// Double lock check: We'd really rather not take a write lock if possible.
240-
// (paired with the below comment)
241-
if let Some(channel) = &*self.channels[index].read_recursive() {
242-
return (id, channel.clone());
243-
}
244-
245-
let mut slot = self.channels[index].write();
246-
247-
// Double lock check: We'd rather not replace the channel if one exists already, they aren't free.
248-
// (paired with the above comment)
249-
// Between returning `None` in the above `read` and getting
250-
// the `WriteGuard` some *other* write to this channel could've happened
251-
// causing the channel to be `Some` here, despite this thread not
252-
// changing it.
253-
if let Some(channel) = &*slot {
254-
return (id, channel.clone());
255-
}
256-
257-
let addresses = &self.addresses[index];
258-
259-
let endpoints = addresses.iter().map(|address| {
260-
let uri = format!("tcp://{address}:50211");
261-
Endpoint::from_shared(uri)
262-
.unwrap()
263-
.keep_alive_timeout(Duration::from_secs(10))
264-
.keep_alive_while_idle(true)
265-
.tcp_keepalive(Some(Duration::from_secs(10)))
266-
.connect_timeout(Duration::from_secs(10))
267-
});
268-
269-
let channel = Channel::balance_list(endpoints);
270-
271-
*slot = Some(channel.clone());
239+
let channel = self.channels[index]
240+
.get_or_init(|| {
241+
let addresses = &self.addresses[index];
242+
243+
let endpoints = addresses.iter().map(|address| {
244+
let uri = format!("tcp://{address}:50211");
245+
Endpoint::from_shared(uri)
246+
.unwrap()
247+
.keep_alive_timeout(Duration::from_secs(10))
248+
.keep_alive_while_idle(true)
249+
.tcp_keepalive(Some(Duration::from_secs(10)))
250+
.connect_timeout(Duration::from_secs(10))
251+
});
252+
253+
Channel::balance_list(endpoints)
254+
})
255+
.clone();
272256

273257
(id, channel)
274258
}

src/contract/contract_function_result.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ impl FromProtobuf<services::response::Response> for ContractFunctionResult {
278278

279279
#[cfg(test)]
280280
mod tests {
281-
use fraction::{
281+
use hedera_proto::services;
282+
use hex_literal::hex;
283+
use num_bigint::{
282284
BigInt,
283285
BigUint,
284286
};
285-
use hedera_proto::services;
286-
use hex_literal::hex;
287287

288288
use crate::protobuf::{
289289
FromProtobuf,

src/execute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ where
194194
)
195195
};
196196

197-
futures_util::pin_mut!(random_node_indexes);
197+
let mut random_node_indexes = std::pin::pin!(random_node_indexes);
198198

199199
while let Some(node_index) = random_node_indexes.next().await {
200200
let tmp = execute_single(

0 commit comments

Comments
 (0)