From 94a9c8ac019517bf25e141a5200a7dc395f51e4b Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 28 Jun 2024 20:54:45 +0700 Subject: [PATCH] Instead of delaying the shutdown in case of a resync we delay the startup. This has the benefit that nodes cannot connect to the seed node while having inconsistant dao data. Signed-off-by: HenrikJannsen --- .../main/java/bisq/core/user/CookieKey.java | 3 ++- .../main/java/bisq/seednode/SeedNodeMain.java | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/user/CookieKey.java b/core/src/main/java/bisq/core/user/CookieKey.java index 2dc3c8a0433..2c6e6705933 100644 --- a/core/src/main/java/bisq/core/user/CookieKey.java +++ b/core/src/main/java/bisq/core/user/CookieKey.java @@ -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 } diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index 15ace134913..f7c329d3a1f 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -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(() -> @@ -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() {