Skip to content

Commit

Permalink
Move statics in GetProposerDuties to SharedApiTypes (Consensys#7912)
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh authored Jan 25, 2024
1 parent 2271309 commit 55b68e2
Show file tree
Hide file tree
Showing 27 changed files with 244 additions and 129 deletions.
1 change: 1 addition & 0 deletions beacon/validator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation project(':infrastructure:events')
implementation project(':infrastructure:exceptions')
implementation project(':infrastructure:metrics')
implementation project(':ethereum:json-types')

implementation 'it.unimi.dsi:fastutil'
implementation 'org.apache.tuweni:tuweni-bytes'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import tech.pegasys.teku.beacon.sync.events.SyncStateProvider;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuty;
import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionPerformance;
import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionPerformanceFactory;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand Down Expand Up @@ -90,8 +92,6 @@
import tech.pegasys.teku.validator.api.AttesterDuties;
import tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest;
import tech.pegasys.teku.validator.api.NodeSyncingException;
import tech.pegasys.teku.validator.api.ProposerDuties;
import tech.pegasys.teku.validator.api.ProposerDuty;
import tech.pegasys.teku.validator.api.SendSignedBlockResult;
import tech.pegasys.teku.validator.api.SubmitDataError;
import tech.pegasys.teku.validator.api.SyncCommitteeDuties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import tech.pegasys.teku.beacon.sync.events.SyncStateProvider;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuty;
import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionPerformance;
import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionPerformanceFactory;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand Down Expand Up @@ -124,8 +126,6 @@
import tech.pegasys.teku.validator.api.AttesterDuty;
import tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest;
import tech.pegasys.teku.validator.api.NodeSyncingException;
import tech.pegasys.teku.validator.api.ProposerDuties;
import tech.pegasys.teku.validator.api.ProposerDuty;
import tech.pegasys.teku.validator.api.SendSignedBlockResult;
import tech.pegasys.teku.validator.api.SubmitDataError;
import tech.pegasys.teku.validator.api.SyncCommitteeDuties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package tech.pegasys.teku.beaconrestapi.handlers.v1.beacon;

import static tech.pegasys.teku.ethereum.json.types.SharedApiTypes.GET_GENESIS_API_DATA_TYPE;
import static tech.pegasys.teku.ethereum.json.types.beacon.GetGenesisApiDataBuilder.GET_GENESIS_API_DATA_TYPE;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_FOUND;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON;
Expand All @@ -23,7 +23,7 @@
import java.util.Optional;
import tech.pegasys.teku.api.ChainDataProvider;
import tech.pegasys.teku.api.DataProvider;
import tech.pegasys.teku.ethereum.json.types.wrappers.GetGenesisApiData;
import tech.pegasys.teku.ethereum.json.types.beacon.GetGenesisApiData;
import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata;
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint;
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,30 @@
package tech.pegasys.teku.beaconrestapi.handlers.v1.validator;

import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.EPOCH_PARAMETER;
import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.PUBLIC_KEY_TYPE;
import static tech.pegasys.teku.ethereum.json.types.validator.ProposerDutiesBuilder.PROPOSER_DUTIES_TYPE;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_SERVICE_UNAVAILABLE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EXECUTION_OPTIMISTIC;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.SERVICE_UNAVAILABLE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_VALIDATOR;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_VALIDATOR_REQUIRED;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BOOLEAN_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BYTES32_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.HTTP_ERROR_RESPONSE_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.INTEGER_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.UINT64_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition.listOf;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.Optional;
import tech.pegasys.teku.api.DataProvider;
import tech.pegasys.teku.api.SyncDataProvider;
import tech.pegasys.teku.api.ValidatorDataProvider;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition;
import tech.pegasys.teku.infrastructure.restapi.endpoints.AsyncApiResponse;
import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata;
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint;
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.validator.api.ProposerDuties;
import tech.pegasys.teku.validator.api.ProposerDuty;

public class GetProposerDuties extends RestApiEndpoint {
public static final String ROUTE = "/eth/v1/validator/duties/proposer/{epoch}";

private static final SerializableTypeDefinition<ProposerDuty> PROPOSER_DUTY_TYPE =
SerializableTypeDefinition.object(ProposerDuty.class)
.withField("pubkey", PUBLIC_KEY_TYPE, ProposerDuty::getPublicKey)
.withField("validator_index", INTEGER_TYPE, ProposerDuty::getValidatorIndex)
.withField("slot", UINT64_TYPE, ProposerDuty::getSlot)
.build();

private static final SerializableTypeDefinition<ProposerDuties> RESPONSE_TYPE =
SerializableTypeDefinition.object(ProposerDuties.class)
.name("GetProposerDutiesResponse")
.withField("dependent_root", BYTES32_TYPE, ProposerDuties::getDependentRoot)
.withField(EXECUTION_OPTIMISTIC, BOOLEAN_TYPE, ProposerDuties::isExecutionOptimistic)
.withField("data", listOf(PROPOSER_DUTY_TYPE), ProposerDuties::getDuties)
.build();

private final ValidatorDataProvider validatorDataProvider;
private final SyncDataProvider syncDataProvider;

Expand All @@ -86,7 +63,7 @@ public GetProposerDuties(final DataProvider dataProvider) {
+ "or the genesis block root in the case of underflow.")
.tags(TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED)
.pathParam(EPOCH_PARAMETER)
.response(SC_OK, "Request successful", RESPONSE_TYPE)
.response(SC_OK, "Request successful", PROPOSER_DUTIES_TYPE)
.response(SC_SERVICE_UNAVAILABLE, "Service unavailable", HTTP_ERROR_RESPONSE_TYPE)
.build());
this.validatorDataProvider = validatorDataProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.beaconrestapi.AbstractMigratedBeaconHandlerWithChainDataProviderTest;
import tech.pegasys.teku.ethereum.json.types.wrappers.GetGenesisApiData;
import tech.pegasys.teku.ethereum.json.types.beacon.GetGenesisApiData;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.SpecMilestone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
import tech.pegasys.teku.beacon.sync.events.SyncState;
import tech.pegasys.teku.beaconrestapi.AbstractMigratedBeaconHandlerTest;
import tech.pegasys.teku.bls.BLSTestUtil;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuty;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.http.HttpErrorResponse;
import tech.pegasys.teku.infrastructure.http.HttpStatusCodes;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.validator.api.ProposerDuties;
import tech.pegasys.teku.validator.api.ProposerDuty;

public class GetProposerDutiesTest extends AbstractMigratedBeaconHandlerTest {
private final ProposerDuties duties =
Expand Down
2 changes: 2 additions & 0 deletions data/provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies {
implementation project(':beacon:sync')
implementation project(':validator:api')

implementation project(':ethereum:json-types')

implementation 'org.apache.tuweni:tuweni-units'

testImplementation testFixtures(project(':ethereum:spec'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import tech.pegasys.teku.api.schema.deneb.SignedBlindedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand Down Expand Up @@ -66,7 +67,6 @@
import tech.pegasys.teku.storage.client.CombinedChainDataClient;
import tech.pegasys.teku.validator.api.AttesterDuties;
import tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest;
import tech.pegasys.teku.validator.api.ProposerDuties;
import tech.pegasys.teku.validator.api.SendSignedBlockResult;
import tech.pegasys.teku.validator.api.SubmitDataError;
import tech.pegasys.teku.validator.api.SyncCommitteeDuties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,17 @@

package tech.pegasys.teku.ethereum.json.types;

import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BYTES32_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BYTES4_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.UINT64_TYPE;

import java.util.Optional;
import java.util.function.Function;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.ethereum.json.types.wrappers.GetGenesisApiData;
import tech.pegasys.teku.ethereum.json.types.wrappers.GetGenesisApiData.GetGenesisApiDataBuilder;
import tech.pegasys.teku.infrastructure.json.types.DeserializableObjectTypeDefinitionBuilder;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.StringValueTypeDefinition;
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;

public class SharedApiTypes {

public static final DeserializableTypeDefinition<GetGenesisApiData> GET_GENESIS_API_DATA_TYPE =
withDataWrapper(
"GetGenesisResponse",
DeserializableTypeDefinition.object(
GetGenesisApiData.class, GetGenesisApiDataBuilder.class)
.initializer(GetGenesisApiDataBuilder::new)
.finisher(GetGenesisApiDataBuilder::build)
.withField(
"genesis_time",
UINT64_TYPE,
GetGenesisApiData::getGenesisTime,
GetGenesisApiDataBuilder::genesisTime)
.withField(
"genesis_validators_root",
BYTES32_TYPE,
GetGenesisApiData::getGenesisValidatorsRoot,
GetGenesisApiDataBuilder::genesisValidatorsRoot)
.withField(
"genesis_fork_version",
BYTES4_TYPE,
GetGenesisApiData::getGenesisForkVersion,
GetGenesisApiDataBuilder::genesisForkVersion)
.build());

public static final StringValueTypeDefinition<BLSPublicKey> PUBKEY_API_TYPE =
DeserializableTypeDefinition.string(BLSPublicKey.class)
.name("Pubkey")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.ethereum.json.types.wrappers;
package tech.pegasys.teku.ethereum.json.types.beacon;

import com.google.common.base.MoreObjects;
import java.util.Objects;
Expand All @@ -20,7 +20,6 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class GetGenesisApiData {

private final UInt64 genesisTime;
private final Bytes32 genesisValidatorsRoot;
private final Bytes4 genesisForkVersion;
Expand Down Expand Up @@ -73,30 +72,4 @@ public String toString() {
.add("genesisForkVersion", genesisForkVersion)
.toString();
}

public static final class GetGenesisApiDataBuilder {

private UInt64 genesisTime;
private Bytes32 genesisValidatorsRoot;
private Bytes4 genesisForkVersion;

public GetGenesisApiDataBuilder genesisTime(UInt64 genesisTime) {
this.genesisTime = genesisTime;
return this;
}

public GetGenesisApiDataBuilder genesisValidatorsRoot(Bytes32 genesisValidatorsRoot) {
this.genesisValidatorsRoot = genesisValidatorsRoot;
return this;
}

public GetGenesisApiDataBuilder genesisForkVersion(Bytes4 genesisForkVersion) {
this.genesisForkVersion = genesisForkVersion;
return this;
}

public GetGenesisApiData build() {
return new GetGenesisApiData(genesisTime, genesisValidatorsRoot, genesisForkVersion);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright Consensys Software Inc., 2024
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.ethereum.json.types.beacon;

import static tech.pegasys.teku.ethereum.json.types.SharedApiTypes.withDataWrapper;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BYTES32_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BYTES4_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.UINT64_TYPE;

import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class GetGenesisApiDataBuilder {
public static final DeserializableTypeDefinition<GetGenesisApiData> GET_GENESIS_API_DATA_TYPE =
withDataWrapper(
"GetGenesisResponse",
DeserializableTypeDefinition.object(
GetGenesisApiData.class, GetGenesisApiDataBuilder.class)
.initializer(GetGenesisApiDataBuilder::new)
.finisher(GetGenesisApiDataBuilder::build)
.withField(
"genesis_time",
UINT64_TYPE,
GetGenesisApiData::getGenesisTime,
GetGenesisApiDataBuilder::genesisTime)
.withField(
"genesis_validators_root",
BYTES32_TYPE,
GetGenesisApiData::getGenesisValidatorsRoot,
GetGenesisApiDataBuilder::genesisValidatorsRoot)
.withField(
"genesis_fork_version",
BYTES4_TYPE,
GetGenesisApiData::getGenesisForkVersion,
GetGenesisApiDataBuilder::genesisForkVersion)
.build());

private UInt64 genesisTime;
private Bytes32 genesisValidatorsRoot;
private Bytes4 genesisForkVersion;

public GetGenesisApiDataBuilder genesisTime(UInt64 genesisTime) {
this.genesisTime = genesisTime;
return this;
}

public GetGenesisApiDataBuilder genesisValidatorsRoot(Bytes32 genesisValidatorsRoot) {
this.genesisValidatorsRoot = genesisValidatorsRoot;
return this;
}

public GetGenesisApiDataBuilder genesisForkVersion(Bytes4 genesisForkVersion) {
this.genesisForkVersion = genesisForkVersion;
return this;
}

public GetGenesisApiData build() {
return new GetGenesisApiData(genesisTime, genesisValidatorsRoot, genesisForkVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.validator.api;
package tech.pegasys.teku.ethereum.json.types.validator;

import com.google.common.base.MoreObjects;
import java.util.List;
Expand All @@ -20,7 +20,6 @@

public class ProposerDuties {
private final Bytes32 dependentRoot;

private final boolean executionOptimistic;
private final List<ProposerDuty> duties;

Expand All @@ -29,22 +28,22 @@ public ProposerDuties(
final List<ProposerDuty> duties,
final boolean executionOptimistic) {
this.dependentRoot = dependentRoot;
this.duties = duties;
this.executionOptimistic = executionOptimistic;
this.duties = duties;
}

public Bytes32 getDependentRoot() {
return dependentRoot;
}

public List<ProposerDuty> getDuties() {
return duties;
}

public boolean isExecutionOptimistic() {
return executionOptimistic;
}

public List<ProposerDuty> getDuties() {
return duties;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down
Loading

0 comments on commit 55b68e2

Please sign in to comment.