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

7632 - add sync-min-peers to log and config overview #7732

Merged
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
3 changes: 2 additions & 1 deletion besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2701,7 +2701,8 @@ private String generateConfigurationOverview() {

builder
.setDataStorage(dataStorageOptions.normalizeDataStorageFormat())
.setSyncMode(syncMode.normalize());
.setSyncMode(syncMode.normalize())
.setSyncMinPeers(syncMinPeerCount);

if (jsonRpcConfiguration != null && jsonRpcConfiguration.isEnabled()) {
builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ConfigurationOverviewBuilder {
private String customGenesisFileName;
private String dataStorage;
private String syncMode;
private Integer syncMinPeers;
private Integer rpcPort;
private Collection<String> rpcHttpApis;
private Integer enginePort;
Expand Down Expand Up @@ -149,6 +150,17 @@ public ConfigurationOverviewBuilder setSyncMode(final String syncMode) {
return this;
}

/**
* Sets sync min peers.
*
* @param syncMinPeers number of min peers for sync
* @return the builder
*/
public ConfigurationOverviewBuilder setSyncMinPeers(final int syncMinPeers) {
this.syncMinPeers = syncMinPeers;
return this;
}

/**
* Sets rpc port.
*
Expand Down Expand Up @@ -353,6 +365,10 @@ public String build() {
lines.add("Sync mode: " + syncMode);
}

if (syncMinPeers != null) {
lines.add("Sync min peers: " + syncMinPeers);
}

if (rpcHttpApis != null) {
lines.add("RPC HTTP APIs: " + String.join(",", rpcHttpApis));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ void setSyncMode() {
assertThat(syncModeSet).contains("Sync mode: fast");
}

@Test
void setSyncMinPeers() {
final String noSyncMinPeersSet = builder.build();
assertThat(noSyncMinPeersSet).doesNotContain("Sync min peers:");

builder.setSyncMinPeers(3);
final String syncMinPeersSet = builder.build();
assertThat(syncMinPeersSet).contains("Sync min peers: 3");
}

@Test
void setRpcPort() {
final String noRpcPortSet = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class SyncTargetManager extends AbstractSyncTargetManager {
private static final int LOG_INFO_REPEAT_DELAY = 120;
private static final int SECONDS_PER_REQUEST = 6; // 5s per request + 1s wait between retries

private final SynchronizerConfiguration config;
private final WorldStateStorageCoordinator worldStateStorageCoordinator;
private final ProtocolSchedule protocolSchedule;
private final ProtocolContext protocolContext;
Expand All @@ -65,6 +66,7 @@ public SyncTargetManager(
final MetricsSystem metricsSystem,
final FastSyncState fastSyncState) {
super(config, protocolSchedule, protocolContext, ethContext, metricsSystem);
this.config = config;
this.worldStateStorageCoordinator = worldStateStorageCoordinator;
this.protocolSchedule = protocolSchedule;
this.protocolContext = protocolContext;
Expand All @@ -82,15 +84,17 @@ protected CompletableFuture<Optional<EthPeer>> selectBestAvailableSyncTarget() {
throttledLog(
LOG::debug,
String.format(
"Unable to find sync target. Currently checking %d peers for usefulness. Pivot block: %d",
ethContext.getEthPeers().peerCount(), pivotBlockHeader.getNumber()),
"Unable to find sync target. Waiting for %d peers minimum. Currently checking %d peers for usefulness. Pivot block: %d",
config.getSyncMinimumPeerCount(),
ethContext.getEthPeers().peerCount(),
pivotBlockHeader.getNumber()),
logDebug,
LOG_DEBUG_REPEAT_DELAY);
throttledLog(
LOG::info,
String.format(
"Unable to find sync target. Currently checking %d peers for usefulness.",
ethContext.getEthPeers().peerCount()),
"Unable to find sync target. Waiting for %d peers minimum. Currently checking %d peers for usefulness.",
config.getSyncMinimumPeerCount(), ethContext.getEthPeers().peerCount()),
logInfo,
LOG_INFO_REPEAT_DELAY);
return completedFuture(Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
class FullSyncTargetManager extends AbstractSyncTargetManager {

private static final Logger LOG = LoggerFactory.getLogger(FullSyncTargetManager.class);
private final SynchronizerConfiguration config;
private final ProtocolContext protocolContext;
private final EthContext ethContext;
private final SyncTerminationCondition terminationCondition;
Expand All @@ -49,6 +50,7 @@ class FullSyncTargetManager extends AbstractSyncTargetManager {
final MetricsSystem metricsSystem,
final SyncTerminationCondition terminationCondition) {
super(config, protocolSchedule, protocolContext, ethContext, metricsSystem);
this.config = config;
this.protocolContext = protocolContext;
this.ethContext = ethContext;
this.terminationCondition = terminationCondition;
Expand Down Expand Up @@ -77,7 +79,8 @@ protected CompletableFuture<Optional<EthPeer>> selectBestAvailableSyncTarget() {
final Optional<EthPeer> maybeBestPeer = ethContext.getEthPeers().bestPeerWithHeightEstimate();
if (!maybeBestPeer.isPresent()) {
LOG.info(
"Unable to find sync target. Currently checking {} peers for usefulness",
"Unable to find sync target. Waiting for {} peers minimum. Currently checking {} peers for usefulness",
config.getSyncMinimumPeerCount(),
ethContext.getEthPeers().peerCount());
return completedFuture(Optional.empty());
} else {
Expand Down
Loading