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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,11 +19,14 @@

import bisq.core.account.witness.AccountAgeWitness;
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
import bisq.core.user.User;

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 @@ -62,10 +65,10 @@ public class SignedWitnessService {
private final KeyRing keyRing;
private final P2PService p2PService;
private final ArbitratorManager arbitratorManager;
private final User user;

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


///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -75,10 +78,12 @@ public SignedWitnessService(KeyRing keyRing,
P2PService p2PService,
ArbitratorManager arbitratorManager,
SignedWitnessStorageService signedWitnessStorageService,
AppendOnlyDataStoreService appendOnlyDataStoreService) {
AppendOnlyDataStoreService appendOnlyDataStoreService,
User user) {
this.keyRing = keyRing;
this.p2PService = p2PService;
this.arbitratorManager = arbitratorManager;
this.user = user;

// 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 (user.getRegisteredArbitrator() != null) {
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));
}
}
Expand Up @@ -81,7 +81,7 @@ public void setup() throws Exception {
AppendOnlyDataStoreService appendOnlyDataStoreService = mock(AppendOnlyDataStoreService.class);
ArbitratorManager arbitratorManager = mock(ArbitratorManager.class);
when(arbitratorManager.isPublicKeyInList(any())).thenReturn(true);
signedWitnessService = new SignedWitnessService(null, null, arbitratorManager, null, appendOnlyDataStoreService);
signedWitnessService = new SignedWitnessService(null, null, arbitratorManager, null, appendOnlyDataStoreService, null);
account1DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{1});
account2DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{2});
account3DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{3});
Expand Down