Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecFactory;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.config.ProgressiveBalancesMode;
import tech.pegasys.teku.spec.networks.Eth2Network;
Expand All @@ -61,6 +62,8 @@ public class Eth2NetworkConfiguration {
private final List<String> discoveryBootnodes;
private final Optional<UInt64> altairForkEpoch;
private final Optional<UInt64> bellatrixForkEpoch;
private final Optional<UInt64> capellaForkEpoch;
private final Optional<UInt64> eip4844ForkEpoch;
private final Eth1Address eth1DepositContractAddress;
private final Optional<UInt64> eth1DepositContractDeployBlock;

Expand All @@ -83,6 +86,8 @@ private Eth2NetworkConfiguration(
final boolean forkChoiceUpdateHeadOnBlockImportEnabled,
final Optional<UInt64> altairForkEpoch,
final Optional<UInt64> bellatrixForkEpoch,
final Optional<UInt64> capellaForkEpoch,
final Optional<UInt64> eip4844ForkEpoch,
final Optional<Bytes32> terminalBlockHashOverride,
final Optional<UInt256> totalTerminalDifficultyOverride,
final Optional<UInt64> terminalBlockHashEpochOverride) {
Expand All @@ -96,6 +101,8 @@ private Eth2NetworkConfiguration(
this.discoveryBootnodes = discoveryBootnodes;
this.altairForkEpoch = altairForkEpoch;
this.bellatrixForkEpoch = bellatrixForkEpoch;
this.capellaForkEpoch = capellaForkEpoch;
this.eip4844ForkEpoch = eip4844ForkEpoch;
this.eth1DepositContractAddress =
eth1DepositContractAddress == null
? spec.getGenesisSpecConfig().getDepositContractAddress()
Expand Down Expand Up @@ -168,12 +175,19 @@ public boolean isForkChoiceUpdateHeadOnBlockImportEnabled() {
return forkChoiceUpdateHeadOnBlockImportEnabled;
}

public Optional<UInt64> getAltairForkEpoch() {
return altairForkEpoch;
}

public Optional<UInt64> getBellatrixForkEpoch() {
return bellatrixForkEpoch;
public Optional<UInt64> getForkEpoch(final SpecMilestone specMilestone) {
switch (specMilestone) {
case ALTAIR:
return altairForkEpoch;
case BELLATRIX:
return bellatrixForkEpoch;
case CAPELLA:
return capellaForkEpoch;
case EIP4844:
return eip4844ForkEpoch;
default:
return Optional.empty();
}
}

public Optional<Bytes32> getTerminalBlockHashOverride() {
Expand Down Expand Up @@ -207,6 +221,7 @@ public static class Builder {
private Optional<UInt64> altairForkEpoch = Optional.empty();
private Optional<UInt64> bellatrixForkEpoch = Optional.empty();
private Optional<UInt64> capellaForkEpoch = Optional.empty();
private Optional<UInt64> eip4844ForkEpoch = Optional.empty();
private Optional<Bytes32> terminalBlockHashOverride = Optional.empty();
private Optional<UInt256> totalTerminalDifficultyOverride = Optional.empty();
private Optional<UInt64> terminalBlockHashEpochOverride = Optional.empty();
Expand Down Expand Up @@ -247,6 +262,9 @@ public Eth2NetworkConfiguration build() {
builder.capellaBuilder(
capellaBuilder ->
capellaForkEpoch.ifPresent(capellaBuilder::capellaForkEpoch));
builder.eip4844Builder(
eip4844Builder ->
eip4844ForkEpoch.ifPresent(eip4844Builder::eip4844ForkEpoch));
});
}
// if the deposit contract was not set, default from constants
Expand All @@ -267,6 +285,8 @@ public Eth2NetworkConfiguration build() {
forkChoiceUpdateHeadOnBlockImportEnabled,
altairForkEpoch,
bellatrixForkEpoch,
capellaForkEpoch,
eip4844ForkEpoch,
terminalBlockHashOverride,
totalTerminalDifficultyOverride,
terminalBlockHashEpochOverride);
Expand Down Expand Up @@ -373,6 +393,11 @@ public Builder capellaForkEpoch(final UInt64 capellaForkEpoch) {
return this;
}

public Builder eip4844ForkEpoch(final UInt64 eip4844ForkEpoch) {
this.eip4844ForkEpoch = Optional.of(eip4844ForkEpoch);
return this;
}

public Builder safeSlotsToImportOptimistically(final int safeSlotsToImportOptimistically) {
if (safeSlotsToImportOptimistically < 0) {
throw new InvalidConfigurationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static tech.pegasys.teku.spec.SpecMilestone.ALTAIR;
import static tech.pegasys.teku.spec.SpecMilestone.BELLATRIX;
import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
import static tech.pegasys.teku.spec.SpecMilestone.EIP4844;
import static tech.pegasys.teku.spec.SpecMilestone.PHASE0;
import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH;

Expand All @@ -26,6 +27,7 @@
import tech.pegasys.teku.spec.config.SpecConfigBellatrix;
import tech.pegasys.teku.spec.config.SpecConfigBuilder;
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigEip4844;
import tech.pegasys.teku.spec.config.SpecConfigLoader;

public class SpecFactory {
Expand All @@ -52,9 +54,16 @@ public static Spec create(final SpecConfig config) {
.toVersionCapella()
.map(SpecConfigCapella::getCapellaForkEpoch)
.orElse(FAR_FUTURE_EPOCH);
final UInt64 eip4844ForkEpoch =
config
.toVersionEip4844()
.map(SpecConfigEip4844::getEip4844ForkEpoch)
.orElse(FAR_FUTURE_EPOCH);
final SpecMilestone highestMilestoneSupported;

if (!capellaForkEpoch.equals(FAR_FUTURE_EPOCH)) {
if (!eip4844ForkEpoch.equals(FAR_FUTURE_EPOCH)) {
highestMilestoneSupported = EIP4844;
} else if (!capellaForkEpoch.equals(FAR_FUTURE_EPOCH)) {
highestMilestoneSupported = CAPELLA;
} else if (!bellatrixForkEpoch.equals(FAR_FUTURE_EPOCH)) {
highestMilestoneSupported = BELLATRIX;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright ConsenSys Software Inc., 2022
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.networking.eth2;

import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.networking.eth2.gossip.topics.OperationMilestoneValidator;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip4844.SignedBeaconBlockAndBlobsSidecar;
import tech.pegasys.teku.spec.datastructures.state.ForkInfo;

public class BlockAndBlobsSidecarOperationMilestoneValidator
implements OperationMilestoneValidator<SignedBeaconBlockAndBlobsSidecar> {

private final Bytes4 forkDigest;

public BlockAndBlobsSidecarOperationMilestoneValidator(final Spec spec, final ForkInfo forkInfo) {
this.forkDigest = forkInfo.getForkDigest(spec);
}

@Override
public boolean isValid(final SignedBeaconBlockAndBlobsSidecar message, final Bytes4 forkDigest) {
return this.forkDigest.equals(forkDigest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import tech.pegasys.teku.networking.eth2.gossip.forks.versions.GossipForkSubscriptionsAltair;
import tech.pegasys.teku.networking.eth2.gossip.forks.versions.GossipForkSubscriptionsBellatrix;
import tech.pegasys.teku.networking.eth2.gossip.forks.versions.GossipForkSubscriptionsCapella;
import tech.pegasys.teku.networking.eth2.gossip.forks.versions.GossipForkSubscriptionsEip4844;
import tech.pegasys.teku.networking.eth2.gossip.forks.versions.GossipForkSubscriptionsPhase0;
import tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationSubnetTopicProvider;
import tech.pegasys.teku.networking.eth2.gossip.subnets.PeerSubnetSubscriptions;
Expand Down Expand Up @@ -65,6 +66,7 @@
import tech.pegasys.teku.spec.config.Constants;
import tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip4844.SignedBeaconBlockAndBlobsSidecar;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
Expand All @@ -91,6 +93,7 @@ public class Eth2P2PNetworkBuilder {
protected EventChannels eventChannels;
protected RecentChainData recentChainData;
protected OperationProcessor<SignedBeaconBlock> gossipedBlockProcessor;
protected OperationProcessor<SignedBeaconBlockAndBlobsSidecar> gossipedBlockAndBlobsProcessor;
protected OperationProcessor<ValidateableAttestation> gossipedAttestationConsumer;
protected OperationProcessor<ValidateableAttestation> gossipedAggregateProcessor;
protected OperationProcessor<AttesterSlashing> gossipedAttesterSlashingConsumer;
Expand Down Expand Up @@ -260,6 +263,25 @@ private GossipForkSubscriptions createSubscriptions(
gossipedSignedContributionAndProofProcessor,
gossipedSyncCommitteeMessageProcessor,
gossipedSignedBlsToExecutionChangeProcessor);
case EIP4844:
return new GossipForkSubscriptionsEip4844(
forkAndSpecMilestone.getFork(),
spec,
asyncRunner,
metricsSystem,
network,
recentChainData,
gossipEncoding,
gossipedBlockProcessor,
gossipedBlockAndBlobsProcessor,
gossipedAttestationConsumer,
gossipedAggregateProcessor,
gossipedAttesterSlashingConsumer,
gossipedProposerSlashingConsumer,
gossipedVoluntaryExitConsumer,
gossipedSignedContributionAndProofProcessor,
gossipedSyncCommitteeMessageProcessor,
gossipedSignedBlsToExecutionChangeProcessor);
default:
throw new UnsupportedOperationException(
"Gossip not supported for fork " + forkAndSpecMilestone.getSpecMilestone());
Expand Down Expand Up @@ -406,6 +428,13 @@ public Eth2P2PNetworkBuilder gossipedBlockProcessor(
return this;
}

public Eth2P2PNetworkBuilder gossipedBlockAndBlobsProcessor(
final OperationProcessor<SignedBeaconBlockAndBlobsSidecar> gossipedBlockAndBlobsProcessor) {
checkNotNull(gossipedBlockAndBlobsProcessor);
this.gossipedBlockAndBlobsProcessor = gossipedBlockAndBlobsProcessor;
return this;
}

public Eth2P2PNetworkBuilder gossipedAttestationProcessor(
final OperationProcessor<ValidateableAttestation> gossipedAttestationProcessor) {
checkNotNull(gossipedAttestationProcessor);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright ConsenSys Software Inc., 2022
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.networking.eth2.gossip;

import java.util.Optional;
import tech.pegasys.teku.infrastructure.async.AsyncRunner;
import tech.pegasys.teku.networking.eth2.BlockAndBlobsSidecarOperationMilestoneValidator;
import tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding;
import tech.pegasys.teku.networking.eth2.gossip.topics.GossipTopicName;
import tech.pegasys.teku.networking.eth2.gossip.topics.OperationProcessor;
import tech.pegasys.teku.networking.p2p.gossip.GossipNetwork;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip4844.SignedBeaconBlockAndBlobsSidecar;
import tech.pegasys.teku.spec.datastructures.state.ForkInfo;
import tech.pegasys.teku.storage.client.RecentChainData;

public class BlockAndBlobsSidecarGossipManager
extends AbstractGossipManager<SignedBeaconBlockAndBlobsSidecar> {

public BlockAndBlobsSidecarGossipManager(
final RecentChainData recentChainData,
final Spec spec,
final AsyncRunner asyncRunner,
final GossipNetwork gossipNetwork,
final GossipEncoding gossipEncoding,
final ForkInfo forkInfo,
final OperationProcessor<SignedBeaconBlockAndBlobsSidecar> processor,
final int maxMessageSize) {
super(
recentChainData,
GossipTopicName.BEACON_BLOCK_AND_BLOBS_SIDECAR,
asyncRunner,
gossipNetwork,
gossipEncoding,
forkInfo,
processor,
spec.atEpoch(forkInfo.getFork().getEpoch())
.getSchemaDefinitions()
.toVersionEip4844()
.orElseThrow()
.getSignedBeaconBlockAndBlobsSidecarSchema(),
Optional.of(new BlockAndBlobsSidecarOperationMilestoneValidator(spec, forkInfo)),
maxMessageSize);
}

public void publishBlockAndBlobsSidecar(final SignedBeaconBlockAndBlobsSidecar message) {
publishMessage(message);
}

@Override
public boolean isEnabledDuringOptimisticSync() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip4844.SignedBeaconBlockAndBlobsSidecar;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
Expand All @@ -38,23 +39,35 @@ public interface GossipForkSubscriptions {

void publishBlock(SignedBeaconBlock block);

default void publishBlockAndBlobsSidecar(SignedBeaconBlockAndBlobsSidecar blockAndBlobsSidecar) {
// from Eip4844
}

void subscribeToAttestationSubnetId(int subnetId);

void unsubscribeFromAttestationSubnetId(int subnetId);

void publishSyncCommitteeMessage(ValidateableSyncCommitteeMessage message);
default void publishSyncCommitteeMessage(ValidateableSyncCommitteeMessage message) {
// from Altair
}

void publishSyncCommitteeContribution(SignedContributionAndProof message);
default void publishSyncCommitteeContribution(SignedContributionAndProof message) {
// from Altair
}

void publishProposerSlashing(ProposerSlashing message);

void publishAttesterSlashing(AttesterSlashing message);

void publishVoluntaryExit(SignedVoluntaryExit message);

void subscribeToSyncCommitteeSubnet(int subnetId);
default void subscribeToSyncCommitteeSubnet(int subnetId) {
// from Altair
}

void unsubscribeFromSyncCommitteeSubnet(int subnetId);
default void unsubscribeFromSyncCommitteeSubnet(int subnetId) {
// from Altair
}

void publishSignedBlsToExecutionChangeMessage(SignedBlsToExecutionChange message);
default void publishSignedBlsToExecutionChangeMessage(SignedBlsToExecutionChange message) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public GossipForkSubscriptionsAltair(
this.syncCommitteeMessageOperationProcessor = syncCommitteeMessageOperationProcessor;
}

@Override
protected void addGossipManagers(final ForkInfo forkInfo) {
super.addGossipManagers(forkInfo);
void addSignedContributionAndProofGossipManager(final ForkInfo forkInfo) {
final SchemaDefinitionsAltair schemaDefinitions =
SchemaDefinitionsAltair.required(spec.atEpoch(getActivationEpoch()).getSchemaDefinitions());
syncCommitteeContributionGossipManager =
Expand All @@ -97,7 +95,11 @@ protected void addGossipManagers(final ForkInfo forkInfo) {
signedContributionAndProofOperationProcessor,
getMessageMaxSize());
addGossipManager(syncCommitteeContributionGossipManager);
}

void addSyncCommitteeMessageGossipManager(final ForkInfo forkInfo) {
final SchemaDefinitionsAltair schemaDefinitions =
SchemaDefinitionsAltair.required(spec.atEpoch(getActivationEpoch()).getSchemaDefinitions());
final SyncCommitteeSubnetSubscriptions syncCommitteeSubnetSubscriptions =
new SyncCommitteeSubnetSubscriptions(
spec,
Expand All @@ -118,6 +120,13 @@ protected void addGossipManagers(final ForkInfo forkInfo) {
addGossipManager(syncCommitteeMessageGossipManager);
}

@Override
protected void addGossipManagers(final ForkInfo forkInfo) {
super.addGossipManagers(forkInfo);
addSignedContributionAndProofGossipManager(forkInfo);
addSyncCommitteeMessageGossipManager(forkInfo);
}

@Override
public void publishSyncCommitteeMessage(final ValidateableSyncCommitteeMessage message) {
syncCommitteeMessageGossipManager.publish(message);
Expand Down
Loading