Skip to content

Commit

Permalink
Merge branch 'master' into teku-8618
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaldanha committed Oct 7, 2024
2 parents 4dc234d + dca8285 commit 5074f31
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexSerializer;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;

public class GetPayloadV2Response {
public final ExecutionPayloadV2 executionPayload;
Expand All @@ -37,4 +39,10 @@ public GetPayloadV2Response(
this.executionPayload = executionPayload;
this.blockValue = blockValue;
}

public GetPayloadResponse asInternalGetPayloadResponse(
final ExecutionPayloadSchema<?> executionPayloadSchema) {
return new GetPayloadResponse(
executionPayload.asInternalExecutionPayload(executionPayloadSchema), blockValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexSerializer;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;

public class GetPayloadV3Response {
public final ExecutionPayloadV3 executionPayload;
Expand All @@ -46,4 +49,13 @@ public GetPayloadV3Response(
this.blobsBundle = blobsBundle;
this.shouldOverrideBuilder = shouldOverrideBuilder;
}

public GetPayloadResponse asInternalGetPayloadResponse(
final ExecutionPayloadSchema<?> executionPayloadSchema, final BlobSchema blobSchema) {
return new GetPayloadResponse(
executionPayload.asInternalExecutionPayload(executionPayloadSchema),
blockValue,
blobsBundle.asInternalBlobsBundle(blobSchema),
shouldOverrideBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexSerializer;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;

public class GetPayloadV4Response {
public final ExecutionPayloadV3 executionPayload;
Expand All @@ -46,4 +49,13 @@ public GetPayloadV4Response(
this.blobsBundle = blobsBundle;
this.shouldOverrideBuilder = shouldOverrideBuilder;
}

public GetPayloadResponse asInternalGetPayloadResponse(
final ExecutionPayloadSchema<?> executionPayloadSchema, final BlobSchema blobSchema) {
return new GetPayloadResponse(
executionPayload.asInternalExecutionPayload(executionPayloadSchema),
blockValue,
blobsBundle.asInternalBlobsBundle(blobSchema),
shouldOverrideBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.ethereum.executionlayer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -30,10 +31,12 @@
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;
import tech.pegasys.teku.spec.datastructures.execution.NewPayloadRequest;
import tech.pegasys.teku.spec.executionlayer.ExecutionPayloadStatus;
import tech.pegasys.teku.spec.executionlayer.ForkChoiceState;
import tech.pegasys.teku.spec.executionlayer.PayloadBuildingAttributes;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
import tech.pegasys.teku.spec.util.DataStructureUtil;

class BellatrixExecutionClientHandlerTest extends ExecutionHandlerClientTest {
Expand All @@ -43,7 +46,6 @@ void setup() {
dataStructureUtil = new DataStructureUtil(spec);
}

@SuppressWarnings("FutureReturnValueIgnored")
@Test
void engineGetPayload_shouldCallGetPayloadV1() {
final ExecutionClientHandler handler = getHandler();
Expand All @@ -54,35 +56,36 @@ void engineGetPayload_shouldCallGetPayloadV1() {
dataStructureUtil.randomForkChoiceState(false),
dataStructureUtil.randomPayloadBuildingAttributes(false));

final ExecutionPayload executionPayload = dataStructureUtil.randomExecutionPayload();
final ExecutionPayloadV1 responseData =
ExecutionPayloadV1.fromInternalExecutionPayload(executionPayload);
final SafeFuture<Response<ExecutionPayloadV1>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
ExecutionPayloadV1.fromInternalExecutionPayload(
dataStructureUtil.randomExecutionPayload())));
SafeFuture.completedFuture(new Response<>(responseData));
when(executionEngineClient.getPayloadV1(context.getPayloadId())).thenReturn(dummyResponse);

handler.engineGetPayload(context, slot);
final SafeFuture<GetPayloadResponse> future = handler.engineGetPayload(context, slot);
verify(executionEngineClient).getPayloadV1(context.getPayloadId());
assertThat(future).isCompletedWithValue(new GetPayloadResponse(executionPayload));
}

@SuppressWarnings("FutureReturnValueIgnored")
@Test
void engineNewPayload_shouldCallNewPayloadV1() {
final ExecutionClientHandler handler = getHandler();
final ExecutionPayload payload = dataStructureUtil.randomExecutionPayload();
final NewPayloadRequest newPayloadRequest = new NewPayloadRequest(payload);
final ExecutionPayloadV1 payloadV1 = ExecutionPayloadV1.fromInternalExecutionPayload(payload);
final PayloadStatusV1 responseData =
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), null);
final SafeFuture<Response<PayloadStatusV1>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), null)));
SafeFuture.completedFuture(new Response<>(responseData));
when(executionEngineClient.newPayloadV1(payloadV1)).thenReturn(dummyResponse);
handler.engineNewPayload(newPayloadRequest, UInt64.ZERO);
final SafeFuture<PayloadStatus> future =
handler.engineNewPayload(newPayloadRequest, UInt64.ZERO);
verify(executionEngineClient).newPayloadV1(payloadV1);
assertThat(future).isCompletedWithValue(responseData.asInternalExecutionPayload());
}

@SuppressWarnings("FutureReturnValueIgnored")
@Test
void engineForkChoiceUpdated_shouldCallEngineForkChoiceUpdatedV1() {
final ExecutionClientHandler handler = getHandler();
Expand All @@ -101,16 +104,18 @@ void engineForkChoiceUpdated_shouldCallEngineForkChoiceUpdatedV1() {
dataStructureUtil.randomBytes32());
final Optional<PayloadAttributesV1> payloadAttributes =
PayloadAttributesV1.fromInternalPayloadBuildingAttributes(Optional.of(attributes));
final ForkChoiceUpdatedResult responseData =
new ForkChoiceUpdatedResult(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), ""),
dataStructureUtil.randomBytes8());
final SafeFuture<Response<ForkChoiceUpdatedResult>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
new ForkChoiceUpdatedResult(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), ""),
dataStructureUtil.randomBytes8())));
SafeFuture.completedFuture(new Response<>(responseData));
when(executionEngineClient.forkChoiceUpdatedV1(forkChoiceStateV1, payloadAttributes))
.thenReturn(dummyResponse);
handler.engineForkChoiceUpdated(forkChoiceState, Optional.of(attributes));
final SafeFuture<tech.pegasys.teku.spec.executionlayer.ForkChoiceUpdatedResult> future =
handler.engineForkChoiceUpdated(forkChoiceState, Optional.of(attributes));
verify(executionEngineClient).forkChoiceUpdatedV1(forkChoiceStateV1, payloadAttributes);
assertThat(future).isCompletedWithValue(responseData.asInternalExecutionPayload());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.apache.tuweni.units.bigints.UInt256;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -35,13 +34,14 @@
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;
import tech.pegasys.teku.spec.datastructures.execution.NewPayloadRequest;
import tech.pegasys.teku.spec.datastructures.execution.versions.capella.ExecutionPayloadCapella;
import tech.pegasys.teku.spec.executionlayer.ExecutionPayloadStatus;
import tech.pegasys.teku.spec.executionlayer.ForkChoiceState;
import tech.pegasys.teku.spec.executionlayer.PayloadBuildingAttributes;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsCapella;
import tech.pegasys.teku.spec.util.DataStructureUtil;

public class CapellaExecutionClientHandlerTest extends ExecutionHandlerClientTest {
Expand All @@ -53,7 +53,7 @@ void setup() {
}

@Test
void engineGetPayload_shouldCallGetPayloadV2() throws ExecutionException, InterruptedException {
void engineGetPayload_shouldCallGetPayloadV2() {
final ExecutionClientHandler handler = getHandler();
final UInt64 slot = dataStructureUtil.randomUInt64(1_000_000);
final ExecutionPayloadContext context =
Expand All @@ -62,19 +62,23 @@ void engineGetPayload_shouldCallGetPayloadV2() throws ExecutionException, Interr
dataStructureUtil.randomForkChoiceState(false),
dataStructureUtil.randomPayloadBuildingAttributes(false));

final GetPayloadV2Response responseData =
new GetPayloadV2Response(
ExecutionPayloadV2.fromInternalExecutionPayload(
dataStructureUtil.randomExecutionPayload()),
UInt256.MAX_VALUE);
final SafeFuture<Response<GetPayloadV2Response>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
new GetPayloadV2Response(
ExecutionPayloadV2.fromInternalExecutionPayload(
dataStructureUtil.randomExecutionPayload()),
UInt256.MAX_VALUE)));
SafeFuture.completedFuture(new Response<>(responseData));
when(executionEngineClient.getPayloadV2(context.getPayloadId())).thenReturn(dummyResponse);

final SafeFuture<GetPayloadResponse> future = handler.engineGetPayload(context, slot);
verify(executionEngineClient).getPayloadV2(context.getPayloadId());
assertThat(future).isCompleted();
assertThat(future.get().getExecutionPayload()).isInstanceOf(ExecutionPayloadCapella.class);
final SchemaDefinitionsCapella schemaDefinitionCapella =
spec.atSlot(slot).getSchemaDefinitions().toVersionCapella().orElseThrow();
final ExecutionPayloadSchema<?> executionPayloadSchema =
schemaDefinitionCapella.getExecutionPayloadSchema();
assertThat(future)
.isCompletedWithValue(responseData.asInternalGetPayloadResponse(executionPayloadSchema));
}

@Test
Expand All @@ -83,16 +87,16 @@ void engineNewPayload_shouldCallNewPayloadV2() {
final ExecutionPayload payload = dataStructureUtil.randomExecutionPayload();
final NewPayloadRequest newPayloadRequest = new NewPayloadRequest(payload);
final ExecutionPayloadV2 payloadV2 = ExecutionPayloadV2.fromInternalExecutionPayload(payload);
final PayloadStatusV1 responseData =
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), null);
final SafeFuture<Response<PayloadStatusV1>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), null)));
SafeFuture.completedFuture(new Response<>(responseData));
when(executionEngineClient.newPayloadV2(payloadV2)).thenReturn(dummyResponse);
final SafeFuture<PayloadStatus> future =
handler.engineNewPayload(newPayloadRequest, UInt64.ZERO);
verify(executionEngineClient).newPayloadV2(payloadV2);
assertThat(future).isCompleted();
assertThat(future).isCompletedWithValue(responseData.asInternalExecutionPayload());
}

@Test
Expand All @@ -101,19 +105,19 @@ void engineForkChoiceUpdated_shouldCallEngineForkChoiceUpdatedV2() {
final ForkChoiceState forkChoiceState = dataStructureUtil.randomForkChoiceState(false);
final ForkChoiceStateV1 forkChoiceStateV1 =
ForkChoiceStateV1.fromInternalForkChoiceState(forkChoiceState);
final ForkChoiceUpdatedResult responseData =
new ForkChoiceUpdatedResult(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), ""),
dataStructureUtil.randomBytes8());
final SafeFuture<Response<ForkChoiceUpdatedResult>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
new ForkChoiceUpdatedResult(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), ""),
dataStructureUtil.randomBytes8())));
SafeFuture.completedFuture(new Response<>(responseData));
when(executionEngineClient.forkChoiceUpdatedV2(forkChoiceStateV1, Optional.empty()))
.thenReturn(dummyResponse);
final SafeFuture<tech.pegasys.teku.spec.executionlayer.ForkChoiceUpdatedResult> future =
handler.engineForkChoiceUpdated(forkChoiceState, Optional.empty());
verify(executionEngineClient).forkChoiceUpdatedV2(forkChoiceStateV1, Optional.empty());
assertThat(future).isCompleted();
assertThat(future).isCompletedWithValue(responseData.asInternalExecutionPayload());
}

@Test
Expand Down Expand Up @@ -141,18 +145,18 @@ void engineForkChoiceUpdatedBuildingBlockOnForkTransition_shouldCallEngineForkCh
capellaStartSlot.minusMinZero(1), dataStructureUtil.randomBytes32(), false);
final ForkChoiceStateV1 forkChoiceStateV1 =
ForkChoiceStateV1.fromInternalForkChoiceState(forkChoiceState);
final ForkChoiceUpdatedResult responseData =
new ForkChoiceUpdatedResult(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), ""),
dataStructureUtil.randomBytes8());
final SafeFuture<Response<ForkChoiceUpdatedResult>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
new ForkChoiceUpdatedResult(
new PayloadStatusV1(
ExecutionPayloadStatus.ACCEPTED, dataStructureUtil.randomBytes32(), ""),
dataStructureUtil.randomBytes8())));
SafeFuture.completedFuture(new Response<>(responseData));
when(executionEngineClient.forkChoiceUpdatedV2(forkChoiceStateV1, payloadAttributes))
.thenReturn(dummyResponse);
final SafeFuture<tech.pegasys.teku.spec.executionlayer.ForkChoiceUpdatedResult> future =
handler.engineForkChoiceUpdated(forkChoiceState, Optional.of(attributes));
verify(executionEngineClient).forkChoiceUpdatedV2(forkChoiceStateV1, payloadAttributes);
assertThat(future).isCompleted();
assertThat(future).isCompletedWithValue(responseData.asInternalExecutionPayload());
}
}
Loading

0 comments on commit 5074f31

Please sign in to comment.