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

Arbitrator republish signedWitnesses on startup #3448

Merged
merged 2 commits into from
Oct 24, 2019
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.
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 @@ -20,10 +20,12 @@
import bisq.core.account.witness.AccountAgeWitness;
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;

import bisq.network.p2p.BootstrapListener;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreService;

import bisq.common.UserThread;
import bisq.common.crypto.CryptoException;
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.Sig;
Expand Down Expand Up @@ -52,6 +54,7 @@
import java.util.Stack;
import java.util.stream.Collectors;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand All @@ -64,7 +67,8 @@ public class SignedWitnessService {
private final ArbitratorManager arbitratorManager;

private final Map<P2PDataStorage.ByteArray, SignedWitness> signedWitnessMap = new HashMap<>();

@Setter
private boolean republishOnStartup = false;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand All @@ -80,6 +84,7 @@ public SignedWitnessService(KeyRing keyRing,
this.p2PService = p2PService;
this.arbitratorManager = arbitratorManager;


// We need to add that early (before onAllServicesInitialized) as it will be used at startup.
appendOnlyDataStoreService.addService(signedWitnessStorageService);
}
Expand All @@ -100,8 +105,24 @@ public void onAllServicesInitialized() {
if (e instanceof SignedWitness)
addToMap((SignedWitness) e);
});

if (p2PService.isBootstrapped()) {
onBootstrapComplete();
} else {
p2PService.addP2PServiceListener(new BootstrapListener() {
@Override
public void onUpdatedDataReceived() {
onBootstrapComplete();
}
});
}
}

private void onBootstrapComplete() {
if (republishOnStartup) {
UserThread.runAfter(this::doRepublishAllSignedWitnesses, 60);
}
}

///////////////////////////////////////////////////////////////////////////////////////////
// API
Expand Down Expand Up @@ -344,4 +365,8 @@ private void publishSignedWitness(SignedWitness signedWitness) {
p2PService.addPersistableNetworkPayload(signedWitness, false);
}
}

private void doRepublishAllSignedWitnesses() {
signedWitnessMap.forEach((e, signedWitness) -> p2PService.addPersistableNetworkPayload(signedWitness, true));
}
}
3 changes: 3 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ private void initDomainServices() {

accountAgeWitnessService.onAllServicesInitialized();
signedWitnessService.onAllServicesInitialized();
if (user.getRegisteredArbitrator() != null) {
signedWitnessService.setRepublishOnStartup(true);
}

priceFeedService.setCurrencyCodeOnInit();

Expand Down