Skip to content

Commit

Permalink
Instead of delaying the shutdown in case of a resync we delay the sta…
Browse files Browse the repository at this point in the history
…rtup. This has the benefit that nodes cannot connect to the seed node while having inconsistant dao data.

Signed-off-by: HenrikJannsen <[email protected]>
  • Loading branch information
HenrikJannsen committed Jun 28, 2024
1 parent aa9d3a3 commit 94a9c8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/user/CookieKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public enum CookieKey {
STAGE_W,
STAGE_H,
TRADE_STAT_CHART_USE_USD,
CLEAN_TOR_DIR_AT_RESTART
CLEAN_TOR_DIR_AT_RESTART,
DELAY_STARTUP
}
22 changes: 18 additions & 4 deletions seednode/src/main/java/bisq/seednode/SeedNodeMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ protected void startApplication() {
super.startApplication();

Cookie cookie = injector.getInstance(User.class).getCookie();
if (cookie.getAsOptionalBoolean(CookieKey.DELAY_STARTUP).orElse(false)) {
cookie.remove(CookieKey.DELAY_STARTUP);
try {
// We create a deterministic delay per seed to avoid that all seeds start up at the
// same time in case of a reorg.
long delay = getMyIndex() * TimeUnit.SECONDS.toMillis(30);
Thread.sleep(delay);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(cleanTorDirAtRestart -> {
if (cleanTorDirAtRestart) {
injector.getInstance(TorSetup.class).cleanupTorFiles(() ->
Expand All @@ -133,10 +145,12 @@ public void onCheckpointFailed() {
});

injector.getInstance(DaoStateSnapshotService.class).setResyncDaoStateFromResourcesHandler(
// We shut down with a deterministic delay per seed to avoid that all seeds shut down at the
// same time in case of a reorg. We use 30 sec. as distance delay between the seeds to be on the
// safe side. We have 12 seeds so that's 6 minutes.
() -> UserThread.runAfter(this::gracefulShutDown, 1 + (getMyIndex() * 30L))
// We set DELAY_STARTUP and shut down. At start up we delay with a deterministic delay to avoid
// that all seeds get restarted at the same time.
() -> {
injector.getInstance(User.class).getCookie().putAsBoolean(CookieKey.DELAY_STARTUP, true);
shutDown(this);
}
);

injector.getInstance(P2PService.class).addP2PServiceListener(new P2PServiceListener() {
Expand Down

0 comments on commit 94a9c8a

Please sign in to comment.