diff --git a/beacon/validator/build.gradle b/beacon/validator/build.gradle index 85900b1d196..813a244f9f4 100644 --- a/beacon/validator/build.gradle +++ b/beacon/validator/build.gradle @@ -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' diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java index 344594dc2bc..593eabbb42e 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java @@ -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; @@ -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; diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandlerTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandlerTest.java index 460d1cd5ac9..faf25e85b6b 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandlerTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandlerTest.java @@ -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; @@ -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; diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesis.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesis.java index 8b1e648df91..06e155f08de 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesis.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesis.java @@ -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; @@ -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; diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDuties.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDuties.java index d18f8668525..6ef14703b80 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDuties.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDuties.java @@ -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 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 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; @@ -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; diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesisTest.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesisTest.java index f9b7013b423..119753f8009 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesisTest.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetGenesisTest.java @@ -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; diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDutiesTest.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDutiesTest.java index f06d34ddbdd..07ccea7eb37 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDutiesTest.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/GetProposerDutiesTest.java @@ -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 = diff --git a/data/provider/build.gradle b/data/provider/build.gradle index ae3ad5306a2..1341dc3a1e6 100644 --- a/data/provider/build.gradle +++ b/data/provider/build.gradle @@ -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')) diff --git a/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java b/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java index 986b21d2a30..6c99e7a74c9 100644 --- a/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java +++ b/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java @@ -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; @@ -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; diff --git a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/SharedApiTypes.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/SharedApiTypes.java index 20bbf1b27f3..5c8abe6df79 100644 --- a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/SharedApiTypes.java +++ b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/SharedApiTypes.java @@ -13,16 +13,10 @@ 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; @@ -30,31 +24,6 @@ import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema; public class SharedApiTypes { - - public static final DeserializableTypeDefinition 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 PUBKEY_API_TYPE = DeserializableTypeDefinition.string(BLSPublicKey.class) .name("Pubkey") diff --git a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/wrappers/GetGenesisApiData.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/beacon/GetGenesisApiData.java similarity index 73% rename from ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/wrappers/GetGenesisApiData.java rename to ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/beacon/GetGenesisApiData.java index 263e9b8a53c..b3fc2ef7071 100644 --- a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/wrappers/GetGenesisApiData.java +++ b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/beacon/GetGenesisApiData.java @@ -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; @@ -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; @@ -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); - } - } } diff --git a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/beacon/GetGenesisApiDataBuilder.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/beacon/GetGenesisApiDataBuilder.java new file mode 100644 index 00000000000..f954031104e --- /dev/null +++ b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/beacon/GetGenesisApiDataBuilder.java @@ -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 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); + } +} diff --git a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ProposerDuties.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDuties.java similarity index 97% rename from validator/api/src/main/java/tech/pegasys/teku/validator/api/ProposerDuties.java rename to ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDuties.java index e951527db5a..5954d95387a 100644 --- a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ProposerDuties.java +++ b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDuties.java @@ -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; @@ -20,7 +20,6 @@ public class ProposerDuties { private final Bytes32 dependentRoot; - private final boolean executionOptimistic; private final List duties; @@ -29,22 +28,22 @@ public ProposerDuties( final List duties, final boolean executionOptimistic) { this.dependentRoot = dependentRoot; - this.duties = duties; this.executionOptimistic = executionOptimistic; + this.duties = duties; } public Bytes32 getDependentRoot() { return dependentRoot; } - public List getDuties() { - return duties; - } - public boolean isExecutionOptimistic() { return executionOptimistic; } + public List getDuties() { + return duties; + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDutiesBuilder.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDutiesBuilder.java new file mode 100644 index 00000000000..479387d0816 --- /dev/null +++ b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDutiesBuilder.java @@ -0,0 +1,71 @@ +/* + * 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.validator; + +import static tech.pegasys.teku.ethereum.json.types.validator.ProposerDutyBuilder.PROPOSER_DUTY_TYPE; +import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EXECUTION_OPTIMISTIC; +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.DeserializableTypeDefinition.listOf; + +import java.util.List; +import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition; + +public class ProposerDutiesBuilder { + public static final DeserializableTypeDefinition PROPOSER_DUTIES_TYPE = + DeserializableTypeDefinition.object(ProposerDuties.class, ProposerDutiesBuilder.class) + .name("GetProposerDutiesResponse") + .initializer(ProposerDutiesBuilder::new) + .finisher(ProposerDutiesBuilder::build) + .withField( + "dependent_root", + BYTES32_TYPE, + ProposerDuties::getDependentRoot, + ProposerDutiesBuilder::dependentRoot) + .withField( + EXECUTION_OPTIMISTIC, + BOOLEAN_TYPE, + ProposerDuties::isExecutionOptimistic, + ProposerDutiesBuilder::executionOptimistic) + .withField( + "data", + listOf(PROPOSER_DUTY_TYPE), + ProposerDuties::getDuties, + ProposerDutiesBuilder::duties) + .build(); + + private Bytes32 dependentRoot; + private boolean executionOptimistic; + private List duties; + + public ProposerDutiesBuilder dependentRoot(Bytes32 dependentRoot) { + this.dependentRoot = dependentRoot; + return this; + } + + public ProposerDutiesBuilder executionOptimistic(boolean executionOptimistic) { + this.executionOptimistic = executionOptimistic; + return this; + } + + public ProposerDutiesBuilder duties(List duties) { + this.duties = duties; + return this; + } + + public ProposerDuties build() { + return new ProposerDuties(dependentRoot, duties, executionOptimistic); + } +} diff --git a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ProposerDuty.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDuty.java similarity index 97% rename from validator/api/src/main/java/tech/pegasys/teku/validator/api/ProposerDuty.java rename to ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDuty.java index e614684e883..9b9747f6217 100644 --- a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ProposerDuty.java +++ b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDuty.java @@ -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.Objects; diff --git a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDutyBuilder.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDutyBuilder.java new file mode 100644 index 00000000000..fa7d6413e80 --- /dev/null +++ b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/validator/ProposerDutyBuilder.java @@ -0,0 +1,61 @@ +/* + * 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.validator; + +import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.PUBLIC_KEY_TYPE; +import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.INTEGER_TYPE; +import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.UINT64_TYPE; + +import tech.pegasys.teku.bls.BLSPublicKey; +import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; + +public class ProposerDutyBuilder { + public static final DeserializableTypeDefinition PROPOSER_DUTY_TYPE = + DeserializableTypeDefinition.object(ProposerDuty.class, ProposerDutyBuilder.class) + .initializer(ProposerDutyBuilder::new) + .finisher(ProposerDutyBuilder::build) + .withField( + "pubkey", PUBLIC_KEY_TYPE, ProposerDuty::getPublicKey, ProposerDutyBuilder::publicKey) + .withField( + "validator_index", + INTEGER_TYPE, + ProposerDuty::getValidatorIndex, + ProposerDutyBuilder::validatorIndex) + .withField("slot", UINT64_TYPE, ProposerDuty::getSlot, ProposerDutyBuilder::slot) + .build(); + + private BLSPublicKey publicKey; + private int validatorIndex; + private UInt64 slot; + + public ProposerDutyBuilder publicKey(BLSPublicKey publicKey) { + this.publicKey = publicKey; + return this; + } + + public ProposerDutyBuilder validatorIndex(int validatorIndex) { + this.validatorIndex = validatorIndex; + return this; + } + + public ProposerDutyBuilder slot(UInt64 slot) { + this.slot = slot; + return this; + } + + public ProposerDuty build() { + return new ProposerDuty(publicKey, validatorIndex, slot); + } +} diff --git a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/wrappers/package-info.java b/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/wrappers/package-info.java deleted file mode 100644 index 9db4e155ee9..00000000000 --- a/ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/wrappers/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Holds data classes specifically required to hold data for serialization as part of the REST API. - * - *

These are not intended for internal business logic and only exist when there isn't a single - * object that holds all the data required in a REST API response. When an existing business logic - * class does exist with all the required data, a type definition should be defined to just extract - * the data from the existing class rather than introducing a new API specific wrapper class. - * - *

This package is definitely not a suitable place to put any classes used outside of - * serializing/deserializing API responses. - */ -package tech.pegasys.teku.ethereum.json.types.wrappers; diff --git a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java b/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java index c2e6b2ffdbe..b6a5ba612fb 100644 --- a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java +++ b/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java @@ -24,6 +24,7 @@ import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus; 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.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.events.ChannelInterface; import tech.pegasys.teku.infrastructure.ssz.SszList; diff --git a/validator/beaconnode/src/main/java/tech/pegasys/teku/validator/beaconnode/metrics/MetricRecordingValidatorApiChannel.java b/validator/beaconnode/src/main/java/tech/pegasys/teku/validator/beaconnode/metrics/MetricRecordingValidatorApiChannel.java index 89bbfa947fb..62af0be9b38 100644 --- a/validator/beaconnode/src/main/java/tech/pegasys/teku/validator/beaconnode/metrics/MetricRecordingValidatorApiChannel.java +++ b/validator/beaconnode/src/main/java/tech/pegasys/teku/validator/beaconnode/metrics/MetricRecordingValidatorApiChannel.java @@ -32,6 +32,7 @@ import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus; 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.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory; import tech.pegasys.teku.infrastructure.metrics.Validator.ValidatorDutyMetricUtils; @@ -52,7 +53,6 @@ import tech.pegasys.teku.spec.datastructures.validator.SubnetSubscription; 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; diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/BlockProductionDutyLoader.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/BlockProductionDutyLoader.java index ab90c415f68..e9447dc7a9a 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/BlockProductionDutyLoader.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/BlockProductionDutyLoader.java @@ -17,10 +17,10 @@ import java.util.Optional; import java.util.function.Function; import org.apache.tuweni.bytes.Bytes32; +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.unsigned.UInt64; -import tech.pegasys.teku.validator.api.ProposerDuties; -import tech.pegasys.teku.validator.api.ProposerDuty; import tech.pegasys.teku.validator.api.ValidatorApiChannel; import tech.pegasys.teku.validator.client.duties.BlockProductionDuty; import tech.pegasys.teku.validator.client.duties.Duty; diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/BlockDutySchedulerTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/BlockDutySchedulerTest.java index e179cd912fc..ceda812a770 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/BlockDutySchedulerTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/BlockDutySchedulerTest.java @@ -33,14 +33,14 @@ import java.util.Optional; import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; +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.metrics.StubMetricsSystem; import tech.pegasys.teku.infrastructure.metrics.Validator.DutyType; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; -import tech.pegasys.teku.validator.api.ProposerDuties; -import tech.pegasys.teku.validator.api.ProposerDuty; import tech.pegasys.teku.validator.client.duties.BlockDutyFactory; import tech.pegasys.teku.validator.client.duties.BlockProductionDuty; import tech.pegasys.teku.validator.client.duties.Duty; diff --git a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java index d9682a5e9d7..16104ae91df 100644 --- a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java +++ b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java @@ -33,6 +33,7 @@ import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus; 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.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.collections.LimitedMap; import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory; @@ -53,7 +54,6 @@ import tech.pegasys.teku.spec.datastructures.validator.SubnetSubscription; 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; diff --git a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandler.java b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandler.java index 6f1834b4b28..3849ab9dcc9 100644 --- a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandler.java +++ b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandler.java @@ -45,6 +45,8 @@ import tech.pegasys.teku.api.schema.altair.ContributionAndProof; 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.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.async.ExceptionThrowingRunnable; import tech.pegasys.teku.infrastructure.async.ExceptionThrowingSupplier; @@ -68,8 +70,6 @@ import tech.pegasys.teku.validator.api.AttesterDuties; import tech.pegasys.teku.validator.api.AttesterDuty; import tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest; -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; diff --git a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/sentry/SentryValidatorApiChannel.java b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/sentry/SentryValidatorApiChannel.java index 094253a8901..8dedfc8ebb3 100644 --- a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/sentry/SentryValidatorApiChannel.java +++ b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/sentry/SentryValidatorApiChannel.java @@ -24,6 +24,7 @@ import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus; 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.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.ssz.SszList; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -42,7 +43,6 @@ import tech.pegasys.teku.spec.datastructures.validator.SubnetSubscription; 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; diff --git a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/typedef/handlers/GetGenesisRequest.java b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/typedef/handlers/GetGenesisRequest.java index 35adb4fec2e..530d0606332 100644 --- a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/typedef/handlers/GetGenesisRequest.java +++ b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/typedef/handlers/GetGenesisRequest.java @@ -13,13 +13,13 @@ package tech.pegasys.teku.validator.remote.typedef.handlers; -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.validator.remote.apiclient.ValidatorApiMethod.GET_GENESIS; import java.util.Optional; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; -import tech.pegasys.teku.ethereum.json.types.wrappers.GetGenesisApiData; +import tech.pegasys.teku.ethereum.json.types.beacon.GetGenesisApiData; import tech.pegasys.teku.validator.remote.typedef.ResponseHandler; public class GetGenesisRequest extends AbstractTypeDefRequest { diff --git a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java index f59484abc3c..60a739dd76f 100644 --- a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java +++ b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java @@ -48,6 +48,7 @@ import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus; 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.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.SafeFutureAssert; import tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem; @@ -73,7 +74,6 @@ import tech.pegasys.teku.spec.util.DataStructureUtil; 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; diff --git a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandlerTest.java b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandlerTest.java index 0c6676843a9..c798c7ea90e 100644 --- a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandlerTest.java +++ b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandlerTest.java @@ -59,6 +59,8 @@ import tech.pegasys.teku.api.schema.Validator; 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.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.StubAsyncRunner; import tech.pegasys.teku.infrastructure.async.Waiter; @@ -82,8 +84,6 @@ import tech.pegasys.teku.validator.api.AttesterDuties; import tech.pegasys.teku.validator.api.AttesterDuty; import tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest; -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.required.SyncingStatus;