Merge pull request #6376 from jmacxx/fix_issue_6367

Fix loss of mailbox messages during SPV resync
This commit is contained in:
Alejandro García 2022-11-29 14:41:27 +02:00 committed by GitHub
commit e054083c1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 10 deletions

View file

@ -58,6 +58,7 @@ import bisq.core.trade.txproof.xmr.XmrTxProofService;
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;
@ -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,
@ -154,7 +156,8 @@ public class DomainInitialisation {
DaoStateSnapshotService daoStateSnapshotService,
TriggerPriceService triggerPriceService,
MempoolService mempoolService,
OpenBsqSwapOfferService openBsqSwapOfferService) {
OpenBsqSwapOfferService openBsqSwapOfferService,
MailboxMessageService mailboxMessageService) {
this.clockWatcher = clockWatcher;
this.tradeLimits = tradeLimits;
this.arbitrationManager = arbitrationManager;
@ -193,6 +196,7 @@ public class DomainInitialisation {
this.triggerPriceService = triggerPriceService;
this.mempoolService = mempoolService;
this.openBsqSwapOfferService = openBsqSwapOfferService;
this.mailboxMessageService = mailboxMessageService;
}
public void initDomainServices(Consumer<String> rejectedTxErrorMessageHandler,
@ -277,6 +281,8 @@ public class DomainInitialisation {
triggerPriceService.onAllServicesInitialized();
mempoolService.onAllServicesInitialized();
mailboxMessageService.onAllServicesInitialized();
if (revolutAccountsUpdateHandler != null) {
revolutAccountsUpdateHandler.accept(user.getPaymentAccountsAsObservable().stream()
.filter(paymentAccount -> paymentAccount instanceof RevolutAccount)

View file

@ -502,9 +502,11 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
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())));
}
}
}

View file

@ -130,6 +130,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,
@ -236,6 +238,12 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD
// 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.
@ -247,11 +255,18 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD
// 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();
}
}
@ -498,7 +513,7 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD
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