process mailbox messages in order

This commit is contained in:
woodser 2022-11-25 11:39:35 +00:00
parent 456ef912ed
commit a266fab6ec
3 changed files with 25 additions and 5 deletions

View file

@ -381,7 +381,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
}
private void initTradeAndProtocol(Trade trade, TradeProtocol tradeProtocol) {
tradeProtocol.initialize(processModelServiceProvider, this, trade.getOffer());
tradeProtocol.initialize(processModelServiceProvider, this);
requestPersistence(); // TODO requesting persistence twice with initPersistedTrade()
}

View file

@ -19,7 +19,6 @@ package bisq.core.trade.protocol;
import bisq.core.trade.SellerTrade;
import bisq.core.trade.Trade;
import bisq.core.trade.messages.PaymentSentMessage;
import bisq.core.trade.messages.SignContractResponse;
import bisq.core.trade.messages.TradeMessage;
import bisq.core.trade.protocol.tasks.ApplyFilter;

View file

@ -17,7 +17,8 @@
package bisq.core.trade.protocol;
import bisq.core.offer.Offer;
import bisq.core.support.dispute.messages.DisputeClosedMessage;
import bisq.core.support.dispute.messages.DisputeOpenedMessage;
import bisq.core.trade.ArbitratorTrade;
import bisq.core.trade.BuyerTrade;
import bisq.core.trade.Trade;
@ -63,8 +64,11 @@ import bisq.common.handlers.ErrorMessageHandler;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.taskrunner.Task;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import lombok.extern.slf4j.Slf4j;
@ -168,9 +172,26 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
.filter(this::isMyMessage)
.filter(e -> e instanceof MailboxMessage)
.map(e -> (MailboxMessage) e)
.sorted(new MailboxMessageComparator())
.forEach(this::handleMailboxMessage);
}
private static class MailboxMessageComparator implements Comparator<MailboxMessage> {
private static List<Class<? extends MailboxMessage>> messageOrder = Arrays.asList(
DepositsConfirmedMessage.class,
PaymentSentMessage.class,
PaymentReceivedMessage.class,
DisputeOpenedMessage.class,
DisputeClosedMessage.class);
@Override
public int compare(MailboxMessage m1, MailboxMessage m2) {
int idx1 = messageOrder.indexOf(m1.getClass());
int idx2 = messageOrder.indexOf(m2.getClass());
return idx1 - idx2;
}
}
private void handleMailboxMessage(MailboxMessage mailboxMessage) {
if (mailboxMessage instanceof TradeMessage) {
TradeMessage tradeMessage = (TradeMessage) mailboxMessage;
@ -209,8 +230,8 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public abstract Class<? extends TradeTask>[] getDepositsConfirmedTasks();
public void initialize(ProcessModelServiceProvider serviceProvider, TradeManager tradeManager, Offer offer) {
processModel.applyTransient(serviceProvider, tradeManager, offer);
public void initialize(ProcessModelServiceProvider serviceProvider, TradeManager tradeManager) {
processModel.applyTransient(serviceProvider, tradeManager, trade.getOffer());
onInitialized();
}