-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
26 changed files
with
689 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...nt/src/main/java/tech/pegasys/teku/ethereum/executionclient/methods/EngineGetBlobsV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.ethereum.executionclient.methods; | ||
|
||
import java.util.List; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import tech.pegasys.teku.ethereum.executionclient.ExecutionEngineClient; | ||
import tech.pegasys.teku.ethereum.executionclient.response.ResponseUnwrapper; | ||
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema; | ||
import tech.pegasys.teku.spec.datastructures.execution.BlobAndProof; | ||
import tech.pegasys.teku.spec.logic.versions.deneb.types.VersionedHash; | ||
import tech.pegasys.teku.spec.schemas.SchemaDefinitions; | ||
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb; | ||
|
||
public class EngineGetBlobsV1 extends AbstractEngineJsonRpcMethod<List<BlobAndProof>> { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
private final Spec spec; | ||
|
||
public EngineGetBlobsV1(final ExecutionEngineClient executionEngineClient, final Spec spec) { | ||
super(executionEngineClient); | ||
this.spec = spec; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return EngineApiMethod.ENGINE_GET_BLOBS.getName(); | ||
} | ||
|
||
@Override | ||
public int getVersion() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public boolean isOptional() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public SafeFuture<List<BlobAndProof>> execute(final JsonRpcRequestParams params) { | ||
|
||
final List<VersionedHash> blobVersionedHashes = | ||
params.getRequiredListParameter(0, VersionedHash.class); | ||
|
||
final UInt64 slot = params.getRequiredParameter(1, UInt64.class); | ||
|
||
LOG.trace( | ||
"Calling {}(blobVersionedHashes={}, slot={})", | ||
getVersionedName(), | ||
blobVersionedHashes, | ||
slot); | ||
|
||
return executionEngineClient | ||
.getBlobsV1(blobVersionedHashes) | ||
.thenApply(ResponseUnwrapper::unwrapExecutionClientResponseOrThrow) | ||
.thenApply( | ||
response -> { | ||
final SchemaDefinitions schemaDefinitions = spec.atSlot(slot).getSchemaDefinitions(); | ||
final BlobSchema blobSchema = | ||
SchemaDefinitionsDeneb.required(schemaDefinitions).getBlobSchema(); | ||
return response.stream() | ||
.map( | ||
blobAndProofV1 -> | ||
blobAndProofV1 == null | ||
? null | ||
: blobAndProofV1.asInternalBlobsAndProofs(blobSchema)) | ||
.toList(); | ||
}) | ||
.thenPeek( | ||
blobsAndProofs -> | ||
LOG.trace( | ||
"Response {}(blobVersionedHashes={}) -> {}", | ||
getVersionedName(), | ||
blobVersionedHashes, | ||
blobsAndProofs)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...lient/src/main/java/tech/pegasys/teku/ethereum/executionclient/schema/BlobAndProofV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.ethereum.executionclient.schema; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.google.common.base.MoreObjects; | ||
import java.util.Objects; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.apache.tuweni.bytes.Bytes48; | ||
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes48Deserializer; | ||
import tech.pegasys.teku.ethereum.executionclient.serialization.BytesDeserializer; | ||
import tech.pegasys.teku.ethereum.executionclient.serialization.BytesSerializer; | ||
import tech.pegasys.teku.kzg.KZGProof; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema; | ||
import tech.pegasys.teku.spec.datastructures.execution.BlobAndProof; | ||
|
||
public class BlobAndProofV1 { | ||
|
||
@JsonSerialize(using = BytesSerializer.class) | ||
@JsonDeserialize(using = BytesDeserializer.class) | ||
private final Bytes blob; | ||
|
||
@JsonSerialize(using = BytesSerializer.class) | ||
@JsonDeserialize(using = Bytes48Deserializer.class) | ||
private final Bytes48 proof; | ||
|
||
public BlobAndProofV1( | ||
@JsonProperty("blob") final Bytes blob, @JsonProperty("proof") final Bytes48 proof) { | ||
checkNotNull(blob, "blob"); | ||
checkNotNull(proof, "proof"); | ||
this.proof = proof; | ||
this.blob = blob; | ||
} | ||
|
||
public BlobAndProof asInternalBlobsAndProofs(final BlobSchema blobSchema) { | ||
return new BlobAndProof(new Blob(blobSchema, blob), new KZGProof(proof)); | ||
} | ||
|
||
public static BlobAndProofV1 fromInternalBlobsBundle(final BlobAndProof blobAndProof) { | ||
return new BlobAndProofV1( | ||
blobAndProof.blob().getBytes(), blobAndProof.proof().getBytesCompressed()); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final BlobAndProofV1 that = (BlobAndProofV1) o; | ||
return Objects.equals(blob, that.blob) && Objects.equals(proof, that.proof); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(blob, proof); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("blob", bytesToBriefString(blob)) | ||
.add("proof", bytesToBriefString(proof)) | ||
.toString(); | ||
} | ||
|
||
private String bytesToBriefString(final Bytes bytes) { | ||
return bytes.slice(0, 7).toUnprefixedHexString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.