mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-22 20:19:21 +00:00
fix publishing duplicate trades after randomization
This commit is contained in:
parent
bdcf8a2182
commit
1e70c70579
3 changed files with 17 additions and 6 deletions
|
@ -2299,7 +2299,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
private void doPublishTradeStatistics() {
|
||||
String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null);
|
||||
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()) {
|
||||
log.info("Publishing trade statistics for {} {}", getClass().getSimpleName(), getId());
|
||||
processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true);
|
||||
|
|
|
@ -72,7 +72,8 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
|||
|
||||
public static TradeStatistics3 from(Trade trade,
|
||||
@Nullable String referralId,
|
||||
boolean isTorNetworkNode) {
|
||||
boolean isTorNetworkNode,
|
||||
boolean isFuzzed) {
|
||||
Map<String, String> extraDataMap = new HashMap<>();
|
||||
if (referralId != null) {
|
||||
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
|
||||
|
@ -90,9 +91,9 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
|||
Offer offer = checkNotNull(trade.getOffer());
|
||||
return new TradeStatistics3(offer.getCurrencyCode(),
|
||||
trade.getPrice().getValue(),
|
||||
fuzzTradeAmountReproducibly(trade),
|
||||
isFuzzed ? fuzzTradeAmountReproducibly(trade) : trade.getAmount().longValueExact(),
|
||||
offer.getPaymentMethod().getId(),
|
||||
fuzzTradeDateReproducibly(trade),
|
||||
isFuzzed ? fuzzTradeDateReproducibly(trade) : trade.getTakeOfferDate().getTime(),
|
||||
truncatedArbitratorNodeAddress,
|
||||
extraDataMap);
|
||||
}
|
||||
|
|
|
@ -206,13 +206,23 @@ public class TradeStatisticsManager {
|
|||
|
||||
TradeStatistics3 tradeStatistics3 = null;
|
||||
try {
|
||||
tradeStatistics3 = TradeStatistics3.from(trade, referralId, isTorNetworkNode);
|
||||
tradeStatistics3 = TradeStatistics3.from(trade, referralId, isTorNetworkNode, false);
|
||||
} catch (Exception e) {
|
||||
log.warn("Error getting trade statistic for {} {}: {}", trade.getClass().getName(), trade.getId(), e.getMessage());
|
||||
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()));
|
||||
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.",
|
||||
trade.getShortId());
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue