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

[MEV Boost\Builder] execution builder client part 3 #5429

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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
Expand All @@ -33,6 +32,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockUnblinder;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
Expand Down Expand Up @@ -155,9 +155,9 @@ public Consumer<BeaconBlockBodyBuilder> createSelector(
spec.atSlot(blockSlotState.getSlot()).getSchemaDefinitions())
.getExecutionPayloadHeaderSchema()
.getHeaderOfDefaultPayload(),
(payloadId) ->
(executionPayloadContext) ->
executionLayerChannel
.getPayloadHeader(payloadId, blockSlotState.getSlot())
.builderGetHeader(executionPayloadContext, blockSlotState.getSlot())
.join()));
return;
}
Expand All @@ -184,9 +184,9 @@ public Consumer<BeaconBlockBodyBuilder> createSelector(
spec.atSlot(blockSlotState.getSlot()).getSchemaDefinitions())
.getExecutionPayloadSchema()
.getDefault(),
(payloadId) ->
(executionPayloadContext) ->
executionLayerChannel
.engineGetPayload(payloadId, blockSlotState.getSlot())
.engineGetPayload(executionPayloadContext, blockSlotState.getSlot())
.join()));
};
}
Expand All @@ -195,7 +195,7 @@ private <T> Supplier<T> payloadProvider(
final Bytes32 parentRoot,
final BeaconState blockSlotState,
Supplier<T> defaultSupplier,
Function<Bytes8, T> supplier) {
Function<ExecutionPayloadContext, T> supplier) {
return () ->
forkChoiceNotifier
.getPayloadId(parentRoot, blockSlotState.getSlot())
Expand Down Expand Up @@ -237,7 +237,7 @@ public Consumer<SignedBeaconBlockUnblinder> createUnblinderSelector() {
} else {
bodyUnblinder.setExecutionPayloadSupplier(
() ->
executionLayerChannel.proposeBlindedBlock(
executionLayerChannel.builderGetPayload(
bodyUnblinder.getSignedBlindedBeaconBlock()));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
Expand Down Expand Up @@ -320,10 +319,12 @@ private BeaconBlock assertBlockCreated(
when(voluntaryExitPool.getItemsForBlock(any(), any(), any())).thenReturn(voluntaryExits);
when(eth1DataCache.getEth1Vote(any())).thenReturn(ETH1_DATA);
when(forkChoiceNotifier.getPayloadId(any(), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(Bytes8.fromHexStringLenient("0x0"))));
.thenReturn(
SafeFuture.completedFuture(
Optional.of(dataStructureUtil.createPayloadExecutionContext(false))));
when(executionLayer.engineGetPayload(any(), any()))
.thenReturn(SafeFuture.completedFuture(executionPayload));
when(executionLayer.getPayloadHeader(any(), any()))
when(executionLayer.builderGetHeader(any(), any()))
.thenReturn(SafeFuture.completedFuture(executionPayloadHeader));
beaconChainUtil.initializeStorage();

Expand Down Expand Up @@ -366,7 +367,7 @@ private SignedBeaconBlock assertBlockUnblinded(
final SignedBeaconBlock beaconBlock, final Spec spec, final boolean isMevBoostEnabled) {
final BlockFactory blockFactory = createBlockFactory(spec, isMevBoostEnabled);

when(executionLayer.proposeBlindedBlock(beaconBlock))
when(executionLayer.builderGetPayload(beaconBlock))
.thenReturn(SafeFuture.completedFuture(executionPayload));

final SignedBeaconBlock block =
Expand All @@ -375,7 +376,7 @@ private SignedBeaconBlock assertBlockUnblinded(
if (!beaconBlock.getMessage().getBody().isBlinded()) {
verifyNoInteractions(executionLayer);
} else {
verify(executionLayer).proposeBlindedBlock(beaconBlock);
verify(executionLayer).builderGetPayload(beaconBlock);
}

assertThat(block).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem;
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.SszList;
Expand All @@ -45,6 +44,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.common.AbstractSignedBeaconBlockUnblinder;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
Expand Down Expand Up @@ -304,12 +304,13 @@ void shouldIncludeNonDefaultExecutionPayload() {
final UInt64 slot = UInt64.ONE;
final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(slot);

final Bytes8 payloadId = dataStructureUtil.randomBytes8();
final ExecutionPayloadContext executionPayloadContext =
dataStructureUtil.createPayloadExecutionContext(false);
final ExecutionPayload randomExecutionPayload = dataStructureUtil.randomExecutionPayload();

when(forkChoiceNotifier.getPayloadId(any(), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(payloadId)));
when(executionLayer.engineGetPayload(payloadId, slot))
.thenReturn(SafeFuture.completedFuture(Optional.of(executionPayloadContext)));
when(executionLayer.engineGetPayload(executionPayloadContext, slot))
.thenReturn(SafeFuture.completedFuture(randomExecutionPayload));

factory
Expand All @@ -325,13 +326,14 @@ void shouldIncludeExecutionPayloadHeaderIfMevBoostEnabledAndBlindedBlockRequeste
final UInt64 slot = UInt64.ONE;
final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(slot);

final Bytes8 payloadId = dataStructureUtil.randomBytes8();
final ExecutionPayloadContext executionPayloadContext =
dataStructureUtil.createPayloadExecutionContext(false);
final ExecutionPayloadHeader randomExecutionPayloadHeader =
dataStructureUtil.randomExecutionPayloadHeader();

when(forkChoiceNotifier.getPayloadId(any(), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(payloadId)));
when(executionLayer.getPayloadHeader(payloadId, slot))
.thenReturn(SafeFuture.completedFuture(Optional.of(executionPayloadContext)));
when(executionLayer.builderGetHeader(executionPayloadContext, slot))
.thenReturn(SafeFuture.completedFuture(randomExecutionPayloadHeader));

factoryWithMevBoost
Expand All @@ -347,12 +349,13 @@ void shouldIncludeExecutionPayloadIfMevBoostEnabledButNoBlindedBlockRequested()
final UInt64 slot = UInt64.ONE;
final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(slot);

final Bytes8 payloadId = dataStructureUtil.randomBytes8();
final ExecutionPayloadContext executionPayloadContext =
dataStructureUtil.createPayloadExecutionContext(false);
final ExecutionPayload randomExecutionPayload = dataStructureUtil.randomExecutionPayload();

when(forkChoiceNotifier.getPayloadId(any(), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(payloadId)));
when(executionLayer.engineGetPayload(payloadId, slot))
.thenReturn(SafeFuture.completedFuture(Optional.of(executionPayloadContext)));
when(executionLayer.engineGetPayload(executionPayloadContext, slot))
.thenReturn(SafeFuture.completedFuture(randomExecutionPayload));

factoryWithMevBoost
Expand All @@ -370,7 +373,7 @@ void shouldUnblindSignedBlindedBeaconBlockIfMevBoostEnabled() {
final CapturingBeaconBlockUnblinder blockUnblinder =
new CapturingBeaconBlockUnblinder(spec.getGenesisSchemaDefinitions(), blindedSignedBlock);

when(executionLayer.proposeBlindedBlock(blindedSignedBlock))
when(executionLayer.builderGetPayload(blindedSignedBlock))
.thenReturn(SafeFuture.completedFuture(randomExecutionPayload));

factoryWithMevBoost.createUnblinderSelector().accept(blockUnblinder);
Expand All @@ -385,7 +388,7 @@ void shouldThrowUnblindSignedBlindedBeaconBlockIfMevBoostDisabled() {
final CapturingBeaconBlockUnblinder blockUnblinder =
new CapturingBeaconBlockUnblinder(spec.getGenesisSchemaDefinitions(), blindedSignedBlock);

when(executionLayer.proposeBlindedBlock(blindedSignedBlock))
when(executionLayer.builderGetPayload(blindedSignedBlock))
.thenReturn(SafeFuture.completedFuture(randomExecutionPayload));

assertThatThrownBy(() -> factory.createUnblinderSelector().accept(blockUnblinder))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadHeaderV1;
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 @@ -25,7 +24,6 @@
import tech.pegasys.teku.ethereum.executionclient.schema.TransitionConfigurationV1;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.execution.PowBlock;

public interface ExecutionEngineClient {
Expand All @@ -44,10 +42,4 @@ SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdated(

SafeFuture<Response<TransitionConfigurationV1>> exchangeTransitionConfiguration(
TransitionConfigurationV1 transitionConfiguration);

// builder namespace
SafeFuture<Response<ExecutionPayloadHeaderV1>> getPayloadHeader(Bytes8 payloadId);

SafeFuture<Response<ExecutionPayloadV1>> proposeBlindedBlock(
SignedBeaconBlock signedBlindedBeaconBlock);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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.ExecutionPayloadHeaderV1;
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 @@ -28,7 +27,6 @@
import tech.pegasys.teku.infrastructure.async.ThrottlingTaskQueue;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.execution.PowBlock;

public class ThrottlingExecutionEngineClient implements ExecutionEngineClient {
Expand Down Expand Up @@ -83,15 +81,4 @@ public SafeFuture<Response<TransitionConfigurationV1>> exchangeTransitionConfigu
return taskQueue.queueTask(
() -> delegate.exchangeTransitionConfiguration(transitionConfiguration));
}

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

@Override
public SafeFuture<Response<ExecutionPayloadV1>> proposeBlindedBlock(
final SignedBeaconBlock signedBlindedBeaconBlock) {
return taskQueue.queueTask(() -> delegate.proposeBlindedBlock(signedBlindedBeaconBlock));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.response.EthBlock;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadHeaderV1;
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 @@ -36,7 +35,6 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.execution.PowBlock;

public class Web3JExecutionEngineClient implements ExecutionEngineClient {
Expand Down Expand Up @@ -127,33 +125,6 @@ public SafeFuture<Response<TransitionConfigurationV1>> exchangeTransitionConfigu
return web3JClient.doRequest(web3jRequest, NON_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<ExecutionPayloadHeaderV1>> getPayloadHeader(Bytes8 payloadId) {
Request<?, ExecutionPayloadHeaderV1Web3jResponse> web3jRequest =
new Request<>(
"builder_getPayloadHeaderV1",
Collections.singletonList(payloadId.toHexString()),
web3JClient.getWeb3jService(),
ExecutionPayloadHeaderV1Web3jResponse.class);
return web3JClient.doRequest(web3jRequest, NON_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<ExecutionPayloadV1>> proposeBlindedBlock(
SignedBeaconBlock signedBlindedBeaconBlock) {
Request<?, ExecutionPayloadV1Web3jResponse> web3jRequest =
new Request<>(
"builder_proposeBlindedBlockV1",
Collections.singletonList(signedBlindedBeaconBlock),
web3JClient.getWeb3jService(),
ExecutionPayloadV1Web3jResponse.class);
return web3JClient.doRequest(web3jRequest, NON_EXECUTION_TIMEOUT);
}

protected Web3JClient getWeb3JClient() {
return web3JClient;
}

static class ExecutionPayloadV1Web3jResponse
extends org.web3j.protocol.core.Response<ExecutionPayloadV1> {}

Expand All @@ -166,9 +137,6 @@ static class ForkChoiceUpdatedResultWeb3jResponse
static class TransitionConfigurationV1Web3jResponse
extends org.web3j.protocol.core.Response<TransitionConfigurationV1> {}

static class ExecutionPayloadHeaderV1Web3jResponse
extends org.web3j.protocol.core.Response<ExecutionPayloadHeaderV1> {}

/**
* Returns a list that supports null items.
*
Expand Down
Loading