mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Use correct txids for getting mempool transactions
If block is found after "getmempoolentry()" and before "gettransactions()", there will be more transactions at `txs` than in `entries` - causing a panic.
This commit is contained in:
parent
ea24d6a01f
commit
d1f5c61def
@ -359,7 +359,7 @@ impl Daemon {
|
||||
tx_from_value(self.request("getrawtransaction", args)?)
|
||||
}
|
||||
|
||||
pub fn gettransactions(&self, txhashes: &[Sha256dHash]) -> Result<Vec<Transaction>> {
|
||||
pub fn gettransactions(&self, txhashes: &[&Sha256dHash]) -> Result<Vec<Transaction>> {
|
||||
let params_list: Vec<Value> = txhashes
|
||||
.iter()
|
||||
.map(|txhash| json!([txhash.be_hex_string(), /*verbose=*/ false]))
|
||||
@ -370,6 +370,7 @@ impl Daemon {
|
||||
for value in values {
|
||||
txs.push(tx_from_value(value)?);
|
||||
}
|
||||
assert_eq!(txhashes.len(), txs.len());
|
||||
Ok(txs)
|
||||
}
|
||||
|
||||
|
@ -201,9 +201,8 @@ impl Tracker {
|
||||
timer.observe_duration();
|
||||
|
||||
let timer = self.stats.start_timer("add");
|
||||
let txids_to_add: Vec<Sha256dHash> = new_txids.difference(&old_txids).cloned().collect();
|
||||
let entries: Vec<(&Sha256dHash, MempoolEntry)> = txids_to_add
|
||||
.iter()
|
||||
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)),
|
||||
@ -214,8 +213,8 @@ impl Tracker {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let txs = daemon.gettransactions(&txids_to_add)?;
|
||||
assert_eq!(entries.len(), txs.len());
|
||||
let txids: Vec<&Sha256dHash> = entries.iter().map(|(txid, _)| *txid).collect();
|
||||
let txs = daemon.gettransactions(&txids)?;
|
||||
for ((txid, entry), tx) in entries.into_iter().zip(txs.into_iter()) {
|
||||
assert_eq!(tx.txid(), *txid);
|
||||
self.add(txid, tx, entry);
|
||||
|
Loading…
Reference in New Issue
Block a user