Skip to content
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
10 changes: 10 additions & 0 deletions common/src/main/java/org/tron/common/prometheus/MetricKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public static class Histogram {
*/
public static final String TX_FETCH_LATENCY = "tron:tx_fetch_latency_seconds";

/**
* Handshake round-trip latency in seconds: from TCP connection
* establishment to {@code HelloMessage} fully processed.
* <p>Sampled only on the SR{@literal <->}FF handshake path — either
* the received {@code HelloMessage} carries a witness signature, or
* the remote peer is in {@code node.fastForward.nodes}. Regular
* FullNode handshakes are not sampled.
*/
public static final String HANDSHAKE_LATENCY = "tron:handshake_latency_seconds";

private Histogram() {
throw new IllegalStateException("Histogram");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class MetricsHistogram {
"receive block delay time, receiveTime - blockTime.");
init(MetricKeys.Histogram.TX_FETCH_LATENCY,
"fetch transaction latency: GET_DATA send to full TXS received round-trip.");
init(MetricKeys.Histogram.HANDSHAKE_LATENCY,
"handshake round-trip latency on the SR<->FF path.");

init(MetricKeys.Histogram.BLOCK_TRANSACTION_COUNT,
"Distribution of transaction counts per block.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.common.prometheus.MetricKeys;
import org.tron.common.prometheus.Metrics;
import org.tron.common.utils.ByteArray;
import org.tron.core.ChainBaseManager;
import org.tron.core.ChainBaseManager.NodeType;
Expand All @@ -15,6 +17,7 @@
import org.tron.core.net.service.effective.EffectiveCheckService;
import org.tron.core.net.service.relay.RelayService;
import org.tron.p2p.discover.Node;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.ReasonCode;

@Slf4j(topic = "net")
Expand Down Expand Up @@ -122,8 +125,17 @@ public void processHelloMessage(PeerConnection peer, HelloMessage msg) {

peer.setHelloMessageReceive(msg);

peer.getChannel().updateAvgLatency(
System.currentTimeMillis() - peer.getChannel().getStartTime());
long latencyMs = System.currentTimeMillis() - peer.getChannel().getStartTime();
peer.getChannel().updateAvgLatency(latencyMs);
// Sample only the SR<->FF handshake path:
// - inbound: received hello carries a witness signature.
// - outbound: peer is in node.fastForward.nodes.
Protocol.HelloMessage hello = msg.getInstance();
boolean signed = !hello.getSignature().isEmpty() || hello.hasPqAuthSig();
if (signed || relayService.isFastForwardPeer(peer.getChannel())) {
Metrics.histogramObserve(MetricKeys.Histogram.HANDSHAKE_LATENCY,
latencyMs / Metrics.MILLISECONDS_PER_SECOND);
}
PeerManager.sortPeers();
peer.onConnect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ public void close() {
ExecutorServiceManager.shutdownAndAwaitTermination(executorService, esName);
}

/**
* Whether the channel's remote peer is in {@code node.fastForward.nodes}.
*/
public boolean isFastForwardPeer(Channel channel) {
if (fastForwardNodes.isEmpty() || channel == null
|| channel.getInetAddress() == null) {
return false;
}
for (InetSocketAddress ff : fastForwardNodes) {
if (channel.getInetAddress().equals(ff.getAddress())) {
return true;
}
}
return false;
}

public void fillHelloMessage(HelloMessage message, Channel channel) {
if (!isActiveWitness()) {
return;
Expand Down