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 init throw #157

Merged
merged 4 commits into from
Apr 21, 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
1 change: 1 addition & 0 deletions hildr-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ dependencies {
implementation('tech.pegasys.teku.internal:serviceutils:23.10.0')
implementation('tech.pegasys.teku.internal:unsigned:23.10.0')
implementation('tech.pegasys.teku.internal:statetransition:23.10.0')
implementation 'tech.pegasys:jc-kzg-4844'
implementation('org.hyperledger.besu.internal:metrics-core:23.10.2')
implementation('org.hyperledger.besu:plugin-api:23.10.2')
implementation('io.libp2p:jvm-libp2p:1.0.1-RELEASE')
Expand Down
7 changes: 5 additions & 2 deletions hildr-node/src/main/java/io/optimism/driver/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.jctools.queues.MessagePassingQueue;
import org.jctools.queues.MpscUnboundedXaddArrayQueue;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -182,7 +183,9 @@ public static Driver<EngineApi> from(Config config, CountDownLatch latch)
}

HeadInfo head;
if (finalizedBlock == null) {
if (finalizedBlock == null
|| finalizedBlock.getBlock() == null
|| CollectionUtils.isEmpty(finalizedBlock.getBlock().getTransactions())) {
LOGGER.warn("could not get head info. Falling back to the genesis head.");
head = new HeadInfo(
config.chainConfig().l2Genesis(), config.chainConfig().l1StartEpoch(), BigInteger.ZERO);
Expand Down Expand Up @@ -218,7 +221,7 @@ public static Driver<EngineApi> from(Config config, CountDownLatch latch)
scope.throwIfFailed();

var block = blockTask.get();
if (block == null) {
if (block == null || block.getBlock() == null) {
return null;
}
final HeadInfo l2BlockInfo = HeadInfo.from(block.getBlock());
Expand Down
35 changes: 35 additions & 0 deletions hildr-node/src/main/java/io/optimism/l1/BeaconBlobFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import ethereum.ckzg4844.CKZG4844JNI;
import io.optimism.type.BlobSidecar;
import io.optimism.type.SpecConfig;
import io.optimism.utilities.rpc.HttpClientProvider;
Expand All @@ -20,6 +21,7 @@
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.utils.Numeric;

/**
* The class of BeaconBlobFetcher.
Expand All @@ -37,6 +39,11 @@ public class BeaconBlobFetcher {

private static final String SIDECARS_METHOD_PREFIX_FORMAT = "%s/eth/v1/beacon/blob_sidecars";

static {
CKZG4844JNI.loadNativeLibrary();
CKZG4844JNI.loadTrustedSetupFromResource("/kzg-trusted-setups/mainnet.txt", BeaconBlobFetcher.class);
}

private final String genesisMethod;

private final String specMethod;
Expand Down Expand Up @@ -145,6 +152,8 @@ public List<BlobSidecar> getBlobSidecards(String blockId, final List<BigInteger>
blockId,
indices);
}
List<BlobSidecar> blobSiders = res.getData();

return res.getData();
}

Expand All @@ -153,6 +162,32 @@ private BeaconApiResponse<List<BlobSidecar>> getBlobSidecars(String url) {
return this.send(req, new TypeReference<BeaconApiResponse<List<BlobSidecar>>>() {});
}

static boolean verifyBlobSidecar(List<BlobSidecar> blobSidecars, List<String> versionedHashes) {
if (blobSidecars == null || versionedHashes == null) {
return false;
}
// check length
if (blobSidecars.size() != versionedHashes.size()) {
return false;
}

for (int i = 0; i < blobSidecars.size(); i++) {
var blobSidecar = blobSidecars.get(i);
var versionedHash = versionedHashes.get(i);
if (!blobSidecar.getVersionedHash().equals(versionedHash)) {
return false;
}
if (!CKZG4844JNI.verifyBlobKzgProof(
Numeric.hexStringToByteArray(blobSidecar.getBlob()),
Numeric.hexStringToByteArray(blobSidecar.getKzgCommitment()),
Numeric.hexStringToByteArray(blobSidecar.getKzgProof()))) {
return false;
}
}

return true;
}

private <T> T send(final Request req, final TypeReference<T> typeRef) {
Call call = this.httpClient.newCall(req);
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
Expand Down
15 changes: 8 additions & 7 deletions hildr-node/src/main/java/io/optimism/network/DiscV5Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ public SafeFuture<Collection<DiscoveryPeer>> searchForPeers() {

private List<NodeRecord> filterByOpStackDataEnr(final Collection<NodeRecord> nodeRecords) {
return nodeRecords.stream()
.filter(nodeRecord -> nodeRecord.containsKey(OP_STACK)
&& OpStackEnrData.decode((Bytes) nodeRecord.get(OP_STACK))
.getChainId()
.equals(chainId)
&& OpStackEnrData.decode((Bytes) nodeRecord.get(OP_STACK))
.getVersion()
.isZero())
.filter(nodeRecord -> {
if (!nodeRecord.containsKey(OP_STACK)) {
return false;
}
OpStackEnrData enrData = OpStackEnrData.decode((Bytes) nodeRecord.get(OP_STACK));
return enrData.getChainId().equals(chainId)
&& enrData.getVersion().isZero();
})
.collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ public NodeRecordConverter() {}
* @return the optional
*/
public Optional<DiscoveryPeer> convertToDiscoveryPeer(final NodeRecord nodeRecord) {
return nodeRecord.getTcpAddress().map(address -> socketAddressToDiscoveryPeer(nodeRecord, address));
if (nodeRecord.getTcpAddress().isPresent()) {
return Optional.of(socketAddressToDiscoveryPeer(
nodeRecord, nodeRecord.getTcpAddress().get()));
} else if (nodeRecord.getUdpAddress().isPresent()) {
return Optional.of(socketAddressToDiscoveryPeer(
nodeRecord, nodeRecord.getUdpAddress().get()));
} else {
return Optional.empty();
}
}

private static DiscoveryPeer socketAddressToDiscoveryPeer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class OpStackNetwork {
"enr:-Ku4QG-2_Md3sZIAUebGYT6g0SMskIml77l6yR-M_JXc-UdNHCmHQeOiMLbylPejyJsdAPsTHJyjJB2sYGDLe0dn8uYBh2F0dG5ldHOIAAAAAAAAAACEZXRoMpC1MD8qAAAAAP__________gmlkgnY0gmlwhBLY-NyJc2VjcDI1NmsxoQORcM6e19T1T9gi7jxEZjk_sjVLGFscUNqAY9obgZaxbIN1ZHCCIyg",
"enr:-Ku4QPn5eVhcoF1opaFEvg1b6JNFD2rqVkHQ8HApOKK61OIcIXD127bKWgAtbwI7pnxx6cDyk_nI88TrZKQaGMZj0q0Bh2F0dG5ldHOIAAAAAAAAAACEZXRoMpC1MD8qAAAAAP__________gmlkgnY0gmlwhDayLMaJc2VjcDI1NmsxoQK2sBOLGcUb4AwuYzFuAVCaNHA-dy24UuEKkeFNgCVCsIN1ZHCCIyg",
"enr:-Ku4QEWzdnVtXc2Q0ZVigfCGggOVB2Vc1ZCPEc6j21NIFLODSJbvNaef1g4PxhPwl_3kax86YPheFUSLXPRs98vvYsoBh2F0dG5ldHOIAAAAAAAAAACEZXRoMpC1MD8qAAAAAP__________gmlkgnY0gmlwhDZBrP2Jc2VjcDI1NmsxoQM6jr8Rb1ktLEsVcKAPa08wCsKUmvoQ8khiOl_SLozf9IN1ZHCCIyg",
// Base
"enr:-J24QNz9lbrKbN4iSmmjtnr7SjUMk4zB7f1krHZcTZx-JRKZd0kA2gjufUROD6T3sOWDVDnFJRvqBBo62zuF-hYCohOGAYiOoEyEgmlkgnY0gmlwhAPniryHb3BzdGFja4OFQgCJc2VjcDI1NmsxoQKNVFlCxh_B-716tTs-h1vMzZkSs1FTu_OYTNjgufplG4N0Y3CCJAaDdWRwgiQG",
"enr:-J24QH-f1wt99sfpHy4c0QJM-NfmsIfmlLAMMcgZCUEgKG_BBYFc6FwYgaMJMQN5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