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

New trade statistics #4611

Merged
merged 59 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9404e8f
Add NO_ADDRESS_PRE_FIX capability.
chimp1984 Oct 7, 2020
e73a4b4
Cleanups
chimp1984 Oct 7, 2020
6f7dfcf
Make onRemoved default in interface
chimp1984 Oct 7, 2020
40f9cfb
Add methods for getting peers capabilities
chimp1984 Oct 7, 2020
8aec306
Remove verification for address prefix
chimp1984 Oct 7, 2020
9821dd6
Clear capabilitiesListeners at shutdown
chimp1984 Oct 7, 2020
17974f3
Refactor: move SupportedCapabilitiesMessage handling code out to a me…
chimp1984 Oct 7, 2020
1c07be0
Use only node address for equals and hashcode
chimp1984 Oct 7, 2020
bf659a1
Pass supportedCapabilities to PeerManager. Not further processed yet,…
chimp1984 Oct 7, 2020
2523c2e
Use getSingleThreadListeningExecutor, cleanups
chimp1984 Oct 7, 2020
765f9ea
Apply code inspection suggestions
chimp1984 Oct 7, 2020
186a9d6
Add findPeersCapabilities method
chimp1984 Oct 7, 2020
7af16d7
Add getDateAsLong method, add setter for capabilities
chimp1984 Oct 7, 2020
25bfe2d
Add findPeersCapabilities method
chimp1984 Oct 7, 2020
2552675
Replace persistedPeers with peerList
chimp1984 Oct 7, 2020
bf674ea
Use getPersistedPeers for peerList.getList() calls
chimp1984 Oct 7, 2020
cf06930
Update common/src/main/java/bisq/common/app/Capability.java
chimp1984 Oct 7, 2020
983f610
Update p2p/src/main/java/bisq/network/p2p/network/Connection.java
chimp1984 Oct 7, 2020
31e7e26
Fix incorrect handling of decryptedEntries size
chimp1984 Oct 7, 2020
4575516
Refactor: Return early
chimp1984 Oct 7, 2020
ed960ab
Refactor: Rearrange code, remove unused methods, renamings (no functi…
chimp1984 Oct 7, 2020
0686079
Refactor: Rename method
chimp1984 Oct 7, 2020
31ce5cc
Use connection.getPeersNodeAddressOptional().isPresent() instead of c…
chimp1984 Oct 7, 2020
cfda0af
Fix tests
chimp1984 Oct 8, 2020
351db88
Use a hashset instead of list to avoid duplicates. Filter out my own …
chimp1984 Oct 8, 2020
2fd0104
Decrease failedConnectionAttempts onConnection
chimp1984 Oct 8, 2020
f36a173
Fix incorrect collection used in == 1 check
chimp1984 Oct 8, 2020
b748bff
Add isPresent check
chimp1984 Oct 8, 2020
c7f23e8
Do not log size as we don't want to call potentially expensive toProt…
chimp1984 Oct 8, 2020
f53290b
Copy peers in a new hashset to avoid concurrent modification exc at s…
chimp1984 Oct 8, 2020
447235c
Dont reassign param
chimp1984 Oct 8, 2020
c88bc1c
Use custom class MailboxItem instead of Tuple
chimp1984 Oct 8, 2020
c8feef1
Apply code review suggestions
chimp1984 Oct 8, 2020
4f685f8
When updating the capability from a reported peer we check if the rep…
chimp1984 Oct 8, 2020
6e3fdbc
Apply codacy suggestions
chimp1984 Oct 8, 2020
00bed02
Add TradeStatistics3 and related classes
chimp1984 Oct 5, 2020
406bcfb
Remove PublishTradeStatistics from buyer protocol
chimp1984 Oct 5, 2020
b75aa67
Refactor: Move class
chimp1984 Oct 5, 2020
a522d0a
Refactor: Rename class
chimp1984 Oct 5, 2020
b2665bd
let seller publish trade statistics only if peer is updated user. If …
chimp1984 Oct 5, 2020
6d43c09
Delete TradeStatistics (version 1)
chimp1984 Oct 5, 2020
9820751
We "hack" TradeStatistics2StorageService to fulfill our needs:
chimp1984 Oct 5, 2020
c4a4c87
Apply TradeStatistics3 to TradeStatisticsManager and some related cla…
chimp1984 Oct 5, 2020
52be126
Apply TradeStatistics3 to client classes
chimp1984 Oct 5, 2020
0e70a99
Adjust tests, remove tests which do not make sense anymore
chimp1984 Oct 5, 2020
6766835
Use TradeStatistics3 in protobuf file
chimp1984 Oct 5, 2020
b14266d
Remove resource file
chimp1984 Oct 5, 2020
9016cb6
Prune mediator and refund agent entries for all entries beside the la…
chimp1984 Oct 6, 2020
f56fe42
Add injector.getInstance(TradeStatisticsConverter.class) to BisqExecu…
chimp1984 Oct 6, 2020
fa374b9
Do conversion in a thread to not block UI thread. takes about 4 secon…
chimp1984 Oct 6, 2020
213050c
Add filter for excluding null objects
chimp1984 Oct 6, 2020
17f4ae2
Add check that size is > LOOK_BACK_RANGE
chimp1984 Oct 6, 2020
e95ab2a
Add resource file for 1.4.0 (should be updated at release time)
chimp1984 Oct 6, 2020
58d2f1b
Apply codacy suggestions
chimp1984 Oct 8, 2020
197d8c1
Remove copy&past mistake
chimp1984 Oct 8, 2020
18a27e9
Republish trade statistics from seller side if peer capability is kno…
chimp1984 Oct 8, 2020
68a10cf
Remove comment line
chimp1984 Oct 8, 2020
66740b7
Remove unused variable
chimp1984 Oct 9, 2020
39c8ade
Cleanups: Remove outdated TODOs, fix typos
chimp1984 Oct 9, 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
18 changes: 18 additions & 0 deletions common/src/main/java/bisq/common/app/Capabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public boolean containsAll(Capability... capabilities) {
return this.capabilities.containsAll(Arrays.asList(capabilities));
}

public boolean contains(Capability capability) {
return this.capabilities.contains(capability);
}

public boolean isEmpty() {
return capabilities.isEmpty();
}
Expand Down Expand Up @@ -180,4 +184,18 @@ public String prettyPrint() {
public int size() {
return capabilities.size();
}

// We return true if our capabilities have less capabilities than the parameter value
public boolean hasLess(Capabilities other) {
return findHighestCapability(this) < findHighestCapability(other);
}

// We use the sum of all capabilities. Alternatively we could use the highest entry.
// Neither would support removal of past capabilities, a use case we never had so far and which might have
// backward compatibility issues, so we should treat capabilities as an append-only data structure.
public int findHighestCapability(Capabilities capabilities) {
return (int) capabilities.capabilities.stream()
.mapToLong(e -> (long) e.ordinal())
.sum();
}
}
4 changes: 3 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,7 @@ 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.
NO_ADDRESS_PRE_FIX, // At 1.4.0 we removed the prefix filter for mailbox messages. If a peer has that capability we do not sent the prefix.
TRADE_STATISTICS_3 // We used a new reduced trade statistics model from v1.4.0 on
}
1 change: 0 additions & 1 deletion common/src/main/java/bisq/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public static void printVersion() {
'}');
}

//TODO move to consensus area
public static final byte COMPENSATION_REQUEST = (byte) 0x01;
public static final byte REIMBURSEMENT_REQUEST = (byte) 0x01;
public static final byte PROPOSAL = (byte) 0x01;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@
* Better to use the excludeFromJsonDataMap (annotated with @JsonExclude; used in PaymentAccountPayload) to
* add a key/value pair.
*/
// TODO PubKeyRing and NodeAddress (network) are using UsedForTradeContractJson that is why it is in common module,
// which is a bit weird... Maybe we need either rename common or split it to util and common where common is common code
// used in network and core?
public interface UsedForTradeContractJson {
}
1 change: 0 additions & 1 deletion common/src/main/java/bisq/common/crypto/Encryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// TODO is Hmac needed/make sense?
public class Encryption {
private static final Logger log = LoggerFactory.getLogger(Encryption.class);

Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/bisq/common/crypto/KeyStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

import static bisq.common.util.Preconditions.checkDir;

// TODO: use a password protection for key storage
@Singleton
public class KeyStorage {
private static final Logger log = LoggerFactory.getLogger(KeyStorage.class);
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/java/bisq/common/file/JsonFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@Slf4j
public class JsonFileManager {
private final ThreadPoolExecutor executor = Utilities.getThreadPoolExecutor("JsonFileManagerExecutor", 5, 50, 60);
private final ThreadPoolExecutor executor;
private final File dir;


Expand All @@ -41,6 +41,8 @@ public class JsonFileManager {
public JsonFileManager(File dir) {
this.dir = dir;

this.executor = Utilities.getThreadPoolExecutor("JsonFileManagerExecutor", 5, 50, 60);

if (!dir.exists())
if (!dir.mkdir())
log.warn("make dir failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public Message toProtoMessage() {
return getNetworkEnvelopeBuilder().build();
}

// todo remove
public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
return getNetworkEnvelopeBuilder().build();
}
Expand Down
42 changes: 42 additions & 0 deletions common/src/test/java/bisq/common/app/CapabilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.junit.Test;

import static bisq.common.app.Capability.DAO_FULL_NODE;
import static bisq.common.app.Capability.SEED_NODE;
import static bisq.common.app.Capability.TRADE_STATISTICS;
import static bisq.common.app.Capability.TRADE_STATISTICS_2;
Expand All @@ -40,6 +41,47 @@ public void testNoCapabilitiesAvailable() {
assertFalse(DUT.containsAll(new Capabilities(SEED_NODE)));
}

@Test
public void testHasLess() {
assertTrue(new Capabilities().hasLess(new Capabilities(SEED_NODE)));
assertFalse(new Capabilities().hasLess(new Capabilities()));
assertFalse(new Capabilities(SEED_NODE).hasLess(new Capabilities()));
assertTrue(new Capabilities(SEED_NODE).hasLess(new Capabilities(DAO_FULL_NODE)));
assertFalse(new Capabilities(DAO_FULL_NODE).hasLess(new Capabilities(SEED_NODE)));

Capabilities all = new Capabilities(
TRADE_STATISTICS,
TRADE_STATISTICS_2,
Capability.ACCOUNT_AGE_WITNESS,
Capability.ACK_MSG,
Capability.PROPOSAL,
Capability.BLIND_VOTE,
Capability.DAO_STATE,
Capability.BUNDLE_OF_ENVELOPES,
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE
);
Capabilities other = new Capabilities(
TRADE_STATISTICS,
TRADE_STATISTICS_2,
Capability.ACCOUNT_AGE_WITNESS,
Capability.ACK_MSG,
Capability.PROPOSAL,
Capability.BLIND_VOTE,
Capability.DAO_STATE,
Capability.BUNDLE_OF_ENVELOPES,
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE,
Capability.NO_ADDRESS_PRE_FIX
);

assertTrue(all.hasLess(other));
}

@Test
public void testO() {
Capabilities DUT = new Capabilities(TRADE_STATISTICS);
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 @@ -22,7 +22,7 @@
import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload;
import bisq.core.payment.PaymentAccount;
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 @@ -196,7 +196,7 @@ public void removeWalletPassword(String password) {
walletsService.removeWalletPassword(password);
}

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

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.setup.CorePersistedDataHost;
import bisq.core.setup.CoreSetup;
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.core.trade.txproof.xmr.XmrTxProofService;

import bisq.network.p2p.P2PService;
Expand Down Expand Up @@ -220,6 +221,7 @@ public void gracefulShutDown(ResultHandler resultHandler) {

try {
injector.getInstance(ArbitratorManager.class).shutDown();
injector.getInstance(TradeStatisticsManager.class).shutDown();
injector.getInstance(XmrTxProofService.class).shutDown();
injector.getInstance(DaoSetup.class).shutDown();
injector.getInstance(AvoidStandbyModeService.class).shutDown();
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 @@ -170,7 +170,7 @@ private void connectToNextNode() {
private void connectToAnyFullNode() {
Capabilities required = new Capabilities(Capability.DAO_FULL_NODE);

List<Peer> list = peerManager.getLivePeers(null).stream()
List<Peer> list = peerManager.getLivePeers().stream()
.filter(peer -> peer.getCapabilities().containsAll(required))
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void onConnection(Connection connection) {
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
closeHandler(connection);

if (peerManager.isNodeBanned(closeConnectionReason, connection)) {
if (peerManager.isPeerBanned(closeConnectionReason, connection)) {
connection.getPeersNodeAddressOptional().ifPresent(nodeAddress -> {
seedNodeAddresses.remove(nodeAddress);
removeFromRequestBlocksHandlerMap(nodeAddress);
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 @@ -42,36 +42,37 @@

@Slf4j
public class DisputeAgentSelection {
public static final int LOOK_BACK_RANGE = 100;

public static <T extends DisputeAgent> T getLeastUsedMediator(TradeStatisticsManager tradeStatisticsManager,
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);
int max = Math.min(list.size(), LOOK_BACK_RANGE);
list = list.subList(0, max);
}

// 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))
.map(tradeStatistics3 -> isMediator ? tradeStatistics3.getMediator() : tradeStatistics3.getRefundAgent())
.filter(Objects::nonNull)
.collect(Collectors.toList());

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 @@ -59,7 +59,6 @@
import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage;
import bisq.core.trade.messages.RefreshTradeStateRequest;
import bisq.core.trade.messages.TraderSignedWitnessMessage;
import bisq.core.trade.statistics.TradeStatistics;

import bisq.network.p2p.AckMessage;
import bisq.network.p2p.BundleOfEnvelopes;
Expand Down Expand Up @@ -265,9 +264,6 @@ public NetworkPayload fromProto(protobuf.StoragePayload proto) {
return RefundAgent.fromProto(proto.getRefundAgent());
case FILTER:
return Filter.fromProto(proto.getFilter());
case TRADE_STATISTICS:
// Still used to convert TradeStatistics data from pre v0.6 versions
return TradeStatistics.fromProto(proto.getTradeStatistics());
case MAILBOX_STORAGE_PAYLOAD:
return MailboxStoragePayload.fromProto(proto.getMailboxStoragePayload());
case OFFER_PAYLOAD:
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 @@ -126,6 +127,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
1 change: 0 additions & 1 deletion core/src/main/java/bisq/core/provider/fee/FeeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

import static com.google.common.base.Preconditions.checkNotNull;

// TODO use dao parameters for fee
@Slf4j
public class FeeService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import bisq.core.monetary.Price;
import bisq.core.provider.PriceNodeHttpClient;
import bisq.core.provider.ProvidersRepository;
import bisq.core.trade.statistics.TradeStatistics2;
import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.user.Preferences;

import bisq.network.http.HttpClient;
Expand All @@ -50,6 +50,7 @@
import java.time.Instant;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -288,12 +289,12 @@ public Date getLastRequestTimeStamp() {
return new Date(epochInMillisAtLastRequest);
}

public void applyLatestBisqMarketPrice(Set<TradeStatistics2> tradeStatisticsSet) {
public void applyLatestBisqMarketPrice(Set<TradeStatistics3> tradeStatisticsSet) {
// takes about 10 ms for 5000 items
Map<String, List<TradeStatistics2>> mapByCurrencyCode = new HashMap<>();
Map<String, List<TradeStatistics3>> mapByCurrencyCode = new HashMap<>();
tradeStatisticsSet.forEach(e -> {
final List<TradeStatistics2> list;
final String currencyCode = e.getCurrencyCode();
List<TradeStatistics3> list;
String currencyCode = e.getCurrency();
if (mapByCurrencyCode.containsKey(currencyCode)) {
list = mapByCurrencyCode.get(currencyCode);
} else {
Expand All @@ -306,9 +307,9 @@ public void applyLatestBisqMarketPrice(Set<TradeStatistics2> tradeStatisticsSet)
mapByCurrencyCode.values().stream()
.filter(list -> !list.isEmpty())
.forEach(list -> {
list.sort((o1, o2) -> o1.getTradeDate().compareTo(o2.getTradeDate()));
TradeStatistics2 tradeStatistics = list.get(list.size() - 1);
setBisqMarketPrice(tradeStatistics.getCurrencyCode(), tradeStatistics.getTradePrice());
list.sort(Comparator.comparing(TradeStatistics3::getTradeDate));
TradeStatistics3 tradeStatistics = list.get(list.size() - 1);
setBisqMarketPrice(tradeStatistics.getCurrency(), tradeStatistics.getTradePrice());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ static void setSupportedCapabilities(Config config) {
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE
Capability.TRADE_STATISTICS_HASH_UPDATE,
Capability.NO_ADDRESS_PRE_FIX,
Capability.TRADE_STATISTICS_3
);

if (config.daoActivated) {
Expand Down
Loading