Skip to content

Commit

Permalink
sl
Browse files Browse the repository at this point in the history
  • Loading branch information
pinges committed Dec 22, 2023
1 parent 2ceffa2 commit 6de0749
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason;
import org.hyperledger.besu.ethereum.rlp.RLPException;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;

import java.math.BigInteger;
import java.util.ArrayList;
Expand All @@ -58,11 +63,6 @@

import com.google.common.annotations.VisibleForTesting;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -133,7 +133,8 @@ public EthProtocolManager(
ethMessages,
ethereumWireProtocolConfiguration);

this.forkIdCounter = metricsSystem.createLabelledCounter(
this.forkIdCounter =
metricsSystem.createLabelledCounter(
BesuMetricCategory.NETWORK,
"discovery_fork_id_counter",
"total number of successful, failed fork id checks, as well as fork id not present",
Expand Down Expand Up @@ -172,25 +173,25 @@ public EthProtocolManager(
Collections.emptyList(),
Collections.emptyList(),
ethereumWireProtocolConfiguration.isLegacyEth64ForkIdEnabled()),
new NoOpMetricsSystem());
new NoOpMetricsSystem());
}

public EthProtocolManager(
final Blockchain blockchain,
final BigInteger networkId,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration,
final EthPeers ethPeers,
final EthMessages ethMessages,
final EthContext ethContext,
final List<PeerValidator> peerValidators,
final Optional<MergePeerFilter> mergePeerFilter,
final SynchronizerConfiguration synchronizerConfiguration,
final EthScheduler scheduler,
final List<Long> blockNumberForks,
final List<Long> timestampForks,
final ObservableMetricsSystem metricsSystem) {
final Blockchain blockchain,
final BigInteger networkId,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration,
final EthPeers ethPeers,
final EthMessages ethMessages,
final EthContext ethContext,
final List<PeerValidator> peerValidators,
final Optional<MergePeerFilter> mergePeerFilter,
final SynchronizerConfiguration synchronizerConfiguration,
final EthScheduler scheduler,
final List<Long> blockNumberForks,
final List<Long> timestampForks,
final ObservableMetricsSystem metricsSystem) {
this(
blockchain,
networkId,
Expand All @@ -209,8 +210,7 @@ public EthProtocolManager(
blockNumberForks,
timestampForks,
ethereumWireProtocolConfiguration.isLegacyEth64ForkIdEnabled()),
metricsSystem
);
metricsSystem);
}

public EthContext ethContext() {
Expand Down Expand Up @@ -439,15 +439,15 @@ private void handleStatusMessage(final EthPeer peer, final Message message) {
forkIdCounter.labels("FAIL").inc();
LOG.debug(
"{} has matching network id ({}), but non-matching fork id: {}",
LOG.isTraceEnabled() ? peer : peer.getShortNodeId(),
LOG.isTraceEnabled() ? peer : peer.getShortNodeId(),
networkId,
forkId);
peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED);
} else if (forkIdManager.peerCheck(status.genesisHash())) {
forkIdCounter.labels("FAIL").inc();
LOG.debug(
"{} has matching network id ({}), but non-matching genesis hash: {}",
LOG.isTraceEnabled() ? peer : peer.getShortNodeId(),
LOG.isTraceEnabled() ? peer : peer.getShortNodeId(),
networkId,
status.genesisHash());
peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ private EthProtocolManager createEthManager(
syncConfig,
mock(EthScheduler.class),
mock(ForkIdManager.class),
new NoOpMetricsSystem())) {
new NoOpMetricsSystem())) {

return ethManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static EthProtocolManager create(
mock(SynchronizerConfiguration.class),
ethScheduler,
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false),
new NoOpMetricsSystem());
new NoOpMetricsSystem());
}

public static EthProtocolManager create(
Expand Down Expand Up @@ -156,7 +156,7 @@ public static EthProtocolManager create(
mock(SynchronizerConfiguration.class),
ethScheduler,
forkIdManager,
new NoOpMetricsSystem());
new NoOpMetricsSystem());
}

public static EthProtocolManager create(final Blockchain blockchain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void setupInitialSyncPhase(final boolean hasInitialSyncPhase) {
mock(SynchronizerConfiguration.class),
mock(EthScheduler.class),
mock(ForkIdManager.class),
new NoOpMetricsSystem());
new NoOpMetricsSystem());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public DiscoveryProtocolLogger(final MetricsSystem metricsSystem) {
"discovery_messages_inbound",
"Total number of P2P discovery messages received",
"name");
forkIdCounter = metricsSystem.createLabelledCounter(
forkIdCounter =
metricsSystem.createLabelledCounter(
BesuMetricCategory.NETWORK,
"discovery_fork_id_counter",
"total number of successful, failed fork id checks, as well as fork id not present",
Expand Down Expand Up @@ -74,17 +75,18 @@ void logReceivedPacket(final Peer peer, final Packet packet) {

void logForkIdSuccess(final Peer peer, final ForkId forkId) {
forkIdCounter.labels("SUCC").inc();
LOG.trace("ForkId successfully checked for peer {}, fork id {}", peer.getId().slice(0,16), forkId);
LOG.trace(
"ForkId successfully checked for peer {}, fork id {}", peer.getId().slice(0, 16), forkId);
}

void logForkIdFailure(final Peer peer, final ForkId forkId) {
forkIdCounter.labels("FAIL").inc();
LOG.trace("ForkId check failed for peer {}, fork id {}", peer.getId().slice(0,16), forkId);
LOG.trace("ForkId check failed for peer {}, fork id {}", peer.getId().slice(0, 16), forkId);
}

void logForkIdNotSent(final Peer peer) {
forkIdCounter.labels("NOSE").inc();
LOG.trace("ForkId not sent by peer {}", peer.getId().slice(0,16));
LOG.trace("ForkId not sent by peer {}", peer.getId().slice(0, 16));
}

void logForkIdNotRequestedt(final Peer peer) {
Expand All @@ -93,7 +95,7 @@ void logForkIdNotRequestedt(final Peer peer) {

void logForkIdRequestedt(final DiscoveryPeer peer) {
forkIdCounter.labels("REQU").inc();
LOG.trace("ForkId requested from peer {}", peer.getId().slice(0,16));
LOG.trace("ForkId requested from peer {}", peer.getId().slice(0, 16));
}

private String shortenPacketType(final Packet packet) {
Expand All @@ -113,5 +115,4 @@ private String shortenPacketType(final Packet packet) {
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ public void start() {
// Periodically initiate outgoing connections to discovered peers
final int checkConnectionsSec = config.getInitiateConnectionsFrequencySec();
peerConnectionScheduler.scheduleWithFixedDelay(
this::attemptPeerConnections, checkConnectionsSec, checkConnectionsSec, TimeUnit.SECONDS); // TODO: stefan: if we do have max peers we could stop doing this. We would still try to connect to every node that we just bonded with
this::attemptPeerConnections,
checkConnectionsSec,
checkConnectionsSec,
TimeUnit
.SECONDS); // TODO: stefan: if we do have max peers we could stop doing this. We would
// still try to connect to every node that we just bonded with
}

@Override
Expand Down

0 comments on commit 6de0749

Please sign in to comment.