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

Access concrete data stores #5031

Merged
merged 3 commits into from
Jan 3, 2021
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.
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 @@ -73,6 +73,7 @@ public class SignedWitnessService {
private final KeyRing keyRing;
private final P2PService p2PService;
private final ArbitratorManager arbitratorManager;
private final SignedWitnessStorageService signedWitnessStorageService;
private final User user;
private final FilterManager filterManager;

Expand All @@ -98,6 +99,7 @@ public SignedWitnessService(KeyRing keyRing,
this.keyRing = keyRing;
this.p2PService = p2PService;
this.arbitratorManager = arbitratorManager;
this.signedWitnessStorageService = signedWitnessStorageService;
this.user = user;
this.filterManager = filterManager;

Expand All @@ -117,7 +119,7 @@ public void onAllServicesInitialized() {
});

// At startup the P2PDataStorage initializes earlier, otherwise we get the listener called.
p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().forEach(e -> {
signedWitnessStorageService.getMap().values().forEach(e -> {
if (e instanceof SignedWitness)
addToMap((SignedWitness) e);
});
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.app;

import bisq.core.account.sign.SignedWitness;
import bisq.core.account.sign.SignedWitnessStorageService;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.alert.Alert;
import bisq.core.alert.AlertManager;
Expand Down Expand Up @@ -124,6 +125,7 @@ default void onRequestWalletPassword() {
private final WalletsSetup walletsSetup;
private final BtcWalletService btcWalletService;
private final P2PService p2PService;
private final SignedWitnessStorageService signedWitnessStorageService;
private final TradeManager tradeManager;
private final OpenOfferManager openOfferManager;
private final Preferences preferences;
Expand Down Expand Up @@ -205,6 +207,7 @@ public BisqSetup(DomainInitialisation domainInitialisation,
WalletsSetup walletsSetup,
BtcWalletService btcWalletService,
P2PService p2PService,
SignedWitnessStorageService signedWitnessStorageService,
TradeManager tradeManager,
OpenOfferManager openOfferManager,
Preferences preferences,
Expand All @@ -225,6 +228,7 @@ public BisqSetup(DomainInitialisation domainInitialisation,
this.walletsSetup = walletsSetup;
this.btcWalletService = btcWalletService;
this.p2PService = p2PService;
this.signedWitnessStorageService = signedWitnessStorageService;
this.tradeManager = tradeManager;
this.openOfferManager = openOfferManager;
this.preferences = preferences;
Expand Down Expand Up @@ -652,7 +656,7 @@ private void maybeShowAccountSigningStateInfo() {

private void checkSigningState(AccountAgeWitnessService.SignState state,
String key, Consumer<String> displayHandler) {
boolean signingStateFound = p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().stream()
boolean signingStateFound = signedWitnessStorageService.getMap().values().stream()
.anyMatch(payload -> isSignedWitnessOfMineWithState(payload, state));

maybeTriggerDisplayHandler(key, displayHandler, signingStateFound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class ProposalService implements HashMapChangedListener, AppendOnlyDataSt
DaoStateListener, DaoSetupService {
private final P2PService p2PService;
private final PeriodService periodService;
private final ProposalStorageService proposalStorageService;
private final DaoStateService daoStateService;
private final ProposalValidatorProvider validatorProvider;

Expand Down Expand Up @@ -100,6 +101,7 @@ public ProposalService(P2PService p2PService,
@Named(Config.DAO_ACTIVATED) boolean daoActivated) {
this.p2PService = p2PService;
this.periodService = periodService;
this.proposalStorageService = proposalStorageService;
this.daoStateService = daoStateService;
this.validatorProvider = validatorProvider;

Expand Down Expand Up @@ -217,7 +219,7 @@ private void fillListFromProtectedStore() {
}

private void fillListFromAppendOnlyDataStore() {
p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().forEach(e -> onAppendOnlyDataAdded(e, false));
proposalStorageService.getMap().values().forEach(e -> onAppendOnlyDataAdded(e, false));
}

private void maybePublishToAppendOnlyDataStore() {
Expand Down
11 changes: 5 additions & 6 deletions desktop/src/main/java/bisq/desktop/main/market/MarketView.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
import bisq.core.locale.Res;
import bisq.core.offer.OfferPayload;
import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.trade.statistics.TradeStatistics3StorageService;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;

import bisq.network.p2p.P2PService;

import bisq.common.util.Utilities;

import javax.inject.Inject;
Expand Down Expand Up @@ -71,7 +70,7 @@ public class MarketView extends ActivatableView<TabPane, Void> {
@FXML
Tab offerBookTab, tradesTab, spreadTab;
private final ViewLoader viewLoader;
private final P2PService p2PService;
private final TradeStatistics3StorageService tradeStatistics3StorageService;
private final OfferBook offerBook;
private final CoinFormatter formatter;
private final Navigation navigation;
Expand All @@ -83,12 +82,12 @@ public class MarketView extends ActivatableView<TabPane, Void> {

@Inject
public MarketView(CachingViewLoader viewLoader,
P2PService p2PService,
TradeStatistics3StorageService tradeStatistics3StorageService,
OfferBook offerBook,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter,
Navigation navigation) {
this.viewLoader = viewLoader;
this.p2PService = p2PService;
this.tradeStatistics3StorageService = tradeStatistics3StorageService;
this.offerBook = offerBook;
this.formatter = formatter;
this.navigation = navigation;
Expand Down Expand Up @@ -181,7 +180,7 @@ private String getAllTradesWithReferralId() {
// all items of both traders in case the referral ID was only set by one trader.
// If both traders had set it the tradeStatistics is only delivered once.
// If both traders used a different referral ID then we would get 2 objects.
List<String> list = p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().stream()
List<String> list = tradeStatistics3StorageService.getMapOfAllData().values().stream()
.filter(e -> e instanceof TradeStatistics3)
.map(e -> (TradeStatistics3) e)
.filter(tradeStatistics3 -> tradeStatistics3.getExtraDataMap() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,10 @@ public void onBootstrapComplete() {
removeExpiredEntriesTimer = UserThread.runPeriodically(this::removeExpiredEntries, CHECK_TTL_INTERVAL_SEC);
}

public Map<ByteArray, PersistableNetworkPayload> getAppendOnlyDataStoreMap() {
// Domain access should use the concrete appendOnlyDataStoreService if available. The Historical data store require
// care which data should be accessed (live data or all data).
@VisibleForTesting
Map<ByteArray, PersistableNetworkPayload> getAppendOnlyDataStoreMap() {
return appendOnlyDataStoreService.getMap();
}

Expand Down Expand Up @@ -642,7 +645,7 @@ private boolean addPersistableNetworkPayload(PersistableNetworkPayload payload,
}

ByteArray hashAsByteArray = new ByteArray(payload.getHash());
boolean payloadHashAlreadyInStore = getAppendOnlyDataStoreMap().containsKey(hashAsByteArray);
boolean payloadHashAlreadyInStore = appendOnlyDataStoreService.getMap().containsKey(hashAsByteArray);

// Store already knows about this payload. Ignore it unless the caller specifically requests a republish.
if (payloadHashAlreadyInStore && !reBroadcast) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public void readFromResourcesSync(String postFix) {

public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> getMap() {
return services.stream()
.flatMap(service -> service.getMap().entrySet().stream())
.flatMap(service -> {
Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = service instanceof HistoricalDataStoreService ?
((HistoricalDataStoreService) service).getMapOfAllData() :
service.getMap();
return map.entrySet().stream();
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.app.DevEnv;
import bisq.common.app.Version;
import bisq.common.persistence.PersistenceManager;

Expand Down Expand Up @@ -109,15 +110,11 @@ public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> getMapOfAllData(
// MapStoreService
///////////////////////////////////////////////////////////////////////////////////////////

// TODO optimize so that callers to AppendOnlyDataStoreService are not invoking that often getMap
// ProposalService is one of the main callers and could avoid it by using the ProposalStoreService directly
// instead of AppendOnlyDataStoreService

// By default we return the live data only. This method should not be used by domain clients but rather the
// custom methods getMapOfAllData, getMapOfLiveData or getMapSinceVersion
@Override
public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> getMap() {
return store.getMap();
DevEnv.logErrorAndThrowIfDevMode("HistoricalDataStoreService.getMap should not be used by domain " +
"clients but rather the custom methods getMapOfAllData, getMapOfLiveData or getMapSinceVersion");
return getMapOfAllData();
}

@Override
Expand Down