diff --git a/core/src/main/java/haveno/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/haveno/core/trade/statistics/TradeStatistics3.java index 75db58808a..37bb9d7be4 100644 --- a/core/src/main/java/haveno/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/haveno/core/trade/statistics/TradeStatistics3.java @@ -54,6 +54,8 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.Random; import static com.google.common.base.Preconditions.checkNotNull; @@ -88,13 +90,32 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl Offer offer = checkNotNull(trade.getOffer()); return new TradeStatistics3(offer.getCurrencyCode(), trade.getPrice().getValue(), - trade.getAmount().longValueExact(), + fuzzTradeAmountReproducibly(trade), offer.getPaymentMethod().getId(), - trade.getTakeOfferDate().getTime(), + fuzzTradeDateReproducibly(trade), truncatedArbitratorNodeAddress, extraDataMap); } + private static long fuzzTradeAmountReproducibly(Trade trade) { // randomize completed trade info #1099 + long originalTimestamp = trade.getTakeOfferDate().getTime(); + long exactAmount = trade.getAmount().longValueExact(); + Random random = new Random(originalTimestamp); // pseudo random generator seeded from take offer datestamp + long adjustedAmount = (long) random.nextDouble( + exactAmount * 0.95, exactAmount * 1.05); + log.debug("trade {} fuzzed trade amount for tradeStatistics is {}", trade.getShortId(), adjustedAmount); + return adjustedAmount; + } + + private static long fuzzTradeDateReproducibly(Trade trade) { // randomize completed trade info #1099 + long originalTimestamp = trade.getTakeOfferDate().getTime(); + Random random = new Random(originalTimestamp); // pseudo random generator seeded from take offer datestamp + long adjustedTimestamp = random.nextLong( + originalTimestamp-TimeUnit.HOURS.toMillis(24), originalTimestamp); + log.debug("trade {} fuzzed trade datestamp for tradeStatistics is {}", trade.getShortId(), new Date(adjustedTimestamp)); + return adjustedTimestamp; + } + // This enum must not change the order as we use the ordinal for storage to reduce data size. // The payment method string can be quite long and would consume 15% more space. // When we get a new payment method we can add it to the enum at the end. Old users would add it as string if not