From 2b7ba37a2b757487654c29e4b6db338e31e0a333 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 6 Jul 2022 19:12:16 +0200 Subject: [PATCH 1/2] bitcoind: check all results in 'importdescriptors' result --- src/bitcoind/interface.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bitcoind/interface.rs b/src/bitcoind/interface.rs index 9d0290e5..a0d70946 100644 --- a/src/bitcoind/interface.rs +++ b/src/bitcoind/interface.rs @@ -401,13 +401,21 @@ impl BitcoinD { "importdescriptors", ¶ms!(Json::Array(all_descriptors)), )?; - if res.get(0).map(|x| x.get("success")) == Some(Some(&Json::Bool(true))) { + let all_succeeded = res + .as_array() + .map(|results| { + results + .iter() + .all(|res| res.get("success") == Some(&Json::Bool(true))) + }) + .unwrap_or(false); + if all_succeeded { return Ok(()); } Err(BitcoindError::Custom(format!( "Error returned from 'importdescriptor': {:?}", - res.get(0).map(|r| r.get("error")) + res ))) } From 6abe1971caea1690c0fa8b2067f1d3cd6c7aa357 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 6 Jul 2022 19:13:41 +0200 Subject: [PATCH 2/2] bitcoind: reduce load in get_spending_txid By ignoring more entries that are obviously not the one we are looking for --- src/bitcoind/interface.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bitcoind/interface.rs b/src/bitcoind/interface.rs index a0d70946..97ff6dcc 100644 --- a/src/bitcoind/interface.rs +++ b/src/bitcoind/interface.rs @@ -5,7 +5,12 @@ use revault_tx::bitcoin::{ Address, Amount, BlockHash, OutPoint, Script, Transaction, TxOut, Txid, }; -use std::{collections::HashMap, fs, str::FromStr, time::Duration}; +use std::{ + collections::{HashMap, HashSet}, + fs, + str::FromStr, + time::Duration, +}; use jsonrpc::{ arg, @@ -835,6 +840,11 @@ impl BitcoinD { block_hash )); + // Get the spent txid to ignore the entries about this transaction + let spent_txid = spent_outpoint.txid.to_string(); + // We use a cache to avoid needless iterations, since listsinceblock returns an entry + // per transaction output, not per transaction. + let mut visited_txs = HashSet::new(); for transaction in transactions { if transaction.get("category").map(|c| c.as_str()).flatten() != Some("send") { continue; @@ -852,6 +862,12 @@ impl BitcoinD { block_hash )); + if visited_txs.contains(&spending_txid) || &spent_txid == spending_txid { + continue; + } else { + visited_txs.insert(spending_txid); + } + let gettx_res = self.make_watchonly_request( "gettransaction", ¶ms!(