Skip to content

Commit

Permalink
Fix: only sync addresses >= address_start_index (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M authored Dec 27, 2021
1 parent 6d390e5 commit 0faf972
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/addressIndex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nodejs-binding": patch
---

Fixes the syncing so when an `addressIndex` is provided, only addresses with an index >= will be synced.
2 changes: 1 addition & 1 deletion bindings/nodejs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/account/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ async fn sync_messages(
options: AccountOptions,
skip_change_addresses: bool,
change_addresses_to_sync: HashSet<AddressWrapper>,
// only sync messages for addresses >= this index
address_start_index: usize,
) -> crate::Result<(Vec<Address>, Vec<SyncedMessage>)> {
log::debug!("[SYNC] sync_messages");
let mut messages = vec![];
Expand All @@ -464,10 +466,14 @@ async fn sync_messages(

let client = crate::client::get_client(&client_options).await?;

log::debug!("[SYNC] sync_messages for {} addresses", account.addresses().len());

// We split the addresses into chunks so we don't get timeouts if we have thousands
let account_addresses = account.addresses().clone();
let account_addresses: Vec<Address> = account
.addresses()
.iter()
.filter(|address| address.key_index() >= &address_start_index)
.cloned()
.collect();
log::debug!("[SYNC] sync_messages for {} addresses", account_addresses.len());
drop(account);
for addresses_chunk in account_addresses
.to_vec()
Expand Down Expand Up @@ -702,6 +708,7 @@ async fn perform_sync(
options,
skip_change_addresses,
change_addresses_to_sync,
address_index,
)
.await?;
found_addresses.extend(synced_addresses);
Expand Down

0 comments on commit 0faf972

Please sign in to comment.