Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 28: [PATCH 28/68] fix(wallet): secure asynchronous sweep cancellation

src/rpc/blockchain.cpp

Before: src/rpc/blockchain.cpp · After: src/rpc/blockchain.cpp

File metadata
index b6c5e442293b508c4245b07d47d3a2f2499f4f76..a8adbba16fdd696f9e9a2b4b6c10b556d70f5556 100644

Download original patch · Release notes

Diff rows 1–37 of 37. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

src/rpc/blockchain.cpp CHANGED
@@ -2157,7 +2157,7 @@ static RPCHelpMan getblockstats()
2157
2157
 
2158
2158
  namespace {
2159
2159
  //! Search for a given set of pubkey scripts
2160
- bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>& should_abort, int64_t& count, CCoinsViewCursor* cursor, const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results, std::function<void()>& interruption_point)
2160
+ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>& should_abort, int64_t& count, CCoinsViewCursor* cursor, const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results, std::function<void()>& interruption_point, const std::function<bool()>& local_should_abort = {})
2161
2161
  {
2162
2162
  scan_progress = 0;
2163
2163
  count = 0;
@@ -2166,7 +2166,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
2166
2166
  Coin coin;
2167
2167
  if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
2168
2168
  if (rpc::scan::CheckInterruption(++count, interruption_point)) {
2169
- if (should_abort) {
2169
+ if (should_abort || (local_should_abort && local_should_abort())) {
2170
2170
  // allow to abort the scan via the abort reference
2171
2171
  return false;
2172
2172
  }
@@ -2201,7 +2201,8 @@ rpc::scan::Reserver::~Reserver() { if (m_reserved) { g_in_progress = false; g_pr
2201
2201
  bool rpc::scan::CheckInterruption(int64_t count, const std::function<void()>& interruption) { if (count % 8192 != 0) return false; interruption(); return true; }
2202
2202
  using rpc::scan::Reserver;
2203
2203
 
2204
- interfaces::ScanResult ScanUTXOSet(NodeContext& node, const std::set<CScript>& needles, std::map<COutPoint, Coin>& coins)
2204
+ interfaces::ScanResult ScanUTXOSet(NodeContext& node, const std::set<CScript>& needles, std::map<COutPoint, Coin>& coins,
2205
+ const std::function<bool()>& should_abort)
2205
2206
  {
2206
2207
  Reserver reserver;
2207
2208
  if (!reserver.reserve()) return interfaces::ScanResult::BUSY;
@@ -2216,10 +2217,10 @@ interfaces::ScanResult ScanUTXOSet(NodeContext& node, const std::set<CScript>& n
2216
2217
  rpc::scan::g_should_abort = false;
2217
2218
  std::atomic<int> progress;
2218
2219
  int64_t count;
2219
- if (FindScriptPubKey(progress, rpc::scan::g_should_abort, count, cursor.get(), needles, coins, node.rpc_interruption_point)) {
2220
+ if (FindScriptPubKey(progress, rpc::scan::g_should_abort, count, cursor.get(), needles, coins, node.rpc_interruption_point, should_abort)) {
2220
2221
  return interfaces::ScanResult::SUCCESS;
2221
2222
  }
2222
- return rpc::scan::g_should_abort ? interfaces::ScanResult::ABORTED : interfaces::ScanResult::UNAVAILABLE;
2223
+ return rpc::scan::g_should_abort || (should_abort && should_abort()) ? interfaces::ScanResult::ABORTED : interfaces::ScanResult::UNAVAILABLE;
2223
2224
  }
2224
2225
 
2225
2226
  static const auto scan_action_arg_desc = RPCArg{