Skip to content

Commit

Permalink
process mailbox messages on main thread on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Nov 21, 2023
1 parent cfaca6e commit 3d0b8c0
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public TradeProtocol(Trade trade) {

protected void onTradeMessage(TradeMessage message, NodeAddress peerNodeAddress) {
log.info("Received {} as TradeMessage from {} with tradeId {} and uid {}", message.getClass().getSimpleName(), peerNodeAddress, message.getTradeId(), message.getUid());
handle(message, peerNodeAddress);
new Thread(() -> handle(message, peerNodeAddress)).start();
}

protected void onMailboxMessage(TradeMessage message, NodeAddress peerNodeAddress) {
Expand All @@ -118,15 +118,13 @@ protected void onMailboxMessage(TradeMessage message, NodeAddress peerNodeAddres
}

private void handle(TradeMessage message, NodeAddress peerNodeAddress) {
new Thread(() -> {
if (message instanceof DepositsConfirmedMessage) {
handle((DepositsConfirmedMessage) message, peerNodeAddress);
} else if (message instanceof PaymentSentMessage) {
handle((PaymentSentMessage) message, peerNodeAddress);
} else if (message instanceof PaymentReceivedMessage) {
handle((PaymentReceivedMessage) message, peerNodeAddress);
}
}).start();
if (message instanceof DepositsConfirmedMessage) {
handle((DepositsConfirmedMessage) message, peerNodeAddress);
} else if (message instanceof PaymentSentMessage) {
handle((PaymentSentMessage) message, peerNodeAddress);
} else if (message instanceof PaymentReceivedMessage) {
handle((PaymentReceivedMessage) message, peerNodeAddress);
}
}

@Override
Expand Down Expand Up @@ -523,7 +521,6 @@ private void handle(PaymentReceivedMessage message, NodeAddress peer, boolean re
Validator.checkTradeId(processModel.getOfferId(), message);
processModel.setTradeMessage(message);


// check minimum trade phase
if (trade.isBuyer() && trade.getPhase().ordinal() < Trade.Phase.PAYMENT_SENT.ordinal()) {
log.warn("Received PaymentReceivedMessage before payment sent for {} {}, ignoring", trade.getClass().getSimpleName(), trade.getId());
Expand Down

0 comments on commit 3d0b8c0

Please sign in to comment.