Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add floodPublish CLI flag #8610

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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;

private Builder() {}

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

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

public Builder isFloodPublishEnabled(final Boolean 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 = 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 floodPublish;
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 floodPublish,
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.floodPublish = floodPublish;
this.scoringConfig = scoringConfig;
}

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

public Boolean getFloodPublish() {
return floodPublish;
}

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 floodPublish = DEFAULT_FLOOD_PUBLISH;

private Builder() {}

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

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

public Builder floodPublish(final Boolean floodPublish) {
this.floodPublish = floodPublish;
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.getFloodPublish())
.gossipSize(gossipConfig.getAdvertise())
.gossipHistoryLength(gossipConfig.getHistory())
.heartbeatInterval(gossipConfig.getHeartbeatInterval())
.floodPublish(true)
.seenTTL(gossipConfig.getSeenTTL());
}

Expand Down
16 changes: 15 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,18 @@ 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",
hidden = true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit tests detected this is declared hidden even if it is not a --X config. You should remove this.

arity = "0..1",
fallbackValue = "true")
private boolean floodPublishEnabled = GossipConfig.DEFAULT_FLOOD_PUBLISH;

private OptionalInt getP2pLowerBound() {
if (p2pUpperBound.isPresent() && p2pLowerBound.isPresent()) {
return p2pLowerBound.getAsInt() < p2pUpperBound.getAsInt() ? p2pLowerBound : p2pUpperBound;
Expand Down Expand Up @@ -395,7 +408,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