Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Bump parking_lot to 0.11.1. Revert std mutex from openethereum#277 (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita authored Apr 27, 2021
1 parent 392a909 commit be9b16a
Show file tree
Hide file tree
Showing 26 changed files with 205 additions and 177 deletions.
216 changes: 134 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ number_prefix = "0.2"
rpassword = "1.0"
semver = "0.9"
ansi_term = "0.10"
parking_lot = "0.7"
parking_lot = "0.11.1"
regex = "1.0"
atty = "0.2.8"
toml = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion bin/ethstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ num_cpus = "1.6"
rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
parking_lot = "0.7"
parking_lot = "0.11.1"
ethstore = { path = "../../crates/accounts/ethstore" }
dir = { path = '../../crates/util/dir' }
panic_hook = { path = "../../crates/util/panic-hook" }
Expand Down
2 changes: 1 addition & 1 deletion bin/oe/logger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ atty = "0.2"
lazy_static = "1.0"
regex = "1.0"
time = "0.1"
parking_lot = "0.7"
parking_lot = "0.11.1"
arrayvec = "0.4"
ansi_term = "0.10"
2 changes: 1 addition & 1 deletion crates/accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ethkey = { path = "ethkey" }
ethstore = { path = "ethstore" }
log = "0.4"
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
parking_lot = "0.7"
parking_lot = "0.11.1"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/accounts/ethstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde_derive = "1.0"
rustc-hex = "1.0"
time = "0.1.34"
itertools = "0.5"
parking_lot = "0.7"
parking_lot = "0.11.1"
parity-crypto = { version = "0.6.2", features = [ "publickey"] }
ethereum-types = "0.9.2"
smallvec = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion crates/concensus/ethash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keccak-hash = "0.5.0"
tiny-keccak = "2.0.2"
log = "0.4"
memmap = "0.6"
parking_lot = "0.7"
parking_lot = "0.11.1"
primal = "0.2.3"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/concensus/miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ log = "0.4"
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
parity-runtime = { path = "../../runtime/runtime" }
parity-util-mem = "0.7"
parking_lot = "0.7"
parking_lot = "0.11.1"
price-info = { path = "./price-info", optional = true }
rlp = { version = "0.4.6" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/concensus/miner/price-info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ log = "0.4"
serde_json = "1.0"

[dev-dependencies]
parking_lot = "0.7"
parking_lot = "0.11.1"
fake-fetch = { path = "../../../net/fake-fetch" }
2 changes: 1 addition & 1 deletion crates/concensus/miner/stratum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keccak-hash = "0.5.0"
jsonrpc-core = "15.0.0"
jsonrpc-tcp-server = "15.0.0"
log = "0.4"
parking_lot = "0.7"
parking_lot = "0.11.1"

[dev-dependencies]
env_logger = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion crates/db/blooms-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Parity Technologies <[email protected]>"]
[dependencies]
byteorder = "1.2"
ethbloom = "0.9.1"
parking_lot = "0.7"
parking_lot = "0.11.1"
tiny-keccak = "1.4"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/db/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kvdb = "0.1"
kvdb-rocksdb = "0.1.3"
kvdb-memorydb = "0.1"
parity-util-mem = "0.7"
parking_lot = "0.7"
parking_lot = "0.11.1"
rlp = { version = "0.4.6" }
rlp_derive = { path = "../../util/rlp-derive" }
stats = { path = "../../util/stats" }
2 changes: 1 addition & 1 deletion crates/db/journaldb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kvdb = "0.1"
log = "0.4"
memory-db = { path = "../memory-db" }
parity-util-mem = "0.7"
parking_lot = "0.7"
parking_lot = "0.11.1"
fastmap = { path = "../../util/fastmap" }
rlp = { version = "0.4.6" }

Expand Down
2 changes: 1 addition & 1 deletion crates/ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ parity-bytes = "0.1"
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
parity-snappy = "0.1"
parity-util-mem = "0.7"
parking_lot = "0.7"
parking_lot = "0.11.1"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../db/patricia-trie-ethereum" }
rand = "0.7.3"
Expand Down
2 changes: 1 addition & 1 deletion crates/ethcore/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log = "0.4"
parity-bytes = "0.1"
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
parity-util-mem = "0.7"
parking_lot = "0.7"
parking_lot = "0.11.1"
rand = "0.7.3"
rayon = "1.1"
rlp = { version = "0.4.6" }
Expand Down
2 changes: 1 addition & 1 deletion crates/ethcore/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ macros = { path = "../../util/macros" }
parity-bytes = "0.1"
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
parity-util-mem = "0.7"
parking_lot = "0.7"
parking_lot = "0.11.1"
rand = "0.7.3"
rand_xorshift = "0.2.0"
rlp = { version = "0.4.6" }
Expand Down
39 changes: 12 additions & 27 deletions crates/ethcore/sync/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,14 @@ use ethereum_types::{H256, U256};
use fastmap::{H256FastMap, H256FastSet};
use hash::keccak;
use network::{self, client_version::ClientVersion, PeerId};
use parking_lot::Mutex;
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
use rand::{seq::SliceRandom, Rng};
use rlp::{DecoderError, RlpStream};
use snapshot::Snapshot;
use std::{
cmp,
collections::{BTreeMap, HashMap, HashSet},
sync::{
atomic::{AtomicBool, Ordering},
mpsc, RwLock as StdRwLock, RwLockWriteGuard as StdRwLockWriteGuard,
},
sync::mpsc,
time::{Duration, Instant},
};
use sync_io::SyncIo;
Expand Down Expand Up @@ -405,10 +402,8 @@ pub type Peers = HashMap<PeerId, PeerInfo>;
pub struct ChainSyncApi {
/// Priority tasks queue
priority_tasks: Mutex<mpsc::Receiver<PriorityTask>>,
/// Gate for executing only one priority timer.
priority_tasks_gate: AtomicBool,
/// The rest of sync data
sync: StdRwLock<ChainSync>,
sync: RwLock<ChainSync>,
}

impl ChainSyncApi {
Expand All @@ -420,33 +415,31 @@ impl ChainSyncApi {
priority_tasks: mpsc::Receiver<PriorityTask>,
) -> Self {
ChainSyncApi {
sync: StdRwLock::new(ChainSync::new(config, chain, fork_filter)),
sync: RwLock::new(ChainSync::new(config, chain, fork_filter)),
priority_tasks: Mutex::new(priority_tasks),
priority_tasks_gate: AtomicBool::new(false),
}
}

/// Gives `write` access to underlying `ChainSync`
pub fn write(&self) -> StdRwLockWriteGuard<ChainSync> {
self.sync.write().unwrap()
pub fn write(&self) -> RwLockWriteGuard<ChainSync> {
self.sync.write()
}

/// Returns info about given list of peers
pub fn peer_info(&self, ids: &[PeerId]) -> Vec<Option<PeerInfoDigest>> {
let sync = self.sync.read().unwrap();
let sync = self.sync.read();
ids.iter().map(|id| sync.peer_info(id)).collect()
}

/// Returns synchonization status
pub fn status(&self) -> SyncStatus {
self.sync.read().unwrap().status()
self.sync.read().status()
}

/// Returns transactions propagation statistics
pub fn transactions_stats(&self) -> BTreeMap<H256, ::TransactionStats> {
self.sync
.read()
.unwrap()
.transactions_stats()
.iter()
.map(|(hash, stats)| (*hash, stats.into()))
Expand All @@ -460,7 +453,7 @@ impl ChainSyncApi {

/// Process the queue with requests, that were delayed with response.
pub fn process_delayed_requests(&self, io: &mut dyn SyncIo) {
let requests = self.sync.write().unwrap().retrieve_delayed_requests();
let requests = self.sync.write().retrieve_delayed_requests();
if !requests.is_empty() {
debug!(target: "sync", "Processing {} delayed requests", requests.len());
for (peer_id, packet_id, packet_data) in requests {
Expand Down Expand Up @@ -491,14 +484,6 @@ impl ChainSyncApi {
}
}

if self
.priority_tasks_gate
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.is_err()
{
return;
}

// deadline to get the task from the queue
let deadline = Instant::now() + ::api::PRIORITY_TIMER_INTERVAL;
let mut work = || {
Expand All @@ -508,8 +493,9 @@ impl ChainSyncApi {
tasks.recv_timeout(left).ok()?
};
task.starting();
// wait for the sync lock
let mut sync = self.sync.write().unwrap();
// wait for the sync lock until deadline,
// note we might drop the task here if we won't manage to acquire the lock.
let mut sync = self.sync.try_write_until(deadline)?;
// since we already have everything let's use a different deadline
// to do the rest of the job now, so that previous work is not wasted.
let deadline = Instant::now() + PRIORITY_TASK_DEADLINE;
Expand Down Expand Up @@ -556,7 +542,6 @@ impl ChainSyncApi {
// Process as many items as we can until the deadline is reached.
loop {
if work().is_none() {
self.priority_tasks_gate.store(false, Ordering::SeqCst);
return;
}
}
Expand Down
35 changes: 17 additions & 18 deletions crates/ethcore/sync/src/chain/supplier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ pub const PAYLOAD_SOFT_LIMIT: usize = 100_000;
use enum_primitive::FromPrimitive;
use ethereum_types::H256;
use network::{self, PeerId};
use parking_lot::RwLock;
use rlp::{Rlp, RlpStream};
use std::{cmp, sync::RwLock as StdRwLock};
use std::cmp;
use types::{ids::BlockId, BlockNumber};

use sync_io::SyncIo;
Expand Down Expand Up @@ -53,7 +54,7 @@ impl SyncSupplier {
// Take a u8 and not a SyncPacketId because this is the entry point
// to chain sync from the outside world.
pub fn dispatch_packet(
sync: &StdRwLock<ChainSync>,
sync: &RwLock<ChainSync>,
io: &mut dyn SyncIo,
peer: PeerId,
packet_id: u8,
Expand Down Expand Up @@ -101,12 +102,12 @@ impl SyncSupplier {
),

StatusPacket => {
sync.write().unwrap().on_packet(io, peer, packet_id, data);
sync.write().on_packet(io, peer, packet_id, data);
Ok(())
}
// Packets that require the peer to be confirmed
_ => {
if !sync.read().unwrap().peers.contains_key(&peer) {
if !sync.read().peers.contains_key(&peer) {
debug!(target:"sync", "Unexpected packet {} from unregistered peer: {}:{}", packet_id, peer, io.peer_version(peer));
return;
}
Expand All @@ -116,17 +117,17 @@ impl SyncSupplier {
ConsensusDataPacket => SyncHandler::on_consensus_packet(io, peer, &rlp),
TransactionsPacket => {
let res = {
let sync_ro = sync.read().unwrap();
let sync_ro = sync.read();
SyncHandler::on_peer_transactions(&*sync_ro, io, peer, &rlp)
};
if res.is_err() {
// peer sent invalid data, disconnect.
io.disable_peer(peer);
sync.write().unwrap().deactivate_peer(io, peer);
sync.write().deactivate_peer(io, peer);
}
}
_ => {
sync.write().unwrap().on_packet(io, peer, packet_id, data);
sync.write().on_packet(io, peer, packet_id, data);
}
}

Expand All @@ -138,10 +139,9 @@ impl SyncSupplier {
Err(PacketProcessError::Decoder(e)) => {
debug!(target:"sync", "{} -> Malformed packet {} : {}", peer, packet_id, e)
}
Err(PacketProcessError::ClientBusy) => sync
.write()
.unwrap()
.add_delayed_request(peer, packet_id, data),
Err(PacketProcessError::ClientBusy) => {
sync.write().add_delayed_request(peer, packet_id, data)
}
Ok(()) => {}
}
}
Expand All @@ -150,7 +150,7 @@ impl SyncSupplier {
/// Dispatch delayed request
/// The main difference with dispatch packet is the direct send of the responses to the peer
pub fn dispatch_delayed_request(
sync: &StdRwLock<ChainSync>,
sync: &RwLock<ChainSync>,
io: &mut dyn SyncIo,
peer: PeerId,
packet_id: u8,
Expand Down Expand Up @@ -178,10 +178,9 @@ impl SyncSupplier {
Err(PacketProcessError::Decoder(e)) => {
debug!(target:"sync", "{} -> Malformed packet {} : {}", peer, packet_id, e)
}
Err(PacketProcessError::ClientBusy) => sync
.write()
.unwrap()
.add_delayed_request(peer, packet_id, data),
Err(PacketProcessError::ClientBusy) => {
sync.write().add_delayed_request(peer, packet_id, data)
}
Ok(()) => {}
}
}
Expand Down Expand Up @@ -421,7 +420,7 @@ mod test {
use ethereum_types::H256;
use parking_lot::RwLock;
use rlp::{Rlp, RlpStream};
use std::{collections::VecDeque, str::FromStr, sync::RwLock as StdRwLock};
use std::{collections::VecDeque, str::FromStr};
use tests::{helpers::TestIo, snapshot::TestSnapshotService};

#[test]
Expand Down Expand Up @@ -649,7 +648,7 @@ mod test {

io.sender = Some(2usize);
SyncSupplier::dispatch_packet(
&StdRwLock::new(sync),
&RwLock::new(sync),
&mut io,
0usize,
GetReceiptsPacket.id(),
Expand Down
11 changes: 4 additions & 7 deletions crates/ethcore/sync/src/tests/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn status_after_sync() {
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
net.sync();
let status = net.peer(0).sync.read().unwrap().status();
let status = net.peer(0).sync.read().status();
assert_eq!(status.state, SyncState::Idle);
}

Expand Down Expand Up @@ -177,22 +177,19 @@ fn restart() {
assert!(net.peer(0).chain.chain_info().best_block_number > 100);
net.restart_peer(0);

let status = net.peer(0).sync.read().unwrap().status();
let status = net.peer(0).sync.read().status();
assert_eq!(status.state, SyncState::Idle);
}

#[test]
fn status_empty() {
let net = TestNet::new(2);
assert_eq!(
net.peer(0).sync.read().unwrap().status().state,
SyncState::Idle
);
assert_eq!(net.peer(0).sync.read().status().state, SyncState::Idle);
let mut config = SyncConfig::default();
config.warp_sync = WarpSync::Enabled;
let net = TestNet::new_with_config(2, config);
assert_eq!(
net.peer(0).sync.read().unwrap().status().state,
net.peer(0).sync.read().status().state,
SyncState::WaitingPeers
);
}
Expand Down
Loading

0 comments on commit be9b16a

Please sign in to comment.