mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 01:43:29 +01:00
Use parking_lot::{Mutex, RwLock} instead of std::sync
This commit is contained in:
parent
188aba50f1
commit
45833c3b61
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -321,6 +321,7 @@ dependencies = [
|
||||
"env_logger",
|
||||
"hyper",
|
||||
"log 0.4.14",
|
||||
"parking_lot",
|
||||
"prometheus",
|
||||
"rayon",
|
||||
"rocksdb",
|
||||
|
@ -29,6 +29,7 @@ dirs-next = "2.0"
|
||||
env_logger = "0.7"
|
||||
hyper = { version = "0.10", optional = true }
|
||||
log = "0.4"
|
||||
parking_lot = "0.11"
|
||||
prometheus = { version = "0.12", features = ["process"], optional = true }
|
||||
rayon = "1.5"
|
||||
serde = "1.0"
|
||||
|
10
src/cache.rs
10
src/cache.rs
@ -1,7 +1,8 @@
|
||||
use bitcoin::{BlockHash, Transaction, Txid};
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::merkle::Proof;
|
||||
|
||||
@ -13,14 +14,14 @@ pub struct Cache {
|
||||
|
||||
impl Cache {
|
||||
pub(crate) fn add_tx(&self, txid: Txid, f: impl FnOnce() -> Transaction) {
|
||||
self.txs.write().unwrap().entry(txid).or_insert_with(f);
|
||||
self.txs.write().entry(txid).or_insert_with(f);
|
||||
}
|
||||
|
||||
pub(crate) fn get_tx<F, T>(&self, txid: &Txid, f: F) -> Option<T>
|
||||
where
|
||||
F: FnOnce(&Transaction) -> T,
|
||||
{
|
||||
self.txs.read().unwrap().get(txid).map(f)
|
||||
self.txs.read().get(txid).map(f)
|
||||
}
|
||||
|
||||
pub(crate) fn add_proof<F>(&self, blockhash: BlockHash, txid: Txid, f: F)
|
||||
@ -29,7 +30,6 @@ impl Cache {
|
||||
{
|
||||
self.proofs
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry((blockhash, txid))
|
||||
.or_insert_with(f);
|
||||
}
|
||||
@ -38,6 +38,6 @@ impl Cache {
|
||||
where
|
||||
F: FnOnce(&Proof) -> T,
|
||||
{
|
||||
self.proofs.read().unwrap().get(&(blockhash, txid)).map(f)
|
||||
self.proofs.read().get(&(blockhash, txid)).map(f)
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ use anyhow::{Context, Result};
|
||||
use std::io::Write;
|
||||
use std::iter::FromIterator;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
|
||||
use std::sync::Mutex;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use bitcoin::consensus::encode;
|
||||
@ -18,6 +17,7 @@ use bitcoin::secp256k1;
|
||||
use bitcoin::secp256k1::rand::Rng;
|
||||
use bitcoin::{Amount, Block, BlockHash, Network, Transaction, Txid};
|
||||
use bitcoincore_rpc::{self, json, RpcApi};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use crate::{
|
||||
chain::{Chain, NewHeader},
|
||||
@ -239,7 +239,7 @@ impl Daemon {
|
||||
}
|
||||
|
||||
pub(crate) fn get_new_headers(&self, chain: &Chain) -> Result<Vec<NewHeader>> {
|
||||
let mut conn = self.p2p.lock().unwrap();
|
||||
let mut conn = self.p2p.lock();
|
||||
|
||||
let msg = GetHeadersMessage::new(chain.locator(), BlockHash::default());
|
||||
conn.send(NetworkMessage::GetHeaders(msg))?;
|
||||
@ -278,7 +278,7 @@ impl Daemon {
|
||||
.map(|h| Inventory::WitnessBlock(*h))
|
||||
.collect();
|
||||
debug!("loading {} blocks", blockhashes.len());
|
||||
let mut conn = self.p2p.lock().unwrap();
|
||||
let mut conn = self.p2p.lock();
|
||||
conn.send(NetworkMessage::GetData(inv))?;
|
||||
for hash in blockhashes {
|
||||
match conn
|
||||
|
Loading…
Reference in New Issue
Block a user