Skip to content

Commit

Permalink
Merge branch 'master' into maxEBProposer
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfyone authored May 30, 2024
2 parents 0a7c31a + 2ce36bb commit cdd8acd
Show file tree
Hide file tree
Showing 65 changed files with 750 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static SyncingNodeManager create(

public SafeFuture<Peer> connect(final SyncingNodeManager peer) {
final PeerAddress peerAddress =
eth2P2PNetwork.createPeerAddress(peer.network().getNodeAddress());
eth2P2PNetwork.createPeerAddress(peer.network().getNodeAddresses().get(0));
return eth2P2PNetwork.connect(peerAddress);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class GetIdentityIntegrationTest extends AbstractDataBackedRestAPIIntegra
void setup() {
when(eth2P2PNetwork.getNodeId()).thenReturn(node1);
when(eth2P2PNetwork.getEnr()).thenReturn(Optional.of(enr));
when(eth2P2PNetwork.getNodeAddress()).thenReturn(address);
when(eth2P2PNetwork.getNodeAddresses()).thenReturn(List.of(address));
when(eth2P2PNetwork.getDiscoveryAddress()).thenReturn(Optional.of(discoveryAddress));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void shouldReturnExpectedObjectType() throws Exception {
when(eth2P2PNetwork.getMetadata()).thenReturn(defaultMetadata);
when(eth2P2PNetwork.getNodeId()).thenReturn(nodeid);
when(nodeid.toBase58()).thenReturn("aeiou");
when(eth2P2PNetwork.getNodeAddress()).thenReturn("address");
when(eth2P2PNetwork.getNodeAddresses()).thenReturn(List.of("address"));

handler.handleRequest(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,8 @@ public long getPeerCount() {
return network.streamPeers().count();
}

/**
* Get the listen port
*
* @return the port this client is listening on
*/
public int getListenPort() {
return network.getListenPort();
}

public List<String> getListeningAddresses() {
return List.of(network.getNodeAddress());
return network.getNodeAddresses();
}

public List<String> getDiscoveryAddresses() {
Expand All @@ -91,11 +82,6 @@ public List<Eth2Peer> getPeerScores() {
return network.streamPeers().toList();
}

public Optional<Peer> getPeerById(final String peerId) {
final NodeId nodeId = network.parseNodeId(peerId);
return network.getPeer(nodeId).map(this::toPeer);
}

public Optional<Eth2Peer> getEth2PeerById(final String peerId) {
final NodeId nodeId = network.parseNodeId(peerId);
return network.getPeer(nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ void getPeerCount_shouldReturnTotalPeersIfEmpty() {
@Test
void getListeningAddresses_shouldReturnAddressFromNetwork() {
final NetworkDataProvider network = new NetworkDataProvider(p2pNetwork);
final String nodeAddress = "/some/libp2p/addr";
final List<String> nodeAddresses = List.of("/some/libp2p/addr");

when(p2pNetwork.getNodeAddress()).thenReturn(nodeAddress);
when(p2pNetwork.getNodeAddresses()).thenReturn(nodeAddresses);

assertThat(network.getListeningAddresses()).isEqualTo(List.of(nodeAddress));
assertThat(network.getListeningAddresses()).isEqualTo(nodeAddresses);
}
}
1 change: 1 addition & 0 deletions ethereum/spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ dependencies {
testImplementation testFixtures(project(':infrastructure:kzg'))
testImplementation testFixtures(project(':infrastructure:ssz'))
testImplementation testFixtures(project(':infrastructure:metrics'))
testImplementation testFixtures(project(':infrastructure:time'))
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package tech.pegasys.teku.spec;

import static tech.pegasys.teku.infrastructure.time.SystemTimeProvider.SYSTEM_TIME_PROVIDER;

import java.util.Optional;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAltair;
Expand Down Expand Up @@ -66,37 +68,43 @@ public static Optional<SpecVersion> create(

static SpecVersion createPhase0(final SpecConfig specConfig) {
final SchemaDefinitions schemaDefinitions = new SchemaDefinitionsPhase0(specConfig);
final SpecLogic specLogic = SpecLogicPhase0.create(specConfig, schemaDefinitions);
final SpecLogic specLogic =
SpecLogicPhase0.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.PHASE0, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createAltair(final SpecConfigAltair specConfig) {
final SchemaDefinitionsAltair schemaDefinitions = new SchemaDefinitionsAltair(specConfig);
final SpecLogic specLogic = SpecLogicAltair.create(specConfig, schemaDefinitions);
final SpecLogic specLogic =
SpecLogicAltair.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.ALTAIR, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createBellatrix(final SpecConfigBellatrix specConfig) {
final SchemaDefinitionsBellatrix schemaDefinitions = new SchemaDefinitionsBellatrix(specConfig);
final SpecLogic specLogic = SpecLogicBellatrix.create(specConfig, schemaDefinitions);
final SpecLogic specLogic =
SpecLogicBellatrix.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.BELLATRIX, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createCapella(final SpecConfigCapella specConfig) {
final SchemaDefinitionsCapella schemaDefinitions = new SchemaDefinitionsCapella(specConfig);
final SpecLogicCapella specLogic = SpecLogicCapella.create(specConfig, schemaDefinitions);
final SpecLogicCapella specLogic =
SpecLogicCapella.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.CAPELLA, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createDeneb(final SpecConfigDeneb specConfig) {
final SchemaDefinitionsDeneb schemaDefinitions = new SchemaDefinitionsDeneb(specConfig);
final SpecLogicDeneb specLogic = SpecLogicDeneb.create(specConfig, schemaDefinitions);
final SpecLogicDeneb specLogic =
SpecLogicDeneb.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.DENEB, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createElectra(final SpecConfigElectra specConfig) {
final SchemaDefinitionsElectra schemaDefinitions = new SchemaDefinitionsElectra(specConfig);
final SpecLogicElectra specLogic = SpecLogicElectra.create(specConfig, schemaDefinitions);
final SpecLogicElectra specLogic =
SpecLogicElectra.create(specConfig, schemaDefinitions, SYSTEM_TIME_PROVIDER);
return new SpecVersion(SpecMilestone.ELECTRA, specConfig, schemaDefinitions, specLogic);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public UInt64 getStep() {
}

public UInt64 getMaxSlot() {
return getStartSlot().plus(getCount().minus(1).times(getStep()));
return getStartSlot().plus(getCount().minusMinZero(1).times(getStep()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public UInt64 getCount() {
}

public UInt64 getMaxSlot() {
return getStartSlot().plus(getCount()).minusMinZero(1);
return getStartSlot().plus(getCount().minusMinZero(1));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static tech.pegasys.teku.infrastructure.time.SystemTimeProvider.SYSTEM_TIME_PROVIDER;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -38,7 +39,6 @@
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.collections.cache.LRUCache;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.kzg.KZG;
Expand Down Expand Up @@ -139,7 +139,7 @@ public ExecutionLayerChannelStub(
final Spec spec,
final boolean enableTransitionEmulation,
final Optional<Bytes32> terminalBlockHashInTTDMode) {
this(spec, new SystemTimeProvider(), enableTransitionEmulation, terminalBlockHashInTTDMode);
this(spec, SYSTEM_TIME_PROVIDER, enableTransitionEmulation, terminalBlockHashInTTDMode);
}

public void addPowBlock(final PowBlock block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List;
import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List;
import tech.pegasys.teku.infrastructure.time.Throttler;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader;
Expand Down Expand Up @@ -66,7 +67,7 @@ public abstract class AbstractEpochProcessor implements EpochProcessor {
protected final UInt64 maxEffectiveBalance;
// Used to log once per minute (throttlingPeriod = 60 seconds)
private final Throttler<Logger> loggerThrottler = new Throttler<>(LOG, UInt64.valueOf(60));
private final Supplier<UInt64> timeSupplier;
private final TimeProvider timeProvider;

protected AbstractEpochProcessor(
final SpecConfig specConfig,
Expand All @@ -76,7 +77,8 @@ protected AbstractEpochProcessor(
final ValidatorsUtil validatorsUtil,
final BeaconStateUtil beaconStateUtil,
final ValidatorStatusFactory validatorStatusFactory,
final SchemaDefinitions schemaDefinitions) {
final SchemaDefinitions schemaDefinitions,
final TimeProvider timeProvider) {
this.specConfig = specConfig;
this.miscHelpers = miscHelpers;
this.beaconStateAccessors = beaconStateAccessors;
Expand All @@ -86,7 +88,7 @@ protected AbstractEpochProcessor(
this.validatorStatusFactory = validatorStatusFactory;
this.schemaDefinitions = schemaDefinitions;
this.maxEffectiveBalance = specConfig.getMaxEffectiveBalance();
this.timeSupplier = () -> UInt64.valueOf(System.currentTimeMillis() / 1000);
this.timeProvider = timeProvider;
}

/**
Expand Down Expand Up @@ -132,7 +134,7 @@ protected void processEpoch(final BeaconState preState, final MutableBeaconState

if (beaconStateAccessors.isInactivityLeak(state)) {
loggerThrottler.invoke(
timeSupplier.get(), (log) -> log.info("Beacon chain is in inactivity leak"));
timeProvider.getTimeInSeconds(), (log) -> log.info("Beacon chain is in inactivity leak"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public NavigableMap<UInt64, Bytes32> getAncestors(
final UInt64 count) {
final NavigableMap<UInt64, Bytes32> roots = new TreeMap<>();
// minus(ONE) because the start block is included
final UInt64 endSlot = startSlot.plus(step.times(count)).minus(UInt64.ONE);
final UInt64 endSlot = startSlot.plus(step.times(count)).minusMinZero(1);
Bytes32 parentRoot = root;
Optional<UInt64> parentSlot = forkChoiceStrategy.blockSlot(parentRoot);
while (parentSlot.isPresent() && parentSlot.get().compareTo(startSlot) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.spec.logic.versions.altair;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.spec.config.SpecConfigAltair;
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators;
Expand Down Expand Up @@ -86,7 +87,9 @@ private SpecLogicAltair(
}

public static SpecLogicAltair create(
final SpecConfigAltair config, final SchemaDefinitionsAltair schemaDefinitions) {
final SpecConfigAltair config,
final SchemaDefinitionsAltair schemaDefinitions,
final TimeProvider timeProvider) {
// Helpers
final Predicates predicates = new Predicates(config);
final MiscHelpersAltair miscHelpers = new MiscHelpersAltair(config);
Expand Down Expand Up @@ -137,7 +140,8 @@ public static SpecLogicAltair create(
validatorsUtil,
beaconStateUtil,
validatorStatusFactory,
schemaDefinitions);
schemaDefinitions,
timeProvider);
final SyncCommitteeUtil syncCommitteeUtil =
new SyncCommitteeUtil(
beaconStateAccessors, validatorsUtil, config, miscHelpers, schemaDefinitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tech.pegasys.teku.infrastructure.ssz.SszMutableList;
import tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAltair;
Expand Down Expand Up @@ -60,7 +61,8 @@ public EpochProcessorAltair(
final ValidatorsUtil validatorsUtil,
final BeaconStateUtil beaconStateUtil,
final ValidatorStatusFactory validatorStatusFactory,
final SchemaDefinitions schemaDefinitions) {
final SchemaDefinitions schemaDefinitions,
final TimeProvider timeProvider) {
super(
specConfig,
miscHelpers,
Expand All @@ -69,7 +71,8 @@ public EpochProcessorAltair(
validatorsUtil,
beaconStateUtil,
validatorStatusFactory,
schemaDefinitions);
schemaDefinitions,
timeProvider);
this.specConfigAltair = specConfig;
this.miscHelpersAltair = miscHelpers;
this.beaconStateAccessorsAltair = beaconStateAccessors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.spec.logic.versions.bellatrix;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.spec.config.SpecConfigBellatrix;
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
Expand Down Expand Up @@ -92,7 +93,9 @@ private SpecLogicBellatrix(
}

public static SpecLogicBellatrix create(
final SpecConfigBellatrix config, final SchemaDefinitionsBellatrix schemaDefinitions) {
final SpecConfigBellatrix config,
final SchemaDefinitionsBellatrix schemaDefinitions,
final TimeProvider timeProvider) {
// Helpers
final Predicates predicates = new Predicates(config);
final MiscHelpersBellatrix miscHelpers = new MiscHelpersBellatrix(config);
Expand Down Expand Up @@ -141,7 +144,8 @@ public static SpecLogicBellatrix create(
validatorsUtil,
beaconStateUtil,
validatorStatusFactory,
schemaDefinitions);
schemaDefinitions,
timeProvider);
final SyncCommitteeUtil syncCommitteeUtil =
new SyncCommitteeUtil(
beaconStateAccessors, validatorsUtil, config, miscHelpers, schemaDefinitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.spec.logic.versions.bellatrix.statetransition.epoch;

import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.spec.config.SpecConfigBellatrix;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.bellatrix.BeaconStateBellatrix;
Expand All @@ -39,7 +40,8 @@ public EpochProcessorBellatrix(
final ValidatorsUtil validatorsUtil,
final BeaconStateUtil beaconStateUtil,
final ValidatorStatusFactory validatorStatusFactory,
final SchemaDefinitions schemaDefinitions) {
final SchemaDefinitions schemaDefinitions,
final TimeProvider timeProvider) {
super(
specConfig,
miscHelpers,
Expand All @@ -48,7 +50,8 @@ public EpochProcessorBellatrix(
validatorsUtil,
beaconStateUtil,
validatorStatusFactory,
schemaDefinitions);
schemaDefinitions,
timeProvider);
specConfigBellatrix = specConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.spec.logic.versions.capella;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
Expand Down Expand Up @@ -92,7 +93,9 @@ private SpecLogicCapella(
}

public static SpecLogicCapella create(
final SpecConfigCapella config, final SchemaDefinitionsCapella schemaDefinitions) {
final SpecConfigCapella config,
final SchemaDefinitionsCapella schemaDefinitions,
final TimeProvider timeProvider) {
// Helpers
final Predicates predicates = new Predicates(config);
final MiscHelpersCapella miscHelpers = new MiscHelpersCapella(config);
Expand Down Expand Up @@ -141,7 +144,8 @@ public static SpecLogicCapella create(
validatorsUtil,
beaconStateUtil,
validatorStatusFactory,
schemaDefinitions);
schemaDefinitions,
timeProvider);
final SyncCommitteeUtil syncCommitteeUtil =
new SyncCommitteeUtil(
beaconStateAccessors, validatorsUtil, config, miscHelpers, schemaDefinitions);
Expand Down
Loading

0 comments on commit cdd8acd

Please sign in to comment.