Skip to content

Commit 6abe197

Browse files
committed
bitcoind: reduce load in get_spending_txid
By ignoring more entries that are obviously not the one we are looking for
1 parent 2b7ba37 commit 6abe197

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/bitcoind/interface.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ use revault_tx::bitcoin::{
55
Address, Amount, BlockHash, OutPoint, Script, Transaction, TxOut, Txid,
66
};
77

8-
use std::{collections::HashMap, fs, str::FromStr, time::Duration};
8+
use std::{
9+
collections::{HashMap, HashSet},
10+
fs,
11+
str::FromStr,
12+
time::Duration,
13+
};
914

1015
use jsonrpc::{
1116
arg,
@@ -835,6 +840,11 @@ impl BitcoinD {
835840
block_hash
836841
));
837842

843+
// Get the spent txid to ignore the entries about this transaction
844+
let spent_txid = spent_outpoint.txid.to_string();
845+
// We use a cache to avoid needless iterations, since listsinceblock returns an entry
846+
// per transaction output, not per transaction.
847+
let mut visited_txs = HashSet::new();
838848
for transaction in transactions {
839849
if transaction.get("category").map(|c| c.as_str()).flatten() != Some("send") {
840850
continue;
@@ -852,6 +862,12 @@ impl BitcoinD {
852862
block_hash
853863
));
854864

865+
if visited_txs.contains(&spending_txid) || &spent_txid == spending_txid {
866+
continue;
867+
} else {
868+
visited_txs.insert(spending_txid);
869+
}
870+
855871
let gettx_res = self.make_watchonly_request(
856872
"gettransaction",
857873
&params!(

0 commit comments

Comments
 (0)