Skip to content

Commit

Permalink
Add getKzgInstance() in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Oct 30, 2023
1 parent 7bdc0f0 commit 472b89e
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 51 deletions.
9 changes: 9 additions & 0 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,6 +42,7 @@
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 @@ -982,6 +983,14 @@ 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,7 +38,6 @@
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 @@ -108,14 +107,7 @@ public ExecutionLayerChannelStub(
this.transitionEmulationEnabled = enableTransitionEmulation;
this.terminalBlockHashInTTDMode =
terminalBlockHashInTTDMode.orElse(Bytes32.fromHexStringLenient("0x01"));
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);
this.blobsUtil = new BlobsUtil(spec, spec.getKzgInstance());
}

public ExecutionLayerChannelStub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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 @@ -121,7 +120,6 @@ public class Eth2P2PNetworkBuilder {
protected OperationProcessor<ValidatableSyncCommitteeMessage>
gossipedSyncCommitteeMessageProcessor;
protected StatusMessageFactory statusMessageFactory;
protected KZG kzg;

protected Eth2P2PNetworkBuilder() {}

Expand Down Expand Up @@ -156,8 +154,7 @@ public Eth2P2PNetwork build() {
timeProvider,
config.getPeerRateLimit(),
config.getPeerRequestLimit(),
spec,
kzg);
spec);
final Collection<RpcMethod<?, ?, ?>> eth2RpcMethods =
eth2PeerManager.getBeaconChainMethods().all();
rpcMethods.addAll(eth2RpcMethods);
Expand Down Expand Up @@ -566,10 +563,4 @@ 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,7 +32,6 @@
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 @@ -84,7 +83,6 @@ 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 @@ -99,8 +97,7 @@ class DefaultEth2Peer extends DelegatingPeer implements Eth2Peer {
final PeerChainValidator peerChainValidator,
final RateTracker blockRequestTracker,
final RateTracker blobSidecarsRequestTracker,
final RateTracker requestTracker,
final KZG kzg) {
final RateTracker requestTracker) {
super(peer);
this.spec = spec;
this.rpcMethods = rpcMethods;
Expand All @@ -110,7 +107,6 @@ 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 @@ -332,7 +328,7 @@ public SafeFuture<Void> requestBlobSidecarsByRange(
this,
listener,
maxBlobsPerBlock.get(),
kzg,
spec.getKzgInstance(),
request.getStartSlot(),
request.getCount()));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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 @@ -47,8 +46,7 @@ static Eth2Peer create(
final PeerChainValidator peerChainValidator,
final RateTracker blockRequestTracker,
final RateTracker blobSidecarsRequestTracker,
final RateTracker requestTracker,
final KZG kzg) {
final RateTracker requestTracker) {
return new DefaultEth2Peer(
spec,
peer,
Expand All @@ -58,8 +56,7 @@ static Eth2Peer create(
peerChainValidator,
blockRequestTracker,
blobSidecarsRequestTracker,
requestTracker,
kzg);
requestTracker);
}

void updateStatus(PeerStatus status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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 @@ -37,7 +36,6 @@ 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 @@ -48,8 +46,7 @@ public Eth2PeerFactory(
final TimeProvider timeProvider,
final Optional<Checkpoint> requiredCheckpoint,
final int peerRateLimit,
final int peerRequestLimit,
final KZG kzg) {
final int peerRequestLimit) {
this.spec = spec;
this.metricsSystem = metricsSystem;
this.chainDataClient = chainDataClient;
Expand All @@ -59,7 +56,6 @@ 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 @@ -73,7 +69,6 @@ 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),
kzg);
RateTracker.create(peerRequestLimit, TIME_OUT, timeProvider));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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 @@ -117,8 +116,7 @@ public static Eth2PeerManager create(
final TimeProvider timeProvider,
final int peerRateLimit,
final int peerRequestLimit,
final Spec spec,
final KZG kzg) {
final Spec spec) {

final MetadataMessagesFactory metadataMessagesFactory = new MetadataMessagesFactory();
attestationSubnetService.subscribeToUpdates(
Expand All @@ -141,8 +139,7 @@ public static Eth2PeerManager create(
timeProvider,
requiredCheckpoint,
peerRateLimit,
peerRequestLimit,
kzg),
peerRequestLimit),
statusMessageFactory,
metadataMessagesFactory,
rpcEncoding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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 @@ -57,7 +56,6 @@ 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 @@ -71,8 +69,7 @@ class Eth2PeerTest {
peerChainValidator,
blockRateTracker,
blobSidecarsRateTracker,
rateTracker,
kzg);
rateTracker);

@Test
void updateStatus_shouldNotUpdateUntilValidationPasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
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 @@ -224,13 +223,12 @@ protected Eth2P2PNetwork buildNetwork(final P2PConfig config) {
timeProvider,
500,
50,
spec,
KZG.NOOP);
spec);

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

this.peerHandler(eth2PeerManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ 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,6 +426,15 @@ 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 472b89e

Please sign in to comment.