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

Fix loss of mailbox messages during SPV resync #6376

Merged
merged 1 commit into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/src/main/java/bisq/core/app/DomainInitialisation.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import bisq.core.user.User;

import bisq.network.p2p.P2PService;
import bisq.network.p2p.mailbox.MailboxMessageService;

import bisq.common.ClockWatcher;
import bisq.common.persistence.PersistenceManager;
Expand Down Expand Up @@ -115,6 +116,7 @@ public class DomainInitialisation {
private final TriggerPriceService triggerPriceService;
private final MempoolService mempoolService;
private final OpenBsqSwapOfferService openBsqSwapOfferService;
private final MailboxMessageService mailboxMessageService;

@Inject
public DomainInitialisation(ClockWatcher clockWatcher,
Expand Down Expand Up @@ -154,7 +156,8 @@ public DomainInitialisation(ClockWatcher clockWatcher,
DaoStateSnapshotService daoStateSnapshotService,
TriggerPriceService triggerPriceService,
MempoolService mempoolService,
OpenBsqSwapOfferService openBsqSwapOfferService) {
OpenBsqSwapOfferService openBsqSwapOfferService,
MailboxMessageService mailboxMessageService) {
this.clockWatcher = clockWatcher;
this.tradeLimits = tradeLimits;
this.arbitrationManager = arbitrationManager;
Expand Down Expand Up @@ -193,6 +196,7 @@ public DomainInitialisation(ClockWatcher clockWatcher,
this.triggerPriceService = triggerPriceService;
this.mempoolService = mempoolService;
this.openBsqSwapOfferService = openBsqSwapOfferService;
this.mailboxMessageService = mailboxMessageService;
}

public void initDomainServices(Consumer<String> rejectedTxErrorMessageHandler,
Expand Down Expand Up @@ -277,6 +281,8 @@ public void initDomainServices(Consumer<String> rejectedTxErrorMessageHandler,
triggerPriceService.onAllServicesInitialized();
mempoolService.onAllServicesInitialized();

mailboxMessageService.onAllServicesInitialized();

if (revolutAccountsUpdateHandler != null) {
revolutAccountsUpdateHandler.accept(user.getPaymentAccountsAsObservable().stream()
.filter(paymentAccount -> paymentAccount instanceof RevolutAccount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,11 @@ private void updateBitcoinPeersTable() {
bitcoinNetworkListItems.setAll(walletsSetup.getPeerGroup().getConnectedPeers().stream()
.map(BitcoinNetworkListItem::new)
.collect(Collectors.toList()));
chainHeightTextField.textProperty().setValue(Res.get("settings.net.chainHeight",
walletsSetup.chainHeightProperty().get(),
PeerGroup.getMostCommonChainHeight(walletsSetup.connectedPeersProperty().get())));
if (walletsSetup.connectedPeersProperty().get() != null) {
chainHeightTextField.textProperty().setValue(Res.get("settings.net.chainHeight",
walletsSetup.chainHeightProperty().get(),
PeerGroup.getMostCommonChainHeight(walletsSetup.connectedPeersProperty().get())));
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD
private final Map<String, MailboxItem> mailboxItemsByUid = new HashMap<>();

private boolean isBootstrapped;
private boolean allServicesInitialized;
private boolean initAfterBootstrapped;

@Inject
public MailboxMessageService(NetworkNode networkNode,
Expand Down Expand Up @@ -215,6 +217,12 @@ public void readPersisted(Runnable completeHandler) {
// API
///////////////////////////////////////////////////////////////////////////////////////////

// We wait until all services are ready to avoid some edge cases as in https://github.com/bisq-network/bisq/issues/6367
public void onAllServicesInitialized() {
allServicesInitialized = true;
init();
}

// We don't listen on requestDataManager directly as we require the correct
// order of execution. The p2pService is handling the correct order of execution and we get called
// directly from there.
Expand All @@ -226,11 +234,18 @@ public void onBootstrapped() {

// second stage starup for MailboxMessageService ... apply existing messages to their modules
public void initAfterBootstrapped() {
// Only now we start listening and processing. The p2PDataStorage is our cache for data we have received
// after the hidden service was ready.
addHashMapChangedListener();
onAdded(p2PDataStorage.getMap().values());
maybeRepublishMailBoxMessages();
initAfterBootstrapped = true;
init();
}

private void init() {
if (allServicesInitialized && initAfterBootstrapped) {
// Only now we start listening and processing. The p2PDataStorage is our cache for data we have received
// after the hidden service was ready.
addHashMapChangedListener();
onAdded(p2PDataStorage.getMap().values());
maybeRepublishMailBoxMessages();
}
}


Expand Down Expand Up @@ -477,7 +492,7 @@ private void processMyMailboxItem(MailboxItem mailboxItem, String uid) {
mailboxMessage.getClass().getSimpleName(), uid, sender);
decryptedMailboxListeners.forEach(e -> e.onMailboxMessageAdded(decryptedMessageWithPubKey, sender));

if (isBootstrapped) {
if (allServicesInitialized && isBootstrapped) { // GH ISSUE 6367 only remove after fully initialized
// After we notified our listeners we remove the data immediately from the network.
// In case the client has not been ready it need to take it via getMailBoxMessages.
// We do not remove the data from our local map at that moment. This has to be called explicitely from the
Expand Down