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

feat: support custom boot nodes #171

Merged
merged 2 commits into from
Jun 29, 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: 2 additions & 2 deletions hildr-batcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ tasks.withType(Test).configureEach {

dependencies {
implementation project(':hildr-utilities')
implementation 'com.github.gestalt-config:gestalt-core:0.20.4'
implementation 'com.github.gestalt-config:gestalt-toml:0.20.4'
implementation 'com.github.gestalt-config:gestalt-core:0.29.0'
implementation 'com.github.gestalt-config:gestalt-toml:0.29.0'

implementation 'com.fasterxml.jackson:jackson-bom:2.15.2'
implementation 'com.fasterxml.jackson.core:jackson-core'
Expand Down
4 changes: 2 additions & 2 deletions hildr-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ dependencies {
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.14")

implementation('net.osslabz.evm:evm-abi-decoder:0.0.6')
implementation 'com.github.gestalt-config:gestalt-core:0.20.4'
implementation 'com.github.gestalt-config:gestalt-toml:0.20.4'
implementation 'com.github.gestalt-config:gestalt-core:0.29.0'
implementation 'com.github.gestalt-config:gestalt-toml:0.29.0'

implementation 'com.fasterxml.jackson:jackson-bom:2.15.2'
implementation 'com.fasterxml.jackson.core:jackson-core'
Expand Down
25 changes: 24 additions & 1 deletion hildr-node/src/main/java/io/optimism/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -77,10 +78,18 @@ public class Cli implements Runnable {
description = "")
Boolean verbose;

@Option(
names = {"--rpc-addr"},
required = false,
description = "The address of RPC server",
defaultValue = "0.0.0.0")
String rpcAddr;

@Option(
names = {"--rpc-port", "-p"},
required = true,
description = "The port of RPC server")
description = "The port of RPC server",
defaultValue = "9545")
Integer rpcPort;

@Option(
Expand All @@ -103,6 +112,17 @@ public class Cli implements Runnable {
description = "The port of metrics server")
Integer metricsPort;

@Option(
names = {"--disc-boot-nodes"},
description = "The custom bootNodes")
List<String> bootNodes;

@Option(
names = {"--disc-port"},
description = "The port of discovery",
defaultValue = "9876")
Integer discPort;

@Option(names = "--devnet", description = "Dev net flag")
Boolean devnet;

Expand Down Expand Up @@ -217,7 +237,10 @@ private Config.CliConfig from(Cli cli) {
cli.l2EngineUrl,
StringUtils.trim(Cli.this.getJwtSecret()),
cli.checkpointSyncUrl,
cli.rpcAddr,
cli.rpcPort,
cli.bootNodes,
cli.discPort,
cli.syncMode,
cli.sequencerEnable,
cli.devnet);
Expand Down
26 changes: 26 additions & 0 deletions hildr-node/src/main/java/io/optimism/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.github.gestalt.config.Gestalt;
Expand All @@ -41,7 +42,10 @@
* @param l2EngineUrl L2 engine API url.
* @param jwtSecret L2 engine API jwt secret.
* @param checkpointSyncUrl The checkpoint sync url.
* @param rpcAddr The rpc address.
* @param rpcPort The rpc port.
* @param bootNodes The custom boot nodes.
* @param discPort The discovery port.
* @param devnet The flag of devnet.
* @param sequencerEnable The flag of sequencerEnable.
* @param syncMode The sync mode
Expand All @@ -58,7 +62,10 @@ public record Config(
String l2EngineUrl,
String jwtSecret,
String checkpointSyncUrl,
String rpcAddr,
Integer rpcPort,
List<String> bootNodes,
Integer discPort,
Boolean devnet,
Boolean sequencerEnable,
SyncMode syncMode,
Expand Down Expand Up @@ -106,6 +113,7 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch
.addSource(chainConfigSource)
.addSource(tomlConfigSource)
.addSource(cliConfigSource)
.setTreatMissingValuesAsErrors(false)
.build();
} else {
gestalt = new GestaltBuilder()
Expand All @@ -116,6 +124,7 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch
.addSource(defaultProviderConfigSource)
.addSource(chainConfigSource)
.addSource(cliConfigSource)
.setTreatMissingValuesAsErrors(false)
.build();
}
gestalt.loadConfigs();
Expand All @@ -137,6 +146,8 @@ private static MapConfigSource getMapConfigSource() {
defaultProvider.put("config.jwtSecret", "");
defaultProvider.put("config.checkpointSyncUrl", "");
defaultProvider.put("config.rpcPort", "9545");
defaultProvider.put("config.rpcAddr", "0.0.0.0");
defaultProvider.put("config.discPort", "9876");
return new MapConfigSource(defaultProvider);
}

Expand All @@ -151,7 +162,10 @@ private static MapConfigSource getMapConfigSource() {
* @param l2EngineUrl L2 engine API url.
* @param jwtSecret L2 engine API jwt secret.
* @param checkpointSyncUrl The checkpoint sync url.
* @param rpcAddr The rpc address.
* @param rpcPort The rpc port.
* @param bootNodes The custom bootNodes.
* @param discPort The custom discovery port.
* @param syncMode The sync mode.
* @param sequencerEnable The sequencer enable flag.
* @param devnet The devnet flag.
Expand All @@ -165,7 +179,10 @@ public record CliConfig(
String l2EngineUrl,
String jwtSecret,
String checkpointSyncUrl,
String rpcAddr,
Integer rpcPort,
List<String> bootNodes,
Integer discPort,
SyncMode syncMode,
Boolean sequencerEnable,
Boolean devnet) {
Expand Down Expand Up @@ -201,6 +218,15 @@ public Map<String, String> toConfigMap() {
if (StringUtils.isNotEmpty(checkpointSyncUrl)) {
map.put("config.checkpointSyncUrl", checkpointSyncUrl);
}
if (bootNodes != null && !bootNodes.isEmpty()) {
map.put("config.bootNodes", String.join(",", bootNodes));
}
if (discPort != null) {
map.put("config.discPort", discPort.toString());
}
if (StringUtils.isNotEmpty(rpcAddr)) {
map.put("config.rpcAddr", rpcAddr);
}
if (rpcPort != null) {
map.put("config.rpcPort", rpcPort.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion hildr-node/src/main/java/io/optimism/driver/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static Driver<EngineApi> from(Config config, CountDownLatch latch)
rpcServer.start();

MpscUnboundedXaddArrayQueue<ExecutionPayload> unsafeBlockQueue = new MpscUnboundedXaddArrayQueue<>(1024 * 64);
OpStackNetwork opStackNetwork = new OpStackNetwork(config.chainConfig(), unsafeBlockQueue);
OpStackNetwork opStackNetwork = new OpStackNetwork(config, unsafeBlockQueue);
ISequencer sequencer = null;
if (config.sequencerEnable()) {
sequencer = new Sequencer(engineDriver, config.chainConfig());
Expand Down
21 changes: 14 additions & 7 deletions hildr-node/src/main/java/io/optimism/network/OpStackNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableSet;
import io.optimism.config.Config;
import io.optimism.engine.ExecutionPayload;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -100,8 +101,8 @@ public class OpStackNetwork {
* @param config the config
* @param unsafeBlockQueue the unsafe block queue
*/
public OpStackNetwork(Config.ChainConfig config, MessagePassingQueue<ExecutionPayload> unsafeBlockQueue) {
UInt64 chainId = UInt64.valueOf(config.l2ChainId());
public OpStackNetwork(Config config, MessagePassingQueue<ExecutionPayload> unsafeBlockQueue) {
UInt64 chainId = UInt64.valueOf(config.chainConfig().l2ChainId());
final MetricsSystem metricsSystem = new PrometheusMetricsSystem(
ImmutableSet.<MetricCategory>builder()
.addAll(EnumSet.allOf(StandardMetricCategory.class))
Expand All @@ -111,9 +112,15 @@ public OpStackNetwork(Config.ChainConfig config, MessagePassingQueue<ExecutionPa
final PeerPools peerPools = new PeerPools();
final ReputationManager reputationManager =
new DefaultReputationManager(metricsSystem, new SystemTimeProvider(), 1024, peerPools);
var bootNodes = new ArrayList<String>();
if (config.bootNodes() != null && !config.bootNodes().isEmpty()) {
bootNodes.addAll(config.bootNodes());
} else {
bootNodes.addAll(BOOTNODES);
}
final DiscoveryConfig discoveryConfig = DiscoveryConfig.builder()
.listenUdpPortDefault(9876)
.bootnodes(BOOTNODES)
.listenUdpPortDefault(config.discPort())
.bootnodes(bootNodes)
.build();
final NetworkConfig p2pConfig = NetworkConfig.builder().build();
final KeyValueStore<String, Bytes> kvStore = new MemKeyValueStore<>();
Expand All @@ -127,19 +134,19 @@ public OpStackNetwork(Config.ChainConfig config, MessagePassingQueue<ExecutionPa
new SnappyPreparedGossipMessageFactory(),
gossipAsyncRunner,
chainId,
config.systemConfig().unsafeBlockSigner(),
config.chainConfig().systemConfig().unsafeBlockSigner(),
unsafeBlockQueue),
new BlockV2TopicHandler(
new SnappyPreparedGossipMessageFactory(),
gossipAsyncRunner,
chainId,
config.systemConfig().unsafeBlockSigner(),
config.chainConfig().systemConfig().unsafeBlockSigner(),
unsafeBlockQueue),
new BlockV3TopicHandler(
new SnappyPreparedGossipMessageFactory(),
gossipAsyncRunner,
chainId,
config.systemConfig().unsafeBlockSigner(),
config.chainConfig().systemConfig().unsafeBlockSigner(),
unsafeBlockQueue));
final AsyncRunner p2pAsyncRunner = AsyncRunnerFactory.createDefault(
new MetricTrackingExecutorFactory(metricsSystem))
Expand Down
2 changes: 1 addition & 1 deletion hildr-node/src/main/java/io/optimism/rpc/RpcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private Handler<HttpConnection> connectionHandler() {

private HttpServerOptions getHttpServerOptions(final Config config) {
final HttpServerOptions httpServerOptions = new HttpServerOptions()
.setHost("0.0.0.0")
.setHost(config.rpcAddr())
.setPort(config.rpcPort())
.setHandle100ContinueAutomatically(true)
.setCompressionSupported(true);
Expand Down
16 changes: 15 additions & 1 deletion hildr-node/src/test/java/io/optimism/HildrTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ class HildrTest {
@Test
void appHasGreeting() throws JsonProcessingException {
CliConfig cliConfig = new CliConfig(
"test", "test", "test", "test", "test", "test", "test", null, null, Config.SyncMode.Full, false, false);
"test",
"test",
"test",
"test",
"test",
"test",
"test",
null,
null,
null,
null,
null,
Config.SyncMode.Full,
false,
false);
TomlMapper mapper = new TomlMapper();
String cliConfigStr = mapper.writerFor(CliConfig.class).writeValueAsString(cliConfig);

Expand Down
3 changes: 3 additions & 0 deletions hildr-node/src/test/java/io/optimism/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public static Config createConfig() {
"testjwt",
null,
null,
null,
null,
null,
Config.SyncMode.Full,
false,
false);
Expand Down
43 changes: 42 additions & 1 deletion hildr-node/src/test/java/io/optimism/config/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -10,6 +11,7 @@
import io.optimism.config.Config.SystemConfig;
import java.math.BigInteger;
import java.nio.file.Paths;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.web3j.utils.Numeric;

Expand All @@ -27,14 +29,53 @@ class ConfigTest {
@Test
void create() {
CliConfig cliConfig = new CliConfig(
null, null, null, null, null, null, "testjwt", null, null, Config.SyncMode.Full, false, false);
null,
null,
null,
null,
null,
null,
"testjwt",
null,
null,
null,
null,
null,
Config.SyncMode.Full,
false,
false);
Config config = Config.create(
Paths.get("src", "test", "resources", "test.toml"), cliConfig, ChainConfig.optimismSepolia());
assertEquals("https://example2.com", config.l2RpcUrl());
assertEquals("http://127.0.0.1:8551", config.l2EngineUrl());
assertEquals("", config.l1RpcUrl());
assertEquals("testjwt", config.jwtSecret());
assertEquals("0.0.0.0", config.rpcAddr());
assertEquals(9545, config.rpcPort());
assertEquals(9876, config.discPort());
assertNull(config.bootNodes());

CliConfig bootCliConfig = new CliConfig(
null,
null,
null,
null,
null,
null,
"testjwt",
null,
null,
null,
List.of("encode://123", "encode://321"),
92,
Config.SyncMode.Full,
false,
false);
Config configBootNodes = Config.create(
Paths.get("src", "test", "resources", "test.toml"), bootCliConfig, ChainConfig.optimismSepolia());
assertEquals(92, configBootNodes.discPort());
assertEquals(List.of("encode://123", "encode://321"), configBootNodes.bootNodes());

assertEquals(
"0x48f520cf4ddaf34c8336e6e490632ea3cf1e5e93b0b2bc6e917557e31845371b",
config.chainConfig().l1StartEpoch().hash());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ private Tuple2<Channels<BatcherTransactions>, MessagePassingQueue<BatcherTransac
"",
null,
null,
null,
9545,
null,
null,
false,
false,
Config.SyncMode.Full,
Expand Down
3 changes: 3 additions & 0 deletions hildr-node/src/test/java/io/optimism/driver/DriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void testNewDriverFromFinalizedHead() throws IOException, ExecutionException, In
"d195a64e08587a3f1560686448867220c2727550ce3e0c95c7200d0ade0f9167",
l2rpc,
null,
null,
null,
null,
Config.SyncMode.Full,
false,
false);
Expand Down
Loading
Loading