mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-01-03 09:29:44 +00:00
use unique deterministic ids for mailbox messages
This commit is contained in:
parent
308f6e8077
commit
21fcdc7e00
6 changed files with 44 additions and 5 deletions
|
@ -18,8 +18,10 @@
|
||||||
package bisq.core.trade;
|
package bisq.core.trade;
|
||||||
|
|
||||||
import bisq.common.config.Config;
|
import bisq.common.config.Config;
|
||||||
|
import bisq.common.crypto.Hash;
|
||||||
import bisq.common.crypto.PubKeyRing;
|
import bisq.common.crypto.PubKeyRing;
|
||||||
import bisq.common.crypto.Sig;
|
import bisq.common.crypto.Sig;
|
||||||
|
import bisq.common.util.Utilities;
|
||||||
import bisq.core.offer.Offer;
|
import bisq.core.offer.Offer;
|
||||||
import bisq.core.offer.OfferPayload;
|
import bisq.core.offer.OfferPayload;
|
||||||
import bisq.core.support.dispute.arbitration.ArbitrationManager;
|
import bisq.core.support.dispute.arbitration.ArbitrationManager;
|
||||||
|
@ -30,6 +32,7 @@ import bisq.core.trade.messages.PaymentSentMessage;
|
||||||
import bisq.core.util.JsonUtil;
|
import bisq.core.util.JsonUtil;
|
||||||
import bisq.core.util.ParsingUtils;
|
import bisq.core.util.ParsingUtils;
|
||||||
import bisq.core.util.coin.CoinUtil;
|
import bisq.core.util.coin.CoinUtil;
|
||||||
|
import bisq.network.p2p.NodeAddress;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -180,6 +183,19 @@ public class HavenoUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a unique deterministic id for sending a trade mailbox message.
|
||||||
|
*
|
||||||
|
* @param trade the trade
|
||||||
|
* @param tradeMessageClass the trade message class
|
||||||
|
* @param receiver the receiver address
|
||||||
|
* @return a unique deterministic id for sending a trade mailbox message
|
||||||
|
*/
|
||||||
|
public static String getDeterministicId(Trade trade, Class<?> tradeMessageClass, NodeAddress receiver) {
|
||||||
|
String uniqueId = trade.getId() + "_" + tradeMessageClass.getSimpleName() + "_" + trade.getRole() + "_to_" + trade.getPeerRole(trade.getTradingPeer(receiver));
|
||||||
|
return Utilities.bytesAsHexString(Hash.getSha256Ripemd160hash(uniqueId.getBytes(Charsets.UTF_8)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the arbitrator signature is valid for an offer.
|
* Check if the arbitrator signature is valid for an offer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1167,6 +1167,20 @@ public abstract class Trade implements Tradable, Model {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRole() {
|
||||||
|
if (isBuyer()) return "Buyer";
|
||||||
|
if (isSeller()) return "Seller";
|
||||||
|
if (isArbitrator()) return "Arbitrator";
|
||||||
|
throw new IllegalArgumentException("Trade is not buyer, seller, or arbitrator");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPeerRole(TradingPeer peer) {
|
||||||
|
if (peer == getBuyer()) return "Buyer";
|
||||||
|
if (peer == getSeller()) return "Seller";
|
||||||
|
if (peer == getArbitrator()) return "Arbitrator";
|
||||||
|
throw new IllegalArgumentException("Peer is not buyer, seller, or arbitrator");
|
||||||
|
}
|
||||||
|
|
||||||
public Date getTakeOfferDate() {
|
public Date getTakeOfferDate() {
|
||||||
return new Date(takeOfferDate);
|
return new Date(takeOfferDate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public final class PaymentReceivedMessage extends TradeMailboxMessage {
|
||||||
|
|
||||||
public PaymentReceivedMessage(String tradeId,
|
public PaymentReceivedMessage(String tradeId,
|
||||||
NodeAddress senderNodeAddress,
|
NodeAddress senderNodeAddress,
|
||||||
|
String uid,
|
||||||
String unsignedPayoutTxHex,
|
String unsignedPayoutTxHex,
|
||||||
String signedPayoutTxHex,
|
String signedPayoutTxHex,
|
||||||
String updatedMultisigHex,
|
String updatedMultisigHex,
|
||||||
|
@ -68,7 +69,7 @@ public final class PaymentReceivedMessage extends TradeMailboxMessage {
|
||||||
PaymentSentMessage paymentSentMessage) {
|
PaymentSentMessage paymentSentMessage) {
|
||||||
this(tradeId,
|
this(tradeId,
|
||||||
senderNodeAddress,
|
senderNodeAddress,
|
||||||
UUID.randomUUID().toString(),
|
uid,
|
||||||
Version.getP2PMessageVersion(),
|
Version.getP2PMessageVersion(),
|
||||||
unsignedPayoutTxHex,
|
unsignedPayoutTxHex,
|
||||||
signedPayoutTxHex,
|
signedPayoutTxHex,
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package bisq.core.trade.protocol.tasks;
|
package bisq.core.trade.protocol.tasks;
|
||||||
|
|
||||||
import bisq.core.network.MessageState;
|
import bisq.core.network.MessageState;
|
||||||
|
import bisq.core.trade.HavenoUtils;
|
||||||
import bisq.core.trade.Trade;
|
import bisq.core.trade.Trade;
|
||||||
import bisq.core.trade.messages.PaymentSentMessage;
|
import bisq.core.trade.messages.PaymentSentMessage;
|
||||||
import bisq.core.trade.messages.TradeMailboxMessage;
|
import bisq.core.trade.messages.TradeMailboxMessage;
|
||||||
|
@ -78,7 +79,7 @@ public abstract class BuyerSendPaymentSentMessage extends SendMailboxMessageTask
|
||||||
// peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox
|
// peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox
|
||||||
// messages where only the one which gets processed by the peer would be removed we use the same uid. All
|
// messages where only the one which gets processed by the peer would be removed we use the same uid. All
|
||||||
// other data stays the same when we re-send the message at any time later.
|
// other data stays the same when we re-send the message at any time later.
|
||||||
String deterministicId = tradeId + processModel.getMyNodeAddress().getFullAddress();
|
String deterministicId = HavenoUtils.getDeterministicId(trade, PaymentSentMessage.class, getReceiverNodeAddress());
|
||||||
|
|
||||||
// create payment sent message
|
// create payment sent message
|
||||||
PaymentSentMessage message = new PaymentSentMessage(
|
PaymentSentMessage message = new PaymentSentMessage(
|
||||||
|
|
|
@ -19,6 +19,7 @@ package bisq.core.trade.protocol.tasks;
|
||||||
|
|
||||||
import bisq.core.account.sign.SignedWitness;
|
import bisq.core.account.sign.SignedWitness;
|
||||||
import bisq.core.account.witness.AccountAgeWitnessService;
|
import bisq.core.account.witness.AccountAgeWitnessService;
|
||||||
|
import bisq.core.trade.HavenoUtils;
|
||||||
import bisq.core.trade.Trade;
|
import bisq.core.trade.Trade;
|
||||||
import bisq.core.trade.messages.PaymentReceivedMessage;
|
import bisq.core.trade.messages.PaymentReceivedMessage;
|
||||||
import bisq.core.trade.messages.TradeMailboxMessage;
|
import bisq.core.trade.messages.TradeMailboxMessage;
|
||||||
|
@ -71,10 +72,15 @@ public abstract class SellerSendPaymentReceivedMessage extends SendMailboxMessag
|
||||||
log.info("{} {} signed and published peers account age witness", trade.getClass().getSimpleName(), trade.getId());
|
log.info("{} {} signed and published peers account age witness", trade.getClass().getSimpleName(), trade.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: create with deterministic id like BuyerSendPaymentSentMessage
|
// We do not use a real unique ID here as we want to be able to re-send the exact same message in case the
|
||||||
|
// peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox
|
||||||
|
// messages where only the one which gets processed by the peer would be removed we use the same uid. All
|
||||||
|
// other data stays the same when we re-send the message at any time later.
|
||||||
|
String deterministicId = HavenoUtils.getDeterministicId(trade, PaymentReceivedMessage.class, getReceiverNodeAddress());
|
||||||
message = new PaymentReceivedMessage(
|
message = new PaymentReceivedMessage(
|
||||||
tradeId,
|
tradeId,
|
||||||
processModel.getMyNodeAddress(),
|
processModel.getMyNodeAddress(),
|
||||||
|
deterministicId,
|
||||||
trade.isPayoutPublished() ? null : trade.getPayoutTxHex(), // unsigned
|
trade.isPayoutPublished() ? null : trade.getPayoutTxHex(), // unsigned
|
||||||
trade.isPayoutPublished() ? trade.getPayoutTxHex() : null, // signed
|
trade.isPayoutPublished() ? trade.getPayoutTxHex() : null, // signed
|
||||||
trade.getSelf().getUpdatedMultisigHex(),
|
trade.getSelf().getUpdatedMultisigHex(),
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package bisq.core.trade.protocol.tasks;
|
package bisq.core.trade.protocol.tasks;
|
||||||
|
|
||||||
import bisq.core.btc.wallet.XmrWalletService;
|
import bisq.core.btc.wallet.XmrWalletService;
|
||||||
|
import bisq.core.trade.HavenoUtils;
|
||||||
import bisq.core.trade.Trade;
|
import bisq.core.trade.Trade;
|
||||||
import bisq.core.trade.messages.DepositsConfirmedMessage;
|
import bisq.core.trade.messages.DepositsConfirmedMessage;
|
||||||
import bisq.core.trade.messages.TradeMailboxMessage;
|
import bisq.core.trade.messages.TradeMailboxMessage;
|
||||||
|
@ -71,13 +72,13 @@ public abstract class SendDepositsConfirmedMessage extends SendMailboxMessageTas
|
||||||
// peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox
|
// peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox
|
||||||
// messages where only the one which gets processed by the peer would be removed we use the same uid. All
|
// messages where only the one which gets processed by the peer would be removed we use the same uid. All
|
||||||
// other data stays the same when we re-send the message at any time later.
|
// other data stays the same when we re-send the message at any time later.
|
||||||
String deterministicId = tradeId + processModel.getMyNodeAddress().getFullAddress();
|
String deterministicId = HavenoUtils.getDeterministicId(trade, DepositsConfirmedMessage.class, getReceiverNodeAddress());
|
||||||
message = new DepositsConfirmedMessage(
|
message = new DepositsConfirmedMessage(
|
||||||
trade.getOffer().getId(),
|
trade.getOffer().getId(),
|
||||||
processModel.getMyNodeAddress(),
|
processModel.getMyNodeAddress(),
|
||||||
processModel.getPubKeyRing(),
|
processModel.getPubKeyRing(),
|
||||||
deterministicId,
|
deterministicId,
|
||||||
getReceiverNodeAddress().equals(trade.getBuyer().getNodeAddress()) ? trade.getSeller().getPaymentAccountKey() : null, // buyer receives seller's payment account decryption key
|
trade.getBuyer() == trade.getTradingPeer(getReceiverNodeAddress()) ? trade.getSeller().getPaymentAccountKey() : null, // buyer receives seller's payment account decryption key
|
||||||
trade.getSelf().getUpdatedMultisigHex());
|
trade.getSelf().getUpdatedMultisigHex());
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
|
|
Loading…
Reference in a new issue