From 27592b52996f7234abd6c653f69ce1b0ba7ccd42 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Wed, 27 Nov 2024 10:08:17 +1100 Subject: [PATCH] Expose start and stop synchronization to plugin aPI (#7940) Signed-off-by: Gabriel-Trintinalia --- .../org/hyperledger/besu/cli/BesuCommand.java | 1 + .../besu/services/SynchronizationServiceImpl.java | 15 +++++++++++++++ plugin-api/build.gradle | 2 +- .../services/sync/SynchronizationService.java | 6 ++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 1a842acc589..e2c657dd18d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1278,6 +1278,7 @@ private void startPlugins(final Runner runner) { besuPluginContext.addService( SynchronizationService.class, new SynchronizationServiceImpl( + besuController.getSynchronizer(), besuController.getProtocolContext(), besuController.getProtocolSchedule(), besuController.getSyncState(), diff --git a/besu/src/main/java/org/hyperledger/besu/services/SynchronizationServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/SynchronizationServiceImpl.java index 2e15e2ab82f..cd4f494dc65 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/SynchronizationServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/SynchronizationServiceImpl.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockImporter; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -45,6 +46,7 @@ public class SynchronizationServiceImpl implements SynchronizationService { private final ProtocolContext protocolContext; private final ProtocolSchedule protocolSchedule; + private final Synchronizer synchronizer; private final SyncState syncState; private final Optional worldStateArchive; @@ -52,16 +54,19 @@ public class SynchronizationServiceImpl implements SynchronizationService { /** * Constructor for SynchronizationServiceImpl. * + * @param synchronizer synchronizer * @param protocolContext protocol context * @param protocolSchedule protocol schedule * @param syncState sync state * @param worldStateArchive world state archive */ public SynchronizationServiceImpl( + final Synchronizer synchronizer, final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final SyncState syncState, final WorldStateArchive worldStateArchive) { + this.synchronizer = synchronizer; this.protocolContext = protocolContext; this.protocolSchedule = protocolSchedule; this.syncState = syncState; @@ -157,4 +162,14 @@ public void disableWorldStateTrie() { } }); } + + @Override + public void stop() { + synchronizer.stop(); + } + + @Override + public void start() { + synchronizer.start(); + } } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 6f83363dd41..d504767138d 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'KuKoCZT1A+gOlJlry5GQMCRKVWWAlO3lGAqt9MDv0r4=' + knownHash = 'PKvPlngg7BfdZ4Jinh0IUsyFOLvNaQU72VD4BHia/WM=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/sync/SynchronizationService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/sync/SynchronizationService.java index ad9682429d0..1b1ea8bdfea 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/sync/SynchronizationService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/sync/SynchronizationService.java @@ -59,4 +59,10 @@ public interface SynchronizationService extends BesuService { /** Disables the worldstate trie for update. */ void disableWorldStateTrie(); + + /** Stops the synchronizer. */ + void stop(); + + /** Starts the synchronizer. */ + void start(); }