1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-25 07:17:41 +01:00

Ignore individual mempool transaction fetch fails

I wrote this in the github editor, so no promises that it compiles, but this should avoid several extra heap allocations and moves while fetching the mempool, and, more importantly, get electrs out of an infinite loop of fetching the full mempool forever when there exist RBF transactions.
This commit is contained in:
Matt Corallo 2021-03-03 21:10:37 +00:00 committed by GitHub
parent 97389fa9a4
commit f256039147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -203,8 +203,7 @@ impl Tracker {
let timer = self.stats.start_timer("add");
let txids_iter = new_txids.difference(&old_txids);
let entries: Vec<(&Txid, MempoolEntry)> = txids_iter
.filter_map(|txid| {
let entries = txids_iter.filter_map(|txid| {
match daemon.getmempoolentry(txid) {
Ok(entry) => Some((txid, entry)),
Err(err) => {
@ -212,23 +211,16 @@ impl Tracker {
None // ignore this transaction for now
}
}
})
.collect();
if !entries.is_empty() {
let txs = match entries
.iter()
.map(|(txid, _)| daemon.gettransaction(txid, None))
.collect::<Result<Vec<_>>>()
{
Ok(txs) => txs,
});
for (txid, entry) in entries {
match daemon.gettransaction(txid, None) {
Ok(tx) => {
assert_eq!(tx.txid(), *txid);
self.add(txid, tx, entry);
},
Err(err) => {
debug!("failed to get {} transactions: {}", entries.len(), err); // e.g. new block or RBF
return Ok(()); // keep the mempool until next update()
debug!("failed to get transaction {}: {}", txid, err); // e.g. new block or RBF
}
};
for ((txid, entry), tx) in entries.into_iter().zip(txs.into_iter()) {
assert_eq!(tx.txid(), *txid);
self.add(txid, tx, entry);
}
}
timer.observe_duration();