Unverified Commit 4b0f3d47 authored by Roman Zeyde's avatar Roman Zeyde
Browse files

Protect mempool tracker with a RwLock inside a Query

parent 95676647
......@@ -89,6 +89,7 @@ fn run_server(config: &Config) {
scope.spawn(|| rpc::serve(config.rpc_addr(), &query, chan));
loop {
thread::sleep(poll_delay);
query.update_mempool();
let current_tip = daemon
.getbestblockhash()
.expect("failed to get latest blockhash");
......
......@@ -3,18 +3,14 @@ use bitcoin::blockdata::transaction::Transaction;
use bitcoin::network::serialize::deserialize;
use bitcoin::util::hash::Sha256dHash;
use itertools::enumerate;
use std::sync::RwLock;
use daemon::Daemon;
use index::{compute_script_hash, HeaderEntry, Index, TxInRow, TxOutRow, TxRow};
use mempool::Tracker;
use store::Store;
use types::HashPrefix;
pub struct Query<'a> {
store: &'a Store,
daemon: &'a Daemon,
index: &'a Index,
}
pub struct FundingOutput {
pub txn_id: Sha256dHash,
pub height: i32,
......@@ -44,6 +40,13 @@ fn merklize(left: Sha256dHash, right: Sha256dHash) -> Sha256dHash {
Sha256dHash::from_data(&data)
}
pub struct Query<'a> {
store: &'a Store,
daemon: &'a Daemon,
index: &'a Index,
tracker: RwLock<Tracker>,
}
// TODO: return errors instead of panics
impl<'a> Query<'a> {
pub fn new(store: &'a Store, daemon: &'a Daemon, index: &'a Index) -> Query<'a> {
......@@ -51,6 +54,7 @@ impl<'a> Query<'a> {
store,
daemon,
index,
tracker: RwLock::new(Tracker::new()),
}
}
......@@ -202,4 +206,12 @@ impl<'a> Query<'a> {
}
Some((merkle, pos))
}
pub fn update_mempool(&self) {
self.tracker
.write()
.unwrap()
.update(self.daemon)
.expect("failed to update mempool")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment