Skip to content

Commit

Permalink
Remove Constants.SLOTS_PER_EPOCH (Consensys#4926)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton committed Feb 3, 2022
1 parent 662887d commit d5d00ea
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 124 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.api.schema.BLSPubKey;
import tech.pegasys.teku.api.schema.BeaconState;
import tech.pegasys.teku.api.schema.ValidatorsRequest;
import tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;
Expand Down Expand Up @@ -172,24 +169,4 @@ void beaconStateJsonTest() throws JsonProcessingException {
String jsonState = jsonProvider.objectToJSON(state);
assertTrue(jsonState.length() > 0);
}

@Test
void validatorsRequestTest() throws JsonProcessingException {
final String PUBKEY =
"0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c";
final String data =
"{\n"
+ " \"epoch\": 0, \n"
+ " \"pubkeys\": [\n"
+ "\""
+ PUBKEY
+ "\"\n"
+ " ]\n"
+ "}";

ValidatorsRequest result = jsonProvider.jsonToObject(data, ValidatorsRequest.class);

assertThat(result.epoch).isEqualTo(UInt64.ZERO);
assertThat(result.pubkeys).isEqualTo(List.of(BLSPubKey.fromHexString(PUBKEY)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import tech.pegasys.teku.bls.BLSKeyPair;
import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread;
import tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.config.Constants;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void init() throws Exception {

String blocksFile =
"/blocks/blocks_epoch_"
+ Constants.SLOTS_PER_EPOCH
+ spec.getSlotsPerEpoch(UInt64.ZERO)
+ "_validators_"
+ validatorsCount
+ ".ssz.gz";
Expand All @@ -114,6 +115,7 @@ public void init() throws Exception {

blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
recentChainData,
forkChoice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void importBlocks() throws Exception {

String blocksFile =
"/blocks/blocks_epoch_"
+ Constants.SLOTS_PER_EPOCH
+ spec.getSlotsPerEpoch(UInt64.ZERO)
+ "_validators_"
+ validatorsCount
+ ".ssz.gz";
Expand All @@ -97,6 +97,7 @@ public void importBlocks() throws Exception {
BeaconChainUtil.create(spec, recentChainData, validatorKeys, false);
BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
recentChainData,
forkChoice,
Expand Down Expand Up @@ -150,7 +151,7 @@ public void importBlocksMemProfiling() throws Exception {

String blocksFile =
"/blocks/blocks_epoch_"
+ Constants.SLOTS_PER_EPOCH
+ spec.getSlotsPerEpoch(UInt64.ZERO)
+ "_validators_"
+ validatorsCount
+ ".ssz.gz";
Expand All @@ -177,6 +178,7 @@ public void importBlocksMemProfiling() throws Exception {
spec, new InlineEventThread(), recentChainData, mock(ForkChoiceNotifier.class));
BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
recentChainData,
forkChoice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import tech.pegasys.teku.benchmarks.gen.BlsKeyPairIO;
import tech.pegasys.teku.bls.BLSKeyPair;
import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.config.Constants;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void init() throws Exception {

String blocksFile =
"/blocks/blocks_epoch_"
+ Constants.SLOTS_PER_EPOCH
+ spec.getSlotsPerEpoch(UInt64.ZERO)
+ "_validators_"
+ validatorsCount
+ ".ssz.gz";
Expand All @@ -96,6 +97,7 @@ public void init() throws Exception {

blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
recentChainData,
forkChoice,
Expand Down Expand Up @@ -136,7 +138,8 @@ public static class Block extends TransitionBenchmark {
@Setup(Level.Iteration)
public void skipAndPrefetch() throws Exception {
if (lastResult != null
&& (lastResult.getBlock().getSlot().longValue() + 1) % Constants.SLOTS_PER_EPOCH == 0) {
&& (lastResult.getBlock().getSlot().longValue() + 1) % spec.getSlotsPerEpoch(UInt64.ZERO)
== 0) {

// import block with epoch transition
importNextBlock();
Expand All @@ -162,7 +165,8 @@ public static class Epoch extends TransitionBenchmark {
public void skipAndPrefetch() throws Exception {
// import all blocks without epoch transition
while (lastResult == null
|| (lastResult.getBlock().getSlot().longValue() + 1) % Constants.SLOTS_PER_EPOCH != 0) {
|| (lastResult.getBlock().getSlot().longValue() + 1) % spec.getSlotsPerEpoch(UInt64.ZERO)
!= 0) {
importNextBlock();
}
prefetchBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class Constants {

@Deprecated public static int MAX_VALIDATORS_PER_COMMITTEE;

@Deprecated public static int SLOTS_PER_EPOCH;
@Deprecated public static int SLOTS_PER_HISTORICAL_ROOT;

// Networking
Expand Down Expand Up @@ -87,7 +86,6 @@ public static void setConstants(final Spec spec) {
@Deprecated
public static void setConstants(final SpecConfig config) {
MAX_VALIDATORS_PER_COMMITTEE = config.getMaxValidatorsPerCommittee();
SLOTS_PER_EPOCH = config.getSlotsPerEpoch();
SLOTS_PER_HISTORICAL_ROOT = config.getSlotsPerHistoricalRoot();
SpecDependent.resetAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.subscribers.Subscribers;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
Expand All @@ -42,6 +42,7 @@

public class BlockImporter {
private static final Logger LOG = LogManager.getLogger();
private final Spec spec;
private final BlockImportNotifications blockImportNotifications;
private final RecentChainData recentChainData;
private final ForkChoice forkChoice;
Expand All @@ -61,11 +62,13 @@ public class BlockImporter {
new AtomicReference<>(null);

public BlockImporter(
final Spec spec,
final BlockImportNotifications blockImportNotifications,
final RecentChainData recentChainData,
final ForkChoice forkChoice,
final WeakSubjectivityValidator weakSubjectivityValidator,
final ExecutionEngineChannel executionEngine) {
this.spec = spec;
this.blockImportNotifications = blockImportNotifications;
this.recentChainData = recentChainData;
this.forkChoice = forkChoice;
Expand Down Expand Up @@ -128,7 +131,7 @@ private SafeFuture<?> validateWeakSubjectivityPeriod() {
final Optional<UInt64> wsPeriodInSlots =
weakSubjectivityValidator
.getWSPeriod(finalizedCheckpointState)
.map(epochs -> epochs.times(Constants.SLOTS_PER_EPOCH));
.map(epochs -> epochs.times(spec.getSlotsPerEpoch(currentSlot)));
final UInt64 headSlot = recentChainData.getHeadSlot();
if (wsPeriodInSlots
.map(wsp -> headSlot.plus(wsp).isGreaterThanOrEqualTo(currentSlot))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import tech.pegasys.teku.infrastructure.subscribers.Subscribers;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.state.Checkpoint;
Expand All @@ -49,8 +48,7 @@ public class PendingPool<T> implements SlotEventsChannel, FinalizedCheckpointCha

private static final Comparator<SlotAndRoot> SLOT_AND_ROOT_COMPARATOR =
Comparator.comparing(SlotAndRoot::getSlot).thenComparing(SlotAndRoot::getRoot);
private static final UInt64 DEFAULT_HISTORICAL_SLOT_TOLERANCE =
UInt64.valueOf(Constants.SLOTS_PER_EPOCH * 10);
private static final UInt64 DEFAULT_HISTORICAL_SLOT_TOLERANCE = UInt64.valueOf(320);
private static final int DEFAULT_MAX_ITEMS = 5000;

private final Spec spec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class BlockImporterTest {

private final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
recentChainData,
forkChoice,
Expand Down Expand Up @@ -361,6 +362,7 @@ public void importBlock_weakSubjectivityFailure_wrongAncestor() throws Exception
WeakSubjectivityValidator.lenient(wsConfig);
final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
recentChainData,
forkChoice,
Expand Down Expand Up @@ -390,6 +392,7 @@ public void importBlock_weakSubjectivityChecksPass() throws Exception {
WeakSubjectivityValidator.lenient(wsConfig);
final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
recentChainData,
forkChoice,
Expand All @@ -413,6 +416,7 @@ public void importBlock_runWSPChecks() throws Exception {
spec, new InlineEventThread(), storageSystem.recentChainData(), forkChoiceNotifier);
final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
storageSystem.recentChainData(),
forkChoice,
Expand Down Expand Up @@ -451,6 +455,7 @@ public void importBlock_nonFinalizingChain_runWSPChecks() throws Exception {
spec, new InlineEventThread(), storageSystem.recentChainData(), forkChoiceNotifier);
final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
storageSystem.recentChainData(),
forkChoice,
Expand Down Expand Up @@ -497,6 +502,7 @@ public void importBlock_nonFinalizingChain_skipWSPChecks() throws Exception {
spec, new InlineEventThread(), storageSystem.recentChainData(), forkChoiceNotifier);
final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
storageSystem.recentChainData(),
forkChoice,
Expand Down Expand Up @@ -535,6 +541,7 @@ public void getLatestCheckpointState_initialCall() {
spec, new InlineEventThread(), storageSystem.recentChainData(), forkChoiceNotifier);
final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
storageSystem.recentChainData(),
forkChoice,
Expand All @@ -561,6 +568,7 @@ public void getLatestCheckpointState_shouldPullUpdatedFinalizedCheckpoint() {
spec, new InlineEventThread(), storageSystem.recentChainData(), forkChoiceNotifier);
final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
storageSystem.recentChainData(),
forkChoice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class BlockManagerTest {

private final BlockImporter blockImporter =
new BlockImporter(
spec,
blockImportNotifications,
localRecentChainData,
forkChoice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.mockito.Mockito.when;
import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE;
import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO;
import static tech.pegasys.teku.spec.config.Constants.SLOTS_PER_EPOCH;
import static tech.pegasys.teku.statetransition.validation.InternalValidationResult.reject;

import java.util.List;
Expand Down Expand Up @@ -155,7 +154,8 @@ public void shouldReturnValidForValidAggregate() {
@Test
public void shouldReturnValidForValidAggregate_whenManyBlocksHaveBeenSkipped() {
final StateAndBlockSummary chainHead = recentChainData.getChainHead().orElseThrow();
final UInt64 currentSlot = chainHead.getSlot().plus(SLOTS_PER_EPOCH * 3);
final UInt64 currentSlot =
chainHead.getSlot().plus(spec.getSlotsPerEpoch(chainHead.getSlot()) * 3L);
storageSystem.chainUpdater().setCurrentSlot(currentSlot);

final SignedAggregateAndProof aggregate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import tech.pegasys.teku.networking.p2p.peer.DisconnectReason;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState;
import tech.pegasys.teku.spec.datastructures.state.AnchorPoint;
Expand Down Expand Up @@ -513,7 +512,7 @@ private void setupRemoteStatusAndValidator(
final Bytes32 headRoot = Bytes32.fromHexString("0xeeee");
// Set a head slot some distance beyond the finalized epoch
final UInt64 headSlot =
remoteFinalizedCheckpoint.getEpoch().times(Constants.SLOTS_PER_EPOCH).plus(10L);
remoteFinalizedCheckpoint.getEpoch().times(spec.getSlotsPerEpoch(UInt64.ZERO)).plus(10L);

final PeerStatus status =
new PeerStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ public void initBlockImporter() {
LOG.debug("BeaconChainController.initBlockImporter()");
blockImporter =
new BlockImporter(
spec,
eventChannels.getPublisher(BlockImportNotifications.class),
recentChainData,
forkChoice,
Expand Down
Loading

0 comments on commit d5d00ea

Please sign in to comment.