Skip to content

Commit a20ae79

Browse files
committed
indexer: Avoid excessive address import/rescanning
Always check if more imports are needed using the gap_limit, including during the initial import. inital_import_size is only used to determine the size of the import batch when the gap_limit requires it.
1 parent 5ba2a0b commit a20ae79

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/wallet.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,20 @@ impl WalletWatcher {
178178
let mut pending_updates = vec![];
179179

180180
for (checksum, wallet) in self.wallets.iter_mut() {
181-
let watch_index = wallet.watch_index();
182-
if wallet.max_imported_index.map_or(true, |i| watch_index > i) {
181+
if wallet.needs_imports() {
183182
let start_index = wallet
184183
.max_imported_index
185184
.map_or(0, |max_imported| max_imported + 1);
185+
let end_index = wallet.import_index();
186186

187187
debug!(
188188
"importing {} range {}-{} with rescan={}",
189-
checksum, start_index, watch_index, rescan,
189+
checksum, start_index, end_index, rescan,
190190
);
191191

192-
import_reqs.append(&mut wallet.make_imports(start_index, watch_index, rescan));
192+
import_reqs.append(&mut wallet.make_imports(start_index, end_index, rescan));
193193

194-
pending_updates.push((wallet, watch_index));
194+
pending_updates.push((wallet, end_index));
195195
} else if !wallet.done_initial_import {
196196
trace!("done initial import for {}", checksum,);
197197
wallet.done_initial_import = true;
@@ -321,8 +321,19 @@ impl Wallet {
321321
])
322322
}
323323

324-
/// Returns the maximum index that needs to be watched
325-
fn watch_index(&self) -> u32 {
324+
fn needs_imports(&self) -> bool {
325+
if !self.is_wildcard {
326+
return self.max_imported_index.is_some();
327+
}
328+
329+
self.max_imported_index.map_or(true, |imported| {
330+
self.max_funded_index
331+
.map_or(false, |funded| imported - funded < self.gap_limit)
332+
})
333+
}
334+
335+
/// Returns the maximum index that needs to be imported
336+
fn import_index(&self) -> u32 {
326337
if !self.is_wildcard {
327338
return 0;
328339
}

0 commit comments

Comments
 (0)