Skip to content

Commit

Permalink
Arbitrator republish signedWitnesses on startup (#3448)
Browse files Browse the repository at this point in the history
* Arbitrator republish signedWitnesses on startup

* Keep republish internal to SignedWitnessService
  • Loading branch information
sqrrm authored and ripcurlx committed Oct 24, 2019
1 parent f0242bf commit ea94cf0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
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));
}
}
Original file line number Diff line number Diff line change
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

0 comments on commit ea94cf0

Please sign in to comment.