mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
improve performance on large wallets with high address reuse
This commit is contained in:
parent
15500b6535
commit
3242f00812
2 changed files with 10 additions and 9 deletions
|
@ -692,7 +692,9 @@ public class ElectrumServer {
|
|||
//First check all provided txes that pay to this node
|
||||
Script nodeScript = node.getOutputScript();
|
||||
Set<BlockTransactionHash> history = nodeTransactionMap.get(node);
|
||||
Map<Sha256Hash, BlockTransactionHash> txHashHistory = new HashMap<>();
|
||||
for(BlockTransactionHash reference : history) {
|
||||
txHashHistory.put(reference.getHash(), reference);
|
||||
BlockTransaction blockTransaction = wallet.getTransactions().get(reference.getHash());
|
||||
if(blockTransaction == null) {
|
||||
throw new IllegalStateException("Did not retrieve transaction for hash " + reference.getHashAsString());
|
||||
|
@ -731,14 +733,13 @@ public class ElectrumServer {
|
|||
throw new IllegalStateException("Could not retrieve transaction for hash " + reference.getHashAsString());
|
||||
}
|
||||
|
||||
Optional<BlockTransactionHash> optionalTxHash = history.stream().filter(txHash -> txHash.getHash().equals(previousHash)).findFirst();
|
||||
if(optionalTxHash.isEmpty()) {
|
||||
BlockTransactionHash spentTxHash = txHashHistory.get(previousHash);
|
||||
if(spentTxHash == null) {
|
||||
//No previous transaction history found, cannot check if spends from wallet
|
||||
//This is fine so long as all referenced transactions have been returned, in which case this refers to a transaction that does not affect this wallet node
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockTransactionHash spentTxHash = optionalTxHash.get();
|
||||
TransactionOutput spentOutput = previousTransaction.getTransaction().getOutputs().get((int)input.getOutpoint().getIndex());
|
||||
if(spentOutput.getScript().equals(nodeScript)) {
|
||||
BlockTransactionHashIndex spendingTXI = new BlockTransactionHashIndex(reference.getHash(), reference.getHeight(), blockTransaction.getDate(), reference.getFee(), inputIndex, spentOutput.getValue());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.protocol.HashIndex;
|
||||
import com.sparrowwallet.drongo.wallet.BlockTransaction;
|
||||
|
@ -72,15 +73,14 @@ public class WalletTransactionsEntry extends Entry {
|
|||
.collect(Collectors.toUnmodifiableMap(entry -> new HashIndex(entry.getKey().getHash(), entry.getKey().getIndex()), Map.Entry::getKey,
|
||||
BinaryOperator.maxBy(BlockTransactionHashIndex::compareTo)));
|
||||
|
||||
List<Entry> current = getWalletTransactions(getWallet()).stream().map(WalletTransaction::getTransactionEntry).collect(Collectors.toList());
|
||||
List<Entry> previous = new ArrayList<>(getChildren());
|
||||
Collection<WalletTransactionsEntry.WalletTransaction> entries = getWalletTransactions(getWallet());
|
||||
Set<Entry> current = entries.stream().map(WalletTransaction::getTransactionEntry).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
Set<Entry> previous = new LinkedHashSet<>(getChildren());
|
||||
|
||||
List<Entry> entriesAdded = new ArrayList<>(current);
|
||||
entriesAdded.removeAll(previous);
|
||||
Set<Entry> entriesAdded = Sets.difference(current, previous);
|
||||
getChildren().addAll(entriesAdded);
|
||||
|
||||
List<Entry> entriesRemoved = new ArrayList<>(previous);
|
||||
entriesRemoved.removeAll(current);
|
||||
Set<Entry> entriesRemoved = Sets.difference(previous, current);
|
||||
getChildren().removeAll(entriesRemoved);
|
||||
|
||||
calculateBalances(true);
|
||||
|
|
Loading…
Reference in a new issue