do not process payment confirmation messages if shut down started

This commit is contained in:
woodser 2025-03-16 18:18:48 -04:00 committed by woodser
parent 5711aabad8
commit 6f3ae49b68

View file

@ -291,10 +291,11 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public void maybeReprocessPaymentSentMessage(boolean reprocessOnError) { public void maybeReprocessPaymentSentMessage(boolean reprocessOnError) {
if (trade.isShutDownStarted()) return; if (trade.isShutDownStarted()) return;
ThreadUtils.execute(() -> { ThreadUtils.execute(() -> {
if (trade.isShutDownStarted()) return;
synchronized (trade.getLock()) { synchronized (trade.getLock()) {
// skip if no need to reprocess // skip if no need to reprocess
if (trade.isBuyer() || trade.getBuyer().getPaymentSentMessage() == null || trade.getState().ordinal() >= Trade.State.BUYER_SENT_PAYMENT_SENT_MSG.ordinal()) { if (trade.isShutDownStarted() || trade.isBuyer() || trade.getBuyer().getPaymentSentMessage() == null || trade.getState().ordinal() >= Trade.State.BUYER_SENT_PAYMENT_SENT_MSG.ordinal()) {
return; return;
} }
@ -307,10 +308,11 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public void maybeReprocessPaymentReceivedMessage(boolean reprocessOnError) { public void maybeReprocessPaymentReceivedMessage(boolean reprocessOnError) {
if (trade.isShutDownStarted()) return; if (trade.isShutDownStarted()) return;
ThreadUtils.execute(() -> { ThreadUtils.execute(() -> {
if (trade.isShutDownStarted()) return;
synchronized (trade.getLock()) { synchronized (trade.getLock()) {
// skip if no need to reprocess // skip if no need to reprocess
if (trade.isSeller() || trade.getSeller().getPaymentReceivedMessage() == null || (trade.getState().ordinal() >= Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG.ordinal() && trade.isPayoutPublished())) { if (trade.isShutDownStarted() || trade.isSeller() || trade.getSeller().getPaymentReceivedMessage() == null || (trade.getState().ordinal() >= Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG.ordinal() && trade.isPayoutPublished())) {
return; return;
} }
@ -525,7 +527,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
trade.getBuyer().setPaymentSentMessage(message); trade.getBuyer().setPaymentSentMessage(message);
trade.requestPersistence(); trade.requestPersistence();
if (!trade.isInitialized() || trade.isShutDown()) return; if (!trade.isInitialized() || trade.isShutDownStarted()) return;
if (!(trade instanceof SellerTrade || trade instanceof ArbitratorTrade)) { if (!(trade instanceof SellerTrade || trade instanceof ArbitratorTrade)) {
log.warn("Ignoring PaymentSentMessage since not seller or arbitrator"); log.warn("Ignoring PaymentSentMessage since not seller or arbitrator");
return; return;
@ -537,7 +539,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
// TODO A better fix would be to add a listener for the wallet sync state and process // TODO A better fix would be to add a listener for the wallet sync state and process
// the mailbox msg once wallet is ready and trade state set. // the mailbox msg once wallet is ready and trade state set.
synchronized (trade.getLock()) { synchronized (trade.getLock()) {
if (!trade.isInitialized() || trade.isShutDown()) return; if (!trade.isInitialized() || trade.isShutDownStarted()) return;
if (trade.getPhase().ordinal() >= Trade.Phase.PAYMENT_SENT.ordinal()) { if (trade.getPhase().ordinal() >= Trade.Phase.PAYMENT_SENT.ordinal()) {
log.warn("Received another PaymentSentMessage which was already processed for {} {}, ACKing", trade.getClass().getSimpleName(), trade.getId()); log.warn("Received another PaymentSentMessage which was already processed for {} {}, ACKing", trade.getClass().getSimpleName(), trade.getId());
handleTaskRunnerSuccess(peer, message); handleTaskRunnerSuccess(peer, message);
@ -604,14 +606,14 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
trade.getSeller().setPaymentReceivedMessage(message); trade.getSeller().setPaymentReceivedMessage(message);
trade.requestPersistence(); trade.requestPersistence();
if (!trade.isInitialized() || trade.isShutDown()) return; if (!trade.isInitialized() || trade.isShutDownStarted()) return;
ThreadUtils.execute(() -> { ThreadUtils.execute(() -> {
if (!(trade instanceof BuyerTrade || trade instanceof ArbitratorTrade)) { if (!(trade instanceof BuyerTrade || trade instanceof ArbitratorTrade)) {
log.warn("Ignoring PaymentReceivedMessage since not buyer or arbitrator"); log.warn("Ignoring PaymentReceivedMessage since not buyer or arbitrator");
return; return;
} }
synchronized (trade.getLock()) { synchronized (trade.getLock()) {
if (!trade.isInitialized() || trade.isShutDown()) return; if (!trade.isInitialized() || trade.isShutDownStarted()) return;
latchTrade(); latchTrade();
Validator.checkTradeId(processModel.getOfferId(), message); Validator.checkTradeId(processModel.getOfferId(), message);
processModel.setTradeMessage(message); processModel.setTradeMessage(message);