Fix issue with getting complete handler called twice from P2PService

We used a delegate method in P2PService for calling readPersisted on p2PDataStorage and peerManager.
This was from old times when those classed have not been injected classes. The complete handlers got
called from both p2PDataStorage and peerManager but we counted only P2PService as host, so the
countdown completed before the last host was really completed, leading to a nullpointer in
MainView (not always).

We removed now PersistedDataHost interface from P2PService and use P2PDataStorage and PeerManager to be added to hosts.
This commit is contained in:
chimp1984 2020-11-03 13:01:35 -05:00
parent 4161ecf239
commit ab5645b864
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
5 changed files with 25 additions and 22 deletions

View File

@ -168,8 +168,8 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
}
AtomicInteger remaining = new AtomicInteger(hosts.size());
hosts.forEach(e -> {
e.readPersisted(() -> {
hosts.forEach(host -> {
host.readPersisted(() -> {
if (remaining.decrementAndGet() == 0) {
UserThread.execute(completeHandler);
}

View File

@ -19,7 +19,6 @@ package bisq.core.app.misc;
import bisq.core.account.sign.SignedWitnessService;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.app.TorSetup;
import bisq.core.filter.FilterManager;
import bisq.core.trade.statistics.TradeStatisticsManager;
@ -28,6 +27,8 @@ import bisq.network.p2p.P2PServiceListener;
import bisq.network.p2p.network.CloseConnectionReason;
import bisq.network.p2p.network.Connection;
import bisq.network.p2p.network.ConnectionListener;
import bisq.network.p2p.peers.PeerManager;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.common.config.Config;
import bisq.common.proto.persistable.PersistedDataHost;
@ -47,32 +48,36 @@ public class AppSetupWithP2P extends AppSetup {
protected final AccountAgeWitnessService accountAgeWitnessService;
private final SignedWitnessService signedWitnessService;
protected final FilterManager filterManager;
private final TorSetup torSetup;
protected BooleanProperty p2pNetWorkReady;
private final P2PDataStorage p2PDataStorage;
private final PeerManager peerManager;
protected final TradeStatisticsManager tradeStatisticsManager;
protected ArrayList<PersistedDataHost> persistedDataHosts;
protected BooleanProperty p2pNetWorkReady;
@Inject
public AppSetupWithP2P(P2PService p2PService,
P2PDataStorage p2PDataStorage,
PeerManager peerManager,
TradeStatisticsManager tradeStatisticsManager,
AccountAgeWitnessService accountAgeWitnessService,
SignedWitnessService signedWitnessService,
FilterManager filterManager,
TorSetup torSetup,
Config config) {
super(config);
this.p2PService = p2PService;
this.p2PDataStorage = p2PDataStorage;
this.peerManager = peerManager;
this.tradeStatisticsManager = tradeStatisticsManager;
this.accountAgeWitnessService = accountAgeWitnessService;
this.signedWitnessService = signedWitnessService;
this.filterManager = filterManager;
this.torSetup = torSetup;
this.persistedDataHosts = new ArrayList<>();
}
@Override
public void initPersistedDataHosts() {
persistedDataHosts.add(p2PService);
persistedDataHosts.add(p2PDataStorage);
persistedDataHosts.add(peerManager);
// we apply at startup the reading of persisted data but don't want to get it triggered in the constructor
persistedDataHosts.forEach(e -> {
@ -88,7 +93,7 @@ public class AppSetupWithP2P extends AppSetup {
@Override
protected void initBasicServices() {
String postFix = "_" + config.baseCurrencyNetwork.name();
p2PService.getP2PDataStorage().readFromResources(postFix, this::startInitP2PNetwork);
p2PDataStorage.readFromResources(postFix, this::startInitP2PNetwork);
}
private void startInitP2PNetwork() {

View File

@ -19,7 +19,6 @@ package bisq.core.app.misc;
import bisq.core.account.sign.SignedWitnessService;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.app.TorSetup;
import bisq.core.dao.DaoSetup;
import bisq.core.dao.governance.ballot.BallotListService;
import bisq.core.dao.governance.blindvote.MyBlindVoteListService;
@ -31,6 +30,8 @@ import bisq.core.filter.FilterManager;
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.peers.PeerManager;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.common.config.Config;
@ -44,6 +45,8 @@ public class AppSetupWithP2PAndDAO extends AppSetupWithP2P {
@Inject
public AppSetupWithP2PAndDAO(P2PService p2PService,
P2PDataStorage p2PDataStorage,
PeerManager peerManager,
TradeStatisticsManager tradeStatisticsManager,
AccountAgeWitnessService accountAgeWitnessService,
SignedWitnessService signedWitnessService,
@ -55,14 +58,14 @@ public class AppSetupWithP2PAndDAO extends AppSetupWithP2P {
MyProposalListService myProposalListService,
MyReputationListService myReputationListService,
MyProofOfBurnListService myProofOfBurnListService,
TorSetup torSetup,
Config config) {
super(p2PService,
p2PDataStorage,
peerManager,
tradeStatisticsManager,
accountAgeWitnessService,
signedWitnessService,
filterManager,
torSetup,
config);
this.daoSetup = daoSetup;

View File

@ -35,7 +35,8 @@ import bisq.core.trade.failed.FailedTradesManager;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.peers.PeerManager;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.common.config.Config;
import bisq.common.proto.persistable.PersistedDataHost;
@ -63,7 +64,8 @@ public class CorePersistedDataHost {
persistedDataHosts.add(injector.getInstance(ArbitrationDisputeListService.class));
persistedDataHosts.add(injector.getInstance(MediationDisputeListService.class));
persistedDataHosts.add(injector.getInstance(RefundDisputeListService.class));
persistedDataHosts.add(injector.getInstance(P2PService.class));
persistedDataHosts.add(injector.getInstance(P2PDataStorage.class));
persistedDataHosts.add(injector.getInstance(PeerManager.class));
if (injector.getInstance(Config.class).daoActivated) {
persistedDataHosts.add(injector.getInstance(BallotListService.class));

View File

@ -52,7 +52,6 @@ import bisq.common.crypto.KeyRing;
import bisq.common.crypto.PubKeyRing;
import bisq.common.proto.ProtobufferException;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.util.Utilities;
import com.google.inject.Inject;
@ -105,7 +104,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public class P2PService implements SetupListener, MessageListener, ConnectionListener, RequestDataManager.Listener,
HashMapChangedListener, PersistedDataHost {
HashMapChangedListener {
private static final Logger log = LoggerFactory.getLogger(P2PService.class);
private final SeedNodeRepository seedNodeRepository;
@ -184,12 +183,6 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
});
}
@Override
public void readPersisted(Runnable completeHandler) {
p2PDataStorage.readPersisted(completeHandler);
peerManager.readPersisted(completeHandler);
}
///////////////////////////////////////////////////////////////////////////////////////////
// API