Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of spv resync edge case #3821

Merged
merged 4 commits into from Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Expand Up @@ -33,6 +33,7 @@
import bisq.core.dao.governance.asset.AssetService;
import bisq.core.dao.governance.voteresult.VoteResultException;
import bisq.core.dao.governance.voteresult.VoteResultService;
import bisq.core.dao.state.unconfirmed.UnconfirmedBsqChangeOutputListService;
import bisq.core.filter.FilterManager;
import bisq.core.locale.Res;
import bisq.core.notifications.MobileNotificationService;
Expand Down Expand Up @@ -170,6 +171,7 @@ default void onRequestWalletPassword() {
private final ClockWatcher clockWatcher;
private final FeeService feeService;
private final DaoSetup daoSetup;
private final UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService;
private final EncryptionService encryptionService;
private final KeyRing keyRing;
private final BisqEnvironment bisqEnvironment;
Expand Down Expand Up @@ -256,6 +258,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
ClockWatcher clockWatcher,
FeeService feeService,
DaoSetup daoSetup,
UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService,
EncryptionService encryptionService,
KeyRing keyRing,
BisqEnvironment bisqEnvironment,
Expand Down Expand Up @@ -302,6 +305,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
this.clockWatcher = clockWatcher;
this.feeService = feeService;
this.daoSetup = daoSetup;
this.unconfirmedBsqChangeOutputListService = unconfirmedBsqChangeOutputListService;
this.encryptionService = encryptionService;
this.keyRing = keyRing;
this.bisqEnvironment = bisqEnvironment;
Expand Down Expand Up @@ -448,6 +452,11 @@ private void maybeReSyncSPVChain() {
if (preferences.isResyncSpvRequested()) {
try {
walletsSetup.reSyncSPVChain();

// In case we had an unconfirmed change output we reset the unconfirmedBsqChangeOutputList so that
// after a SPV resync we do not have any dangling BSQ utxos in that list which would cause an incorrect
// BSQ balance state after the SPV resync.
unconfirmedBsqChangeOutputListService.onSpvResync();
} catch (IOException e) {
log.error(e.toString());
e.printStackTrace();
Expand Down
Expand Up @@ -148,8 +148,11 @@ public void onCommitTx(Transaction tx, TxType txType, Wallet wallet) {
}

public void onReorganize() {
unconfirmedBsqChangeOutputList.clear();
persist();
reset();
}

public void onSpvResync() {
reset();
}

public void onTransactionConfidenceChanged(Transaction tx) {
Expand Down Expand Up @@ -191,6 +194,11 @@ private void removeConnectedOutputsOfInputsOfTx(Transaction tx) {
});
}

private void reset() {
unconfirmedBsqChangeOutputList.clear();
persist();
}

private void persist() {
storage.queueUpForSave();
}
Expand Down