diff --git a/hildr-node/build.gradle b/hildr-node/build.gradle index eb925251..9fdbcaff 100644 --- a/hildr-node/build.gradle +++ b/hildr-node/build.gradle @@ -1,3 +1,5 @@ +import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer + /* * This file was generated by the Gradle 'init' task. * @@ -317,7 +319,7 @@ jar { shadowJar { archiveFileName = "${project.name}-${project.version}.jar" - transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer) + transform(Log4j2PluginsCacheFileTransformer) } task buildJarForDocker { diff --git a/hildr-node/src/main/java/io/optimism/cli/Cli.java b/hildr-node/src/main/java/io/optimism/cli/Cli.java index cb000676..5306e5c5 100644 --- a/hildr-node/src/main/java/io/optimism/cli/Cli.java +++ b/hildr-node/src/main/java/io/optimism/cli/Cli.java @@ -34,6 +34,10 @@ public class Cli implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(Cli.class); + private static final int DEFAULT_METRICS_PORT = 9200; + + private static final int MAX_PORT_NUMBER = 65535; + @Option( names = "--network", defaultValue = "optimism", @@ -49,7 +53,7 @@ public class Cli implements Runnable { @Option(names = "--l1-beacon-url", required = true, description = "The l1 chain beacon client RPC URL") String l1BeaconUrl; - @Option(names = "--l1-beacon-archiver-url", required = false, description = "The l1 beacon chain archiver RPC URL") + @Option(names = "--l1-beacon-archiver-url", description = "The l1 beacon chain archiver RPC URL") String l1BeaconArchiverUrl; @Option(names = "--l2-rpc-url", required = true, description = "The L2 engine RPC URL") @@ -73,14 +77,8 @@ public class Cli implements Runnable { @Option(names = "--jwt-file", description = "Path to a JWT secret to use for authenticated RPC endpoints") String jwtFile; - @Option( - names = {"--verbose", "-v"}, - description = "") - Boolean verbose; - @Option( names = {"--rpc-addr"}, - required = false, description = "The address of RPC server", defaultValue = "0.0.0.0") String rpcAddr; @@ -146,15 +144,14 @@ public Cli() {} @Override public void run() { var logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); - if (logger instanceof ch.qos.logback.classic.Logger) { - var logbackLogger = (ch.qos.logback.classic.Logger) logger; + if (logger instanceof ch.qos.logback.classic.Logger logbackLogger) { logbackLogger.setLevel(logLevel); } TracerTaskWrapper.setTracerSupplier(Logging.INSTANCE::getTracer); if (Boolean.TRUE.equals(metricsEnable)) { var metricsPort = this.metricsPort; - if (metricsPort == null || metricsPort > 65535) { - metricsPort = 9200; + if (metricsPort == null || metricsPort > MAX_PORT_NUMBER) { + metricsPort = DEFAULT_METRICS_PORT; } InnerMetrics.start(metricsPort); } @@ -163,7 +160,6 @@ public void run() { Signal.handle(new Signal("TERM"), sig -> System.exit(0)); var syncMode = this.syncMode; - var unusedVerbose = this.verbose; var checkpointHash = this.checkpointHash; var config = this.toConfig(); Runner runner = Runner.create(config).setSyncMode(syncMode).setCheckpointHash(checkpointHash); @@ -218,12 +214,12 @@ private String getJwtFromFile() { ? Paths.get(Cli.this.jwtFile) : Paths.get(System.getProperty("user.dir"), "jwt.hex"); if (!Files.exists(jwtFilePath)) { - throw new RuntimeException("Failed to read JWT secret from file: " + jwtFilePath); + throw new RuntimeException("Failed to read JWT secret from file: %s".formatted(jwtFilePath)); } try { return Files.readString(jwtFilePath, StandardCharsets.UTF_8); } catch (IOException e) { - throw new RuntimeException("Failed to read JWT secret from file: " + jwtFilePath, e); + throw new RuntimeException("Failed to read JWT secret from file: %s".formatted(jwtFilePath), e); } } diff --git a/hildr-node/src/main/java/io/optimism/cli/typeconverter/SyncModeConverter.java b/hildr-node/src/main/java/io/optimism/cli/typeconverter/SyncModeConverter.java index 77d90519..13bfb765 100644 --- a/hildr-node/src/main/java/io/optimism/cli/typeconverter/SyncModeConverter.java +++ b/hildr-node/src/main/java/io/optimism/cli/typeconverter/SyncModeConverter.java @@ -15,7 +15,7 @@ public class SyncModeConverter implements CommandLine.ITypeConverter defaultProvider = getDefaultConfigMap(); Map chainProvider = chainConfig.toConfigMap(); - MapConfigSource chainConfigSource = new MapConfigSource(chainProvider); Map cliProvider = cliConfig.toConfigMap(); - MapConfigSource cliConfigSource = new MapConfigSource(cliProvider); Gestalt gestalt; if (configPath != null) { - FileConfigSource tomlConfigSource = new FileConfigSource(configPath); gestalt = new GestaltBuilder() .addConfigLoader(environmentVarsLoader) .addConfigLoader(mapConfigLoader) .addConfigLoader(tomlLoader) .addConfigLoader(propertyLoader) - .addSource(defaultProviderConfigSource) - .addSource(chainConfigSource) - .addSource(tomlConfigSource) - .addSource(cliConfigSource) + .addSource(MapConfigSourceBuilder.builder() + .setCustomConfig(defaultProvider) + .build()) + .addSource(MapConfigSourceBuilder.builder() + .setCustomConfig(chainProvider) + .build()) + .addSource(FileConfigSourceBuilder.builder() + .setPath(configPath) + .build()) + .addSource(MapConfigSourceBuilder.builder() + .setCustomConfig(cliProvider) + .build()) .setTreatMissingValuesAsErrors(false) .build(); } else { @@ -121,9 +126,15 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch .addConfigLoader(mapConfigLoader) .addConfigLoader(tomlLoader) .addConfigLoader(propertyLoader) - .addSource(defaultProviderConfigSource) - .addSource(chainConfigSource) - .addSource(cliConfigSource) + .addSource(MapConfigSourceBuilder.builder() + .setCustomConfig(defaultProvider) + .build()) + .addSource(MapConfigSourceBuilder.builder() + .setCustomConfig(chainProvider) + .build()) + .addSource(MapConfigSourceBuilder.builder() + .setCustomConfig(cliProvider) + .build()) .setTreatMissingValuesAsErrors(false) .build(); } @@ -135,7 +146,7 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch } } - private static MapConfigSource getMapConfigSource() { + private static Map getDefaultConfigMap() { Map defaultProvider = new HashMap<>(); defaultProvider.put("config.l2RpcUrl", "http://127.0.0.1:8545"); defaultProvider.put("config.l2EngineUrl", "http://127.0.0.1:8551"); @@ -148,7 +159,7 @@ private static MapConfigSource getMapConfigSource() { defaultProvider.put("config.rpcPort", "9545"); defaultProvider.put("config.rpcAddr", "0.0.0.0"); defaultProvider.put("config.discPort", "9876"); - return new MapConfigSource(defaultProvider); + return defaultProvider; } /**