From bafa8e4bae362b7ed30185afcb21d4ea87904d2c Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Mon, 30 Oct 2023 08:46:00 +0000 Subject: [PATCH] Revert "Add getKzgInstance() in spec" This reverts commit 472b89ea4f4ab9ca7ceb93e849a19572ad37dbb1. --- .../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, 51 insertions(+), 31 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 726929c3895..ef9cc3146d6 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,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; @@ -985,14 +984,6 @@ 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 382048af953..47b7850c34f 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,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; @@ -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( 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 fcfb61305dd..c0ae86d93ef 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,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; @@ -120,6 +121,7 @@ public class Eth2P2PNetworkBuilder { protected OperationProcessor gossipedSyncCommitteeMessageProcessor; protected StatusMessageFactory statusMessageFactory; + protected KZG kzg; protected Eth2P2PNetworkBuilder() {} @@ -154,7 +156,8 @@ public Eth2P2PNetwork build() { timeProvider, config.getPeerRateLimit(), config.getPeerRequestLimit(), - spec); + spec, + kzg); final Collection> eth2RpcMethods = eth2PeerManager.getBeaconChainMethods().all(); rpcMethods.addAll(eth2RpcMethods); @@ -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; + } } 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 aa72bfac714..b4105730529 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,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; @@ -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 firstSlotSupportingBlobSidecarsByRange; private final Supplier blobSidecarsByRootRequestMessageSchema; @@ -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; @@ -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( () -> { @@ -328,7 +332,7 @@ public SafeFuture requestBlobSidecarsByRange( this, listener, maxBlobsPerBlock.get(), - spec.getKzgInstance(), + kzg, 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 c07a3b9a60d..5480b26df89 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,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; @@ -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, @@ -56,7 +58,8 @@ static Eth2Peer create( peerChainValidator, blockRequestTracker, blobSidecarsRequestTracker, - requestTracker); + requestTracker, + kzg); } 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 0740e98c58a..dd996a4c7de 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,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; @@ -36,6 +37,7 @@ public class Eth2PeerFactory { private final Optional requiredCheckpoint; private final int peerRateLimit; private final int peerRequestLimit; + private final KZG kzg; public Eth2PeerFactory( final Spec spec, @@ -46,7 +48,8 @@ public Eth2PeerFactory( final TimeProvider timeProvider, final Optional requiredCheckpoint, final int peerRateLimit, - final int peerRequestLimit) { + final int peerRequestLimit, + final KZG kzg) { this.spec = spec; this.metricsSystem = metricsSystem; this.chainDataClient = chainDataClient; @@ -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) { @@ -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); } } 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 b8612f50ef3..96b1bf98dde 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,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; @@ -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( @@ -139,7 +141,8 @@ public static Eth2PeerManager create( timeProvider, requiredCheckpoint, peerRateLimit, - peerRequestLimit), + peerRequestLimit, + kzg), 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 ee4ff7e092e..c1b16ce44e9 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,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; @@ -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(); @@ -69,7 +71,8 @@ class Eth2PeerTest { peerChainValidator, blockRateTracker, blobSidecarsRateTracker, - rateTracker); + rateTracker, + kzg); @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 918549f8acc..416ddbc248a 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,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; @@ -223,12 +224,13 @@ protected Eth2P2PNetwork buildNetwork(final P2PConfig config) { timeProvider, 500, 50, - spec); + spec, + KZG.NOOP); List> rpcMethods = eth2PeerManager.getBeaconChainMethods().all().stream() .flatMap(rpcMethodsModifier) - .toList(); + .collect(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 6752a717e53..2eecce2d79a 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,6 +1002,7 @@ 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 4165c909101..623edc75281 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java @@ -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 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 =