Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of unconfirmed offers #4053

Merged
merged 5 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/btc/wallet/WalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,15 @@ public int getLastBlockSeenHeight() {
return wallet.getLastBlockSeenHeight();
}

/**
* Check if there are more than 20 unconfirmed transactions in the chain right now.
*
* @return true when queue is full
*/
public boolean isUnconfirmedTransactionsLimitHit() {
return 20 < getTransactions(true).stream().filter(transaction -> transaction.isPending()).count();
}

public Set<Transaction> getTransactions(boolean includeDead) {
return wallet.getTransactions(includeDead);
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/bisq/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.core.btc.wallet.TradeWalletService;
import bisq.core.dao.DaoFacade;
import bisq.core.exceptions.TradePriceOutOfToleranceException;
import bisq.core.locale.Res;
import bisq.core.offer.availability.DisputeAgentSelection;
import bisq.core.offer.messages.OfferAvailabilityRequest;
import bisq.core.offer.messages.OfferAvailabilityResponse;
Expand Down Expand Up @@ -637,6 +638,12 @@ private void handleOfferAvailabilityRequest(OfferAvailabilityRequest request, No
availabilityResult = AvailabilityResult.OFFER_TAKEN;
}

if (btcWalletService.isUnconfirmedTransactionsLimitHit() || bsqWalletService.isUnconfirmedTransactionsLimitHit()) {
errorMessage = Res.get("shared.unconfirmedTransactionsLimitReached");
log.warn(errorMessage);
availabilityResult = AvailabilityResult.UNKNOWN_FAILURE;
}

OfferAvailabilityResponse offerAvailabilityResponse = new OfferAvailabilityResponse(request.offerId,
availabilityResult,
arbitratorNodeAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.offer.placeoffer;

import bisq.core.offer.placeoffer.tasks.AddToOfferBook;
import bisq.core.offer.placeoffer.tasks.CheckNumberOfUnconfirmedTransactions;
import bisq.core.offer.placeoffer.tasks.CreateMakerFeeTx;
import bisq.core.offer.placeoffer.tasks.ValidateOffer;
import bisq.core.trade.handlers.TransactionResultHandler;
Expand Down Expand Up @@ -71,11 +72,13 @@ public void placeOffer() {
},
log::error);
}
model.getOffer().setErrorMessage(errorMessage);
errorMessageHandler.handleErrorMessage(errorMessage);
}
);
taskRunner.addTasks(
ValidateOffer.class,
CheckNumberOfUnconfirmedTransactions.class,
CreateMakerFeeTx.class,
AddToOfferBook.class
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package bisq.core.offer.placeoffer.tasks;

import bisq.core.locale.Res;
import bisq.core.offer.placeoffer.PlaceOfferModel;

import bisq.common.taskrunner.Task;
import bisq.common.taskrunner.TaskRunner;

public class CheckNumberOfUnconfirmedTransactions extends Task<PlaceOfferModel> {
public CheckNumberOfUnconfirmedTransactions(TaskRunner taskHandler, PlaceOfferModel model) {
super(taskHandler, model);
}

@Override
protected void run() {
if (model.getWalletService().isUnconfirmedTransactionsLimitHit() || model.getBsqWalletService().isUnconfirmedTransactionsLimitHit())
failed(Res.get("shared.unconfirmedTransactionsLimitReached"));
complete();
}
}
8 changes: 8 additions & 0 deletions core/src/main/java/bisq/core/trade/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,14 @@ public void onOfferRemovedFromRemoteOfferBook(Offer offer) {
public void checkOfferAvailability(Offer offer,
ResultHandler resultHandler,
ErrorMessageHandler errorMessageHandler) {

if (btcWalletService.isUnconfirmedTransactionsLimitHit() || bsqWalletService.isUnconfirmedTransactionsLimitHit()) {
String errorMessage = Res.get("shared.unconfirmedTransactionsLimitReached");
errorMessageHandler.handleErrorMessage(errorMessage);
log.warn(errorMessage);
return;
}

offer.checkOfferAvailability(getOfferAvailabilityModel(offer), resultHandler, errorMessageHandler);
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ shared.arbitrator=Arbitrator
shared.refundAgent=Arbitrator
shared.refundAgentForSupportStaff=Refund agent
shared.delayedPayoutTxId=Refund collateral transaction ID
shared.unconfirmedTransactionsLimitReached=You have too many unconfirmed transactions at the moment. Please try again later.


####################################################################
Expand Down