Skip to content

Commit

Permalink
feat: inner watcher add devnet config
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed Nov 4, 2023
1 parent 2a2fd72 commit 1dc15b5
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.optimism.type.L2BlockRef;
import io.optimism.type.OpEthSyncStatusRes;
import io.optimism.type.RollupConfigRes;
import io.optimism.type.RollupConfigResutl;
import io.optimism.type.RollupConfigResult;
import io.optimism.utilities.rpc.Web3jProvider;
import java.io.Closeable;
import java.math.BigInteger;
Expand Down Expand Up @@ -74,7 +74,7 @@ public class BlockLoader implements Closeable {

BlockId latestLoadedBlock;

private RollupConfigResutl rollupConfig;
private RollupConfigResult rollupConfig;

/**
* Constructor of BlockLoader.
Expand Down Expand Up @@ -104,7 +104,7 @@ public void init() {
*
* @return rollup config object
*/
public RollupConfigResutl getRollConfig() {
public RollupConfigResult getRollConfig() {
return this.rollupConfig;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ private EthBlock.Block loadBlockToChannel(BigInteger number) {
}
}

RollupConfigResutl loadRollConfig() {
RollupConfigResult loadRollConfig() {
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
var future =
scope.fork(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import io.optimism.batcher.config.Config;
import io.optimism.batcher.telemetry.BatcherMetrics;
import io.optimism.type.RollupConfigResutl;
import io.optimism.type.RollupConfigResult;
import java.math.BigInteger;

/**
Expand Down Expand Up @@ -46,7 +46,7 @@ public record PublisherConfig(
* @param rollupConfig Rollup config, get from rollup node api
* @return PublisherConfig instance
*/
public static PublisherConfig from(Config config, RollupConfigResutl rollupConfig) {
public static PublisherConfig from(Config config, RollupConfigResult rollupConfig) {
return new PublisherConfig(
config.l1RpcUrl(),
config.l1Signer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author thinkAfCod
* @since 0.1.1
*/
public class RollupConfigRes extends Response<RollupConfigResutl> {
public class RollupConfigRes extends Response<RollupConfigResult> {

/** Constructor of RollupConfigRes. */
public RollupConfigRes() {}
Expand All @@ -34,12 +34,12 @@ public RollupConfigRes() {}
*
* @return rollup config info
*/
public RollupConfigResutl getConfig() {
public RollupConfigResult getConfig() {
return getResult();
}

@Override
public void setResult(RollupConfigResutl result) {
public void setResult(RollupConfigResult result) {
super.setResult(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import io.optimism.type.L1BlockRef;
import io.optimism.type.L2BlockRef;
import io.optimism.type.OpEthSyncStatusRes;
import io.optimism.type.RollupConfigResutl;
import io.optimism.type.RollupConfigResult;
import io.optimism.utilities.rpc.Web3jProvider;
import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -137,7 +137,7 @@ public void testLoadBlock() throws IOException {
.when(loader)
.calculateL2BlockRangeToStore();
doReturn(null).when(loader).l2BlockToBlockRef(any(), any());
doReturn(new RollupConfigResutl()).when(loader).getRollConfig();
doReturn(new RollupConfigResult()).when(loader).getRollConfig();
loader.loadBlocksIntoState();
assertEquals(20, consumeCount.get());
assertEquals(loader.latestLoadedBlock.number(), mockedBlock.getNumber());
Expand Down
9 changes: 6 additions & 3 deletions hildr-node/src/main/java/io/optimism/common/BlockInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ public static BlockInfo from(ExecutionPayload payload) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlockInfo blockInfo = (BlockInfo) o;
if (this == o) {
return true;
}
if (!(o instanceof BlockInfo blockInfo)) {
return false;
}
return Objects.equals(hash, blockInfo.hash)
&& Objects.equals(number, blockInfo.number)
&& Objects.equals(parentHash, blockInfo.parentHash)
Expand Down
3 changes: 3 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 @@ -52,6 +52,7 @@
* @param jwtSecret L2 engine API jwt secret.
* @param chainConfig The chain config.
* @param rpcPort The rpc port.
* @param devnet The flag of devnet.
* @param checkpointSyncUrl The checkpoint sync url.
* @author grapebaba
* @since 0.1.0
Expand All @@ -63,6 +64,7 @@ public record Config(
String jwtSecret,
String checkpointSyncUrl,
Integer rpcPort,
Boolean devnet,
ChainConfig chainConfig) {

/**
Expand Down Expand Up @@ -175,6 +177,7 @@ public Map<String, String> toConfigMap() {
if (rpcPort != null) {
map.put("config.rpcPort", rpcPort.toString());
}
map.put("config.devnet", String.valueOf(devnet != null && devnet));
return map;
}
}
Expand Down
44 changes: 26 additions & 18 deletions hildr-node/src/main/java/io/optimism/driver/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import io.optimism.type.Genesis;
import io.optimism.type.L1BlockInfo;
import io.optimism.type.L2BlockRef;
import io.optimism.type.RollupConfigResutl;
import io.optimism.type.RollupConfigResult;
import io.optimism.type.SystemConfig;
import io.optimism.utilities.TxDecoder;
import io.optimism.utilities.rpc.Web3jProvider;
Expand Down Expand Up @@ -109,7 +109,7 @@ public class Driver<E extends Engine> extends AbstractExecutionThreadService {

private final Config config;

private RollupConfigResutl cachedRollConfig;
private RollupConfigResult cachedRollConfig;

/**
* Instantiates a new Driver.
Expand Down Expand Up @@ -240,10 +240,10 @@ public static Driver<EngineApi> from(Config config, CountDownLatch latch)
*
* @return The rollup config
*/
public RollupConfigResutl getRollupConfig() {
public RollupConfigResult getRollupConfig() {
var chainConfig = this.config.chainConfig();
if (this.cachedRollConfig == null) {
var rollupConfig = new RollupConfigResutl();
var rollupConfig = new RollupConfigResult();
rollupConfig.setBlockTime(chainConfig.blockTime());
rollupConfig.setMaxSequencerDrift(chainConfig.maxSeqDrift());
rollupConfig.setSeqWindowSize(chainConfig.seqWindowSize());
Expand All @@ -253,22 +253,23 @@ public RollupConfigResutl getRollupConfig() {
rollupConfig.setRegolithTime(chainConfig.regolithTime());
rollupConfig.setBatchInboxAddress(chainConfig.batchInbox());
rollupConfig.setDepositContractAddress(chainConfig.depositContract());
rollupConfig.setL1SystemConfigAddress(chainConfig.systemConfigContract());
var curSysConfig = chainConfig.systemConfig();
var sc =
new SystemConfig(
curSysConfig.batchSender(),
curSysConfig.l1FeeOverhead(),
curSysConfig.l1FeeScalar(),
curSysConfig.gasLimit());
var latestGenesis =
new Genesis(
new BlockId(chainConfig.l1StartEpoch().hash(), chainConfig.l1StartEpoch().number()),
new BlockId(chainConfig.l2Genesis().hash(), chainConfig.l2Genesis().number()),
chainConfig.l2Genesis().timestamp(),
sc);
this.cachedRollConfig.setGenesis(latestGenesis);
this.cachedRollConfig = rollupConfig;
}
var curSysConfig = this.chainWatcher.getSystemConfig();
var sc =
new SystemConfig(
curSysConfig.batchSender(),
curSysConfig.l1FeeOverhead(),
curSysConfig.l1FeeScalar(),
curSysConfig.gasLimit());
var latestGenesis =
new Genesis(
new BlockId(chainConfig.l1StartEpoch().hash(), chainConfig.l1StartEpoch().number()),
new BlockId(chainConfig.l2Genesis().hash(), chainConfig.l2Genesis().number()),
chainConfig.l2Genesis().timestamp(),
sc);
this.cachedRollConfig.setGenesis(latestGenesis);
return this.cachedRollConfig;
}

Expand Down Expand Up @@ -586,6 +587,13 @@ private L2BlockRef unsafeL2SyncTarget() {
return Driver.payloadToRef(unsafePayload, this.config.chainConfig());
}

/**
* Read L2BlockRef info from Execution payload.
*
* @param payload l2 execution payload info
* @param genesis L2 genesis info
* @return L2BlockRef instance
*/
public static L2BlockRef payloadToRef(ExecutionPayload payload, Config.ChainConfig genesis) {
BlockId l1Origin;
BigInteger sequenceNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DepositsNotFoundException() {
/**
* Instantiates a new Deposits not found exception.
*
* @param message
* @param message exception message info
*/
public DepositsNotFoundException(String message) {
super(message);
Expand Down
40 changes: 37 additions & 3 deletions hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import org.jctools.queues.MessagePassingQueue;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.abi.EventEncoder;
Expand Down Expand Up @@ -150,6 +149,8 @@ public class InnerWatcher extends AbstractExecutionThreadService {

private Disposable l1HeadListener;

private boolean devnet = false;

/**
* create a InnerWatcher instance.
*
Expand All @@ -170,6 +171,7 @@ public InnerWatcher(
this.provider = Web3jProvider.createClient(config.l1RpcUrl());
this.l1StartBlock = l1StartBlock;
this.l2StartBlock = l2StartBlock;
this.devnet = config.devnet() != null && config.devnet();

this.blockUpdateQueue = queue;
this.currentBlock = l1StartBlock;
Expand Down Expand Up @@ -405,7 +407,9 @@ private EthBlock.Block getSafe() throws ExecutionException, InterruptedException
}

private EthBlock.Block getFinalized() throws ExecutionException, InterruptedException {
return this.pollBlock(this.provider, DefaultBlockParameterName.FINALIZED, false);
var parameter =
this.devnet ? DefaultBlockParameterName.LATEST : DefaultBlockParameterName.FINALIZED;
return this.pollBlock(this.provider, parameter, false);
}

private EthBlock.Block getHead() throws ExecutionException, InterruptedException {
Expand Down Expand Up @@ -518,7 +522,7 @@ protected void run() {
}
}

@NotNull @Override
@Override
protected Executor executor() {
return this.executor;
}
Expand All @@ -537,26 +541,56 @@ protected void triggerShutdown() {
this.isShutdownTriggered = true;
}

/**
* Gets Current L1 block.
*
* @return Current L1 BlockInfo instance
*/
public BlockInfo getCurrentL1() {
return this.currentBlockInfo;
}

/**
* Gets Current L1 finalized block.
*
* @return Current L1 finalized BlockInfo instance
*/
public BlockInfo getCurrentL1Finalized() {
return this.l1Finalized;
}

/**
* Gets L1 head block.
*
* @return L1 head BlockInfo instance
*/
public BlockInfo getL1HeadBlock() {
return this.l1Head;
}

/**
* Gets L1 safe block.
*
* @return L1 safe BlockInfo instance
*/
public BlockInfo getL1SafeBlock() {
return this.l1Safe;
}

/**
* Gets L1 finalized block.
*
* @return L1 finalized BlockInfo instance
*/
public BlockInfo getL1FinalizedBlock() {
return this.l1Finalized;
}

/**
* Get system config info.
*
* @return SystemConfig instance
*/
public SystemConfig getSystemConfig() {
return this.systemConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions hildr-node/src/main/java/io/optimism/rpc/RpcMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public enum RpcMethod {

/** optimism_outputAtBlock api. */
OP_OUTPUT_AT_BLOCK("optimism_outputAtBlock"),
/** optimism_syncStatus api */
/** optimism_syncStatus api. */
OP_SYNC_STATUS("optimism_syncStatus"),
/** optimism_rollupConfig api */
/** optimism_rollupConfig api. */
OP_ROLLUP_CONFIG("optimism_rollupConfig");

private final String rpcMethodName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class JsonRpcMethodAdapter implements JsonRpcMethod {

private final Function fn;

/**
* JsonRpcMethodAdapter type constructor.
*
* @param name json rpc method name
* @param responseSupplier response result supplier
*/
public JsonRpcMethodAdapter(String name, Function responseSupplier) {
this.name = name;
this.fn = responseSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void testReadyChannelStillPending() {

private Tuple2<Channels<BatcherTransactions>, MessagePassingQueue<BatcherTransactionMessage>>
createStage() {
Config config = new Config("", "", "", "", null, 9545, ChainConfig.optimismGoerli());
Config config = new Config("", "", "", "", null, 9545, false, ChainConfig.optimismGoerli());
MessagePassingQueue<BatcherTransactionMessage> transactionMessageMessagePassingQueue =
new MpscGrowableArrayQueue<>(4096);
Channels<BatcherTransactions> channels =
Expand Down
9 changes: 8 additions & 1 deletion hildr-node/src/test/java/io/optimism/rpc/RpcServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ void testRpcServerRegister() throws IOException, InterruptedException, Execution
RpcServer rpcServer =
createRpcServer(
new Config(
null, "http://fakeurl", null, null, null, 9545, Config.ChainConfig.optimism()));
null,
"http://fakeurl",
null,
null,
null,
9545,
false,
Config.ChainConfig.optimism()));
rpcServer.start();
HashMap<String, Function> rpcHandler = HashMap.newHashMap(1);
rpcHandler.put("test_url", unused -> "response data");
Expand Down
Loading

0 comments on commit 1dc15b5

Please sign in to comment.