resend deposits confirmed messages until delivered

This commit is contained in:
woodser 2023-01-14 10:56:11 -05:00
parent cd7f176e2b
commit 435fc164b2
3 changed files with 25 additions and 8 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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;