reprocess trade messages off UserThread

This commit is contained in:
woodser 2024-01-01 09:04:18 -05:00
parent 9a6a9ac93e
commit 0a3736bba0
2 changed files with 42 additions and 42 deletions

View File

@ -325,6 +325,7 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
} }
public void maybeReprocessDisputeClosedMessage(Trade trade, boolean reprocessOnError) { public void maybeReprocessDisputeClosedMessage(Trade trade, boolean reprocessOnError) {
new Thread(() -> {
synchronized (trade) { synchronized (trade) {
// skip if no need to reprocess // skip if no need to reprocess
@ -333,8 +334,9 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
} }
log.warn("Reprocessing dispute closed message for {} {}", trade.getClass().getSimpleName(), trade.getId()); log.warn("Reprocessing dispute closed message for {} {}", trade.getClass().getSimpleName(), trade.getId());
new Thread(() -> handleDisputeClosedMessage(trade.getArbitrator().getDisputeClosedMessage(), reprocessOnError)).start(); handleDisputeClosedMessage(trade.getArbitrator().getDisputeClosedMessage(), reprocessOnError);
} }
}).start();
} }
private MoneroTxSet signAndPublishDisputePayoutTx(Trade trade) { private MoneroTxSet signAndPublishDisputePayoutTx(Trade trade) {

View File

@ -259,17 +259,33 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
} }
// send deposits confirmed message if applicable // send deposits confirmed message if applicable
maybeSendDepositsConfirmedMessage(); maybeSendDepositsConfirmedMessages();
EasyBind.subscribe(trade.stateProperty(), state -> maybeSendDepositsConfirmedMessages());
} }
private void maybeSendDepositsConfirmedMessage() { public void maybeSendDepositsConfirmedMessages() {
HavenoUtils.submitToThread(() -> maybeSendDepositsConfirmedMessages(), trade.getId()); HavenoUtils.submitToThread(() -> {
EasyBind.subscribe(trade.stateProperty(), state -> { if (!trade.isDepositsConfirmed() || trade.isDepositsConfirmedAcked() || trade.isPayoutPublished()) return;
HavenoUtils.submitToThread(() -> maybeSendDepositsConfirmedMessages(), trade.getId()); synchronized (trade) {
}); if (!trade.isInitialized() || trade.isShutDownStarted()) return; // skip if shutting down
latchTrade();
expect(new Condition(trade))
.setup(tasks(getDepositsConfirmedTasks())
.using(new TradeTaskRunner(trade,
() -> {
handleTaskRunnerSuccess(null, null, "maybeSendDepositsConfirmedMessages");
},
(errorMessage) -> {
handleTaskRunnerFault(null, null, "maybeSendDepositsConfirmedMessages", errorMessage);
})))
.executeTasks(true);
awaitTradeLatch();
}
}, trade.getId());
} }
public void maybeReprocessPaymentReceivedMessage(boolean reprocessOnError) { public void maybeReprocessPaymentReceivedMessage(boolean reprocessOnError) {
HavenoUtils.submitToThread(() -> {
synchronized (trade) { synchronized (trade) {
// skip if no need to reprocess // skip if no need to reprocess
@ -278,11 +294,12 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
} }
log.warn("Reprocessing payment received message for {} {}", trade.getClass().getSimpleName(), trade.getId()); log.warn("Reprocessing payment received message for {} {}", trade.getClass().getSimpleName(), trade.getId());
HavenoUtils.submitToThread(() -> { handle(trade.getSeller().getPaymentReceivedMessage(), trade.getSeller().getPaymentReceivedMessage().getSenderNodeAddress(), reprocessOnError);
}
handle(trade.getSeller().getPaymentReceivedMessage(), trade.getSeller().getPaymentReceivedMessage().getSenderNodeAddress(), reprocessOnError); handle(trade.getSeller().getPaymentReceivedMessage(), trade.getSeller().getPaymentReceivedMessage().getSenderNodeAddress(), reprocessOnError);
}, trade.getId()); }, trade.getId());
} }
}
public void handleInitMultisigRequest(InitMultisigRequest request, NodeAddress sender) { public void handleInitMultisigRequest(InitMultisigRequest request, NodeAddress sender) {
System.out.println(getClass().getSimpleName() + ".handleInitMultisigRequest()"); System.out.println(getClass().getSimpleName() + ".handleInitMultisigRequest()");
@ -844,23 +861,4 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
return false; return false;
} }
} }
public void maybeSendDepositsConfirmedMessages() {
if (!trade.isDepositsConfirmed() || trade.isDepositsConfirmedAcked() || trade.isPayoutPublished()) return;
synchronized (trade) {
if (!trade.isInitialized() || trade.isShutDownStarted()) return; // skip if shutting down
latchTrade();
expect(new Condition(trade))
.setup(tasks(getDepositsConfirmedTasks())
.using(new TradeTaskRunner(trade,
() -> {
handleTaskRunnerSuccess(null, null, "maybeSendDepositsConfirmedMessages");
},
(errorMessage) -> {
handleTaskRunnerFault(null, null, "maybeSendDepositsConfirmedMessages", errorMessage);
})))
.executeTasks(true);
awaitTradeLatch();
}
}
} }