fix offer message order by waiting 5s after edit offer start to publish (#2016)

This commit is contained in:
woodser 2025-10-11 15:20:03 -04:00 committed by GitHub
parent ed41671df9
commit c1f2ee9e77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,6 +62,7 @@ import haveno.core.offer.OpenOfferManager;
import haveno.core.payment.PaymentAccount; import haveno.core.payment.PaymentAccount;
import haveno.core.proto.persistable.CorePersistenceProtoResolver; import haveno.core.proto.persistable.CorePersistenceProtoResolver;
import haveno.core.provider.price.PriceFeedService; import haveno.core.provider.price.PriceFeedService;
import haveno.core.trade.HavenoUtils;
import static haveno.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer; import static haveno.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer;
import haveno.core.user.User; import haveno.core.user.User;
@ -84,6 +85,8 @@ import org.bitcoinj.core.Transaction;
@Slf4j @Slf4j
public class CoreOffersService { public class CoreOffersService {
private static final long WAIT_FOR_EDIT_REMOVAL_MS = 5000;
private final Supplier<Comparator<Offer>> priceComparator = () -> comparing(Offer::getPrice); private final Supplier<Comparator<Offer>> priceComparator = () -> comparing(Offer::getPrice);
private final Supplier<Comparator<OpenOffer>> openOfferPriceComparator = () -> comparing(openOffer -> openOffer.getOffer().getPrice()); private final Supplier<Comparator<OpenOffer>> openOfferPriceComparator = () -> comparing(openOffer -> openOffer.getOffer().getPrice());
private final Supplier<Comparator<Offer>> reversePriceComparator = () -> comparing(Offer::getPrice).reversed(); private final Supplier<Comparator<Offer>> reversePriceComparator = () -> comparing(Offer::getPrice).reversed();
@ -329,6 +332,10 @@ public class CoreOffersService {
openOfferManager.editOpenOfferStart(openOffer, () -> { openOfferManager.editOpenOfferStart(openOffer, () -> {
try { try {
// wait for remove offer to propagate
// TODO: if offer edit is published too quickly, the remove message can be received after the add message, in which case the offer will be offline until the next offer refresh
HavenoUtils.waitFor(WAIT_FOR_EDIT_REMOVAL_MS);
// create edited offer // create edited offer
Price price = priceAsString.isEmpty() ? null : Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode)); Price price = priceAsString.isEmpty() ? null : Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
final OfferPayload newOfferPayload = createOfferService.createAndGetOffer(offerId, final OfferPayload newOfferPayload = createOfferService.createAndGetOffer(offerId,