fix publishing duplicate trades after randomization

This commit is contained in:
woodser 2024-07-23 08:05:41 -04:00 committed by GitHub
parent bdcf8a2182
commit 1e70c70579
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 6 deletions

View File

@ -2299,7 +2299,7 @@ public abstract class Trade implements Tradable, Model {
private void doPublishTradeStatistics() { private void doPublishTradeStatistics() {
String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null); String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null);
boolean isTorNetworkNode = getProcessModel().getP2PService().getNetworkNode() instanceof TorNetworkNode; boolean isTorNetworkNode = getProcessModel().getP2PService().getNetworkNode() instanceof TorNetworkNode;
TradeStatistics3 tradeStatistics = TradeStatistics3.from(this, referralId, isTorNetworkNode); TradeStatistics3 tradeStatistics = TradeStatistics3.from(this, referralId, isTorNetworkNode, true);
if (tradeStatistics.isValid()) { if (tradeStatistics.isValid()) {
log.info("Publishing trade statistics for {} {}", getClass().getSimpleName(), getId()); log.info("Publishing trade statistics for {} {}", getClass().getSimpleName(), getId());
processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true); processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true);

View File

@ -72,7 +72,8 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
public static TradeStatistics3 from(Trade trade, public static TradeStatistics3 from(Trade trade,
@Nullable String referralId, @Nullable String referralId,
boolean isTorNetworkNode) { boolean isTorNetworkNode,
boolean isFuzzed) {
Map<String, String> extraDataMap = new HashMap<>(); Map<String, String> extraDataMap = new HashMap<>();
if (referralId != null) { if (referralId != null) {
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId); extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
@ -90,9 +91,9 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
Offer offer = checkNotNull(trade.getOffer()); Offer offer = checkNotNull(trade.getOffer());
return new TradeStatistics3(offer.getCurrencyCode(), return new TradeStatistics3(offer.getCurrencyCode(),
trade.getPrice().getValue(), trade.getPrice().getValue(),
fuzzTradeAmountReproducibly(trade), isFuzzed ? fuzzTradeAmountReproducibly(trade) : trade.getAmount().longValueExact(),
offer.getPaymentMethod().getId(), offer.getPaymentMethod().getId(),
fuzzTradeDateReproducibly(trade), isFuzzed ? fuzzTradeDateReproducibly(trade) : trade.getTakeOfferDate().getTime(),
truncatedArbitratorNodeAddress, truncatedArbitratorNodeAddress,
extraDataMap); extraDataMap);
} }

View File

@ -206,13 +206,23 @@ public class TradeStatisticsManager {
TradeStatistics3 tradeStatistics3 = null; TradeStatistics3 tradeStatistics3 = null;
try { try {
tradeStatistics3 = TradeStatistics3.from(trade, referralId, isTorNetworkNode); tradeStatistics3 = TradeStatistics3.from(trade, referralId, isTorNetworkNode, false);
} catch (Exception e) { } catch (Exception e) {
log.warn("Error getting trade statistic for {} {}: {}", trade.getClass().getName(), trade.getId(), e.getMessage()); log.warn("Error getting trade statistic for {} {}: {}", trade.getClass().getName(), trade.getId(), e.getMessage());
return; return;
} }
TradeStatistics3 tradeStatistics3Fuzzed = null;
try {
tradeStatistics3Fuzzed = TradeStatistics3.from(trade, referralId, isTorNetworkNode, true);
} catch (Exception e) {
log.warn("Error getting trade statistic for {} {}: {}", trade.getClass().getName(), trade.getId(), e.getMessage());
return;
}
boolean hasTradeStatistics3 = hashes.contains(new P2PDataStorage.ByteArray(tradeStatistics3.getHash())); boolean hasTradeStatistics3 = hashes.contains(new P2PDataStorage.ByteArray(tradeStatistics3.getHash()));
if (hasTradeStatistics3) { boolean hasTradeStatistics3Fuzzed = hashes.contains(new P2PDataStorage.ByteArray(tradeStatistics3Fuzzed.getHash()));
if (hasTradeStatistics3 || hasTradeStatistics3Fuzzed) {
log.debug("Trade: {}. We have already a tradeStatistics matching the hash of tradeStatistics3.", log.debug("Trade: {}. We have already a tradeStatistics matching the hash of tradeStatistics3.",
trade.getShortId()); trade.getShortId());
return; return;