From 7ca3b8cee18a1d1aea42e669a0ebf897436d5313 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 26 Nov 2022 17:22:20 +0000 Subject: [PATCH] re-send payment sent/received messages on startup if not arrived --- .../core/trade/protocol/BuyerProtocol.java | 32 +++++++++++++------ .../core/trade/protocol/SellerProtocol.java | 29 +++++++++++++++-- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerProtocol.java index c7722f9324..ff247489ec 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerProtocol.java @@ -53,16 +53,28 @@ public class BuyerProtocol extends DisputeProtocol { protected void onInitialized() { super.onInitialized(); - // TODO: run with trade lock and latch, otherwise getting invalid transition warnings on startup after offline trades - - // send payment sent message - given(anyPhase(Trade.Phase.PAYMENT_SENT) - .anyState(Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG, Trade.State.BUYER_SEND_FAILED_PAYMENT_SENT_MSG) - .with(BuyerEvent.STARTUP)) - .setup(tasks( - BuyerSendPaymentSentMessageToSeller.class, - BuyerSendPaymentSentMessageToArbitrator.class)) - .executeTasks(); + // re-send payment sent message if not arrived + if (trade.getState() == Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG || trade.getState() == Trade.State.BUYER_SEND_FAILED_PAYMENT_SENT_MSG) { + synchronized (trade) { + latchTrade(); + given(anyPhase(Trade.Phase.PAYMENT_SENT) + .anyState(Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG, Trade.State.BUYER_SEND_FAILED_PAYMENT_SENT_MSG) + .with(BuyerEvent.STARTUP)) + .setup(tasks( + BuyerSendPaymentSentMessageToSeller.class, + BuyerSendPaymentSentMessageToArbitrator.class) + .using(new TradeTaskRunner(trade, + () -> { + unlatchTrade(); + }, + (errorMessage) -> { + log.warn("Error sending PaymentSentMessage on startup: " + errorMessage); + unlatchTrade(); + }))) + .executeTasks(); + awaitTradeLatch(); + } + } } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java index 7e0f325cc0..561a8a3225 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java @@ -17,6 +17,8 @@ package bisq.core.trade.protocol; +import bisq.common.handlers.ErrorMessageHandler; +import bisq.common.handlers.ResultHandler; import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; import bisq.core.trade.messages.SignContractResponse; @@ -24,13 +26,11 @@ import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.SellerPreparePaymentReceivedMessage; import bisq.core.trade.protocol.tasks.SellerSendPaymentReceivedMessageToArbitrator; -import bisq.core.trade.protocol.tasks.SendDepositsConfirmedMessageToBuyer; import bisq.core.trade.protocol.tasks.SellerSendPaymentReceivedMessageToBuyer; import bisq.core.trade.protocol.tasks.SendDepositsConfirmedMessageToArbitrator; +import bisq.core.trade.protocol.tasks.SendDepositsConfirmedMessageToBuyer; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.network.p2p.NodeAddress; -import bisq.common.handlers.ErrorMessageHandler; -import bisq.common.handlers.ResultHandler; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -48,6 +48,29 @@ public class SellerProtocol extends DisputeProtocol { @Override protected void onInitialized() { super.onInitialized(); + + // re-send payment received message if not arrived + if (trade.getState() == Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG || trade.getState() == Trade.State.SELLER_SEND_FAILED_PAYMENT_RECEIVED_MSG) { + synchronized (trade) { + latchTrade(); + given(anyPhase(Trade.Phase.PAYMENT_RECEIVED) + .anyState(Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG, Trade.State.SELLER_SEND_FAILED_PAYMENT_RECEIVED_MSG) + .with(SellerEvent.STARTUP)) + .setup(tasks( + SellerSendPaymentReceivedMessageToBuyer.class, + SellerSendPaymentReceivedMessageToArbitrator.class) + .using(new TradeTaskRunner(trade, + () -> { + unlatchTrade(); + }, + (errorMessage) -> { + log.warn("Error sending PaymentReceivedMessage on startup: " + errorMessage); + unlatchTrade(); + }))) + .executeTasks(); + awaitTradeLatch(); + } + } } @Override