mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 21:26:43 +00:00
cormorant: round up wallet range to avoid frequent rescans with a large gap limit
This commit is contained in:
parent
6ee3755ce4
commit
06489d8339
1 changed files with 8 additions and 1 deletions
|
@ -260,7 +260,7 @@ public class BitcoindClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScanDate getScanDate(String normalizedDescriptor, Wallet wallet, KeyPurpose keyPurpose, Date earliestBirthDate) {
|
private ScanDate getScanDate(String normalizedDescriptor, Wallet wallet, KeyPurpose keyPurpose, Date earliestBirthDate) {
|
||||||
Integer range = (keyPurpose == null ? null : Math.max(getHighestUsedIndex(normalizedDescriptor, wallet, keyPurpose) + wallet.getGapLimit(), getDefaultRange(wallet, keyPurpose)));
|
Integer range = (keyPurpose == null ? null : Math.max(getWalletRange(normalizedDescriptor, wallet, keyPurpose), getDefaultRange(wallet, keyPurpose)));
|
||||||
|
|
||||||
//Force a rescan if loading a wallet with a birthday later than existing transactions, or if the wallet birthdate has been set or changed to an earlier date from the last check
|
//Force a rescan if loading a wallet with a birthday later than existing transactions, or if the wallet birthdate has been set or changed to an earlier date from the last check
|
||||||
boolean forceRescan = false;
|
boolean forceRescan = false;
|
||||||
|
@ -274,6 +274,13 @@ public class BitcoindClient {
|
||||||
return new ScanDate(earliestBirthDate, range, forceRescan);
|
return new ScanDate(earliestBirthDate, range, forceRescan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getWalletRange(String normalizedDescriptor, Wallet wallet, KeyPurpose keyPurpose) {
|
||||||
|
int maxIndex = getHighestUsedIndex(normalizedDescriptor, wallet, keyPurpose) + wallet.getGapLimit();
|
||||||
|
//Default keypool size of 1000 will mean no rescans with a normal (<1000) gap limit as range is automatically extended by keypool size on address use
|
||||||
|
//Rounding up to the nearest 500 will ensure reduced rescans where gap limit is over 1000
|
||||||
|
return maxIndex % 500 == 0 ? maxIndex : ((maxIndex / 500) + 1) * 500;
|
||||||
|
}
|
||||||
|
|
||||||
private int getHighestUsedIndex(String descriptor, Wallet wallet, KeyPurpose keyPurpose) {
|
private int getHighestUsedIndex(String descriptor, Wallet wallet, KeyPurpose keyPurpose) {
|
||||||
int highestUsedIndex = wallet.getFreshNode(keyPurpose).getIndex() - 1;
|
int highestUsedIndex = wallet.getFreshNode(keyPurpose).getIndex() - 1;
|
||||||
return descriptorUsedIndexes.compute(descriptor, (d, lastHighestUsedIndex) -> lastHighestUsedIndex == null ? highestUsedIndex : Math.max(highestUsedIndex, lastHighestUsedIndex));
|
return descriptorUsedIndexes.compute(descriptor, (d, lastHighestUsedIndex) -> lastHighestUsedIndex == null ? highestUsedIndex : Math.max(highestUsedIndex, lastHighestUsedIndex));
|
||||||
|
|
Loading…
Reference in a new issue