Skip to content

Commit

Permalink
Merge branch 'master' into remove-consolidation-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfyone authored Sep 24, 2024
2 parents 28d14e6 + c48a2ce commit 33cb40e
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CapellaUpgradeAcceptanceTest extends AcceptanceTestBase {
@Test
void shouldUpgradeToCapella() throws Exception {
final UInt64 currentTime = timeProvider.getTimeInSeconds();
final int genesisTime = currentTime.plus(30).intValue(); // magic node startup time
final int genesisTime = currentTime.plus(60).intValue(); // magic node startup time
final int shanghaiTime = genesisTime + 4 * 2; // 4 slots, 2 seconds each
final Map<String, String> genesisOverrides =
Map.of("shanghaiTime", String.valueOf(shanghaiTime));
Expand All @@ -51,6 +51,15 @@ void shouldUpgradeToCapella() throws Exception {
genesisOverrides);
primaryEL.start();

TekuBeaconNode primaryNode =
createTekuBeaconNode(
beaconNodeConfigWithForks(genesisTime, primaryEL)
.withStartupTargetPeerCount(0)
.build());

primaryNode.start();
primaryNode.waitForMilestone(SpecMilestone.CAPELLA);

BesuNode secondaryEL =
createBesuNode(
BesuDockerVersion.STABLE,
Expand All @@ -64,15 +73,6 @@ void shouldUpgradeToCapella() throws Exception {
secondaryEL.start();
secondaryEL.addPeer(primaryEL);

TekuBeaconNode primaryNode =
createTekuBeaconNode(
beaconNodeConfigWithForks(genesisTime, primaryEL)
.withStartupTargetPeerCount(0)
.build());

primaryNode.start();
primaryNode.waitForMilestone(SpecMilestone.CAPELLA);

final int primaryNodeGenesisTime = primaryNode.getGenesisTime().intValue();

TekuBeaconNode lateJoiningNode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DenebUpgradeAcceptanceTest extends AcceptanceTestBase {
@Test
void shouldUpgradeToDeneb() throws Exception {
final UInt64 currentTime = timeProvider.getTimeInSeconds();
final int genesisTime = currentTime.plus(30).intValue(); // magic node startup time
final int genesisTime = currentTime.plus(60).intValue(); // magic node startup time
final int epochDuration = 4 * 2; // 4 slots, 2 seconds each for swift
final int shanghaiTime = genesisTime + epochDuration;
final Map<String, String> genesisOverrides =
Expand All @@ -56,6 +56,15 @@ void shouldUpgradeToDeneb() throws Exception {
genesisOverrides);
primaryEL.start();

TekuBeaconNode primaryNode =
createTekuBeaconNode(
beaconNodeWithTrustedSetup(genesisTime, primaryEL)
.withStartupTargetPeerCount(0)
.build());

primaryNode.start();
primaryNode.waitForMilestone(SpecMilestone.DENEB);

BesuNode secondaryEL =
createBesuNode(
BesuDockerVersion.STABLE,
Expand All @@ -69,15 +78,6 @@ void shouldUpgradeToDeneb() throws Exception {
secondaryEL.start();
secondaryEL.addPeer(primaryEL);

TekuBeaconNode primaryNode =
createTekuBeaconNode(
beaconNodeWithTrustedSetup(genesisTime, primaryEL)
.withStartupTargetPeerCount(0)
.build());

primaryNode.start();
primaryNode.waitForMilestone(SpecMilestone.DENEB);

final int primaryNodeGenesisTime = primaryNode.getGenesisTime().intValue();

TekuBeaconNode lateJoiningNode =
Expand Down
2 changes: 1 addition & 1 deletion gradle/trivyignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# The following comment is an example of how CVE entries should be used in this file:
# CVE-2022-0123
CVE-2023-39017
CVE-2024-7254
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,8 @@ public boolean isWritableSupported() {
public String toString() {
return "SszBitlist{size=" + this.size() + ", " + value.toString() + "}";
}

public static SszBitlist fromBytes(final SszBitlistSchema<?> schema, final Bytes value) {
return new SszBitlistImpl(schema, BitlistImpl.fromSszBytes(value, schema.getMaxLength()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.infrastructure.ssz.schema.collections;

import java.util.BitSet;
import org.apache.tuweni.bytes.Bytes;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBit;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.impl.SszBitlistSchemaImpl;
Expand Down Expand Up @@ -41,4 +42,22 @@ default SszBitlistT empty() {
* @return SszBitlist instance
*/
SszBitlistT wrapBitSet(int size, BitSet bitSet);

/**
* Creates a SszBitlist from bytes.
*
* @param bytes The bytes to create the SszBitlist from
* @return A new SszBitlist instance
*/
SszBitlistT fromBytes(Bytes bytes);

/**
* Creates a SszBitlist from a hexadecimal string.
*
* @param hexString The hexadecimal string to create the SszBitlist from
* @return A new SszBitlist instance
*/
default SszBitlistT fromHexString(final String hexString) {
return fromBytes(Bytes.fromHexString(hexString));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,13 @@ public int flushWithBoundaryBit(final SszWriter writer, final int boundaryBitOff
}
}
}

@Override
public SszBitlist fromBytes(final Bytes bytes) {
checkArgument(bytes != null, "Input bytes cannot be null");
try (final SszReader reader = SszReader.fromBytes(bytes)) {
final TreeNode node = sszDeserializeTree(reader);
return createFromBackingNode(node);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public Stream<Arguments> emptyBitlistArgs() {
return sszData().filter(SszCollection::isEmpty).map(Arguments::of);
}

public Stream<Arguments> fromBytesTestCases() {
return sszData().map(bitlist -> Arguments.of(bitlist, bitlist.sszSerialize()));
}

public Stream<Arguments> fromHexStringTestCases() {
return sszData().map(bitlist -> Arguments.of(bitlist, bitlist.sszSerialize().toHexString()));
}

@ParameterizedTest
@MethodSource("bitlistArgs")
void testSszRoundtrip(final SszBitlist bitlist1) {
Expand Down Expand Up @@ -394,4 +402,65 @@ void testBitEmptyListSsz(final SszBitlist bitlist) {
SszBitlist emptyList1 = bitlist.getSchema().sszDeserialize(Bytes.of(1));
assertThat(emptyList1).isEmpty();
}

@ParameterizedTest
@MethodSource("fromBytesTestCases")
void testFromBytes(final SszBitlist bitlist, final Bytes serialized) {
SszBitlist deserialized = bitlist.getSchema().fromBytes(serialized);

assertThat(deserialized).isEqualTo(bitlist);
assertThat(deserialized.size()).isEqualTo(bitlist.size());
assertThatIntCollection(deserialized.getAllSetBits()).isEqualTo(bitlist.getAllSetBits());
assertThat(deserialized.hashTreeRoot()).isEqualTo(bitlist.hashTreeRoot());
}

@ParameterizedTest
@MethodSource("fromHexStringTestCases")
void testFromHexString(final SszBitlist bitlist, final String hexString) {
SszBitlist deserialized = bitlist.getSchema().fromHexString(hexString);

assertThat(deserialized).isEqualTo(bitlist);
assertThat(deserialized.size()).isEqualTo(bitlist.size());
assertThatIntCollection(deserialized.getAllSetBits()).isEqualTo(bitlist.getAllSetBits());
assertThat(deserialized.hashTreeRoot()).isEqualTo(bitlist.hashTreeRoot());
}

private static final SszBitlistSchema<SszBitlist> FROM_HEX_STRING_TEST_SCHEMA =
SszBitlistSchema.create(100);

@Test
public void fromHexString_shouldHandleMinimalValidHexString() {
String minimalHex = "0x01";
SszBitlist validResult = FROM_HEX_STRING_TEST_SCHEMA.fromHexString(minimalHex);
assertThat(validResult).isNotNull();
assertThat(validResult.sszSerialize()).isEqualTo(Bytes.fromHexString(minimalHex));
assertThat(validResult.size()).isZero();
}

@Test
public void fromHexString_shouldHandleComplexValidHexString() {
String complexHex = "0x01020304";
SszBitlist complexResult = FROM_HEX_STRING_TEST_SCHEMA.fromHexString(complexHex);
assertThat(complexResult).isNotNull();
assertThat(complexResult.sszSerialize()).isEqualTo(Bytes.fromHexString(complexHex));
}

@Test
public void fromHexString_shouldThrowForEmptyString() {
assertThatThrownBy(() -> FROM_HEX_STRING_TEST_SCHEMA.fromHexString(""))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
public void fromHexString_shouldThrowForOnlyPrefix() {
assertThatThrownBy(() -> FROM_HEX_STRING_TEST_SCHEMA.fromHexString("0x"))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
public void fromHexString_shouldThrowForInvalidHexString() {
String invalidHex = "i am a string, not a valid hex string";
assertThatThrownBy(() -> FROM_HEX_STRING_TEST_SCHEMA.fromHexString(invalidHex))
.isInstanceOf(IllegalArgumentException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tech.pegasys.teku.networking.eth2.gossip.config.GossipConfigurator;
import tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding;
import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig;
import tech.pegasys.teku.networking.p2p.gossip.config.GossipConfig;
import tech.pegasys.teku.networking.p2p.network.config.NetworkConfig;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.config.NetworkingSpecConfig;
Expand Down Expand Up @@ -174,6 +175,7 @@ public static class Builder {
private boolean batchVerifyStrictThreadLimitEnabled =
DEFAULT_BATCH_VERIFY_STRICT_THREAD_LIMIT_ENABLED;
private boolean allTopicsFilterEnabled = DEFAULT_PEER_ALL_TOPIC_FILTER_ENABLED;
private Boolean isFloodPublishEnabled = GossipConfig.DEFAULT_FLOOD_PUBLISH_ENABLED;

private Builder() {}

Expand All @@ -196,6 +198,7 @@ public P2PConfig build() {
builder.seenTTL(
Duration.ofSeconds(
(long) specConfig.getSecondsPerSlot() * specConfig.getSlotsPerEpoch() * 2));
builder.floodPublishEnabled(isFloodPublishEnabled);
});

final NetworkConfig networkConfig = this.networkConfig.build();
Expand Down Expand Up @@ -284,6 +287,12 @@ public Builder peerRequestLimit(final Integer peerRequestLimit) {
return this;
}

public Builder isFloodPublishEnabled(final Boolean floodPublishEnabled) {
checkNotNull(floodPublishEnabled);
this.isFloodPublishEnabled = floodPublishEnabled;
return this;
}

public Builder batchVerifyMaxThreads(final int batchVerifyMaxThreads) {
if (batchVerifyMaxThreads < 0) {
throw new InvalidConfigurationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class GossipConfig {
// After EIP-7045, attestations are valid for up to 2 full epochs, so TTL is 65
// slots 1115 * HEARTBEAT = 1115 * 0.7 / 12 = 65.125
static final Duration DEFAULT_SEEN_TTL = DEFAULT_HEARTBEAT_INTERVAL.multipliedBy(1115);
public static final Boolean DEFAULT_FLOOD_PUBLISH_ENABLED = Boolean.TRUE;

private final int d;
private final int dLow;
Expand All @@ -46,6 +47,7 @@ public class GossipConfig {
private final int history;
private final Duration heartbeatInterval;
private final Duration seenTTL;
private final Boolean floodPublishEnabled;
private final GossipScoringConfig scoringConfig;

private GossipConfig(
Expand All @@ -58,6 +60,7 @@ private GossipConfig(
final int history,
final Duration heartbeatInterval,
final Duration seenTTL,
final Boolean floodPublishEnabled,
final GossipScoringConfig scoringConfig) {
this.d = d;
this.dLow = dLow;
Expand All @@ -68,6 +71,7 @@ private GossipConfig(
this.history = history;
this.heartbeatInterval = heartbeatInterval;
this.seenTTL = seenTTL;
this.floodPublishEnabled = floodPublishEnabled;
this.scoringConfig = scoringConfig;
}

Expand Down Expand Up @@ -115,6 +119,10 @@ public Duration getSeenTTL() {
return seenTTL;
}

public boolean isFloodPublishEnabled() {
return floodPublishEnabled;
}

public GossipScoringConfig getScoringConfig() {
return scoringConfig;
}
Expand All @@ -131,6 +139,7 @@ public static class Builder {
private Integer history = DEFAULT_HISTORY;
private Duration heartbeatInterval = DEFAULT_HEARTBEAT_INTERVAL;
private Duration seenTTL = DEFAULT_SEEN_TTL;
private Boolean floodPublishEnabled = DEFAULT_FLOOD_PUBLISH_ENABLED;

private Builder() {}

Expand All @@ -145,6 +154,7 @@ public GossipConfig build() {
history,
heartbeatInterval,
seenTTL,
floodPublishEnabled,
scoringConfigBuilder.build());
}

Expand Down Expand Up @@ -217,6 +227,11 @@ public Builder seenTTL(final Duration seenTTL) {
return this;
}

public Builder floodPublishEnabled(final Boolean floodPublishEnabled) {
this.floodPublishEnabled = floodPublishEnabled;
return this;
}

public Builder directPeerManager(final DirectPeerManager directPeerManager) {
checkNotNull(directPeerManager);
this.scoringConfigBuilder.directPeerManager(directPeerManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ private static void addGossipParamsMiscValues(
final GossipConfig gossipConfig, final GossipParamsBuilder builder) {
builder
.fanoutTTL(gossipConfig.getFanoutTTL())
.floodPublish(gossipConfig.isFloodPublishEnabled())
.gossipSize(gossipConfig.getAdvertise())
.gossipHistoryLength(gossipConfig.getHistory())
.heartbeatInterval(gossipConfig.getHeartbeatInterval())
.floodPublish(true)
.seenTTL(gossipConfig.getSeenTTL());
}

Expand Down
15 changes: 14 additions & 1 deletion teku/src/main/java/tech/pegasys/teku/cli/options/P2POptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import tech.pegasys.teku.config.TekuConfiguration;
import tech.pegasys.teku.networking.eth2.P2PConfig;
import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig;
import tech.pegasys.teku.networking.p2p.gossip.config.GossipConfig;
import tech.pegasys.teku.networking.p2p.libp2p.MultiaddrPeerAddress;
import tech.pegasys.teku.networking.p2p.network.config.NetworkConfig;

Expand Down Expand Up @@ -366,6 +367,17 @@ The network interface(s) on which the node listens for P2P communication.
fallbackValue = "true")
private boolean yamuxEnabled = NetworkConfig.DEFAULT_YAMUX_ENABLED;

// More about flood publishing
// https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#flood-publishing
@Option(
names = {"--p2p-flood-publish-enabled"},
paramLabel = "<BOOLEAN>",
showDefaultValue = Visibility.ALWAYS,
description = "Enables gossip 'floodPublish' feature",
arity = "0..1",
fallbackValue = "true")
private boolean floodPublishEnabled = GossipConfig.DEFAULT_FLOOD_PUBLISH_ENABLED;

private OptionalInt getP2pLowerBound() {
if (p2pUpperBound.isPresent() && p2pLowerBound.isPresent()) {
return p2pLowerBound.getAsInt() < p2pUpperBound.getAsInt() ? p2pLowerBound : p2pUpperBound;
Expand Down Expand Up @@ -395,7 +407,8 @@ public void configure(final TekuConfiguration.Builder builder) {
.isGossipScoringEnabled(gossipScoringEnabled)
.peerRateLimit(peerRateLimit)
.allTopicsFilterEnabled(allTopicsFilterEnabled)
.peerRequestLimit(peerRequestLimit);
.peerRequestLimit(peerRequestLimit)
.isFloodPublishEnabled(floodPublishEnabled);
batchVerifyQueueCapacity.ifPresent(b::batchVerifyQueueCapacity);
})
.discovery(
Expand Down
Loading

0 comments on commit 33cb40e

Please sign in to comment.