diff --git a/Cargo.lock b/Cargo.lock index b02841020cc..ae507dbe194 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3713,9 +3713,7 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +version = "1.11.0" [[package]] name = "oorandom" diff --git a/Cargo.toml b/Cargo.toml index c8b538b5523..2cf518e3d91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,7 @@ version = "0.13.0" exclude = [ "neard" ] [patch.crates-io] +once_cell = {path="/home/matklad/p/once_cell"} # Note that "bench" profile inherits from "release" profile and # "test" profile inherits from "dev" profile. diff --git a/chain/network/src/test_utils.rs b/chain/network/src/test_utils.rs index 259c6812c45..4940807fa3d 100644 --- a/chain/network/src/test_utils.rs +++ b/chain/network/src/test_utils.rs @@ -13,7 +13,7 @@ use near_primitives::hash::hash; use near_primitives::network::PeerId; use near_primitives::types::EpochId; use near_primitives::utils::index_to_bytes; -use once_cell::sync::Lazy; +use once_cell::sync::{Lazy, OnceCell}; use rand::{thread_rng, RngCore}; use std::collections::{HashMap, HashSet, VecDeque}; use std::net::TcpListener; @@ -387,39 +387,27 @@ pub mod test_features { } } +#[derive(Default)] +pub struct NetworkRecipient { + peer_manager_recipient: OnceCell>, +} + impl NetworkRecipient { pub fn set_recipient(&self, peer_manager_recipient: Recipient) { - *self.peer_manager_recipient.write().unwrap() = Some(peer_manager_recipient); + self.peer_manager_recipient.set(peer_manager_recipient); } } -#[derive(Default)] -pub struct NetworkRecipient { - peer_manager_recipient: RwLock>>, -} - impl PeerManagerAdapter for NetworkRecipient { fn send( &self, msg: PeerManagerMessageRequest, ) -> BoxFuture<'static, Result> { - self.peer_manager_recipient - .read() - .unwrap() - .as_ref() - .expect("Recipient must be set") - .send(msg) - .boxed() + self.peer_manager_recipient.wait().send(msg).boxed() } fn do_send(&self, msg: PeerManagerMessageRequest) { - let _ = self - .peer_manager_recipient - .read() - .unwrap() - .as_ref() - .expect("Recipient must be set") - .do_send(msg); + let _ = self.peer_manager_recipient.wait().do_send(msg); } }