This commit is contained in:
woodser 2026-01-07 09:25:29 -05:00 committed by GitHub
commit beee784477
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View file

@ -129,7 +129,7 @@ public class OfferBookService {
replaceValidOffer(offer);
announceOfferAdded(offer);
} catch (IllegalArgumentException e) {
// ignore illegal offers
log.warn("Ignoring invalid offer {}: {}", offerPayload.getId(), e.getMessage());
} catch (RuntimeException e) {
replaceInvalidOffer(offer); // offer can become valid later
}
@ -379,6 +379,12 @@ public class OfferBookService {
throw new IllegalArgumentException("Offer with non-V3 node address is not allowed with offerId=" + offerPayload.getId());
}
// validate market price margin
double marketPriceMarginPct = offerPayload.getMarketPriceMarginPct();
if (marketPriceMarginPct <= -1 || marketPriceMarginPct >= 1) {
throw new IllegalArgumentException("Market price margin must be greater than -100% and less than 100% but was " + (marketPriceMarginPct * 100) + "% with offerId=" + offerPayload.getId());
}
// validate against existing offers
synchronized (validOffers) {
int numOffersWithSharedKeyImages = 0;

View file

@ -1629,6 +1629,15 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
}
}
// verify market price margin
double marketPriceMarginPct = request.getOfferPayload().getMarketPriceMarginPct();
if (marketPriceMarginPct <= -1 || marketPriceMarginPct >= 1) {
errorMessage = "Market price margin must be greater than -100% and less than 100% but was " + (marketPriceMarginPct * 100) + "%";
log.warn(errorMessage);
sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), false, errorMessage);
return;
}
// verify maker and taker fees
boolean hasBuyerAsTakerWithoutDeposit = offer.getDirection() == OfferDirection.SELL && offer.isPrivateOffer() && offer.getChallengeHash() != null && offer.getChallengeHash().length() > 0 && offer.getTakerFeePct() == 0;
if (hasBuyerAsTakerWithoutDeposit) {

View file

@ -109,6 +109,9 @@ public class ValidateOffer extends Task<PlaceOfferModel> {
if (!offer.isUseMarketBasedPrice()) checkArgument(offer.getPrice().isPositive(),
"Price must be positive unless using market based price. price=" + offer.getPrice().toFriendlyString());
checkArgument(offer.getOfferPayload().getMarketPriceMarginPct() > -1 && offer.getOfferPayload().getMarketPriceMarginPct() < 1,
"Market price margin must be greater than -100% and less than 100% but was " + (offer.getOfferPayload().getMarketPriceMarginPct() * 100) + "%");
checkArgument(offer.getDate().getTime() > 0,
"Date must not be 0. date=" + offer.getDate().toString());