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 haveno.common.ThreadUtils;
import haveno.common.UserThread;
import haveno.common.app.Capability;
import haveno.common.crypto.Encryption;
import haveno.common.crypto.PubKeyRing;
import haveno.common.proto.ProtoUtil;
@ -2181,23 +2180,15 @@ public abstract class Trade implements Tradable, Model {
}
private void doPublishTradeStatistics() {
processModel.getP2PService().findPeersCapabilities(getTradePeer().getNodeAddress())
.filter(capabilities -> capabilities.containsAll(Capability.TRADE_STATISTICS_3))
.ifPresentOrElse(capabilities -> {
String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null);
boolean isTorNetworkNode = getProcessModel().getP2PService().getNetworkNode() instanceof TorNetworkNode;
TradeStatistics3 tradeStatistics = TradeStatistics3.from(this, referralId, isTorNetworkNode);
if (tradeStatistics.isValid()) {
log.info("Publishing trade statistics");
log.info("Publishing trade statistics for {} {}", getClass().getSimpleName(), getId());
processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true);
} else {
log.warn("Trade statistics are invalid. We do not publish. {}", tradeStatistics);
log.warn("Trade statistics are invalid for {} {}. We do not publish: {}", getClass().getSimpleName(), getId(), 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;
}
// 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) {
return networkNode.getConfirmedConnections().stream()
.filter(e -> e.getPeersNodeAddressOptional().isPresent())