Skip to content

Commit

Permalink
7632 - add sync-min-peers to log and config overview
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin King <[email protected]>
  • Loading branch information
kingnhcomcast committed Oct 4, 2024
1 parent 94099d1 commit a0fd3bf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
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 @@ -2902,7 +2902,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 @@ -148,6 +149,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 @@ -340,6 +352,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

0 comments on commit a0fd3bf

Please sign in to comment.