Skip to content

Commit

Permalink
Merge pull request #6402 from HenrikJannsen/refactor-dispute-validation
Browse files Browse the repository at this point in the history
Refactor dispute validation
  • Loading branch information
sqrrm authored Nov 3, 2022
2 parents cc8fe09 + 7f5675f commit 212cd77
Show file tree
Hide file tree
Showing 23 changed files with 342 additions and 319 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ deploy
.java-version
.localnet
/apitest/src/main/resources/dao-setup*
/.run
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/support/SupportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public ChatMessage sendChatMessage(ChatMessage message) {
PubKeyRing receiverPubKeyRing = getPeerPubKeyRing(message);
if (peersNodeAddress == null || receiverPubKeyRing == null) {
UserThread.runAfter(() ->
message.setSendMessageError(Res.get("support.receiverNotKnown")), 1);
message.setSendMessageError(Res.get("support.receiverNotKnown")), 1);
} else {
log.info("Send {} to peer {}. tradeId={}, uid={}",
message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid());
Expand Down
10 changes: 8 additions & 2 deletions core/src/main/java/bisq/core/support/dispute/Dispute.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ public static protobuf.Dispute.State toProtoMessage(Dispute.State state) {

private transient FileTransferReceiver fileTransferSession = null;

public FileTransferReceiver createOrGetFileTransferReceiver(NetworkNode networkNode, NodeAddress peerNodeAddress, FileTransferSession.FtpCallback callback) throws IOException {
public FileTransferReceiver createOrGetFileTransferReceiver(NetworkNode networkNode,
NodeAddress peerNodeAddress,
FileTransferSession.FtpCallback callback) throws IOException {
// the receiver stores its state temporarily here in the dispute
// this method gets called to retrieve the session each time a part of the log files is received
if (fileTransferSession == null) {
Expand All @@ -173,7 +175,9 @@ public FileTransferReceiver createOrGetFileTransferReceiver(NetworkNode networkN
return fileTransferSession;
}

public FileTransferSender createFileTransferSender(NetworkNode networkNode, NodeAddress peerNodeAddress, FileTransferSession.FtpCallback callback) {
public FileTransferSender createFileTransferSender(NetworkNode networkNode,
NodeAddress peerNodeAddress,
FileTransferSession.FtpCallback callback) {
return new FileTransferSender(networkNode, peerNodeAddress, this.tradeId, this.traderId, this.getRoleStringForLogFile(), callback);
}

Expand Down Expand Up @@ -421,9 +425,11 @@ public String getShortTradeId() {
public ReadOnlyBooleanProperty isClosedProperty() {
return isClosedProperty;
}

public ReadOnlyIntegerProperty getBadgeCountProperty() {
return badgeCountProperty;
}

public ReadOnlyObjectProperty<DisputeResult> disputeResultProperty() {
return disputeResultProperty;
}
Expand Down
38 changes: 20 additions & 18 deletions core/src/main/java/bisq/core/support/dispute/DisputeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -98,7 +99,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
protected String pendingOutgoingMessage;

@Getter
protected final ObservableList<TradeDataValidation.ValidationException> validationExceptions =
protected final ObservableList<DisputeValidation.ValidationException> validationExceptions =
FXCollections.observableArrayList();
@Getter
private final KeyPair signatureKeyPair;
Expand Down Expand Up @@ -272,16 +273,15 @@ public void onUpdatedDataReceived() {
List<Dispute> disputes = getDisputeList().getList();
disputes.forEach(dispute -> {
try {
TradeDataValidation.validateDonationAddress(dispute, dispute.getDonationAddressOfDelayedPayoutTx(), daoFacade);
TradeDataValidation.validateNodeAddress(dispute, dispute.getContract().getBuyerNodeAddress(), config);
TradeDataValidation.validateNodeAddress(dispute, dispute.getContract().getSellerNodeAddress(), config);
} catch (TradeDataValidation.AddressException | TradeDataValidation.NodeAddressException e) {
DisputeValidation.validateDonationAddressMatchesAnyPastParamValues(dispute, dispute.getDonationAddressOfDelayedPayoutTx(), daoFacade);
DisputeValidation.validateNodeAddresses(dispute, config);
} catch (DisputeValidation.AddressException | DisputeValidation.NodeAddressException e) {
log.error(e.toString());
validationExceptions.add(e);
}
});

TradeDataValidation.testIfAnyDisputeTriedReplay(disputes,
DisputeValidation.testIfAnyDisputeTriedReplay(disputes,
disputeReplayException -> {
log.error(disputeReplayException.toString());
validationExceptions.add(disputeReplayException);
Expand Down Expand Up @@ -368,13 +368,12 @@ protected void onOpenNewDisputeMessage(OpenNewDisputeMessage openNewDisputeMessa
addMediationResultMessage(dispute);

try {
TradeDataValidation.validateDonationAddress(dispute.getDonationAddressOfDelayedPayoutTx(), daoFacade);
TradeDataValidation.testIfDisputeTriesReplay(dispute, disputeList.getList());
TradeDataValidation.validateNodeAddress(dispute, dispute.getContract().getBuyerNodeAddress(), config);
TradeDataValidation.validateNodeAddress(dispute, dispute.getContract().getSellerNodeAddress(), config);
} catch (TradeDataValidation.AddressException |
TradeDataValidation.DisputeReplayException |
TradeDataValidation.NodeAddressException e) {
DisputeValidation.validateDonationAddressMatchesAnyPastParamValues(dispute, dispute.getDonationAddressOfDelayedPayoutTx(), daoFacade);
DisputeValidation.testIfDisputeTriesReplay(dispute, disputeList.getList());
DisputeValidation.validateNodeAddresses(dispute, config);
} catch (DisputeValidation.AddressException |
DisputeValidation.DisputeReplayException |
DisputeValidation.NodeAddressException e) {
log.error(e.toString());
validationExceptions.add(e);
}
Expand All @@ -399,12 +398,14 @@ protected void onPeerOpenedDisputeMessage(PeerOpenedDisputeMessage peerOpenedDis

Trade trade = optionalTrade.get();
try {
DisputeValidation.validateDonationAddress(dispute,
Objects.requireNonNull(trade.getDelayedPayoutTx()),
btcWalletService.getParams(),
daoFacade);
TradeDataValidation.validateDelayedPayoutTx(trade,
trade.getDelayedPayoutTx(),
dispute,
daoFacade,
btcWalletService);
} catch (TradeDataValidation.ValidationException e) {
} catch (TradeDataValidation.ValidationException | DisputeValidation.ValidationException e) {
// The peer sent us an invalid donation address. We do not return here as we don't want to break
// mediation/arbitration and log only the issue. The dispute agent will run validation as well and will get
// a popup displayed to react.
Expand Down Expand Up @@ -577,8 +578,8 @@ private void sendPeerOpenedDisputeMessage(Dispute disputeFromOpener,
// message and not skip the system message of the peer as it would be the case if we have created the system msg
// from the code below.
UserThread.runAfter(() -> doSendPeerOpenedDisputeMessage(disputeFromOpener,
contractFromOpener,
pubKeyRing),
contractFromOpener,
pubKeyRing),
100, TimeUnit.MILLISECONDS);
}

Expand Down Expand Up @@ -1017,6 +1018,7 @@ public boolean hasPendingMessageAtShutdown() {
private void recordPendingMessage(String className) {
pendingOutgoingMessage = className;
}

private void clearPendingMessage() {
pendingOutgoingMessage = "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public enum PayoutSuggestion {
CUSTOM_PAYOUT("disputeSummaryWindow.payout.custom", null);

private String suggestionKey;
@Nullable private String buyerSellerKey;
@Nullable
private String buyerSellerKey;

PayoutSuggestion(String suggestionKey, @Nullable String buyerSellerKey) {
this.suggestionKey = suggestionKey;
Expand Down Expand Up @@ -279,9 +280,9 @@ public Date getCloseDate() {

public String getPayoutSuggestionText() {
if (payoutSuggestion.equals(PayoutSuggestion.BUYER_GETS_TRADE_AMOUNT_MINUS_PENALTY)
|| payoutSuggestion.equals(PayoutSuggestion.BUYER_GETS_TRADE_AMOUNT_PLUS_COMPENSATION)
|| payoutSuggestion.equals(PayoutSuggestion.SELLER_GETS_TRADE_AMOUNT_MINUS_PENALTY)
|| payoutSuggestion.equals(PayoutSuggestion.SELLER_GETS_TRADE_AMOUNT_PLUS_COMPENSATION)) {
|| payoutSuggestion.equals(PayoutSuggestion.BUYER_GETS_TRADE_AMOUNT_PLUS_COMPENSATION)
|| payoutSuggestion.equals(PayoutSuggestion.SELLER_GETS_TRADE_AMOUNT_MINUS_PENALTY)
|| payoutSuggestion.equals(PayoutSuggestion.SELLER_GETS_TRADE_AMOUNT_PLUS_COMPENSATION)) {
return payoutSuggestion + " " + payoutAdjustmentPercent + "%";
}
return payoutSuggestion.toString();
Expand Down
Loading

0 comments on commit 212cd77

Please sign in to comment.