From d87b21c773de42042cf66b43e53452df747adcc5 Mon Sep 17 00:00:00 2001 From: thinkAfCod Date: Mon, 11 Mar 2024 22:50:41 +0800 Subject: [PATCH] fix: test case --- .../src/main/java/io/optimism/cli/Cli.java | 10 ++- .../main/java/io/optimism/config/Config.java | 46 ++++++---- .../io/optimism/l1/BeaconBlobFetcher.java | 47 ++++++++-- .../java/io/optimism/l1/InnerWatcher.java | 2 +- .../src/test/java/io/optimism/HildrTest.java | 2 +- .../test/java/io/optimism/TestConstants.java | 2 +- .../java/io/optimism/config/ConfigTest.java | 2 +- .../optimism/derive/stages/ChannelsTest.java | 2 +- .../java/io/optimism/driver/DriverTest.java | 1 + .../java/io/optimism/driver/HeadInfoTest.java | 88 ++++++------------- .../io/optimism/engine/EngineApiTest.java | 15 ++-- .../io/optimism/l1/BeaconBlobFetcherTest.java | 3 +- .../java/io/optimism/rpc/RpcServerTest.java | 12 ++- .../src/test/resources/bedrock_raw_block.txt | 52 +++++++++++ .../src/test/resources/ectone_raw_block.txt | 57 ++++++++++++ .../java/io/optimism/type/L1BlockInfo.java | 8 +- 16 files changed, 244 insertions(+), 105 deletions(-) create mode 100644 hildr-node/src/test/resources/bedrock_raw_block.txt create mode 100644 hildr-node/src/test/resources/ectone_raw_block.txt 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 c10a63c1..4fb688d9 100644 --- a/hildr-node/src/main/java/io/optimism/cli/Cli.java +++ b/hildr-node/src/main/java/io/optimism/cli/Cli.java @@ -39,15 +39,18 @@ public class Cli implements Runnable { description = "network type, or rollup.json file path, support: optimism-goerli, base-goerli") String network; - @Option(names = "--l1-rpc-url", required = true, description = "The base chain RPC URL") + @Option(names = "--l1-rpc-url", required = true, description = "The l1 chain RPC URL") String l1RpcUrl; - @Option(names = "--l1-ws-rpc-url", required = true, description = "The base chain WS RPC URL") + @Option(names = "--l1-ws-rpc-url", required = true, description = "The l1 chain WS RPC URL") String l1WsRpcUrl; - @Option(names = "--l1-beacon-url", required = false, description = "The base chain beacon client RPC URL") + @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") + String l1BeaconArchiverUrl; + @Option(names = "--l2-rpc-url", required = true, description = "The L2 engine RPC URL") String l2RpcUrl; @@ -201,6 +204,7 @@ private Config.CliConfig from(Cli cli) { cli.l1RpcUrl, cli.l1WsRpcUrl, cli.l1BeaconUrl, + cli.l1BeaconArchiverUrl, cli.l2RpcUrl, cli.l2EngineUrl, StringUtils.trim(Cli.this.getJwtSecret()), diff --git a/hildr-node/src/main/java/io/optimism/config/Config.java b/hildr-node/src/main/java/io/optimism/config/Config.java index 38790e7e..b294b88b 100644 --- a/hildr-node/src/main/java/io/optimism/config/Config.java +++ b/hildr-node/src/main/java/io/optimism/config/Config.java @@ -33,16 +33,17 @@ /** * The type Config. * - * @param l1RpcUrl L1 chain rpc url. - * @param l1WsRpcUrl L1 chain websocket rpc url. - * @param l1BeaconUrl L1 chain websocket rpc url. - * @param l2RpcUrl L2 chain rpc url. - * @param l2EngineUrl L2 engine API url. - * @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. + * @param l1RpcUrl L1 chain rpc url. + * @param l1WsRpcUrl L1 chain websocket rpc url. + * @param l1BeaconUrl L1 beacon chain rpc url. + * @param l1BeaconArchiverUrl L1 beacon chain archiver rpc url. + * @param l2RpcUrl L2 chain rpc url. + * @param l2EngineUrl L2 engine API url. + * @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 */ @@ -50,6 +51,7 @@ public record Config( String l1RpcUrl, String l1WsRpcUrl, String l1BeaconUrl, + String l1BeaconArchiverUrl, String l2RpcUrl, String l2EngineUrl, String jwtSecret, @@ -121,6 +123,7 @@ private static MapConfigSource getMapConfigSource() { defaultProvider.put("config.l1RpcUrl", ""); defaultProvider.put("config.l1WsRpcUrl", ""); defaultProvider.put("config.l1BeaconUrl", ""); + defaultProvider.put("config.l1BeaconArchiverUrl", ""); defaultProvider.put("config.jwtSecret", ""); defaultProvider.put("config.checkpointSyncUrl", ""); defaultProvider.put("config.rpcPort", "9545"); @@ -130,20 +133,22 @@ private static MapConfigSource getMapConfigSource() { /** * The type Cli config. * - * @param l1RpcUrl L1 chain rpc url. - * @param l1WsRpcUrl L1 chain websocket rpc url. - * @param l1BeaconUrl L1 chain beacon client API rpc url. - * @param l2RpcUrl L2 chain rpc url. - * @param l2EngineUrl L2 engine API url. - * @param jwtSecret L2 engine API jwt secret. - * @param checkpointSyncUrl The checkpoint sync url. - * @param rpcPort The rpc port. - * @param devnet The devnet flag. + * @param l1RpcUrl L1 chain rpc url. + * @param l1WsRpcUrl L1 chain websocket rpc url. + * @param l1BeaconUrl L1 chain beacon client API rpc url. + * @param l1BeaconArchiverUrl L1 chain beacon archiver API rpc url. + * @param l2RpcUrl L2 chain rpc url. + * @param l2EngineUrl L2 engine API url. + * @param jwtSecret L2 engine API jwt secret. + * @param checkpointSyncUrl The checkpoint sync url. + * @param rpcPort The rpc port. + * @param devnet The devnet flag. */ public record CliConfig( String l1RpcUrl, String l1WsRpcUrl, String l1BeaconUrl, + String l1BeaconArchiverUrl, String l2RpcUrl, String l2EngineUrl, String jwtSecret, @@ -167,6 +172,9 @@ public Map toConfigMap() { if (StringUtils.isNotEmpty(l1BeaconUrl)) { map.put("config.l1BeaconUrl", l1BeaconUrl); } + if (StringUtils.isNotEmpty(l1BeaconArchiverUrl)) { + map.put("config.l1BeaconArchiverUrl", l1BeaconArchiverUrl); + } if (StringUtils.isNotEmpty(l2RpcUrl)) { map.put("config.l2RpcUrl", l2RpcUrl); } diff --git a/hildr-node/src/main/java/io/optimism/l1/BeaconBlobFetcher.java b/hildr-node/src/main/java/io/optimism/l1/BeaconBlobFetcher.java index 507663b2..cee6efac 100644 --- a/hildr-node/src/main/java/io/optimism/l1/BeaconBlobFetcher.java +++ b/hildr-node/src/main/java/io/optimism/l1/BeaconBlobFetcher.java @@ -17,6 +17,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +43,8 @@ public class BeaconBlobFetcher { private final String sidecarsMethod; + private final String archiverSidecarsMethod; + private final OkHttpClient httpClient; private final ObjectMapper mapper; @@ -52,13 +55,25 @@ public class BeaconBlobFetcher { /** * Beacon blob info fetcher constructor. - * * @param beaconUrl L1 beacon client url */ public BeaconBlobFetcher(String beaconUrl) { + this(beaconUrl, null); + } + + /** + * Beacon blob info fetcher constructor. + * + * @param beaconUrl L1 beacon client url + * @param beaconArchiverUrl L1 beacon archiver client url + */ + public BeaconBlobFetcher(String beaconUrl, String beaconArchiverUrl) { this.genesisMethod = GENESIS_METHOD_FORMAT.formatted(beaconUrl); this.specMethod = SPEC_METHOD_FORMAT.formatted(beaconUrl); this.sidecarsMethod = SIDECARS_METHOD_PREFIX_FORMAT.formatted(beaconUrl); + this.archiverSidecarsMethod = StringUtils.isEmpty(beaconArchiverUrl) + ? null + : SIDECARS_METHOD_PREFIX_FORMAT.formatted(beaconArchiverUrl); this.httpClient = HttpClientProvider.create(); this.mapper = new ObjectMapper(); this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); @@ -110,14 +125,34 @@ public List getBlobSidecards(String blockId, final List var params = indices == null || indices.isEmpty() ? null : Map.of("indices", indices.stream().map(BigInteger::toString).collect(Collectors.joining(","))); - var req = new Request.Builder() - .get() - .url(this.sidecarsMethod + "/" + blockId + prepareQueryParams(params)) - .build(); - var res = this.send(req, new TypeReference>>() {}); + var postfix = "%s%s".formatted(blockId, prepareQueryParams(params)); + var res = getBlobSidecars("%s/%s".formatted(this.sidecarsMethod, postfix)); + if (res.getData() != null && res.getData().isEmpty()) { + return res.getData(); + } + if (this.archiverSidecarsMethod != null) { + LOGGER.debug( + "blob sidecars may be pruned, try blob archiver sidecars method: blockId = {}, indices = {}", + blockId, + indices); + var archiverRes = getBlobSidecars("%s/%s".formatted(this.archiverSidecarsMethod, postfix)); + if (archiverRes.getData() != null && !archiverRes.getData().isEmpty()) { + return archiverRes.getData(); + } + } else { + LOGGER.debug( + "blob archiver sidecars method is empty, skip retry: block Id = {}, indices = {}", + blockId, + indices); + } return res.getData(); } + private BeaconApiResponse> getBlobSidecars(String url) { + var req = new Request.Builder().get().url(url).build(); + return this.send(req, new TypeReference>>() {}); + } + private T send(final Request req, final TypeReference typeRef) { Call call = this.httpClient.newCall(req); try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { diff --git a/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java b/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java index 12d749c6..efd21652 100644 --- a/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java +++ b/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java @@ -169,7 +169,7 @@ public InnerWatcher( this.config = config; this.provider = Web3jProvider.createClient(config.l1RpcUrl()); this.wsProvider = Web3jProvider.createClient(config.l1WsRpcUrl()); - this.beaconFetcher = new BeaconBlobFetcher(config.l1BeaconUrl()); + this.beaconFetcher = new BeaconBlobFetcher(config.l1BeaconUrl(), config.l1BeaconArchiverUrl()); this.l2StartBlock = l2StartBlock; this.devnet = config.devnet() != null && config.devnet(); diff --git a/hildr-node/src/test/java/io/optimism/HildrTest.java b/hildr-node/src/test/java/io/optimism/HildrTest.java index 1811a0fa..aec95ab4 100644 --- a/hildr-node/src/test/java/io/optimism/HildrTest.java +++ b/hildr-node/src/test/java/io/optimism/HildrTest.java @@ -23,7 +23,7 @@ class HildrTest { */ @Test void appHasGreeting() throws JsonProcessingException { - CliConfig cliConfig = new CliConfig("test", "test", "test", "test", "test", null, null, null, false); + CliConfig cliConfig = new CliConfig("test", "test", "test", "test", "test", "test", "test", null, null, false); TomlMapper mapper = new TomlMapper(); String cliConfigStr = mapper.writerFor(CliConfig.class).writeValueAsString(cliConfig); diff --git a/hildr-node/src/test/java/io/optimism/TestConstants.java b/hildr-node/src/test/java/io/optimism/TestConstants.java index 2e66d8b9..61bc5298 100644 --- a/hildr-node/src/test/java/io/optimism/TestConstants.java +++ b/hildr-node/src/test/java/io/optimism/TestConstants.java @@ -45,7 +45,7 @@ public static Config createConfig() { var l1BeaconRpcUrl = l1RpcBeaconUrlFormat.formatted(envs.get(ETH_API_ENV)); var l2RpcUrl = l2RpcUrlFormat.formatted(envs.get(OPT_API_ENV)); Config.CliConfig cliConfig = new Config.CliConfig( - l1RpcUrl, l1WsRpcUrl, l1BeaconRpcUrl, l2RpcUrl, null, "testjwt", null, null, false); + l1RpcUrl, l1WsRpcUrl, l1BeaconRpcUrl, l1BeaconRpcUrl, l2RpcUrl, null, "testjwt", null, null, false); return Config.create(null, cliConfig, Config.ChainConfig.optimismGoerli()); } } diff --git a/hildr-node/src/test/java/io/optimism/config/ConfigTest.java b/hildr-node/src/test/java/io/optimism/config/ConfigTest.java index a2e51f36..5045586f 100644 --- a/hildr-node/src/test/java/io/optimism/config/ConfigTest.java +++ b/hildr-node/src/test/java/io/optimism/config/ConfigTest.java @@ -26,7 +26,7 @@ class ConfigTest { */ @Test void create() { - CliConfig cliConfig = new CliConfig(null, null, null, null, "testjwt", null, null, null, false); + CliConfig cliConfig = new CliConfig(null, null, null, null, null, null, "testjwt", null, null, false); Config config = Config.create( Paths.get("src", "test", "resources", "test.toml"), cliConfig, ChainConfig.optimismGoerli()); assertEquals("https://example2.com", config.l2RpcUrl()); diff --git a/hildr-node/src/test/java/io/optimism/derive/stages/ChannelsTest.java b/hildr-node/src/test/java/io/optimism/derive/stages/ChannelsTest.java index f7da4b67..4c52e799 100644 --- a/hildr-node/src/test/java/io/optimism/derive/stages/ChannelsTest.java +++ b/hildr-node/src/test/java/io/optimism/derive/stages/ChannelsTest.java @@ -116,7 +116,7 @@ void testReadChannelData() { } private Tuple2, MessagePassingQueue> createStage() { - Config config = new Config("", "", "", "", "", null, null, 9545, false, ChainConfig.optimismGoerli()); + Config config = new Config("", "", "", "", "", "", null, null, 9545, false, ChainConfig.optimismGoerli()); MessagePassingQueue transactionMessageMessagePassingQueue = new MpscGrowableArrayQueue<>(4096); Channels channels = diff --git a/hildr-node/src/test/java/io/optimism/driver/DriverTest.java b/hildr-node/src/test/java/io/optimism/driver/DriverTest.java index 48e38e27..1944355b 100644 --- a/hildr-node/src/test/java/io/optimism/driver/DriverTest.java +++ b/hildr-node/src/test/java/io/optimism/driver/DriverTest.java @@ -30,6 +30,7 @@ void testNewDriverFromFinalizedHead() throws IOException, ExecutionException, In l1rpc, l1WsRpc, l1BeaconRpc, + l1BeaconRpc, l2rpc, null, "d195a64e08587a3f1560686448867220c2727550ce3e0c95c7200d0ade0f9167", diff --git a/hildr-node/src/test/java/io/optimism/driver/HeadInfoTest.java b/hildr-node/src/test/java/io/optimism/driver/HeadInfoTest.java index bda81f48..cd31c318 100644 --- a/hildr-node/src/test/java/io/optimism/driver/HeadInfoTest.java +++ b/hildr-node/src/test/java/io/optimism/driver/HeadInfoTest.java @@ -5,8 +5,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Charsets; +import com.google.common.io.Resources; import java.io.IOException; import java.math.BigInteger; +import java.net.URL; +import java.util.List; +import java.util.Map; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.web3j.protocol.Web3j; @@ -73,71 +78,34 @@ void shouldFailConversionFromBlockToHeadInfoIfMissingL1DepositedTx() throws Json @Test @DisplayName("should convert from a block to head info") @SuppressWarnings("checkstyle:LineLength") - void shouldConvertFromBlockToHeadInfo() throws JsonProcessingException { + void shouldConvertFromBlockToHeadInfo() throws IOException { ObjectMapper objectMapper = new ObjectMapper(); - String rawBlock = - """ - { - "hash": "0x2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb", - "parentHash": "0xeccf4c06ad0d27be1cadee5720a509d31a9de0462b52f2cf6045d9a73c9aa504", - "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "miner": "0x4200000000000000000000000000000000000011", - "stateRoot": "0x5905b2423f299a29db41e377d7ceadf4baa49eed04e1b72957e8c0985e04e730", - "transactionsRoot": "0x030e481411042a769edde83d790d583ed69f9d3098d4a78d00e008f749fcfd97", - "receiptsRoot": "0x29079b696c12a19999f3bb303fddb6fc12fb701f427678cca24954b91080ada3", - "number": "0x7fe52f", - "gasUsed": "0xb711", - "gasLimit": "0x17d7840", - "extraData": "0x", - "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "timestamp": "0x644434c2", - "difficulty": "0x0", - "totalDifficulty": "0x0", - "sealFields": [], - "uncles": [], - "transactions": [ - { - "hash": "0x661df2908a63c9701ef4f9bc1d62432f08cbdc8c6fe6012af49405c00de5f69d", - "nonce": "0x41ed06", - "blockHash": "0x2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb", - "blockNumber": "0x7fe52f", - "transactionIndex": "0x0", - "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", - "to": "0x4200000000000000000000000000000000000015", - "value": "0x0", - "gasPrice": "0x0", - "gas": "0xf4240", - "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000008768240000000000000000000000000000000000000000000000000000000064443450000000000000000000000000000000000000000000000000000000000000000e0444c991c5fe1d7291ff34b3f5c3b44ee861f021396d33ba3255b83df30e357d00000000000000000000000000000000000000000000000000000000000000050000000000000000000000007431310e026b69bfc676c0013e12a1a11411eec9000000000000000000000000000000000000000000000000000000000000083400000000000000000000000000000000000000000000000000000000000f4240", - "v": "0x0", - "r": "0x0", - "s": "0x0", - "type": "0x7e", - "mint": "0x0", - "sourceHash": "0x34ad504eea583add76d3b9d249965356ef6ca344d6766644c929357331bb0dc9" - } - ], - "size": "0x365", - "mixHash": "0x7aeec5550a9b0616701e49ab835af5f10eadba2a0582016f0e256c9cace0c046", - "nonce": "0x0000000000000000", - "baseFeePerGas": "0x32" - }"""; - - EthBlock.Block block = objectMapper.readValue(rawBlock, EthBlock.Block.class); + List rawBlockFiles = List.of("bedrock_raw_block.txt", "ectone_raw_block.txt"); + for (String path : rawBlockFiles) { + URL url = Resources.getResource(path); + String testData = Resources.toString(url, Charsets.UTF_8); + Map map = objectMapper.readValue(testData, Map.class); - HeadInfo headInfo = HeadInfo.from(block); + EthBlock.Block block = objectMapper.convertValue(map.get("test_block_data"), EthBlock.Block.class); - assertEquals( - "0x2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb", - headInfo.l2BlockInfo().hash()); - assertEquals(BigInteger.valueOf(8381743L), headInfo.l2BlockInfo().number()); - assertEquals(BigInteger.valueOf(1682191554L), headInfo.l2BlockInfo().timestamp()); + HeadInfo headInfo = HeadInfo.from(block); + assertEquals(map.get("assert_l2_block_hash"), headInfo.l2BlockInfo().hash()); + assertEquals( + new BigInteger((String) map.get("assert_l2_block_number")), + headInfo.l2BlockInfo().number()); + assertEquals( + new BigInteger((String) map.get("assert_l2_block_timestamp")), + headInfo.l2BlockInfo().timestamp()); - assertEquals( - "0x0444c991c5fe1d7291ff34b3f5c3b44ee861f021396d33ba3255b83df30e357d", - headInfo.l1Epoch().hash()); - assertEquals(BigInteger.valueOf(8874020L), headInfo.l1Epoch().number()); - assertEquals(BigInteger.valueOf(1682191440L), headInfo.l1Epoch().timestamp()); + assertEquals(map.get("assert_l1_block_hash"), headInfo.l1Epoch().hash()); + assertEquals( + new BigInteger((String) map.get("assert_l1_block_number")), + headInfo.l1Epoch().number()); + assertEquals( + new BigInteger((String) map.get("assert_l1_block_timestamp")), + headInfo.l1Epoch().timestamp()); + } } @Test diff --git a/hildr-node/src/test/java/io/optimism/engine/EngineApiTest.java b/hildr-node/src/test/java/io/optimism/engine/EngineApiTest.java index ffd59ce5..d49bcf25 100644 --- a/hildr-node/src/test/java/io/optimism/engine/EngineApiTest.java +++ b/hildr-node/src/test/java/io/optimism/engine/EngineApiTest.java @@ -1,6 +1,5 @@ package io.optimism.engine; -import static io.optimism.type.L1BlockInfo.L1_INFO_ECOTONE_SIGN_BYTES; import static org.junit.jupiter.api.Assertions.assertEquals; import com.fasterxml.jackson.core.JsonProcessingException; @@ -106,6 +105,9 @@ String initExecutionPayloadJson() throws JsonProcessingException { @Test void testForkChoiceUpdate() throws IOException { + if (!TestConstants.isConfiguredApiKeyEnv) { + return; + } String baseUrl = EngineApi.authUrlFromAddr(AUTH_ADDR, null); assertEquals("http://127.0.0.1:8851", baseUrl); server.enqueue(new MockResponse().setBody(initForkChoiceUpdateResp())); @@ -131,6 +133,9 @@ void testForkChoiceUpdate() throws IOException { @Test void testNewPayload() throws IOException { + if (!TestConstants.isConfiguredApiKeyEnv) { + return; + } String baseUrl = EngineApi.authUrlFromAddr(AUTH_ADDR, null); assertEquals("http://127.0.0.1:8851", baseUrl); server.enqueue(new MockResponse().setBody(initPayloadStatusResp())); @@ -143,6 +148,9 @@ void testNewPayload() throws IOException { @Test void testGetPayload() throws IOException { + if (!TestConstants.isConfiguredApiKeyEnv) { + return; + } String baseUrl = EngineApi.authUrlFromAddr(AUTH_ADDR, null); assertEquals("http://127.0.0.1:8851", baseUrl); server.enqueue(new MockResponse().setBody(initExecutionPayloadJson())); @@ -168,9 +176,4 @@ void testJwts() { - jwt.getBody().getIssuedAt().toInstant().getEpochSecond(), 60L); } - - @Test - void testHash() { - System.out.println(Numeric.toHexString(L1_INFO_ECOTONE_SIGN_BYTES)); - } } diff --git a/hildr-node/src/test/java/io/optimism/l1/BeaconBlobFetcherTest.java b/hildr-node/src/test/java/io/optimism/l1/BeaconBlobFetcherTest.java index cc1e9446..0c3baaf8 100644 --- a/hildr-node/src/test/java/io/optimism/l1/BeaconBlobFetcherTest.java +++ b/hildr-node/src/test/java/io/optimism/l1/BeaconBlobFetcherTest.java @@ -15,7 +15,8 @@ */ class BeaconBlobFetcherTest { - private static String beaconUrl = "https://beacon-nd-182-746-446.p2pify.com/ae65ad4cb1ef42d6a520ac0516776939"; + private static String beaconUrl = + "https://few-sleek-sound.ethereum-sepolia.quiknode.pro/8e8c3ae8c9ddf50628ad22d3d8cdaf36230d52e1"; private static BeaconBlobFetcher fetcher; @BeforeAll diff --git a/hildr-node/src/test/java/io/optimism/rpc/RpcServerTest.java b/hildr-node/src/test/java/io/optimism/rpc/RpcServerTest.java index 80548af7..544af880 100644 --- a/hildr-node/src/test/java/io/optimism/rpc/RpcServerTest.java +++ b/hildr-node/src/test/java/io/optimism/rpc/RpcServerTest.java @@ -105,7 +105,17 @@ void testRpcServerStart() throws Exception { @SuppressWarnings("rawtypes") void testRpcServerRegister() throws IOException, InterruptedException { RpcServer rpcServer = createRpcServer(new Config( - null, null, "http://fakeurl", null, null, null, null, 9545, false, Config.ChainConfig.optimism())); + null, + null, + "http://fakeurl", + "http://fakeurl", + "http://fakeurl", + null, + null, + null, + 9545, + false, + Config.ChainConfig.optimism())); rpcServer.start(); HashMap rpcHandler = HashMap.newHashMap(1); rpcHandler.put("test_url", unused -> "response data"); diff --git a/hildr-node/src/test/resources/bedrock_raw_block.txt b/hildr-node/src/test/resources/bedrock_raw_block.txt new file mode 100644 index 00000000..3573d7c9 --- /dev/null +++ b/hildr-node/src/test/resources/bedrock_raw_block.txt @@ -0,0 +1,52 @@ +{ + "test_block_data": { + "hash": "0x2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb", + "parentHash": "0xeccf4c06ad0d27be1cadee5720a509d31a9de0462b52f2cf6045d9a73c9aa504", + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "miner": "0x4200000000000000000000000000000000000011", + "stateRoot": "0x5905b2423f299a29db41e377d7ceadf4baa49eed04e1b72957e8c0985e04e730", + "transactionsRoot": "0x030e481411042a769edde83d790d583ed69f9d3098d4a78d00e008f749fcfd97", + "receiptsRoot": "0x29079b696c12a19999f3bb303fddb6fc12fb701f427678cca24954b91080ada3", + "number": "0x7fe52f", + "gasUsed": "0xb711", + "gasLimit": "0x17d7840", + "extraData": "0x", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "timestamp": "0x644434c2", + "difficulty": "0x0", + "totalDifficulty": "0x0", + "sealFields": [], + "uncles": [], + "transactions": [ + { + "hash": "0x661df2908a63c9701ef4f9bc1d62432f08cbdc8c6fe6012af49405c00de5f69d", + "nonce": "0x41ed06", + "blockHash": "0x2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb", + "blockNumber": "0x7fe52f", + "transactionIndex": "0x0", + "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", + "to": "0x4200000000000000000000000000000000000015", + "value": "0x0", + "gasPrice": "0x0", + "gas": "0xf4240", + "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000008768240000000000000000000000000000000000000000000000000000000064443450000000000000000000000000000000000000000000000000000000000000000e0444c991c5fe1d7291ff34b3f5c3b44ee861f021396d33ba3255b83df30e357d00000000000000000000000000000000000000000000000000000000000000050000000000000000000000007431310e026b69bfc676c0013e12a1a11411eec9000000000000000000000000000000000000000000000000000000000000083400000000000000000000000000000000000000000000000000000000000f4240", + "v": "0x0", + "r": "0x0", + "s": "0x0", + "type": "0x7e", + "mint": "0x0", + "sourceHash": "0x34ad504eea583add76d3b9d249965356ef6ca344d6766644c929357331bb0dc9" + } + ], + "size": "0x365", + "mixHash": "0x7aeec5550a9b0616701e49ab835af5f10eadba2a0582016f0e256c9cace0c046", + "nonce": "0x0000000000000000", + "baseFeePerGas": "0x32" + }, + "assert_l2_block_hash": "0x2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb", + "assert_l2_block_number": "8381743", + "assert_l2_block_timestamp": "1682191554", + "assert_l1_block_hash": "0x0444c991c5fe1d7291ff34b3f5c3b44ee861f021396d33ba3255b83df30e357d", + "assert_l1_block_number": "8874020", + "assert_l1_block_timestamp": "1682191440" +} \ No newline at end of file diff --git a/hildr-node/src/test/resources/ectone_raw_block.txt b/hildr-node/src/test/resources/ectone_raw_block.txt new file mode 100644 index 00000000..78733b83 --- /dev/null +++ b/hildr-node/src/test/resources/ectone_raw_block.txt @@ -0,0 +1,57 @@ +{ + "test_block_data": { + "baseFeePerGas": "0xfc", + "blobGasUsed": "0x0", + "difficulty": "0x0", + "excessBlobGas": "0x0", + "extraData": "0x", + "gasLimit": "0x1c9c380", + "gasUsed": "0xfd6b", + "hash": "0xe6560f66990f4c13615156ca27f25d8b8cd74974d400eba1a3731d2beaed2dc5", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "miner": "0x4200000000000000000000000000000000000011", + "mixHash": "0x5031b5b0ce908e11d65d80ff6862020108f3accbd7ba8b79b135c5e2199bd34f", + "nonce": "0x0000000000000000", + "number": "0x862387", + "parentBeaconBlockRoot": "0xa78e2bcef82a22fa8293a35715d0c1cdc29e4ed5cf27f641f767ac554fcebbea", + "parentHash": "0x3dd0c601ccaef17058cb2b84656a2dfe465564e44b59d47f2746d0875c8c191a", + "receiptsRoot": "0x505a21ca6c601c5daec62841bd84be99e72b7842acd84e5b8a26bf49de0356e5", + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "size": "0x3ba", + "stateRoot": "0x06fa66b035988e41bcab78f4ef1e2b8ec9de3661b02e75a831c8b41a5b27d00b", + "timestamp": "0x65e322ba", + "totalDifficulty": "0x0", + "transactions": [ + { + "blockHash": "0xe6560f66990f4c13615156ca27f25d8b8cd74974d400eba1a3731d2beaed2dc5", + "blockNumber": "0x862387", + "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", + "gas": "0xf4240", + "gasPrice": "0x0", + "hash": "0x90f6a969b3198a6b3c52137011d2dda89669cbcd846e5577c3af384dcd0a3508", + "input": "0x440a5e2000001db0000d273000000000000000010000000065e322640000000000526aa20000000000000000000000000000000000000000000000000000000004af091400000000000000000000000000000000000000000000000000000004d137e31bd78837506c512be05719fb86ddc374cb76a9954d2c8d370bba7dfe7f4cfa91ba0000000000000000000000008f23bb38f531600e5d8fddaaec41f13fab46e98c", + "nonce": "0x862387", + "to": "0x4200000000000000000000000000000000000015", + "transactionIndex": "0x0", + "value": "0x0", + "type": "0x7e", + "v": "0x0", + "r": "0x0", + "s": "0x0", + "sourceHash": "0x6b0c7c29430ca306ea4ad8a28b82ae09ff8b53e94955cbc744731f0e6c409f3f", + "mint": "0x0", + "depositReceiptVersion": "0x1" + } + ], + "transactionsRoot": "0x407cb257e72cdda553bcafca1703cb71d8747f21af25f9bf8da6a3766169f80d", + "uncles": [], + "withdrawals": [], + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "assert_l2_block_hash": "0xe6560f66990f4c13615156ca27f25d8b8cd74974d400eba1a3731d2beaed2dc5", + "assert_l2_block_number": "8790919", + "assert_l2_block_timestamp": "1709384378", + "assert_l1_block_hash": "0xd78837506c512be05719fb86ddc374cb76a9954d2c8d370bba7dfe7f4cfa91ba", + "assert_l1_block_number": "5401250", + "assert_l1_block_timestamp": "1709384292" +} \ No newline at end of file diff --git a/hildr-utilities/src/main/java/io/optimism/type/L1BlockInfo.java b/hildr-utilities/src/main/java/io/optimism/type/L1BlockInfo.java index 2554fd9e..9ec24f93 100644 --- a/hildr-utilities/src/main/java/io/optimism/type/L1BlockInfo.java +++ b/hildr-utilities/src/main/java/io/optimism/type/L1BlockInfo.java @@ -74,9 +74,9 @@ private static L1BlockInfo fromBedrock(byte[] data) { BigInteger number = Numeric.toBigInt(data, 4, 32); BigInteger time = Numeric.toBigInt(data, 36, 32); BigInteger baseFee = Numeric.toBigInt(data, 68, 32); - String blockHash = Numeric.toHexString(ArrayUtils.subarray(data, 100, 32)); + String blockHash = Numeric.toHexString(ArrayUtils.subarray(data, 100, 132)); BigInteger sequenceNumber = Numeric.toBigInt(data, 132, 32); - String batcherAddr = Numeric.toHexString(ArrayUtils.subarray(data, 176, 20)); + String batcherAddr = Numeric.toHexString(ArrayUtils.subarray(data, 176, 196)); BigInteger l1FeeOverhead = Numeric.toBigInt(data, 196, 32); BigInteger l1FeeScalar = Numeric.toBigInt(data, 228, 32); return new L1BlockInfo( @@ -120,10 +120,10 @@ private static L1BlockInfo fromEcotone(byte[] data) { BigInteger blobBaseFee = Numeric.toBigInt(data, offset, 32); offset += 32; - String blockHash = Numeric.toHexString(ArrayUtils.subarray(data, offset, 32)); + String blockHash = Numeric.toHexString(ArrayUtils.subarray(data, offset, offset + 32)); offset += 32; - String batcherAddr = Numeric.toHexString(ArrayUtils.subarray(data, offset, 32)); + String batcherAddr = Numeric.toHexString(ArrayUtils.subarray(data, offset, offset + 32)); return new L1BlockInfo( number, time,