process ack on DepositsConfirmedMessage from peer with changed address

This commit is contained in:
woodser 2023-10-28 09:39:21 -04:00
parent 05e2d925f0
commit 3450f3799e
2 changed files with 17 additions and 10 deletions

View File

@ -529,7 +529,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
processModel.setTradeMessage(message); processModel.setTradeMessage(message);
expect(anyPhase( expect(anyPhase(
trade.isBuyer() ? new Trade.Phase[] {Trade.Phase.PAYMENT_SENT, Trade.Phase.PAYMENT_RECEIVED} : trade.isBuyer() ? new Trade.Phase[] {Trade.Phase.PAYMENT_SENT, Trade.Phase.PAYMENT_RECEIVED} :
trade.isArbitrator() ? new Trade.Phase[] {Trade.Phase.DEPOSITS_CONFIRMED, Trade.Phase.DEPOSITS_UNLOCKED, Trade.Phase.PAYMENT_SENT} : // arbitrator syncs slowly after deposits confirmed trade.isArbitrator() ? new Trade.Phase[] {Trade.Phase.DEPOSITS_CONFIRMED, Trade.Phase.DEPOSITS_UNLOCKED, Trade.Phase.PAYMENT_SENT} : // arbitrator syncs slowly after deposits confirmed
new Trade.Phase[] {Trade.Phase.DEPOSITS_UNLOCKED, Trade.Phase.PAYMENT_SENT}) new Trade.Phase[] {Trade.Phase.DEPOSITS_UNLOCKED, Trade.Phase.PAYMENT_SENT})
.with(message) .with(message)
.from(peer)) .from(peer))
@ -614,14 +614,14 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
// ACK msg // ACK msg
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void onAckMessage(AckMessage ackMessage, NodeAddress peer) { private void onAckMessage(AckMessage ackMessage, NodeAddress sender) {
// handle ack for PaymentSentMessage, which automatically re-sends if not ACKed in a certain time // handle ack for PaymentSentMessage, which automatically re-sends if not ACKed in a certain time
if (ackMessage.getSourceMsgClassName().equals(PaymentSentMessage.class.getSimpleName())) { if (ackMessage.getSourceMsgClassName().equals(PaymentSentMessage.class.getSimpleName())) {
if (trade.getTradePeer(peer) == trade.getSeller()) { if (trade.getTradePeer(sender) == trade.getSeller()) {
processModel.setPaymentSentAckMessage(ackMessage); processModel.setPaymentSentAckMessage(ackMessage);
} else if (!ackMessage.isSuccess()) { } else if (!ackMessage.isSuccess()) {
String err = "Received AckMessage with error state for " + ackMessage.getSourceMsgClassName() + " from "+ peer + " with tradeId " + trade.getId() + " and errorMessage=" + ackMessage.getErrorMessage(); String err = "Received AckMessage with error state for " + ackMessage.getSourceMsgClassName() + " from "+ sender + " with tradeId " + trade.getId() + " and errorMessage=" + ackMessage.getErrorMessage();
log.warn(err); log.warn(err);
return; // log error and ignore nack if not seller return; // log error and ignore nack if not seller
} }
@ -629,16 +629,23 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
if (ackMessage.isSuccess()) { if (ackMessage.isSuccess()) {
log.info("Received AckMessage for {} from {} with tradeId {} and uid {}", log.info("Received AckMessage for {} from {} with tradeId {} and uid {}",
ackMessage.getSourceMsgClassName(), peer, trade.getId(), ackMessage.getSourceUid()); ackMessage.getSourceMsgClassName(), sender, trade.getId(), ackMessage.getSourceUid());
// handle ack for DepositsConfirmedMessage, which automatically re-sends if not ACKed in a certain time // handle ack for DepositsConfirmedMessage, which automatically re-sends if not ACKed in a certain time
if (ackMessage.getSourceMsgClassName().equals(DepositsConfirmedMessage.class.getSimpleName())) { if (ackMessage.getSourceMsgClassName().equals(DepositsConfirmedMessage.class.getSimpleName())) {
if (trade.getTradePeer(peer) != null) { TradePeer peer = trade.getTradePeer(sender);
trade.getTradePeer(peer).setDepositsConfirmedMessageAcked(true); if (peer == null) {
// get the applicable peer based on the sourceUid
if (ackMessage.getSourceUid().equals(HavenoUtils.getDeterministicId(trade, DepositsConfirmedMessage.class, trade.getArbitrator().getNodeAddress()))) peer = trade.getArbitrator();
else if (ackMessage.getSourceUid().equals(HavenoUtils.getDeterministicId(trade, DepositsConfirmedMessage.class, trade.getMaker().getNodeAddress()))) peer = trade.getMaker();
else if (ackMessage.getSourceUid().equals(HavenoUtils.getDeterministicId(trade, DepositsConfirmedMessage.class, trade.getTaker().getNodeAddress()))) peer = trade.getTaker();
} }
if (peer == null) log.warn("Received AckMesage for DepositsConfirmedMessage for unknown peer: " + sender);
else peer.setDepositsConfirmedMessageAcked(true);
} }
} else { } else {
String err = "Received AckMessage with error state for " + ackMessage.getSourceMsgClassName() + " from "+ peer + " with tradeId " + trade.getId() + " and errorMessage=" + ackMessage.getErrorMessage(); String err = "Received AckMessage with error state for " + ackMessage.getSourceMsgClassName() + " from "+ sender + " with tradeId " + trade.getId() + " and errorMessage=" + ackMessage.getErrorMessage();
log.warn(err); log.warn(err);
// set trade state on deposit request nack // set trade state on deposit request nack

View File

@ -125,8 +125,8 @@ public abstract class SendDepositsConfirmedMessage extends SendMailboxMessageTas
private void tryToSendAgainLater() { private void tryToSendAgainLater() {
// skip if already acked // skip if already acked or payout published
if (ackedByReceiver()) return; if (ackedByReceiver() || trade.isPayoutPublished()) return;
if (resendCounter >= MAX_RESEND_ATTEMPTS) { if (resendCounter >= MAX_RESEND_ATTEMPTS) {
cleanup(); cleanup();