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

7390 consensus block value #7574

Merged
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e28db67
add block v3 API
mehdi-aouadi Sep 19, 2023
43b37a7
Add execution payload value
mehdi-aouadi Sep 20, 2023
f0f210e
Add integration test (in progress)
mehdi-aouadi Sep 20, 2023
e50bd72
Override equals
mehdi-aouadi Sep 21, 2023
387002b
fix serialisation
mehdi-aouadi Sep 26, 2023
81b7959
remove duplicated schemas
mehdi-aouadi Sep 26, 2023
4d76d4a
keep schema deinitions order
mehdi-aouadi Sep 27, 2023
5cc0692
return blinded block for block v3
mehdi-aouadi Oct 2, 2023
f55c223
add execution payload value to the blinded flow
mehdi-aouadi Oct 3, 2023
851145a
refactor execution builder module
mehdi-aouadi Oct 17, 2023
ab9f0b4
add execution payload callback test
mehdi-aouadi Oct 24, 2023
3d8d0ce
add block v3 API
mehdi-aouadi Sep 19, 2023
21c735a
Add execution payload value
mehdi-aouadi Sep 20, 2023
0b65bfa
refactor tests
mehdi-aouadi Oct 23, 2023
e4ccbdf
add block v3 API
mehdi-aouadi Sep 19, 2023
2adb52d
Add execution payload value
mehdi-aouadi Sep 20, 2023
05ff9c5
fix serialisation
mehdi-aouadi Sep 26, 2023
2fd1c9d
remove duplicated schemas
mehdi-aouadi Sep 26, 2023
db8f41f
keep schema deinitions order
mehdi-aouadi Sep 27, 2023
cc71b05
add execution payload value to the blinded flow
mehdi-aouadi Oct 3, 2023
73a0866
rename data provider
mehdi-aouadi Oct 3, 2023
17cef58
Add consensus block value to block V3
mehdi-aouadi Oct 4, 2023
a39b192
update produce block request
mehdi-aouadi Oct 5, 2023
ffe7593
Merge branch 'master' into 7390-consensus-block-value
mehdi-aouadi Oct 26, 2023
2a3fd9f
refactor consensus block value
mehdi-aouadi Oct 31, 2023
570efea
handle exception when block reward calculation fails
mehdi-aouadi Oct 31, 2023
5791009
Merge branch 'master' into 7390-consensus-block-value
mehdi-aouadi Oct 31, 2023
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
2 changes: 1 addition & 1 deletion data/beaconrestapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ dependencies {
testImplementation testFixtures(project(':infrastructure:bls'))
testImplementation testFixtures(project(':infrastructure:restapi'))
testImplementation testFixtures(project(':infrastructure:time'))

testImplementation testFixtures(project(':infrastructure:json'))
testImplementation testFixtures(project(':infrastructure:logging'))

testCompileOnly 'io.libp2p:jvm-libp2p'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.junit.jupiter.api.AfterEach;
import tech.pegasys.teku.api.DataProvider;
import tech.pegasys.teku.api.ExecutionClientDataProvider;
import tech.pegasys.teku.api.RewardCalculator;
import tech.pegasys.teku.beacon.sync.SyncService;
import tech.pegasys.teku.bls.BLSKeyGenerator;
import tech.pegasys.teku.bls.BLSKeyPair;
Expand Down Expand Up @@ -134,6 +135,8 @@ public abstract class AbstractDataBackedRestAPIIntegrationTest {
protected final ExecutionLayerBlockProductionManager executionLayerBlockProductionManager =
mock(ExecutionLayerBlockProductionManager.class);

protected RewardCalculator rewardCalculator = mock(RewardCalculator.class);

protected OperationPool<SignedBlsToExecutionChange> blsToExecutionChangePool;

protected final SignedBlsToExecutionChangeValidator validator =
Expand Down Expand Up @@ -241,6 +244,7 @@ private void setupAndStartRestAPI(BeaconRestApiConfig config) {
.syncCommitteeContributionPool(syncCommitteeContributionPool)
.proposersDataManager(proposersDataManager)
.executionLayerBlockProductionManager(executionLayerBlockProductionManager)
.rewardCalculator(rewardCalculator)
.build();

beaconRestApi =
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.when;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_BLOCK_VALUE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_EXECUTION_PAYLOAD_BLINDED;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_EXECUTION_PAYLOAD_VALUE;
Expand All @@ -40,6 +41,7 @@
import org.apache.tuweni.units.bigints.UInt256;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import tech.pegasys.teku.api.migrated.BlockRewardData;
import tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest;
import tech.pegasys.teku.beaconrestapi.handlers.v3.validator.GetNewBlockV3;
import tech.pegasys.teku.bls.BLSSignature;
Expand All @@ -49,6 +51,7 @@
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecContext;
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider;
import tech.pegasys.teku.spec.constants.EthConstants;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlindedBlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContents;
Expand All @@ -62,22 +65,17 @@ public class GetNewBlockV3IntegrationTest extends AbstractDataBackedRestAPIInteg
private DataStructureUtil dataStructureUtil;
private SpecMilestone specMilestone;
private final UInt256 executionPayloadValue = UInt256.valueOf(12345);
private final UInt256 consensusBlockValue = UInt256.valueOf(123);

private final String consensusBlockValueWei =
EthConstants.GWEI_TO_WEI.multiply(consensusBlockValue).toDecimalString();

@BeforeEach
void setup(final TestSpecInvocationContextProvider.SpecContext specContext) {
spec = specContext.getSpec();
specMilestone = specContext.getSpecMilestone();
startRestAPIAtGenesis(specMilestone);
dataStructureUtil = new DataStructureUtil(spec);
}

@TestTemplate
void shouldGetUnBlindedBeaconBlockAsJson() throws IOException {
assumeThat(specMilestone).isLessThan(DENEB);
final BeaconBlock beaconBlock = dataStructureUtil.randomBeaconBlock(ONE);
final BLSSignature signature = beaconBlock.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(beaconBlock)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
Expand All @@ -87,14 +85,20 @@ void shouldGetUnBlindedBeaconBlockAsJson() throws IOException {
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
final BlockRewardData blockRewardDataMock = mock(BlockRewardData.class);
when(blockRewardDataMock.getTotal()).thenReturn(consensusBlockValue.toLong());
when(rewardCalculator.getBlockRewardData(any(), any())).thenReturn(blockRewardDataMock);
}

@TestTemplate
void shouldGetUnBlindedBeaconBlockAsJson() throws IOException {
assumeThat(specMilestone).isLessThan(DENEB);
final BeaconBlock beaconBlock = dataStructureUtil.randomBeaconBlock(ONE);
final BLSSignature signature = beaconBlock.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(beaconBlock)));
Response response = get(signature, ContentTypes.JSON);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED))
.isEqualTo(Boolean.toString(false));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, false);
final String body = response.body().string();
assertThat(body).isEqualTo(getExpectedBlockAsJson(specMilestone, false, false));
}
Expand All @@ -106,23 +110,8 @@ void shouldGetUnblindedBeaconBlockAsSsz() throws IOException {
final BLSSignature signature = beaconBlock.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(beaconBlock)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
new ExecutionPayloadResult(
mock(ExecutionPayloadContext.class),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
Response response = get(signature, ContentTypes.OCTET_STREAM);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED))
.isEqualTo(Boolean.toString(false));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, false);
final BeaconBlock result =
spec.getGenesisSchemaDefinitions()
.getBeaconBlockSchema()
Expand All @@ -137,22 +126,8 @@ void shouldGetBlindedBeaconBlockAsJson() throws IOException {
final BLSSignature signature = blindedBeaconBlock.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blindedBeaconBlock)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
new ExecutionPayloadResult(
mock(ExecutionPayloadContext.class),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
Response response = get(signature, ContentTypes.JSON);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED)).isEqualTo(Boolean.toString(true));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, true);
final String body = response.body().string();
assertThat(body).isEqualTo(getExpectedBlockAsJson(specMilestone, true, false));
}
Expand All @@ -164,22 +139,8 @@ void shouldGetBlindedBeaconBlockAsSsz() throws IOException {
final BLSSignature signature = blindedBeaconBlock.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blindedBeaconBlock)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
new ExecutionPayloadResult(
mock(ExecutionPayloadContext.class),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
Response response = get(signature, ContentTypes.OCTET_STREAM);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED)).isEqualTo(Boolean.toString(true));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, true);
final BeaconBlock result =
spec.getGenesisSchemaDefinitions()
.getBlindedBeaconBlockSchema()
Expand All @@ -194,23 +155,8 @@ void shouldGetUnBlindedBlockContentPostDenebAsJson() throws IOException {
final BLSSignature signature = blockContents.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blockContents)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
new ExecutionPayloadResult(
mock(ExecutionPayloadContext.class),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
Response response = get(signature, ContentTypes.JSON);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED))
.isEqualTo(Boolean.toString(false));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, false);
final String body = response.body().string();
assertThat(body).isEqualTo(getExpectedBlockAsJson(specMilestone, false, true));
}
Expand All @@ -222,23 +168,8 @@ void shouldGetUnBlindedBlockContentPostDenebAsSsz() throws IOException {
final BLSSignature signature = blockContents.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blockContents)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
new ExecutionPayloadResult(
mock(ExecutionPayloadContext.class),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
Response response = get(signature, ContentTypes.OCTET_STREAM);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED))
.isEqualTo(Boolean.toString(false));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, false);
final BlockContents result =
(BlockContents)
spec.getGenesisSchemaDefinitions()
Expand All @@ -255,22 +186,8 @@ void shouldGetBlindedBlockContentPostDenebAsJson() throws IOException {
final BLSSignature signature = blindedBlockContents.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blindedBlockContents)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
new ExecutionPayloadResult(
mock(ExecutionPayloadContext.class),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
Response response = get(signature, ContentTypes.JSON);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED)).isEqualTo(Boolean.toString(true));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, true);
final String body = response.body().string();
assertThat(body).isEqualTo(getExpectedBlockAsJson(specMilestone, true, true));
}
Expand All @@ -283,22 +200,8 @@ void shouldGetBlindedBlockContentPostDenebAsSsz() throws IOException {
final BLSSignature signature = blindedBlockContents.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blindedBlockContents)));
when(executionLayerBlockProductionManager.getCachedPayloadResult(UInt64.ONE))
.thenReturn(
Optional.of(
new ExecutionPayloadResult(
mock(ExecutionPayloadContext.class),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(SafeFuture.completedFuture(executionPayloadValue)))));
Response response = get(signature, ContentTypes.OCTET_STREAM);
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED)).isEqualTo(Boolean.toString(true));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertResponseWithHeaders(response, true);
final BlindedBlockContents result =
(BlindedBlockContents)
spec.getGenesisSchemaDefinitions()
Expand Down Expand Up @@ -378,4 +281,15 @@ private String getExpectedBlockAsJson(
return Resources.toString(
Resources.getResource(GetNewBlockV3IntegrationTest.class, fileName), UTF_8);
}

private void assertResponseWithHeaders(Response response, boolean blinded) {
assertThat(response.code()).isEqualTo(SC_OK);
assertThat(response.header(HEADER_CONSENSUS_VERSION))
.isEqualTo(specMilestone.name().toLowerCase(Locale.ROOT));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_BLINDED))
.isEqualTo(Boolean.toString(blinded));
assertThat(response.header(HEADER_EXECUTION_PAYLOAD_VALUE))
.isEqualTo(executionPayloadValue.toDecimalString());
assertThat(response.header(HEADER_CONSENSUS_BLOCK_VALUE)).isEqualTo(consensusBlockValueWei);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "ProduceBlockV3Response",
"type" : "object",
"required" : [ "version", "execution_payload_blinded", "execution_payload_value", "data" ],
"required" : [ "version", "execution_payload_blinded", "execution_payload_value", "consensus_block_value", "data" ],
"properties" : {
"version" : {
"type" : "string",
Expand All @@ -16,6 +16,12 @@
"example" : "1",
"format" : "uint256"
},
"consensus_block_value" : {
"type" : "string",
"description" : "unsigned 256 bit integer",
"example" : "1",
"format" : "uint256"
},
"data" : {
"title" : "Block",
"type" : "object",
Expand Down
Loading
Loading