From 11e3b15e42139a70a055da6e1bbc285d88ad92af Mon Sep 17 00:00:00 2001 From: Pedro Novais <1478752+jpnovais@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:01:00 +0000 Subject: [PATCH] staterecovery: disable synch and maining services again on afterExternalServicePostMainLoop callback --- .../staterecovery/plugin/LineaStateRecoveryPlugin.kt | 3 +++ .../linea/staterecovery/plugin/RecoveryModeManager.kt | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/LineaStateRecoveryPlugin.kt b/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/LineaStateRecoveryPlugin.kt index 9cd19ec6b..adf1f758e 100644 --- a/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/LineaStateRecoveryPlugin.kt +++ b/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/LineaStateRecoveryPlugin.kt @@ -113,6 +113,9 @@ open class LineaStateRecoveryPlugin : BesuPlugin { } override fun afterExternalServicePostMainLoop() { + // we need to recall this again because Sync and Mining services + // bay have been started after the plugin start + this.recoveryModeManager.enableRecoveryModeIfNecessary() } override fun stop() { diff --git a/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/RecoveryModeManager.kt b/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/RecoveryModeManager.kt index f7fb0bde8..4465e7e06 100644 --- a/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/RecoveryModeManager.kt +++ b/state-recovery/besu-plugin/src/main/kotlin/linea/staterecovery/plugin/RecoveryModeManager.kt @@ -27,6 +27,11 @@ class RecoveryModeManager( init { log.info("RecoveryModeManager initializing: headBlockNumber={}", headBlockNumber) + enableRecoveryModeIfNecessary() + } + + @Synchronized + fun enableRecoveryModeIfNecessary() { if (hasReachedTargetBlock()) { log.info( "enabling recovery mode immediately at blockNumber={} recoveryTargetBlockNumber={}", @@ -92,9 +97,6 @@ class RecoveryModeManager( /** Switches the node to recovery mode. */ private fun switchToRecoveryMode() { - check(!recoveryModeTriggered.get()) { - "cannot enable already enabled recovery mode" - } log.warn("Stopping synchronization service") synchronizationService.stop() @@ -105,7 +107,7 @@ class RecoveryModeManager( miningService.stop() log.info( - "Switched to state recovery mode at block={}", + "switched to state recovery mode at block={}", headBlockNumber ) recoveryModeTriggered.set(true)