From 4c64dbe1cd678efabcda798ae8bebe43e844a5d7 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 18 Sep 2024 08:15:35 +1000 Subject: [PATCH 1/7] 7311: Add feature toggle for enabling use of the peertask system where available Signed-off-by: Matilda Clerke --- .../org/hyperledger/besu/cli/BesuCommand.java | 10 ++++ .../cli/custom/PeerTaskFeatureToggle.java | 53 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java 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 ecfc0eaadb..a6e7712724 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.cli.converter.MetricCategoryConverter; import org.hyperledger.besu.cli.converter.PercentageConverter; import org.hyperledger.besu.cli.converter.SubnetInfoConverter; import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; +import org.hyperledger.besu.cli.custom.PeerTaskFeatureToggle; import org.hyperledger.besu.cli.error.BesuExecutionExceptionHandler; import org.hyperledger.besu.cli.error.BesuParameterExceptionHandler; import org.hyperledger.besu.cli.options.MiningOptions; @@ -842,6 +843,12 @@ public class BesuCommand implements DefaultCommandValues, Runnable { description = "Specifies the number of last blocks to cache (default: ${DEFAULT-VALUE})") private final Integer numberOfblocksToCache = 0; + @Option( + names = {"--peertask-system-enabled"}, + description = + "Temporary feature toggle to enable using the new peertask system (default: ${DEFAULT-VALUE})") + private final Boolean isPeerTaskSystemEnabled = false; + @Mixin private P2PTLSConfigOptions p2pTLSConfigOptions; // Plugins Configuration Option Group @@ -1784,6 +1791,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable { instantiateSignatureAlgorithmFactory(); + PeerTaskFeatureToggle.initialize(isPeerTaskSystemEnabled); + logger.info("PeerTask feature toggle is {}", PeerTaskFeatureToggle.usePeerTaskSystem() ? "enabled" : "disabled"); + logger.info(generateConfigurationOverview()); logger.info("Security Module: {}", securityModuleName); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java new file mode 100644 index 0000000000..0d929f006a --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java @@ -0,0 +1,53 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.custom; + +/** + * Temporary class to allow easy access to the PeerTask feature toggle. This class can be removed + * once we've properly tested the PeerTask system and want to enable it permanently + */ +public class PeerTaskFeatureToggle { + private static Boolean USE_PEER_TASK_SYSTEM = null; + + /** + * Initialize the PeerTaskFeatureToggle with the supplied usePeerTaskSystem Boolean. + * PeerTaskFeatureToggle may only be initialized once! + * + * @param usePeerTaskSystem Boolean indicating whether or not the PeerTask system should be used + * @throws IllegalStateException if PeerTaskFeatureToggle has already been initialized + */ + public static void initialize(final Boolean usePeerTaskSystem) { + if (USE_PEER_TASK_SYSTEM != null) { + throw new IllegalStateException( + "PeerTaskFeatureToggle has already been initialized, and cannot be initialized again"); + } + USE_PEER_TASK_SYSTEM = usePeerTaskSystem; + } + + /** + * Indicates whether or not to use the PeerTask system. PeerTaskFeatureToggle must have been + * initialized before this method can be called! + * + * @return whether or not to use the PeerTask system + * @throws IllegalStateException if the PeerTaskFeatureToggle has not been initialized + */ + public static Boolean usePeerTaskSystem() { + if (USE_PEER_TASK_SYSTEM == null) { + throw new IllegalStateException( + "PeerTaskFeatureToggle has not been initialized, but getUsePeerTaskSystem() has been called"); + } + return USE_PEER_TASK_SYSTEM; + } +} From 7a94fe2d6d5666def85c6db4f1d3d4d2385e4df8 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 18 Sep 2024 08:32:54 +1000 Subject: [PATCH 2/7] 7311: Remove log used for testing, apply spotless Signed-off-by: Matilda Clerke --- besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java | 1 - 1 file changed, 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 a6e7712724..cee8a49c88 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1792,7 +1792,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { instantiateSignatureAlgorithmFactory(); PeerTaskFeatureToggle.initialize(isPeerTaskSystemEnabled); - logger.info("PeerTask feature toggle is {}", PeerTaskFeatureToggle.usePeerTaskSystem() ? "enabled" : "disabled"); logger.info(generateConfigurationOverview()); logger.info("Security Module: {}", securityModuleName); From ace5dd1918836cb2b881d171a570ba9e2916be35 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 18 Sep 2024 08:52:20 +1000 Subject: [PATCH 3/7] 7311: Add private constructor to PeerTaskFeatureToggle to prevent instantiation Signed-off-by: Matilda Clerke --- .../org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java index 0d929f006a..a817e84e3d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java @@ -50,4 +50,6 @@ public class PeerTaskFeatureToggle { } return USE_PEER_TASK_SYSTEM; } + + private PeerTaskFeatureToggle() {} } From 52d440afbe3c5c3b785831495672ec7ef912a381 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 18 Sep 2024 09:16:14 +1000 Subject: [PATCH 4/7] 7311: Switch to logging a warning instead of throwing an exception when initializing PeerTaskFeatureToggle multiple times Signed-off-by: Matilda Clerke --- .../besu/cli/custom/PeerTaskFeatureToggle.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java index a817e84e3d..a6fc636fb5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java @@ -14,11 +14,15 @@ */ package org.hyperledger.besu.cli.custom; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Temporary class to allow easy access to the PeerTask feature toggle. This class can be removed * once we've properly tested the PeerTask system and want to enable it permanently */ public class PeerTaskFeatureToggle { + private static final Logger LOGGER = LoggerFactory.getLogger(PeerTaskFeatureToggle.class); private static Boolean USE_PEER_TASK_SYSTEM = null; /** @@ -30,10 +34,10 @@ public class PeerTaskFeatureToggle { */ public static void initialize(final Boolean usePeerTaskSystem) { if (USE_PEER_TASK_SYSTEM != null) { - throw new IllegalStateException( - "PeerTaskFeatureToggle has already been initialized, and cannot be initialized again"); + LOGGER.warn("PeerTaskFeatureToggle has already been initialized, and cannot be initialized again"); + } else { + USE_PEER_TASK_SYSTEM = usePeerTaskSystem; } - USE_PEER_TASK_SYSTEM = usePeerTaskSystem; } /** From f392a0feda02546a8deb48f7158b7003f29fb498 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 18 Sep 2024 09:16:34 +1000 Subject: [PATCH 5/7] 7311: Update javadoc to match previous commit Signed-off-by: Matilda Clerke --- .../org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java | 1 - 1 file changed, 1 deletion(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java index a6fc636fb5..19e66a9208 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java @@ -30,7 +30,6 @@ public class PeerTaskFeatureToggle { * PeerTaskFeatureToggle may only be initialized once! * * @param usePeerTaskSystem Boolean indicating whether or not the PeerTask system should be used - * @throws IllegalStateException if PeerTaskFeatureToggle has already been initialized */ public static void initialize(final Boolean usePeerTaskSystem) { if (USE_PEER_TASK_SYSTEM != null) { From 2fb2690e0109a9bec8126d8305be04ceb4536dbc Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 18 Sep 2024 09:22:47 +1000 Subject: [PATCH 6/7] 7311: spotless Signed-off-by: Matilda Clerke --- .../org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java index 19e66a9208..b1035cfd07 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/custom/PeerTaskFeatureToggle.java @@ -33,7 +33,8 @@ public class PeerTaskFeatureToggle { */ public static void initialize(final Boolean usePeerTaskSystem) { if (USE_PEER_TASK_SYSTEM != null) { - LOGGER.warn("PeerTaskFeatureToggle has already been initialized, and cannot be initialized again"); + LOGGER.warn( + "PeerTaskFeatureToggle has already been initialized, and cannot be initialized again"); } else { USE_PEER_TASK_SYSTEM = usePeerTaskSystem; } From f14aaebef6ebf404753cc2c9561aa5422d85f2df Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 18 Sep 2024 10:24:10 +1000 Subject: [PATCH 7/7] 7311: Fix broken BesuCommandTest Signed-off-by: Matilda Clerke --- besu/src/test/resources/everything_config.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index e3d7a3f28d..73a1775462 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -226,6 +226,7 @@ Xsecp256k1-native-enabled=false Xaltbn128-native-enabled=false Xsnapsync-server-enabled=true Xbonsai-full-flat-db-enabled=true +peertask-system-enabled=false # compatibility flags compatibility-eth64-forkid-enabled=false