Commit 1beabb4b authored by kenshin-samourai's avatar kenshin-samourai
Browse files

reomove MempoolEntry

parent 1080dad4
......@@ -115,34 +115,6 @@ struct NetworkInfo {
subversion: String,
}
pub struct MempoolEntry {
fee: u64, // in satoshis
vsize: u32, // in virtual bytes (= weight/4)
fee_per_vbyte: f32,
}
impl MempoolEntry {
fn new(fee: u64, vsize: u32) -> MempoolEntry {
MempoolEntry {
fee,
vsize,
fee_per_vbyte: fee as f32 / vsize as f32,
}
}
pub fn fee_per_vbyte(&self) -> f32 {
self.fee_per_vbyte
}
pub fn fee(&self) -> u64 {
self.fee
}
pub fn vsize(&self) -> u32 {
self.vsize
}
}
pub trait CookieGetter: Send + Sync {
fn get(&self) -> Result<Vec<u8>>;
}
......@@ -566,23 +538,6 @@ impl Daemon {
Ok(result)
}
pub fn getmempoolentry(&self, txid: &Sha256dHash) -> Result<MempoolEntry> {
let entry = self.request("getmempoolentry", json!([txid.to_hex()]))?;
let fee = (entry
.get("fee")
.chain_err(|| "missing fee")?
.as_f64()
.chain_err(|| "non-float fee")?
* 100_000_000f64) as u64;
let vsize = entry
.get("size")
.or_else(|| entry.get("vsize")) // (https://github.com/bitcoin/bitcoin/pull/15637)
.chain_err(|| "missing vsize")?
.as_u64()
.chain_err(|| "non-integer vsize")? as u32;
Ok(MempoolEntry::new(fee, vsize))
}
fn get_all_headers(&self, tip: &Sha256dHash) -> Result<Vec<BlockHeader>> {
let info: Value = self.request("getblockheader", json!([tip.to_hex()]))?;
let tip_height = info
......
......@@ -5,7 +5,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::iter::FromIterator;
use std::ops::Bound;
use crate::daemon::{Daemon, MempoolEntry};
use crate::daemon::Daemon;
use crate::errors::*;
use crate::index::index_transaction;
use crate::store::{ReadStore, Row};
......@@ -85,13 +85,8 @@ impl ReadStore for MempoolStore {
}
}
struct Item {
tx: Transaction, // stored for faster retrieval and index removal
entry: MempoolEntry, // caches mempool fee rates
}
pub struct Tracker {
items: HashMap<Sha256dHash, Item>,
items: HashMap<Sha256dHash, Transaction>,
index: MempoolStore,
}
......@@ -104,7 +99,7 @@ impl Tracker {
}
pub fn get_txn(&self, txid: &Sha256dHash) -> Option<Transaction> {
self.items.get(txid).map(|stats| stats.tx.clone())
self.items.get(txid).map(|tx| tx.clone())
}
pub fn index(&self) -> &dyn ReadStore {
......@@ -120,31 +115,19 @@ impl Tracker {
let txids_iter = new_txids.difference(&old_txids);
let entries: Vec<(&Sha256dHash, MempoolEntry)> = txids_iter
.filter_map(|txid| {
match daemon.getmempoolentry(txid) {
Ok(entry) => Some((txid, entry)),
Err(err) => {
warn!("no mempool entry {}: {}", txid, err); // e.g. new block or RBF
None // ignore this transaction for now
}
}
})
.collect();
if !entries.is_empty() {
let txids: Vec<&Sha256dHash> = entries.iter().map(|(txid, _)| *txid).collect();
let txs = match daemon.gettransactions(&txids) {
Ok(txs) => txs,
Err(err) => {
warn!("failed to get transactions {:?}: {}", txids, err); // e.g. new block or RBF
return Ok(()); // keep the mempool until next update()
}
};
for ((txid, entry), tx) in entries.into_iter().zip(txs.into_iter()) {
assert_eq!(tx.txid(), *txid);
self.add(txid, tx, entry);
let txids: Vec<&Sha256dHash> = txids_iter.collect();
let txs = match daemon.gettransactions(&txids) {
Ok(txs) => txs,
Err(err) => {
warn!("failed to get transactions {:?}: {}", txids, err); // e.g. new block or RBF
return Ok(()); // keep the mempool until next update()
}
};
for (txid, tx) in txids.into_iter().zip(txs.into_iter()) {
assert_eq!(tx.txid(), *txid);
self.add(txid, tx);
}
for txid in old_txids.difference(&new_txids) {
......@@ -154,16 +137,16 @@ impl Tracker {
Ok(())
}
fn add(&mut self, txid: &Sha256dHash, tx: Transaction, entry: MempoolEntry) {
fn add(&mut self, txid: &Sha256dHash, tx: Transaction) {
self.index.add(&tx);
self.items.insert(*txid, Item { tx, entry });
self.items.insert(*txid, tx);
}
fn remove(&mut self, txid: &Sha256dHash) {
let stats = self
let tx = self
.items
.remove(txid)
.unwrap_or_else(|| panic!("missing mempool tx {}", txid));
self.index.remove(&stats.tx);
self.index.remove(&tx);
}
}
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