From 472b89ea4f4ab9ca7ceb93e849a19572ad37dbb1 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Mon, 30 Oct 2023 08:39:28 +0000 Subject: [PATCH] Add getKzgInstance() in spec --- .../src/main/java/tech/pegasys/teku/spec/Spec.java | 9 +++++++++ .../executionlayer/ExecutionLayerChannelStub.java | 10 +--------- .../teku/networking/eth2/Eth2P2PNetworkBuilder.java | 11 +---------- .../teku/networking/eth2/peers/DefaultEth2Peer.java | 8 ++------ .../pegasys/teku/networking/eth2/peers/Eth2Peer.java | 7 ++----- .../teku/networking/eth2/peers/Eth2PeerFactory.java | 9 ++------- .../teku/networking/eth2/peers/Eth2PeerManager.java | 7 ++----- .../teku/networking/eth2/peers/Eth2PeerTest.java | 5 +---- .../teku/networking/eth2/Eth2P2PNetworkFactory.java | 6 ++---- .../services/beaconchain/BeaconChainController.java | 1 - .../tech/pegasys/teku/cli/BeaconNodeCommandTest.java | 9 +++++++++ 11 files changed, 31 insertions(+), 51 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java index b8583b31e13..636379c6fe9 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java @@ -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; @@ -982,6 +983,14 @@ public Optional 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 getSpecConfigDeneb() { final SpecMilestone highestSupportedMilestone = diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java index f0ec23eff28..4ca520447fa 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java @@ -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; @@ -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( diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java index c0ae86d93ef..fcfb61305dd 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java @@ -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; @@ -121,7 +120,6 @@ public class Eth2P2PNetworkBuilder { protected OperationProcessor gossipedSyncCommitteeMessageProcessor; protected StatusMessageFactory statusMessageFactory; - protected KZG kzg; protected Eth2P2PNetworkBuilder() {} @@ -156,8 +154,7 @@ public Eth2P2PNetwork build() { timeProvider, config.getPeerRateLimit(), config.getPeerRequestLimit(), - spec, - kzg); + spec); final Collection> eth2RpcMethods = eth2PeerManager.getBeaconChainMethods().all(); rpcMethods.addAll(eth2RpcMethods); @@ -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; - } } diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java index b4105730529..aa72bfac714 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/DefaultEth2Peer.java @@ -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; @@ -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 firstSlotSupportingBlobSidecarsByRange; private final Supplier blobSidecarsByRootRequestMessageSchema; @@ -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; @@ -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( () -> { @@ -332,7 +328,7 @@ public SafeFuture requestBlobSidecarsByRange( this, listener, maxBlobsPerBlock.get(), - kzg, + spec.getKzgInstance(), request.getStartSlot(), request.getCount())); }) diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2Peer.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2Peer.java index 5480b26df89..c07a3b9a60d 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2Peer.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2Peer.java @@ -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; @@ -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, @@ -58,8 +56,7 @@ static Eth2Peer create( peerChainValidator, blockRequestTracker, blobSidecarsRequestTracker, - requestTracker, - kzg); + requestTracker); } void updateStatus(PeerStatus status); diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java index dd996a4c7de..0740e98c58a 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java @@ -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; @@ -37,7 +36,6 @@ public class Eth2PeerFactory { private final Optional requiredCheckpoint; private final int peerRateLimit; private final int peerRequestLimit; - private final KZG kzg; public Eth2PeerFactory( final Spec spec, @@ -48,8 +46,7 @@ public Eth2PeerFactory( final TimeProvider timeProvider, final Optional requiredCheckpoint, final int peerRateLimit, - final int peerRequestLimit, - final KZG kzg) { + final int peerRequestLimit) { this.spec = spec; this.metricsSystem = metricsSystem; this.chainDataClient = chainDataClient; @@ -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) { @@ -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)); } } diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java index 96b1bf98dde..b8612f50ef3 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java @@ -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; @@ -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( @@ -141,8 +139,7 @@ public static Eth2PeerManager create( timeProvider, requiredCheckpoint, peerRateLimit, - peerRequestLimit, - kzg), + peerRequestLimit), statusMessageFactory, metadataMessagesFactory, rpcEncoding, diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerTest.java index c1b16ce44e9..ee4ff7e092e 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerTest.java @@ -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; @@ -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(); @@ -71,8 +69,7 @@ class Eth2PeerTest { peerChainValidator, blockRateTracker, blobSidecarsRateTracker, - rateTracker, - kzg); + rateTracker); @Test void updateStatus_shouldNotUpdateUntilValidationPasses() { diff --git a/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java b/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java index 416ddbc248a..918549f8acc 100644 --- a/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java +++ b/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java @@ -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; @@ -224,13 +223,12 @@ protected Eth2P2PNetwork buildNetwork(final P2PConfig config) { timeProvider, 500, 50, - spec, - KZG.NOOP); + spec); List> rpcMethods = eth2PeerManager.getBeaconChainMethods().all().stream() .flatMap(rpcMethodsModifier) - .collect(toList()); + .toList(); this.peerHandler(eth2PeerManager); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index 0334a6e895e..78483e02bad 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -1002,7 +1002,6 @@ protected void initP2PNetwork() { .keyValueStore(keyValueStore) .requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint()) .specProvider(spec) - .kzg(kzg) .build(); syncCommitteeMessagePool.subscribeOperationAdded( diff --git a/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java b/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java index 623edc75281..4165c909101 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java @@ -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 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 =