1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

Dedup txids at Status::new

This commit is contained in:
Roman Zeyde 2020-11-05 21:40:20 +02:00
parent 8742114702
commit 40306cbbe5
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -6,7 +6,7 @@ use serde_json::{from_value, json, Value};
use std::{
cmp::min,
collections::hash_map::Entry::{Occupied, Vacant},
collections::HashMap,
collections::{HashMap, HashSet},
sync::RwLock,
time::{Duration, Instant},
};
@ -91,7 +91,12 @@ struct Status {
}
impl Status {
fn new(entries: Vec<TxEntry>, tip: BlockHash) -> Self {
fn new(mut entries: Vec<TxEntry>, tip: BlockHash) -> Self {
let mut txids = HashSet::new();
entries = entries
.into_iter()
.filter(|e| txids.insert(e.txid)) // deduplicate txids, assuming the latter are from mempool
.collect();
let hash = StatusHash::new(&entries);
Self { entries, hash, tip }
}