fix erroneous warning in arbitrator about invalid offer signatures

This commit is contained in:
woodser 2023-05-02 11:46:48 -04:00
parent 1b37a0ab9b
commit d1d39e3482

View File

@ -27,6 +27,7 @@ import haveno.core.trade.HavenoUtils;
import haveno.core.user.Preferences; import haveno.core.user.Preferences;
import haveno.core.user.User; import haveno.core.user.User;
import haveno.network.p2p.NodeAddress; import haveno.network.p2p.NodeAddress;
import haveno.network.p2p.P2PService;
import javafx.collections.SetChangeListener; import javafx.collections.SetChangeListener;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -44,6 +45,7 @@ import java.util.stream.Collectors;
@Singleton @Singleton
public class OfferFilterService { public class OfferFilterService {
private final User user; private final User user;
private final P2PService p2PService;
private final Preferences preferences; private final Preferences preferences;
private final FilterManager filterManager; private final FilterManager filterManager;
private final AccountAgeWitnessService accountAgeWitnessService; private final AccountAgeWitnessService accountAgeWitnessService;
@ -52,10 +54,12 @@ public class OfferFilterService {
@Inject @Inject
public OfferFilterService(User user, public OfferFilterService(User user,
P2PService p2PService,
Preferences preferences, Preferences preferences,
FilterManager filterManager, FilterManager filterManager,
AccountAgeWitnessService accountAgeWitnessService) { AccountAgeWitnessService accountAgeWitnessService) {
this.user = user; this.user = user;
this.p2PService = p2PService;
this.preferences = preferences; this.preferences = preferences;
this.filterManager = filterManager; this.filterManager = filterManager;
this.accountAgeWitnessService = accountAgeWitnessService; this.accountAgeWitnessService = accountAgeWitnessService;
@ -220,11 +224,20 @@ public class OfferFilterService {
public boolean hasValidArbitrator(Offer offer) { public boolean hasValidArbitrator(Offer offer) {
Arbitrator arbitrator = user.getAcceptedArbitratorByAddress(offer.getOfferPayload().getArbitratorSigner()); Arbitrator arbitrator = user.getAcceptedArbitratorByAddress(offer.getOfferPayload().getArbitratorSigner());
if (arbitrator == null && offer.getOfferPayload().getArbitratorSigner() != null) { if (arbitrator != null) return true;
// accepted arbitrator is null if we are the signing arbitrator
if (offer.getOfferPayload().getArbitratorSigner() != null) {
Arbitrator thisArbitrator = user.getRegisteredArbitrator();
if (thisArbitrator != null && thisArbitrator.getNodeAddress().equals(offer.getOfferPayload().getArbitratorSigner())) {
if (thisArbitrator.getNodeAddress().equals(p2PService.getNetworkNode().getNodeAddress())) return true; // TODO: unnecessary to compare arbitrator and p2pservice address?
}
// otherwise log warning
List<NodeAddress> arbitratorAddresses = user.getAcceptedArbitrators().stream().map(Arbitrator::getNodeAddress).collect(Collectors.toList()); List<NodeAddress> arbitratorAddresses = user.getAcceptedArbitrators().stream().map(Arbitrator::getNodeAddress).collect(Collectors.toList());
log.warn("No arbitrator is registered with offer's signer. offerId={}, arbitrator signer={}, accepted arbitrators={}", offer.getId(), offer.getOfferPayload().getArbitratorSigner(), arbitratorAddresses); log.warn("No arbitrator is registered with offer's signer. offerId={}, arbitrator signer={}, accepted arbitrators={}", offer.getId(), offer.getOfferPayload().getArbitratorSigner(), arbitratorAddresses);
} }
return arbitrator != null; return false;
} }
public boolean hasValidSignature(Offer offer) { public boolean hasValidSignature(Offer offer) {