Skip to content

Commit

Permalink
Merge pull request #3821 from chimp1984/handle-spv-resync-edge-cases
Browse files Browse the repository at this point in the history
Improve handling of spv resync edge case
  • Loading branch information
sqrrm authored Jan 2, 2020
2 parents ab3b0ec + 47647a9 commit 5676841
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
16 changes: 13 additions & 3 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2604,10 +2604,20 @@ popup.warning.openOfferWithInvalidMakerFeeTx=The maker fee transaction for offer
Please go to \"Settings/Network info\" and do a SPV resync.\n\
For further help please contact the Bisq support channel at the Bisq Keybase team.

popup.warning.trade.depositTxNull=The trade with ID {0} has no deposit transaction set.\n\
Please restart the application and if the problem remains move the trade to failed trades and report the problem to \
the Bisq support channel at the Bisq Keybase team.
popup.warning.trade.depositTxNull=The trade with ID ''{0}'' has no deposit transaction set.\n\n\
Please restart the application to see if the problem still exists.\n\n\
If it does, please open the trade details popup by clicking on the trade ID. Then click on the transaction IDs for \
the maker fee transaction and the taker fee transaction to view them on a block explorer. A transaction \
that cannot be found in a block explorer is probably an invalid transaction.\n\n\
If this happens, please report it in the #support channel on the Bisq Keybase (https://keybase.io/team/bisq). \
If your trade fee transaction is invalid, no funds have left your wallet, you can move the trade to failed trades,\
and do an SPV resync for your funds to reappear (see how below).\n\n\
If your trade fee transaction is valid, the fee amount is lost, and you can make a \
request for reimbursement on the support repository on GitHub (https://github.com/bisq-network/support/issues).\n\n\
In both cases, please do an SPV resync from the ''Settings/Network'' screen to clean your wallet of any lingering issues!

popup.warning.trade.depositTxNull.moveToFailedTrades=Move to failed trades
popup.warning.trade.depositTxNull.shutDown=Shut down Bisq

popup.info.securityDepositInfo=To ensure both traders follow the trade protocol, both traders need to pay a security \
deposit.\n\nThis deposit is kept in your trade wallet until your trade has been successfully completed, and then it's \
Expand Down
6 changes: 4 additions & 2 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,10 @@ private void setupHandlers() {
if (c.wasAdded()) {
c.getAddedSubList().forEach(trade -> {
new Popup().warning(Res.get("popup.warning.trade.depositTxNull", trade.getShortId()))
.actionButtonText(Res.get("popup.warning.trade.depositTxNull.moveToFailedTrades"))
.onAction(() -> tradeManager.addTradeToFailedTrades(trade))
.actionButtonText(Res.get("popup.warning.trade.depositTxNull.shutDown"))
.onAction(() -> BisqApp.getShutDownHandler().run())
.secondaryActionButtonText(Res.get("popup.warning.trade.depositTxNull.moveToFailedTrades"))
.onSecondaryAction(() -> tradeManager.addTradeToFailedTrades(trade))
.show();
});
}
Expand Down

0 comments on commit 5676841

Please sign in to comment.