Skip to content

Commit

Permalink
Revert "Add getKzgInstance() in spec"
Browse files Browse the repository at this point in the history
This reverts commit 472b89e.
  • Loading branch information
StefanBratanov committed Nov 1, 2023
1 parent f24a619 commit bafa8e4
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 31 deletions.
9 changes: 0 additions & 9 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.spec.cache.IndexedAttestationCache;
import tech.pegasys.teku.spec.config.NetworkingSpecConfig;
import tech.pegasys.teku.spec.config.NetworkingSpecConfigDeneb;
Expand Down Expand Up @@ -985,14 +984,6 @@ public Optional<UInt64> computeFirstSlotWithBlobSupport() {
.map(this::computeStartSlotAtEpoch);
}

// trusted setup loading is handled by the BeaconChainController
public KZG getKzgInstance() {
if (isMilestoneSupported(DENEB)) {
return KZG.getInstance();
}
return KZG.NOOP;
}

// Deneb private helpers
private Optional<SpecConfigDeneb> getSpecConfigDeneb() {
final SpecMilestone highestSupportedMilestone =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
import tech.pegasys.teku.kzg.KZGCommitment;
import tech.pegasys.teku.kzg.KZGProof;
import tech.pegasys.teku.spec.Spec;
Expand Down Expand Up @@ -107,7 +108,14 @@ public ExecutionLayerChannelStub(
this.transitionEmulationEnabled = enableTransitionEmulation;
this.terminalBlockHashInTTDMode =
terminalBlockHashInTTDMode.orElse(Bytes32.fromHexStringLenient("0x01"));
this.blobsUtil = new BlobsUtil(spec, spec.getKzgInstance());
final KZG kzg;
if (spec.isMilestoneSupported(SpecMilestone.DENEB)) {
// trusted setup loading will be handled by the BeaconChainController
kzg = KZG.getInstance();
} else {
kzg = KZG.NOOP;
}
this.blobsUtil = new BlobsUtil(spec, kzg);
}

public ExecutionLayerChannelStub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding;
import tech.pegasys.teku.networking.eth2.gossip.forks.GossipForkManager;
import tech.pegasys.teku.networking.eth2.gossip.forks.GossipForkSubscriptions;
Expand Down Expand Up @@ -120,6 +121,7 @@ public class Eth2P2PNetworkBuilder {
protected OperationProcessor<ValidatableSyncCommitteeMessage>
gossipedSyncCommitteeMessageProcessor;
protected StatusMessageFactory statusMessageFactory;
protected KZG kzg;

protected Eth2P2PNetworkBuilder() {}

Expand Down Expand Up @@ -154,7 +156,8 @@ public Eth2P2PNetwork build() {
timeProvider,
config.getPeerRateLimit(),
config.getPeerRequestLimit(),
spec);
spec,
kzg);
final Collection<RpcMethod<?, ?, ?>> eth2RpcMethods =
eth2PeerManager.getBeaconChainMethods().all();
rpcMethods.addAll(eth2RpcMethods);
Expand Down Expand Up @@ -563,4 +566,10 @@ public Eth2P2PNetworkBuilder statusMessageFactory(
this.statusMessageFactory = statusMessageFactory;
return this;
}

public Eth2P2PNetworkBuilder kzg(final KZG kzg) {
checkNotNull(kzg);
this.kzg = kzg;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;
import tech.pegasys.teku.infrastructure.subscribers.Subscribers;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethods;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlobSidecarsByRangeListenerValidatingProxy;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlocksByRangeListenerWrapper;
Expand Down Expand Up @@ -83,6 +84,7 @@ class DefaultEth2Peer extends DelegatingPeer implements Eth2Peer {
private final RateTracker blockRequestTracker;
private final RateTracker blobSidecarsRequestTracker;
private final RateTracker requestTracker;
private final KZG kzg;
private final Supplier<UInt64> firstSlotSupportingBlobSidecarsByRange;
private final Supplier<BlobSidecarsByRootRequestMessageSchema>
blobSidecarsByRootRequestMessageSchema;
Expand All @@ -97,7 +99,8 @@ class DefaultEth2Peer extends DelegatingPeer implements Eth2Peer {
final PeerChainValidator peerChainValidator,
final RateTracker blockRequestTracker,
final RateTracker blobSidecarsRequestTracker,
final RateTracker requestTracker) {
final RateTracker requestTracker,
final KZG kzg) {
super(peer);
this.spec = spec;
this.rpcMethods = rpcMethods;
Expand All @@ -107,6 +110,7 @@ class DefaultEth2Peer extends DelegatingPeer implements Eth2Peer {
this.blockRequestTracker = blockRequestTracker;
this.blobSidecarsRequestTracker = blobSidecarsRequestTracker;
this.requestTracker = requestTracker;
this.kzg = kzg;
this.firstSlotSupportingBlobSidecarsByRange =
Suppliers.memoize(
() -> {
Expand Down Expand Up @@ -328,7 +332,7 @@ public SafeFuture<Void> requestBlobSidecarsByRange(
this,
listener,
maxBlobsPerBlock.get(),
spec.getKzgInstance(),
kzg,
request.getStartSlot(),
request.getCount()));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethods;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessagesFactory;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.StatusMessageFactory;
Expand All @@ -46,7 +47,8 @@ static Eth2Peer create(
final PeerChainValidator peerChainValidator,
final RateTracker blockRequestTracker,
final RateTracker blobSidecarsRequestTracker,
final RateTracker requestTracker) {
final RateTracker requestTracker,
final KZG kzg) {
return new DefaultEth2Peer(
spec,
peer,
Expand All @@ -56,7 +58,8 @@ static Eth2Peer create(
peerChainValidator,
blockRequestTracker,
blobSidecarsRequestTracker,
requestTracker);
requestTracker,
kzg);
}

void updateStatus(PeerStatus status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethods;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessagesFactory;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.StatusMessageFactory;
Expand All @@ -36,6 +37,7 @@ public class Eth2PeerFactory {
private final Optional<Checkpoint> requiredCheckpoint;
private final int peerRateLimit;
private final int peerRequestLimit;
private final KZG kzg;

public Eth2PeerFactory(
final Spec spec,
Expand All @@ -46,7 +48,8 @@ public Eth2PeerFactory(
final TimeProvider timeProvider,
final Optional<Checkpoint> requiredCheckpoint,
final int peerRateLimit,
final int peerRequestLimit) {
final int peerRequestLimit,
final KZG kzg) {
this.spec = spec;
this.metricsSystem = metricsSystem;
this.chainDataClient = chainDataClient;
Expand All @@ -56,6 +59,7 @@ public Eth2PeerFactory(
this.requiredCheckpoint = requiredCheckpoint;
this.peerRateLimit = peerRateLimit;
this.peerRequestLimit = peerRequestLimit;
this.kzg = kzg;
}

public Eth2Peer create(final Peer peer, final BeaconChainMethods rpcMethods) {
Expand All @@ -69,6 +73,7 @@ public Eth2Peer create(final Peer peer, final BeaconChainMethods rpcMethods) {
RateTracker.create(peerRateLimit, TIME_OUT, timeProvider),
RateTracker.create(
peerRateLimit * spec.getMaxBlobsPerBlock().orElse(1), TIME_OUT, timeProvider),
RateTracker.create(peerRequestLimit, TIME_OUT, timeProvider));
RateTracker.create(peerRequestLimit, TIME_OUT, timeProvider),
kzg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.subscribers.Subscribers;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.networking.eth2.SubnetSubscriptionService;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethods;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessagesFactory;
Expand Down Expand Up @@ -116,7 +117,8 @@ public static Eth2PeerManager create(
final TimeProvider timeProvider,
final int peerRateLimit,
final int peerRequestLimit,
final Spec spec) {
final Spec spec,
final KZG kzg) {

final MetadataMessagesFactory metadataMessagesFactory = new MetadataMessagesFactory();
attestationSubnetService.subscribeToUpdates(
Expand All @@ -139,7 +141,8 @@ public static Eth2PeerManager create(
timeProvider,
requiredCheckpoint,
peerRateLimit,
peerRequestLimit),
peerRequestLimit,
kzg),
statusMessageFactory,
metadataMessagesFactory,
rpcEncoding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.mockito.ArgumentCaptor;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.networking.eth2.peers.Eth2Peer.PeerStatusSubscriber;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethods;
import tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessagesFactory;
Expand Down Expand Up @@ -56,6 +57,7 @@ class Eth2PeerTest {
private final RateTracker blockRateTracker = mock(RateTracker.class);
private final RateTracker blobSidecarsRateTracker = mock(RateTracker.class);
private final RateTracker rateTracker = mock(RateTracker.class);
private final KZG kzg = mock(KZG.class);

private final PeerStatus randomPeerStatus = randomPeerStatus();

Expand All @@ -69,7 +71,8 @@ class Eth2PeerTest {
peerChainValidator,
blockRateTracker,
blobSidecarsRateTracker,
rateTracker);
rateTracker,
kzg);

@Test
void updateStatus_shouldNotUpdateUntilValidationPasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import tech.pegasys.teku.infrastructure.subscribers.Subscribers;
import tech.pegasys.teku.infrastructure.time.StubTimeProvider;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.network.p2p.jvmlibp2p.PrivateKeyGenerator;
import tech.pegasys.teku.networking.eth2.gossip.config.GossipConfigurator;
import tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding;
Expand Down Expand Up @@ -223,12 +224,13 @@ protected Eth2P2PNetwork buildNetwork(final P2PConfig config) {
timeProvider,
500,
50,
spec);
spec,
KZG.NOOP);

List<RpcMethod<?, ?, ?>> rpcMethods =
eth2PeerManager.getBeaconChainMethods().all().stream()
.flatMap(rpcMethodsModifier)
.toList();
.collect(toList());

this.peerHandler(eth2PeerManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ protected void initP2PNetwork() {
.keyValueStore(keyValueStore)
.requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint())
.specProvider(spec)
.kzg(kzg)
.build();

syncCommitteeMessagePool.subscribeOperationAdded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,6 @@ public void shouldParseDenebEpochsStoreBlobs() {
assertThat(specConfigDeneb.getEpochsStoreBlobs()).isEqualTo(12345);
}

@Test
public void shouldHaveTrustedSetupConfiguredForDeneb() {
final String[] args = {XDENEB_FORK_EPOCH_OPTION, "200000"};
beaconNodeCommand.parse(args);
final Optional<String> trustedSetup =
beaconNodeCommand.tekuConfiguration().eth2NetworkConfiguration().getTrustedSetup();
assertThat(trustedSetup).isPresent();
}

private Path createConfigFile() throws IOException {
final URL configFile = BeaconNodeCommandTest.class.getResource("/complete_config.yaml");
final String updatedConfig =
Expand Down

0 comments on commit bafa8e4

Please sign in to comment.