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 p2pNetworkAndWalletReady #4479

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class XmrTxProofService implements AssetTxProofService {
private Map<String, ChangeListener<Trade.State>> tradeStateListenerMap = new HashMap<>();
private ChangeListener<Number> btcPeersListener, btcBlockListener;
private BootstrapListener bootstrapListener;
private MonadicBinding<Boolean> p2pNetworkAndWalletReady;
private ChangeListener<Boolean> p2pNetworkAndWalletReadyListener;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -122,18 +124,26 @@ public void onAllServicesInitialized() {
// As we might trigger the payout tx we want to be sure that we are well connected to the Bitcoin network.
// onAllServicesInitialized is called once we have received the initial data but we want to have our
// hidden service published and upDatedDataResponse received before we start.
MonadicBinding<Boolean> p2pNetworkAndWalletReady = EasyBind.combine(isP2pBootstrapped(), hasSufficientBtcPeers(), isBtcBlockDownloadComplete(),
(isP2pBootstrapped, hasSufficientBtcPeers, isBtcBlockDownloadComplete) -> {
log.info("isP2pBootstrapped={}, hasSufficientBtcPeers={} isBtcBlockDownloadComplete={}",
isP2pBootstrapped, hasSufficientBtcPeers, isBtcBlockDownloadComplete);
return isP2pBootstrapped && hasSufficientBtcPeers && isBtcBlockDownloadComplete;
});

p2pNetworkAndWalletReady.subscribe((observable, oldValue, newValue) -> {
if (newValue) {
onP2pNetworkAndWalletReady();
}
});
BooleanProperty isP2pBootstrapped = isP2pBootstrapped();
BooleanProperty hasSufficientBtcPeers = hasSufficientBtcPeers();
BooleanProperty isBtcBlockDownloadComplete = isBtcBlockDownloadComplete();
if (isP2pBootstrapped.get() && hasSufficientBtcPeers.get() && isBtcBlockDownloadComplete.get()) {
onP2pNetworkAndWalletReady();
} else {
p2pNetworkAndWalletReady = EasyBind.combine(isP2pBootstrapped, hasSufficientBtcPeers, isBtcBlockDownloadComplete,
(bootstrapped, sufficientPeers, downloadComplete) -> {
log.info("isP2pBootstrapped={}, hasSufficientBtcPeers={} isBtcBlockDownloadComplete={}",
bootstrapped, sufficientPeers, downloadComplete);
return bootstrapped && sufficientPeers && downloadComplete;
});

p2pNetworkAndWalletReadyListener = (observable, oldValue, newValue) -> {
if (newValue) {
onP2pNetworkAndWalletReady();
}
};
p2pNetworkAndWalletReady.subscribe(p2pNetworkAndWalletReadyListener);
}
}

@Override
Expand All @@ -148,6 +158,12 @@ public void shutDown() {
///////////////////////////////////////////////////////////////////////////////////////////

private void onP2pNetworkAndWalletReady() {
if (p2pNetworkAndWalletReady != null) {
p2pNetworkAndWalletReady.removeListener(p2pNetworkAndWalletReadyListener);
p2pNetworkAndWalletReady = null;
p2pNetworkAndWalletReadyListener = null;
}

if (!preferences.findAutoConfirmSettings("XMR").isPresent()) {
log.error("AutoConfirmSettings is not present");
}
Expand Down