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

Improve offer publishing #4950

Merged
merged 7 commits into from
Dec 29, 2020
Merged
Changes from 1 commit
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
53 changes: 32 additions & 21 deletions core/src/main/java/bisq/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -871,39 +871,46 @@ private void maybeUpdatePersistedOffers() {
///////////////////////////////////////////////////////////////////////////////////////////

private void republishOffers() {
int size = openOffers.size();
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOffers.getList());
if (!stopped) {
stopPeriodicRefreshOffersTimer();
for (int i = 0; i < size; i++) {
// we delay to avoid reaching throttle limits

long delay = 700;
final long minDelay = (i + 1) * delay;
final long maxDelay = (i + 2) * delay;
final OpenOffer openOffer = openOffersList.get(i);
UserThread.runAfterRandomDelay(() -> {
if (openOffers.contains(openOffer)) {
String id = openOffer.getId();
if (id != null && !openOffer.isDeactivated())
republishOffer(openOffer);
}
if (stopped) {
return;
}

}, minDelay, maxDelay, TimeUnit.MILLISECONDS);
}
} else {
log.debug("We have stopped already. We ignore that republishOffers call.");
List<OpenOffer> openOffersList = new ArrayList<>(openOffers.getList());
republishOffers(openOffersList);

stopPeriodicRefreshOffersTimer();
}

private void republishOffers(List<OpenOffer> list) {
if (list.isEmpty()) {
return;
}

OpenOffer openOffer = list.remove(0);
if (!openOffers.contains(openOffer) || openOffer.isDeactivated()) {
chimp1984 marked this conversation as resolved.
Show resolved Hide resolved
republishOffers(list);
}

republishOffer(openOffer,
() -> UserThread.runAfter(() -> republishOffers(list),
30, TimeUnit.MILLISECONDS));
chimp1984 marked this conversation as resolved.
Show resolved Hide resolved
}

private void republishOffer(OpenOffer openOffer) {
republishOffer(openOffer, null);
}

private void republishOffer(OpenOffer openOffer, @Nullable Runnable completeHandler) {
offerBookService.addOffer(openOffer.getOffer(),
() -> {
if (!stopped) {
// Refresh means we send only the data needed to refresh the TTL (hash, signature and sequence no.)
if (periodicRefreshOffersTimer == null) {
startPeriodicRefreshOffersTimer();
}
if (completeHandler != null) {
completeHandler.run();
}
}
},
errorMessage -> {
Expand All @@ -912,6 +919,10 @@ private void republishOffer(OpenOffer openOffer) {
stopRetryRepublishOffersTimer();
retryRepublishOffersTimer = UserThread.runAfter(OpenOfferManager.this::republishOffers,
RETRY_REPUBLISH_DELAY_SEC);

if (completeHandler != null) {
completeHandler.run();
}
}
});
}
Expand Down