seller publishes trade statistics without checking peer capabilities

This commit is contained in:
woodser 2024-06-07 06:45:12 -04:00
parent 37af7e5338
commit ca125dbc48
2 changed files with 10 additions and 18 deletions

View File

@ -39,7 +39,6 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.Message; import com.google.protobuf.Message;
import haveno.common.ThreadUtils; import haveno.common.ThreadUtils;
import haveno.common.UserThread; import haveno.common.UserThread;
import haveno.common.app.Capability;
import haveno.common.crypto.Encryption; import haveno.common.crypto.Encryption;
import haveno.common.crypto.PubKeyRing; import haveno.common.crypto.PubKeyRing;
import haveno.common.proto.ProtoUtil; import haveno.common.proto.ProtoUtil;
@ -2181,23 +2180,15 @@ public abstract class Trade implements Tradable, Model {
} }
private void doPublishTradeStatistics() { private void doPublishTradeStatistics() {
processModel.getP2PService().findPeersCapabilities(getTradePeer().getNodeAddress()) String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null);
.filter(capabilities -> capabilities.containsAll(Capability.TRADE_STATISTICS_3)) boolean isTorNetworkNode = getProcessModel().getP2PService().getNetworkNode() instanceof TorNetworkNode;
.ifPresentOrElse(capabilities -> { TradeStatistics3 tradeStatistics = TradeStatistics3.from(this, referralId, isTorNetworkNode);
String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null); if (tradeStatistics.isValid()) {
boolean isTorNetworkNode = getProcessModel().getP2PService().getNetworkNode() instanceof TorNetworkNode; log.info("Publishing trade statistics for {} {}", getClass().getSimpleName(), getId());
TradeStatistics3 tradeStatistics = TradeStatistics3.from(this, referralId, isTorNetworkNode); processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true);
if (tradeStatistics.isValid()) { } else {
log.info("Publishing trade statistics"); log.warn("Trade statistics are invalid for {} {}. We do not publish: {}", getClass().getSimpleName(), getId(), tradeStatistics);
processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true); }
} else {
log.warn("Trade statistics are invalid. We do not publish. {}", tradeStatistics);
}
},
() -> {
log.info("Our peer does not has updated yet, so they will publish the trade statistics. " +
"To avoid duplicates we do not publish from our side.");
});
} }

View File

@ -564,6 +564,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
return keyRing; return keyRing;
} }
// TODO: this is unreliable and unused, because peer sometimes reports no TRADE_STATISTICS_3 capability, causing valid trades to be unpublished
public Optional<Capabilities> findPeersCapabilities(NodeAddress peer) { public Optional<Capabilities> findPeersCapabilities(NodeAddress peer) {
return networkNode.getConfirmedConnections().stream() return networkNode.getConfirmedConnections().stream()
.filter(e -> e.getPeersNodeAddressOptional().isPresent()) .filter(e -> e.getPeersNodeAddressOptional().isPresent())