Browse Source

Remove unused TransactionCache

(cherry picked from commit a31e828976)
liquid_e
Roman Zeyde 6 years ago
committed by Nadav Ivgi
parent
commit
678630038b
  1. 5
      src/bin/electrs.rs
  2. 31
      src/query.rs

5
src/bin/electrs.rs

@ -17,7 +17,7 @@ use electrs::{
errors::*,
index::Index,
metrics::Metrics,
query::{Query, TransactionCache},
query::Query,
signal::Waiter,
store::{full_compaction, is_fully_compacted, DBStore},
};
@ -54,8 +54,7 @@ fn run_server(config: &Config) -> Result<()> {
}.enable_compaction(); // enable auto compactions before starting incremental index updates.
let app = App::new(store, index, daemon)?;
let tx_cache = TransactionCache::new(config.tx_cache_size);
let query = Query::new(app.clone(), &metrics, tx_cache);
let query = Query::new(app.clone(), &metrics);
let mut server = None; // HTTP REST server
loop {

31
src/query.rs

@ -4,10 +4,9 @@ use bitcoin::util::hash::Sha256dHash;
use crypto::digest::Digest;
use crypto::sha2::Sha256;
use elements::{confidential, Block, Transaction};
use lru::LruCache;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap};
use std::sync::{Arc, Mutex, RwLock};
use std::sync::{Arc, RwLock};
use app::App;
use index::{compute_script_hash, RawTxRow, TxInRow, TxOutRow, TxRow};
@ -208,10 +207,6 @@ fn txids_by_funding_output(
.collect()
}
pub struct TransactionCache {
map: Mutex<LruCache<Sha256dHash, Transaction>>,
}
pub fn get_block_meta(store: &ReadStore, blockhash: &Sha256dHash) -> Option<BlockMeta> {
let key = [b"M", &blockhash[..]].concat();
let value = store.get(&key)?;
@ -226,38 +221,16 @@ pub fn get_block_txids(store: &ReadStore, blockhash: &Sha256dHash) -> Option<Vec
Some(txids)
}
impl TransactionCache {
pub fn new(capacity: usize) -> TransactionCache {
TransactionCache {
map: Mutex::new(LruCache::new(capacity)),
}
}
fn _get_or_else<F>(&self, txid: &Sha256dHash, load_txn_func: F) -> Result<Transaction>
where
F: FnOnce() -> Result<Transaction>,
{
if let Some(txn) = self.map.lock().unwrap().get(txid) {
return Ok(txn.clone());
}
let txn = load_txn_func()?;
self.map.lock().unwrap().put(*txid, txn.clone());
Ok(txn)
}
}
pub struct Query {
app: Arc<App>,
tracker: RwLock<Tracker>,
tx_cache: TransactionCache,
}
impl Query {
pub fn new(app: Arc<App>, metrics: &Metrics, tx_cache: TransactionCache) -> Arc<Query> {
pub fn new(app: Arc<App>, metrics: &Metrics) -> Arc<Query> {
Arc::new(Query {
app,
tracker: RwLock::new(Tracker::new(metrics)),
tx_cache,
})
}

Loading…
Cancel
Save