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

[WIP] New trade stats #4577

Closed
wants to merge 97 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
cb9f0f0
Initial tests
freimair Apr 9, 2020
3296db3
Version helper uses real Bisq version
freimair Apr 15, 2020
e7831d6
Tests use static fixtures
freimair Apr 16, 2020
581286e
Migration test succeeds
freimair Apr 16, 2020
fc7a43d
GetMap test succeeds
freimair Apr 16, 2020
d111d8c
GetMapSinceFilter works
freimair Apr 16, 2020
6eda9a9
updateScenario works
freimair Apr 16, 2020
ff53f51
freshInstall scenario works
freimair Apr 16, 2020
49731f9
put scenario works
freimair Apr 16, 2020
e123a0b
Introduce SplitStore and Service to handle BL
freimair Apr 17, 2020
da5d41b
Moved file handling logic to SplitStoreService
freimair Apr 17, 2020
c7351a0
Activate other split data stores
freimair Apr 17, 2020
e2e80d7
Refactored tests
freimair Apr 20, 2020
10c1ecc
Initial tests for requests
freimair Apr 20, 2020
f6cea15
Requests are smaller
freimair Apr 20, 2020
0d80123
Prevent adding duplicate data
freimair Apr 24, 2020
aad57c3
Enforce version format and filter faulty ones
freimair Apr 24, 2020
faca8e4
Test incoming special keys from the future
freimair Apr 24, 2020
72600b1
Javadoc cosmetics
freimair Apr 24, 2020
3ad395b
Init integration test script
freimair Apr 29, 2020
2589137
Persist live database after split
freimair May 1, 2020
34abad0
Integration test script tests stock
freimair May 1, 2020
62a77e3
Use version history array
freimair May 1, 2020
39fcca5
Integration test script tests new system
freimair May 4, 2020
a3628ff
Use full sync between seednodes
freimair May 4, 2020
a374249
Cleanup integration test script
freimair May 4, 2020
8e55f64
Ignore some tests
freimair May 11, 2020
e927e6d
Adjust P2PDataStorage tests
freimair May 11, 2020
2fb2232
Add another migration test
freimair May 12, 2020
5f8b7cf
Reactivate ignored tests
freimair May 12, 2020
f8320fe
Refactoring and cleaning up
freimair May 20, 2020
017bbfd
Cleanup
freimair May 20, 2020
d2a6655
Refactored test helpers
freimair May 21, 2020
469c374
Fixed a potential issue when loading stores
freimair May 21, 2020
249e185
Fixed wrong filename
freimair May 22, 2020
06ec223
Refactoring
freimair May 22, 2020
eabadc0
Make special key platform-independent
freimair May 26, 2020
755fc03
Fixed persisting wrong data store
freimair Jun 12, 2020
d218f2e
Renamed data stores
freimair Jun 12, 2020
c34bfee
Replace TODO comment
freimair Jun 16, 2020
d6f195d
Fixed a timing issue
freimair Jul 1, 2020
d81bdab
Added 1.3.6 and 1.3.7 data stores
freimair Sep 1, 2020
abbfedc
Update history version list
freimair Sep 1, 2020
5f94406
Removed deprecated test mechanisms
freimair Sep 1, 2020
0eccec7
Cleanup imports
freimair Sep 1, 2020
270f1e7
Included PR feedback
freimair Sep 1, 2020
c8c63ef
Included PR feedback
freimair Sep 1, 2020
76cc37e
Added 1.3.8 data stores
freimair Sep 12, 2020
b4aae51
Use Version.VERSION again
freimair Sep 12, 2020
f83c147
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 13, 2020
5f8e779
Refactor: Add getStore method to be reused by SplitStoreService
chimp1984 Sep 13, 2020
3100888
Use readStore(); instead of store = readStore(getFileName());
chimp1984 Sep 13, 2020
591c2fb
Apply code inspection suggestions
chimp1984 Sep 13, 2020
d5c6644
Add mapOfHistoricalStores field
chimp1984 Sep 13, 2020
3dac4c4
Revert critical data stores to current version.
chimp1984 Sep 13, 2020
2cef411
Add version field
chimp1984 Sep 13, 2020
8458a88
Remove methods in MapStoreService and do instead instance of check in…
chimp1984 Sep 13, 2020
2ece512
Add current version to version list. Makes it more clear that those a…
chimp1984 Sep 13, 2020
965de7f
Remove file
chimp1984 Sep 13, 2020
cfefae2
Rename SplitStore to PersistableNetworkPayload
chimp1984 Sep 13, 2020
28987f5
Rename for better clarity
chimp1984 Sep 13, 2020
6cf054c
Fix bug with missing replace -> use existing methods in Version for v…
chimp1984 Sep 13, 2020
aadd2e4
Revert version to 1.3.7 to not break build
chimp1984 Sep 13, 2020
7a5ba0b
Fix param in test. Add Ignore to the 2 test classes handling the new …
chimp1984 Sep 13, 2020
224eaab
Fix param in test.
chimp1984 Sep 13, 2020
98877b4
Revert changes at tests from prev version
chimp1984 Sep 13, 2020
32cf32c
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 15, 2020
8f2e4ca
Change dev mode price
chimp1984 Sep 15, 2020
22fc97d
Remove test files from previous version
chimp1984 Sep 16, 2020
9c873a6
Add getPersisted method
chimp1984 Sep 16, 2020
3252a50
remove test files
chimp1984 Sep 16, 2020
a3ea54a
remove test
chimp1984 Sep 16, 2020
2b61563
Fix issues and refactor
chimp1984 Sep 16, 2020
996364e
Cleanup
chimp1984 Sep 16, 2020
4115c0c
Add data from non-splitStoreService as well
chimp1984 Sep 16, 2020
ad95019
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 17, 2020
e680c4d
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 19, 2020
80bf8bf
Merge branch 'master_upstream' into chimp-reduce_initial_request_size
chimp1984 Sep 27, 2020
3a4784e
Merge branch 'chimp-reduce_initial_request_size' of https://github.co…
chimp1984 Sep 27, 2020
c482a1b
Cleanups, renaming, add comments
chimp1984 Sep 27, 2020
ba0dc1b
Fix mock class to reflect real class better.
chimp1984 Sep 28, 2020
f132a35
Fix incorrect test.
chimp1984 Sep 28, 2020
6eb1efb
Remove todo, add system line break
chimp1984 Sep 28, 2020
ee725bc
Add more logs
chimp1984 Sep 28, 2020
82c5b5e
Add isEmpty check
chimp1984 Sep 29, 2020
171be24
Do not call super.readFromResources(postFix); as we do not have a no…
chimp1984 Sep 29, 2020
bd38097
Add more logs
chimp1984 Sep 29, 2020
0feece6
Remove toProtoNetworkEnvelope call used only for debug logs
chimp1984 Sep 29, 2020
e402c8a
Only call pruneStore if we have created a new historical store from r…
chimp1984 Sep 29, 2020
620dfca
Fix wrong param order in log
chimp1984 Sep 29, 2020
90da37f
Remove dev test data
chimp1984 Sep 29, 2020
9240eec
Add more info in log
chimp1984 Sep 29, 2020
ab82286
Rename SplitStoreService to HistoricalDataStoreService
chimp1984 Sep 29, 2020
5e09eeb
Add TradeStatistics3
chimp1984 Sep 30, 2020
d0b5faf
Use a set instead of a list
chimp1984 Sep 30, 2020
86101b8
Convert TradeStatistics2 to TradeStatistics3
chimp1984 Sep 30, 2020
c360196
Listen to old TradeStatistics2 objects, convert and store them and re…
chimp1984 Sep 30, 2020
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
3 changes: 2 additions & 1 deletion common/src/main/java/bisq/common/app/Capability.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public enum Capability {
SIGNED_ACCOUNT_AGE_WITNESS, // Supports the signed account age witness feature
MEDIATION, // Supports mediation feature
REFUND_AGENT, // Supports refund agents
TRADE_STATISTICS_HASH_UPDATE // We changed the hash method in 1.2.0 and that requires update to 1.2.2 for handling it correctly, otherwise the seed nodes have to process too much data.
TRADE_STATISTICS_HASH_UPDATE, // We changed the hash method in 1.2.0 and that requires update to 1.2.2 for handling it correctly, otherwise the seed nodes have to process too much data.
TRADE_STATISTICS_3 // We used a new reduced trade statistics model from v1.4.0 on
}
10 changes: 9 additions & 1 deletion common/src/main/java/bisq/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package bisq.common.app;

import java.util.Arrays;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;
Expand All @@ -29,6 +32,11 @@ public class Version {
// We use semantic versioning with major, minor and patch
public static final String VERSION = "1.3.9";

/**
* Holds a list of the versions of tagged resource files for optimizing the getData requests.
*/
public static final List<String> HISTORY = Arrays.asList("1.4.0");

public static int getMajorVersion(String version) {
return getSubVersion(version, 0);
}
Expand All @@ -45,7 +53,7 @@ public static boolean isNewVersion(String newVersion) {
return isNewVersion(newVersion, VERSION);
}

static boolean isNewVersion(String newVersion, String currentVersion) {
public static boolean isNewVersion(String newVersion, String currentVersion) {
if (newVersion.equals(currentVersion))
return false;
else if (getMajorVersion(newVersion) > getMajorVersion(currentVersion))
Expand Down
11 changes: 8 additions & 3 deletions common/src/main/java/bisq/common/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ public Storage(@Named(Config.STORAGE_DIR) File dir,
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
}

@Nullable
public T getPersisted(String fileName) {
return getPersisted(new File(dir, fileName));
}

@Nullable
public T initAndGetPersistedWithFileName(String fileName, long delay) {
this.fileName = fileName;
storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted();
return getPersisted(storageFile);
}

@Nullable
Expand All @@ -96,7 +101,7 @@ public T initAndGetPersisted(T persistable, String fileName, long delay) {
this.fileName = fileName;
storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted();
return getPersisted(storageFile);
}

public void queueUpForSave() {
Expand Down Expand Up @@ -144,7 +149,7 @@ public void remove(String fileName) {
// We do the file read on the UI thread to avoid problems from multi threading.
// Data are small and read is done only at startup, so it is no performance issue.
@Nullable
private T getPersisted() {
private T getPersisted(File storageFile) {
if (storageFile.exists()) {
long now = System.currentTimeMillis();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import bisq.common.config.Config;
import bisq.common.storage.Storage;

import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Named;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@


import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -40,9 +35,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class SignedWitnessStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class SignedWitnessStore extends PersistableNetworkPayloadStore {

SignedWitnessStore() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import bisq.common.config.Config;
import bisq.common.storage.Storage;

import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Named;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
package bisq.core.account.witness;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -39,9 +34,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class AccountAgeWitnessStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class AccountAgeWitnessStore extends PersistableNetworkPayloadStore {

AccountAgeWitnessStore() {
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import bisq.core.offer.OfferPayload;
import bisq.core.payment.PaymentAccount;
import bisq.core.trade.handlers.TransactionResultHandler;
import bisq.core.trade.statistics.TradeStatistics2;
import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.trade.statistics.TradeStatisticsManager;

import bisq.common.app.Version;
Expand Down Expand Up @@ -189,7 +189,7 @@ public void removeWalletPassword(String password) {
walletsService.removeWalletPassword(password);
}

public List<TradeStatistics2> getTradeStatistics() {
public List<TradeStatistics3> getTradeStatistics() {
return new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public void updateAssetStates() {
// TradeAmountDateTuple object holding only the data we need.
Map<String, List<TradeAmountDateTuple>> lookupMap = new HashMap<>();
tradeStatisticsManager.getObservableTradeStatisticsSet().stream()
.filter(e -> CurrencyUtil.isCryptoCurrency(e.getBaseCurrency()))
.filter(e -> CurrencyUtil.isCryptoCurrency(e.getCurrency()))
.forEach(e -> {
lookupMap.putIfAbsent(e.getBaseCurrency(), new ArrayList<>());
lookupMap.get(e.getBaseCurrency()).add(new TradeAmountDateTuple(e.getTradeAmount().getValue(), e.getTradeDate().getTime()));
lookupMap.putIfAbsent(e.getCurrency(), new ArrayList<>());
lookupMap.get(e.getCurrency()).add(new TradeAmountDateTuple(e.getAmount(), e.getDate()));
});

getStatefulAssets().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
package bisq.core.dao.governance.blindvote.storage;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -39,9 +34,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class BlindVoteStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class BlindVoteStore extends PersistableNetworkPayloadStore {

BlindVoteStore() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ private void fillListFromProtectedStore() {
p2PService.getDataMap().values().forEach(e -> onProtectedDataAdded(e, false));
}

//todo use proposalStorageService
private void fillListFromAppendOnlyDataStore() {
p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().forEach(e -> onAppendOnlyDataAdded(e, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
package bisq.core.dao.governance.proposal.storage.appendonly;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;

import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;

import com.google.protobuf.Message;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -39,9 +34,7 @@
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class ProposalStore implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
public class ProposalStore extends PersistableNetworkPayloadStore {

ProposalStore() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import bisq.core.support.dispute.agent.DisputeAgent;
import bisq.core.support.dispute.agent.DisputeAgentManager;
import bisq.core.trade.statistics.TradeStatistics2;
import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.trade.statistics.TradeStatisticsManager;

import bisq.common.util.Tuple2;
Expand All @@ -30,7 +30,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -46,22 +45,22 @@ public static <T extends DisputeAgent> T getLeastUsedMediator(TradeStatisticsMan
DisputeAgentManager<T> disputeAgentManager) {
return getLeastUsedDisputeAgent(tradeStatisticsManager,
disputeAgentManager,
TradeStatistics2.MEDIATOR_ADDRESS);
true);
}

public static <T extends DisputeAgent> T getLeastUsedRefundAgent(TradeStatisticsManager tradeStatisticsManager,
DisputeAgentManager<T> disputeAgentManager) {
return getLeastUsedDisputeAgent(tradeStatisticsManager,
disputeAgentManager,
TradeStatistics2.REFUND_AGENT_ADDRESS);
false);
}

private static <T extends DisputeAgent> T getLeastUsedDisputeAgent(TradeStatisticsManager tradeStatisticsManager,
DisputeAgentManager<T> disputeAgentManager,
String extraMapKey) {
boolean isMediator) {
// We take last 100 entries from trade statistics
List<TradeStatistics2> list = new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet());
list.sort(Comparator.comparing(TradeStatistics2::getTradeDate));
List<TradeStatistics3> list = new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet());
list.sort(Comparator.comparing(TradeStatistics3::getDate));
Collections.reverse(list);
if (!list.isEmpty()) {
int max = Math.min(list.size(), 100);
Expand All @@ -70,9 +69,7 @@ private static <T extends DisputeAgent> T getLeastUsedDisputeAgent(TradeStatisti

// We stored only first 4 chars of disputeAgents onion address
List<String> lastAddressesUsedInTrades = list.stream()
.filter(tradeStatistics2 -> tradeStatistics2.getExtraDataMap() != null)
.map(tradeStatistics2 -> tradeStatistics2.getExtraDataMap().get(extraMapKey))
.filter(Objects::nonNull)
.map(stat -> isMediator ? stat.getMediator() : stat.getRefundAgent())
.collect(Collectors.toList());

Set<String> disputeAgents = disputeAgentManager.getObservableMap().values().stream()
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/bisq/core/proto/CoreProtoResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import bisq.core.payment.payload.WeChatPayAccountPayload;
import bisq.core.payment.payload.WesternUnionAccountPayload;
import bisq.core.trade.statistics.TradeStatistics2;
import bisq.core.trade.statistics.TradeStatistics3;

import bisq.common.proto.ProtoResolver;
import bisq.common.proto.ProtobufferRuntimeException;
Expand Down Expand Up @@ -178,6 +179,8 @@ public PersistablePayload fromProto(protobuf.PersistableNetworkPayload proto) {
return BlindVotePayload.fromProto(proto.getBlindVotePayload());
case SIGNED_WITNESS:
return SignedWitness.fromProto(proto.getSignedWitness());
case TRADE_STATISTICS3:
return TradeStatistics3.fromProto(proto.getTradeStatistics3());
default:
throw new ProtobufferRuntimeException("Unknown proto message case (PB.PersistableNetworkPayload). messageCase=" + proto.getMessageCase());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import bisq.core.support.dispute.refund.RefundDisputeList;
import bisq.core.trade.TradableList;
import bisq.core.trade.statistics.TradeStatistics2Store;
import bisq.core.trade.statistics.TradeStatistics3Store;
import bisq.core.user.PreferencesPayload;
import bisq.core.user.UserPayload;

Expand Down Expand Up @@ -148,6 +149,8 @@ public PersistableEnvelope fromProto(protobuf.PersistableEnvelope proto) {
return UnconfirmedBsqChangeOutputList.fromProto(proto.getUnconfirmedBsqChangeOutputList());
case SIGNED_WITNESS_STORE:
return SignedWitnessStore.fromProto(proto.getSignedWitnessStore());
case TRADE_STATISTICS3_STORE:
return TradeStatistics3Store.fromProto(proto.getTradeStatistics3Store());

default:
throw new ProtobufferRuntimeException("Unknown proto message case(PB.PersistableEnvelope). " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ public void applyBannedNodes(@Nullable List<String> bannedNodes) {
fillProviderList();
selectNextProviderBaseUrl();

if (bannedNodes == null)
if (bannedNodes == null) {
log.info("Selected provider baseUrl={}, providerList={}", baseUrl, providerList);
else
} else if (!bannedNodes.isEmpty()) {
log.warn("We have banned provider nodes: bannedNodes={}, selected provider baseUrl={}, providerList={}",
bannedNodes, baseUrl, providerList);
}
}

public void selectNextProviderBaseUrl() {
Expand Down
Loading