Skip to content

Commit

Permalink
Merge branch 'master' into 7707-6-vc-slashing-single-process
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi authored Jan 25, 2024
2 parents 80322e4 + 524809a commit 037a9f1
Show file tree
Hide file tree
Showing 43 changed files with 382 additions and 221 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# teku

[![Build Status](https://circleci.com/gh/Consensys/teku.svg?style=svg)](https://circleci.com/gh/Consensys/workflows/teku)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/Consensys/teku/blob/master/LICENSE)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Consensys/teku)](https://github.com/Consensys/teku/releases/latest)
[![GitHub License](https://img.shields.io/github/license/Consensys/teku.svg?logo=apache)](https://github.com/Consensys/teku/blob/master/LICENSE)
[![Documentation](https://img.shields.io/badge/docs-readme-blue?logo=readme&logoColor=white)](https://docs.teku.consensys.io/)
[![Discord](https://img.shields.io/badge/Chat-on%20Discord-%235865F2?logo=discord&logoColor=white)](https://discord.gg/7hPv2T6)
[![Twitter Follow](https://img.shields.io/twitter/follow/Teku_Consensys)](https://twitter.com/Teku_Consensys)
[![GitPOAP Badge](https://public-api.gitpoap.io/v1/repo/ConsenSys/teku/badge)](https://www.gitpoap.io/gh/ConsenSys/teku)
Expand Down
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 @@ -30,7 +30,7 @@ public interface BlockFactory {

SafeFuture<BlockContainer> createUnsignedBlock(
BeaconState blockSlotState,
UInt64 newSlot,
UInt64 proposalSlot,
BLSSignature randaoReveal,
Optional<Bytes32> optionalGraffiti,
Optional<Boolean> requestedBlinded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public BlockFactoryDeneb(final Spec spec, final BlockOperationSelectorFactory op
@Override
public SafeFuture<BlockContainer> createUnsignedBlock(
final BeaconState blockSlotState,
final UInt64 newSlot,
final UInt64 proposalSlot,
final BLSSignature randaoReveal,
final Optional<Bytes32> optionalGraffiti,
final Optional<Boolean> requestedBlinded,
final BlockProductionPerformance blockProductionPerformance) {
return super.createUnsignedBlock(
blockSlotState,
newSlot,
proposalSlot,
randaoReveal,
optionalGraffiti,
requestedBlinded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ public BlockFactoryPhase0(
@Override
public SafeFuture<BlockContainer> createUnsignedBlock(
final BeaconState blockSlotState,
final UInt64 newSlot,
final UInt64 proposalSlot,
final BLSSignature randaoReveal,
final Optional<Bytes32> optionalGraffiti,
final Optional<Boolean> requestedBlinded,
final BlockProductionPerformance blockProductionPerformance) {
checkArgument(
blockSlotState.getSlot().equals(newSlot),
blockSlotState.getSlot().equals(proposalSlot),
"Block slot state for slot %s but should be for slot %s",
blockSlotState.getSlot(),
newSlot);
proposalSlot);

// Process empty slots up to the one before the new block slot
final UInt64 slotBeforeBlock = newSlot.minus(UInt64.ONE);
final UInt64 slotBeforeBlock = proposalSlot.minus(UInt64.ONE);

final Bytes32 parentRoot = spec.getBlockRootAtSlot(blockSlotState, slotBeforeBlock);

return spec.createNewUnsignedBlock(
newSlot,
spec.getBeaconProposerIndex(blockSlotState, newSlot),
proposalSlot,
spec.getBeaconProposerIndex(blockSlotState, proposalSlot),
blockSlotState,
parentRoot,
operationSelector.createSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ public MilestoneBasedBlockFactory(
@Override
public SafeFuture<BlockContainer> createUnsignedBlock(
final BeaconState blockSlotState,
final UInt64 newSlot,
final UInt64 proposalSlot,
final BLSSignature randaoReveal,
final Optional<Bytes32> optionalGraffiti,
final Optional<Boolean> requestedBlinded,
final BlockProductionPerformance blockProductionPerformance) {
final SpecMilestone milestone = getMilestone(newSlot);
final SpecMilestone milestone = getMilestone(proposalSlot);
return registeredFactories
.get(milestone)
.createUnsignedBlock(
blockSlotState,
newSlot,
proposalSlot,
randaoReveal,
optionalGraffiti,
requestedBlinded,
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 @@ -17,7 +17,6 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static tech.pegasys.teku.infrastructure.async.SafeFutureAssert.safeJoin;
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis;
import static tech.pegasys.teku.networks.Eth2NetworkConfiguration.DEFAULT_FORK_CHOICE_LATE_BLOCK_REORG_ENABLED;

import com.google.common.collect.ImmutableMap;
import java.io.IOException;
Expand Down Expand Up @@ -127,6 +126,8 @@ spec, new SignedBlockAndState(anchorBlock, anchorState)),
final InlineEventThread eventThread = new InlineEventThread();
final KZG kzg = KzgRetriever.getKzgWithLoadedTrustedSetup(spec, testDefinition.getConfigName());
final StubBlobSidecarManager blobSidecarManager = new StubBlobSidecarManager(kzg);
// forkChoiceLateBlockReorgEnabled is true here always because this is the reference test
// executor
final ForkChoice forkChoice =
new ForkChoice(
spec,
Expand All @@ -137,7 +138,7 @@ spec, new SignedBlockAndState(anchorBlock, anchorState)),
new ForkChoiceStateProvider(eventThread, recentChainData),
new TickProcessor(spec, recentChainData),
transitionBlockValidator,
DEFAULT_FORK_CHOICE_LATE_BLOCK_REORG_ENABLED,
true,
storageSystem.getMetricsSystem());
final ExecutionLayerChannelStub executionLayer =
new ExecutionLayerChannelStub(spec, false, Optional.empty());
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);
}
}
}
Loading

0 comments on commit 037a9f1

Please sign in to comment.