Skip to content

Commit

Permalink
Merge getPayloadV3 and getBlobsBundleV1 (part 1) (#7096)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov authored May 4, 2023
1 parent 4d42661 commit 8549bcf
Show file tree
Hide file tree
Showing 29 changed files with 147 additions and 519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,24 @@ private void builderSetKzgCommitments(
final SafeFuture<ExecutionPayloadResult> executionPayloadResultFuture) {
final SchemaDefinitionsDeneb schemaDefinitionsDeneb =
SchemaDefinitionsDeneb.required(schemaDefinitions);
final SafeFuture<SszList<SszKZGCommitment>> commitments =
final SafeFuture<SszList<SszKZGCommitment>> blobKzgCommitments =
executionPayloadResultFuture.thenCompose(
executionPayloadResult ->
executionPayloadResult
.getKzgs()
.getCommitments()
.orElseThrow()
.thenApply(
kzgs ->
commitments ->
schemaDefinitionsDeneb
.getBeaconBlockBodySchema()
.toVersionDeneb()
.orElseThrow()
.getBlobKzgCommitmentsSchema()
.createFromElements(
kzgs.stream()
commitments.stream()
.map(SszKZGCommitment::new)
.collect(Collectors.toList()))));
bodyBuilder.blobKzgCommitments(commitments);
bodyBuilder.blobKzgCommitments(blobKzgCommitments);
}

public Consumer<SignedBeaconBlockUnblinder> createUnblinderSelector() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.ethereum.executionclient.schema.BlobsBundleV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
Expand All @@ -43,8 +42,6 @@ public interface ExecutionEngineClient {

SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(Bytes8 payloadId);

SafeFuture<Response<BlobsBundleV1>> getBlobsBundleV1(Bytes8 payloadId);

SafeFuture<Response<PayloadStatusV1>> newPayloadV1(ExecutionPayloadV1 executionPayload);

SafeFuture<Response<PayloadStatusV1>> newPayloadV2(ExecutionPayloadV1 executionPayload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import tech.pegasys.teku.ethereum.executionclient.schema.BlobsBundleV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
Expand Down Expand Up @@ -75,11 +74,6 @@ public SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(final Bytes8 payl
return taskQueue.queueTask(() -> delegate.getPayloadV3(payloadId));
}

@Override
public SafeFuture<Response<BlobsBundleV1>> getBlobsBundleV1(final Bytes8 payloadId) {
return taskQueue.queueTask(() -> delegate.getBlobsBundleV1(payloadId));
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV1(
final ExecutionPayloadV1 executionPayload) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public enum EngineApiMethods {
ENGINE_NEW_PAYLOAD("engine_newPayload"),
ENGINE_GET_PAYLOAD("engine_getPayload"),
ENGINE_FORK_CHOICE_UPDATED("engine_forkchoiceUpdated"),
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION("engine_exchangeTransitionConfiguration"),
ENGINE_GET_BLOBS_BUNDLE("engine_getBlobsBundle");
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION("engine_exchangeTransitionConfiguration");

private final String name;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import tech.pegasys.teku.ethereum.executionclient.ExecutionEngineClient;
import tech.pegasys.teku.ethereum.executionclient.schema.BlobsBundleV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
Expand Down Expand Up @@ -53,7 +52,6 @@ public class MetricRecordingExecutionEngineClient extends MetricRecordingAbstrac
"forkchoice_updated_with_attributesV2";
public static final String GET_PAYLOAD_V3_METHOD = "get_payloadV3";
public static final String NEW_PAYLOAD_V3_METHOD = "new_payloadV3";
public static final String GET_BLOBS_BUNDLE_V1_METHOD = "engine_getBlobsBundleV1";

private final ExecutionEngineClient delegate;

Expand Down Expand Up @@ -98,11 +96,6 @@ public SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(final Bytes8 payl
return countRequest(() -> delegate.getPayloadV3(payloadId), GET_PAYLOAD_V3_METHOD);
}

@Override
public SafeFuture<Response<BlobsBundleV1>> getBlobsBundleV1(final Bytes8 payloadId) {
return countRequest(() -> delegate.getBlobsBundleV1(payloadId), GET_BLOBS_BUNDLE_V1_METHOD);
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV1(
final ExecutionPayloadV1 executionPayload) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,53 @@
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes32Deserializer;
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.infrastructure.ssz.collections.impl.SszByteVectorImpl;
import tech.pegasys.teku.kzg.KZGCommitment;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.kzg.KZGProof;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobsBundle;

public class BlobsBundleV1 {
@JsonSerialize(using = BytesSerializer.class)
@JsonDeserialize(using = Bytes32Deserializer.class)
private final Bytes32 blockHash;
@JsonSerialize(contentUsing = BytesSerializer.class)
@JsonDeserialize(contentUsing = Bytes48Deserializer.class)
private final List<Bytes48> commitments;

@JsonSerialize(contentUsing = BytesSerializer.class)
@JsonDeserialize(contentUsing = Bytes48Deserializer.class)
private final List<Bytes48> kzgs;
private final List<Bytes48> proofs;

@JsonSerialize(contentUsing = BytesSerializer.class)
@JsonDeserialize(contentUsing = BytesDeserializer.class)
private final List<Bytes> blobs;

public BlobsBundleV1(
@JsonProperty("blockHash") final Bytes32 blockHash,
@JsonProperty("kzgs") final List<Bytes48> kzgs,
@JsonProperty("commitments") final List<Bytes48> commitments,
@JsonProperty("proofs") final List<Bytes48> proofs,
@JsonProperty("blobs") final List<Bytes> blobs) {
checkNotNull(blockHash, "blockHash");
checkNotNull(kzgs, "kzgs");
checkNotNull(commitments, "commitments");
checkNotNull(proofs, "proofs");
checkNotNull(blobs, "blobs");
this.blockHash = blockHash;
this.kzgs = kzgs;
this.commitments = commitments;
this.proofs = proofs;
this.blobs = blobs;
}

public static BlobsBundleV1 fromInternalBlobsBundle(final BlobsBundle blobsBundle) {
return new BlobsBundleV1(
blobsBundle.getBlockHash(),
blobsBundle.getKzgs().stream()
blobsBundle.getCommitments().stream()
.map(KZGCommitment::getBytesCompressed)
.collect(Collectors.toList()),
blobsBundle.getProofs().stream()
.map(KZGProof::getBytesCompressed)
.collect(Collectors.toList()),
blobsBundle.getBlobs().stream()
.map(SszByteVectorImpl::getBytes)
.collect(Collectors.toList()));
}

public BlobsBundle asInternalBlobsBundle(final BlobSchema blobSchema) {
return new BlobsBundle(
blockHash,
kzgs.stream().map(KZGCommitment::new).collect(Collectors.toList()),
blobs.stream().map(bytes -> new Blob(blobSchema, bytes)).collect(Collectors.toList()));
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -87,26 +79,28 @@ public boolean equals(final Object o) {
return false;
}
final BlobsBundleV1 that = (BlobsBundleV1) o;
return Objects.equals(blockHash, that.blockHash)
&& Objects.equals(kzgs, that.kzgs)
return Objects.equals(commitments, that.commitments)
&& Objects.equals(proofs, that.proofs)
&& Objects.equals(blobs, that.blobs);
}

@Override
public int hashCode() {
return Objects.hash(blockHash, kzgs, blobs);
return Objects.hash(commitments, proofs, blobs);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("blockHash", blockHash)
.add("kzgs", kzgs)
.add(
"blobs",
blobs.stream()
.map(blob -> blob.slice(0, 7).toUnprefixedHexString())
.collect(Collectors.toList()))
"commitments",
commitments.stream().map(this::bytesToBriefString).collect(Collectors.toList()))
.add("proofs", proofs.stream().map(this::bytesToBriefString).collect(Collectors.toList()))
.add("blobs", blobs.stream().map(this::bytesToBriefString).collect(Collectors.toList()))
.toString();
}

private String bytesToBriefString(final Bytes bytes) {
return bytes.slice(0, 7).toUnprefixedHexString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ public class GetPayloadV3Response {
@JsonDeserialize(using = UInt256AsHexDeserializer.class)
public final UInt256 blockValue;

public final BlobsBundleV1 blobsBundle;

public GetPayloadV3Response(
@JsonProperty("executionPayload") final ExecutionPayloadV3 executionPayload,
@JsonProperty("blockValue") final UInt256 blockValue) {
@JsonProperty("blockValue") final UInt256 blockValue,
@JsonProperty("blobsBundle") final BlobsBundleV1 blobsBundle) {
this.executionPayload = executionPayload;
this.blockValue = blockValue;
this.blobsBundle = blobsBundle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.response.EthBlock;
import tech.pegasys.teku.ethereum.executionclient.ExecutionEngineClient;
import tech.pegasys.teku.ethereum.executionclient.schema.BlobsBundleV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
Expand Down Expand Up @@ -116,17 +115,6 @@ public SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(final Bytes8 payl
return web3JClient.doRequest(web3jRequest, EL_ENGINE_NON_BLOCK_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<BlobsBundleV1>> getBlobsBundleV1(final Bytes8 payloadId) {
Request<?, BlobsBundleV1Web3jResponse> web3jRequest =
new Request<>(
"engine_getBlobsBundleV1",
Collections.singletonList(payloadId.toHexString()),
web3JClient.getWeb3jService(),
BlobsBundleV1Web3jResponse.class);
return web3JClient.doRequest(web3jRequest, EL_ENGINE_NON_BLOCK_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV1(ExecutionPayloadV1 executionPayload) {
Request<?, PayloadStatusV1Web3jResponse> web3jRequest =
Expand Down Expand Up @@ -219,8 +207,6 @@ static class GetPayloadV2Web3jResponse
static class GetPayloadV3Web3jResponse
extends org.web3j.protocol.core.Response<GetPayloadV3Response> {}

static class BlobsBundleV1Web3jResponse extends org.web3j.protocol.core.Response<BlobsBundleV1> {}

static class PayloadStatusV1Web3jResponse
extends org.web3j.protocol.core.Response<PayloadStatusV1> {}

Expand Down
Loading

0 comments on commit 8549bcf

Please sign in to comment.