From 435fc164b22a4443dd6c0d315d913218b77e0f36 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 14 Jan 2023 10:56:11 -0500 Subject: [PATCH] resend deposits confirmed messages until delivered --- .../core/trade/protocol/ProcessModel.java | 3 ++ .../core/trade/protocol/TradeProtocol.java | 29 ++++++++++++++----- proto/src/main/proto/pb.proto | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java b/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java index 7545464fb3..07820a552f 100644 --- a/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java +++ b/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java @@ -172,6 +172,9 @@ public class ProcessModel implements Model, PersistablePayload { @Setter private String multisigAddress; @Nullable + @Getter + @Setter + private boolean isDepositsConfirmedMessagesDelivered; // We want to indicate the user the state of the message delivery of the // PaymentSentMessage. As well we do an automatic re-send in case it was not ACKed yet. diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index 9c1fbaca3c..04a4dd3a03 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -72,6 +72,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.fxmisc.easybind.EasyBind; @@ -244,13 +245,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D processModel.getP2PService().addDecryptedDirectMessageListener(this); } - // handle trade events - EasyBind.subscribe(trade.stateProperty(), state -> { - if (state == Trade.State.DEPOSIT_TXS_CONFIRMED_IN_BLOCKCHAIN) { - new Thread(() -> sendDepositsConfirmedMessage()).start(); - } - }); - // initialize trade trade.initialize(processModel.getProvider()); @@ -258,6 +252,17 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D MailboxMessageService mailboxMessageService = processModel.getP2PService().getMailboxMessageService(); mailboxMessageService.addDecryptedMailboxListener(this); handleMailboxCollection(mailboxMessageService.getMyDecryptedMailboxMessages()); + + // send deposit confirmed message on startup or event + if (trade.getState().ordinal() >= Trade.State.DEPOSIT_TXS_CONFIRMED_IN_BLOCKCHAIN.ordinal()) { + new Thread(() -> sendDepositsConfirmedMessages()).start(); + } else { + EasyBind.subscribe(trade.stateProperty(), state -> { + if (state == Trade.State.DEPOSIT_TXS_CONFIRMED_IN_BLOCKCHAIN) { + new Thread(() -> sendDepositsConfirmedMessages()).start(); + } + }); + } } public void handleInitMultisigRequest(InitMultisigRequest request, NodeAddress sender) { @@ -770,16 +775,24 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D } } - private void sendDepositsConfirmedMessage() { + private void sendDepositsConfirmedMessages() { synchronized (trade) { + if (!trade.isInitialized()) return; // skip if shutting down + if (trade.getProcessModel().isDepositsConfirmedMessagesDelivered()) return; // skip if already delivered latchTrade(); expect(new Condition(trade)) .setup(tasks(getDepositsConfirmedTasks()) .using(new TradeTaskRunner(trade, () -> { + trade.getProcessModel().setDepositsConfirmedMessagesDelivered(true); handleTaskRunnerSuccess(null, null, "SendDepositsConfirmedMessages"); }, (errorMessage) -> { + + // retry in 15 minutes + UserThread.runAfter(() -> { + sendDepositsConfirmedMessages(); + }, 15, TimeUnit.MINUTES); handleTaskRunnerFault(null, null, "SendDepositsConfirmedMessages", errorMessage); }))) .executeTasks(true); diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index a1f292de7f..7132e8c4f0 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1708,6 +1708,7 @@ message ProcessModel { bytes mediated_payout_tx_signature = 18; int64 buyer_payout_amount_from_mediation = 19; int64 seller_payout_amount_from_mediation = 20; + bool deposits_confirmed_messages_delivered = 21; string maker_signature = 1001; TradingPeer maker = 1002;