Skip to content

Commit

Permalink
update produce block request
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Oct 26, 2023
1 parent 17cef58 commit a39b192
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public abstract class AbstractDataBackedRestAPIIntegrationTest {
protected final ExecutionLayerBlockProductionManager executionLayerBlockProductionManager =
mock(ExecutionLayerBlockProductionManager.class);

protected final RewardCalculator rewardCalculator = mock(RewardCalculator.class);
protected RewardCalculator rewardCalculator = mock(RewardCalculator.class);

protected OperationPool<SignedBlsToExecutionChange> blsToExecutionChangePool;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import okhttp3.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.api.RewardCalculator;
import tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest;
import tech.pegasys.teku.beaconrestapi.handlers.v1.rewards.GetBlockRewards;
import tech.pegasys.teku.infrastructure.json.JsonTestUtil;
Expand All @@ -37,6 +38,7 @@ public class GetBlockRewardsIntegrationTest extends AbstractDataBackedRestAPIInt
@BeforeEach
public void setup() {
spec = TestSpecFactory.createMinimalAltair();
rewardCalculator = new RewardCalculator(spec);
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
startRestAPIAtGenesis(SpecMilestone.ALTAIR);
chainBuilder.generateBlocksUpToSlot(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import okhttp3.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.api.RewardCalculator;
import tech.pegasys.teku.api.migrated.SyncCommitteeRewardData;
import tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest;
import tech.pegasys.teku.beaconrestapi.handlers.v1.rewards.GetSyncCommitteeRewards;
Expand All @@ -46,6 +47,7 @@ public class GetSyncCommitteeRewardsIntegrationTest
@BeforeEach
public void setup() {
spec = TestSpecFactory.createMinimalAltair();
rewardCalculator = new RewardCalculator(spec);
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
startRestAPIAtGenesis(SpecMilestone.ALTAIR);
final SyncAggregate syncAggregate =
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,21 @@ public RewardCalculator(Spec spec) {

ObjectAndMetaData<BlockRewardData> getBlockRewardData(
final BlockAndMetaData blockAndMetaData, final BeaconState parentState) {
final BeaconBlock block = blockAndMetaData.getData().getMessage();
if (!spec.atSlot(block.getSlot()).getMilestone().isGreaterThanOrEqualTo(SpecMilestone.ALTAIR)) {
throw new BadRequestException(
"Slot "
+ block.getSlot()
+ " is pre altair, and no sync committee information is available");
}

final BeaconState preState = getPreState(block.getSlot(), parentState);

final SpecVersion specVersion = spec.atSlot(preState.getSlot());
return blockAndMetaData.map(
__ -> getBlockRewardData(blockAndMetaData.getData().getMessage(), parentState));
__ ->
calculateBlockRewards(
block, BlockProcessorAltair.required(specVersion.getBlockProcessor()), preState));
}

public BlockRewardData getBlockRewardData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,16 @@ public SafeFuture<Optional<BlockContainerAndMetaData<BlockContainer>>> produceBl

private SafeFuture<Optional<BlockContainerAndMetaData<BlockContainer>>> lookUpBlockValues(
Optional<BlockContainer> maybeBlockContainer) {
final BlockContainer blockContainer = maybeBlockContainer.orElseThrow();
return retrieveExecutionPayloadValue(blockContainer.getSlot())
.thenCombine(
retrieveConsensusBlockRewards(blockContainer),
(executionPayloadValue, consensusBlockValue) ->
addMetaData(maybeBlockContainer, executionPayloadValue, consensusBlockValue));
return maybeBlockContainer
.map(
blockContainer ->
retrieveExecutionPayloadValue(maybeBlockContainer.get().getSlot())
.thenCombine(
retrieveConsensusBlockRewards(maybeBlockContainer.get()),
(executionPayloadValue, consensusBlockValue) ->
addMetaData(
maybeBlockContainer, executionPayloadValue, consensusBlockValue)))
.orElse(SafeFuture.completedFuture(Optional.empty()));
}

private Optional<BlockContainerAndMetaData<BlockContainer>> addMetaData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public void getStateSyncCommittees_shouldReturnEmptyListBeforeAltair() {
@Test
public void getSyncCommitteeRewardsFromBlockId_slotIsPreAltair() {
final ChainDataProvider provider =
new ChainDataProvider(spec, recentChainData, combinedChainDataClient, rewardCalculatorMock);
new ChainDataProvider(
spec, recentChainData, combinedChainDataClient, new RewardCalculator(spec));
final SafeFuture<Optional<SyncCommitteeRewardData>> future =
provider.getSyncCommitteeRewardsFromBlockId("head", Set.of());
assertThat(future).isCompletedExceptionally();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ private ExecutionPayloadResult builderGetHeader(
.builderGetHeader(executionPayloadContext, state, executionPayloadValueFuture)
.whenException(executionPayloadValueFuture::completeExceptionally);

final SafeFuture<GetPayloadResponse> getPayloadResponseFuture =
executionLayerChannel.engineGetPayload(executionPayloadContext, state.getSlot());

final SafeFuture<UInt256> executionPayloadValueFuture =
getPayloadResponseFuture.thenApply(GetPayloadResponse::getExecutionPayloadValue);

return new ExecutionPayloadResult(
executionPayloadContext,
Optional.empty(),
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.validator.remote.typedef.handlers;

import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.CONSENSUS_BLOCK_VALUE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EXECUTION_PAYLOAD_BLINDED;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EXECUTION_PAYLOAD_VALUE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_EXECUTION_PAYLOAD_BLINDED;
Expand Down Expand Up @@ -153,6 +154,11 @@ private DeserializableTypeDefinition<ProduceBlockResponse> buildDeserializableTy
UINT256_TYPE,
ProduceBlockResponse::getExecutionPayloadValue,
ProduceBlockResponse::setExecutionPayloadValue)
.withField(
CONSENSUS_BLOCK_VALUE,
UINT256_TYPE,
ProduceBlockResponse::getConsensusBlockValue,
ProduceBlockResponse::setConsensusBlockValue)
.withField(
"data",
jsonTypeDefinition,
Expand All @@ -170,6 +176,7 @@ static class ProduceBlockResponse {
private BlockContainer data;
private Boolean executionPayloadBlinded;
private UInt256 executionPayloadValue;
private UInt256 consensusBlockValue;
private SpecMilestone specMilestone;

public ProduceBlockResponse() {}
Expand All @@ -194,6 +201,14 @@ public void setExecutionPayloadBlinded(Boolean executionPayloadBlinded) {
this.executionPayloadBlinded = executionPayloadBlinded;
}

public UInt256 getConsensusBlockValue() {
return consensusBlockValue;
}

public void setConsensusBlockValue(UInt256 consensusBlockValue) {
this.consensusBlockValue = consensusBlockValue;
}

public UInt256 getExecutionPayloadValue() {
return executionPayloadValue;
}
Expand Down

0 comments on commit a39b192

Please sign in to comment.