Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:fix ide warning and remove unused cli arg, also unuse deprecated code. #192

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion hildr-node/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer

/*
* This file was generated by the Gradle 'init' task.
*
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 10 additions & 14 deletions hildr-node/src/main/java/io/optimism/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SyncModeConverter implements CommandLine.ITypeConverter<Config.Sync
public SyncModeConverter() {}

@Override
public Config.SyncMode convert(String value) throws Exception {
public Config.SyncMode convert(String value) {
return Config.SyncMode.from(value);
}
}

This file was deleted.

41 changes: 26 additions & 15 deletions hildr-node/src/main/java/io/optimism/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.github.gestalt.config.loader.EnvironmentVarsLoader;
import org.github.gestalt.config.loader.MapConfigLoader;
import org.github.gestalt.config.loader.PropertyLoader;
import org.github.gestalt.config.source.FileConfigSource;
import org.github.gestalt.config.source.MapConfigSource;
import org.github.gestalt.config.source.FileConfigSourceBuilder;
import org.github.gestalt.config.source.MapConfigSourceBuilder;
import org.github.gestalt.config.toml.TomlLoader;
import org.web3j.tuples.generated.Tuple2;
import org.web3j.utils.Numeric;
Expand Down Expand Up @@ -93,26 +93,31 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch
TomlLoader tomlLoader = new TomlLoader();
PropertyLoader propertyLoader = new PropertyLoader();

MapConfigSource defaultProviderConfigSource = getMapConfigSource();
Map<String, String> defaultProvider = getDefaultConfigMap();

Map<String, String> chainProvider = chainConfig.toConfigMap();
MapConfigSource chainConfigSource = new MapConfigSource(chainProvider);

Map<String, String> 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 {
Expand All @@ -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();
}
Expand All @@ -135,7 +146,7 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch
}
}

private static MapConfigSource getMapConfigSource() {
private static Map<String, String> getDefaultConfigMap() {
Map<String, String> defaultProvider = new HashMap<>();
defaultProvider.put("config.l2RpcUrl", "http://127.0.0.1:8545");
defaultProvider.put("config.l2EngineUrl", "http://127.0.0.1:8551");
Expand All @@ -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;
}

/**
Expand Down
Loading