diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftSubProtocol.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftSubProtocol.java index d140b08980..0518e7cc7e 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftSubProtocol.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftSubProtocol.java @@ -51,4 +51,22 @@ public class IbftSubProtocol implements SubProtocol { return false; } } + + @Override + public String messageName(final int protocolVersion, final int code) { + switch (code) { + case IbftV2.PROPOSAL: + return "Proposal"; + case IbftV2.PREPARE: + return "Prepare"; + case IbftV2.COMMIT: + return "Commit"; + case IbftV2.ROUND_CHANGE: + return "RoundChange"; + case IbftV2.NEW_ROUND: + return "NewRound"; + default: + return INVALID_MESSAGE_NAME; + } + } } diff --git a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64Protocol.java b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64Protocol.java index eff7cf3a88..150647a496 100644 --- a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64Protocol.java +++ b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64Protocol.java @@ -69,6 +69,40 @@ public class Istanbul64Protocol implements SubProtocol { return false; } + @Override + public String messageName(final int protocolVersion, final int code) { + switch (code) { + case EthPV62.STATUS: + return "Status"; + case EthPV62.NEW_BLOCK_HASHES: + return "NewBlockHashes"; + case EthPV62.TRANSACTIONS: + return "Transactions"; + case EthPV62.GET_BLOCK_HEADERS: + return "GetBlockHeaders"; + case EthPV62.BLOCK_HEADERS: + return "BlockHeaders"; + case EthPV62.GET_BLOCK_BODIES: + return "GetBlockBodies"; + case EthPV62.BLOCK_BODIES: + return "BlockBodies"; + case EthPV62.NEW_BLOCK: + return "NewBlock"; + case EthPV63.GET_NODE_DATA: + return "GetNodeData"; + case EthPV63.NODE_DATA: + return "NodeData"; + case EthPV63.GET_RECEIPTS: + return "GetReceipts"; + case EthPV63.RECEIPTS: + return "Receipts"; + case INSTANBUL_MSG: + return "InstanbulMsg"; + default: + return INVALID_MESSAGE_NAME; + } + } + public static Istanbul64Protocol get() { return INSTANCE; } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthProtocol.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthProtocol.java index 16f67b0c16..f346e18de4 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthProtocol.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthProtocol.java @@ -21,6 +21,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +/** + * Eth protocol messages as defined in + * https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol#new-model-syncing-pv62} + */ public class EthProtocol implements SubProtocol { public static final String NAME = "eth"; public static final Capability ETH62 = Capability.create(NAME, EthVersion.V62); @@ -75,6 +79,30 @@ public class EthProtocol implements SubProtocol { } } + @Override + public String messageName(final int protocolVersion, final int code) { + switch (code) { + case EthPV62.STATUS: + return "Status"; + case EthPV62.NEW_BLOCK_HASHES: + return "NewBlockHashes"; + case EthPV62.TRANSACTIONS: + return "Transactions"; + case EthPV62.GET_BLOCK_HEADERS: + return "GetBlockHeaders"; + case EthPV62.BLOCK_HEADERS: + return "BlockHeaders"; + case EthPV62.GET_BLOCK_BODIES: + return "GetBlockBodies"; + case EthPV62.BLOCK_BODIES: + return "BlockBodies"; + case EthPV62.NEW_BLOCK: + return "NewBlock"; + default: + return INVALID_MESSAGE_NAME; + } + } + public static EthProtocol get() { return INSTANCE; } diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java index 64c3f0bace..c0867bfc8f 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java @@ -119,6 +119,7 @@ public class TestNode implements Closeable { new PeerBlacklist(), new NoOpMetricsSystem(), new NodeWhitelistController(PermissioningConfiguration.createDefault()))) + .metricsSystem(new NoOpMetricsSystem()) .build(); network = networkRunner.getNetwork(); this.port = network.getSelf().getPort(); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java index 63de82ccf4..8d3a40fc2c 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java @@ -17,6 +17,10 @@ import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; +import tech.pegasys.pantheon.metrics.Counter; +import tech.pegasys.pantheon.metrics.LabelledMetric; +import tech.pegasys.pantheon.metrics.MetricCategory; +import tech.pegasys.pantheon.metrics.MetricsSystem; import java.util.ArrayList; import java.util.Arrays; @@ -50,14 +54,24 @@ public class NetworkRunner implements AutoCloseable { private final P2PNetwork network; private final Map subProtocols; private final List protocolManagers; + private final LabelledMetric inboundMessageCounter; private NetworkRunner( final P2PNetwork network, final Map subProtocols, - final List protocolManagers) { + final List protocolManagers, + final MetricsSystem metricsSystem) { this.network = network; this.protocolManagers = protocolManagers; this.subProtocols = subProtocols; + inboundMessageCounter = + metricsSystem.createLabelledCounter( + MetricCategory.NETWORK, + "p2p_messages_inbound", + "Count of each P2P message received inbound.", + "protocol", + "name", + "code"); } public P2PNetwork getNetwork() { @@ -116,6 +130,7 @@ public class NetworkRunner implements AutoCloseable { message -> { final int code = message.getData().getCode(); if (!protocol.isValidMessageCode(cap.getVersion(), code)) { + inboundMessageCounter.labels(cap.toString(), "Invalid", "").inc(); // Handle invalid messages by disconnecting LOG.debug( "Invalid message code ({}-{}, {}) received from peer, disconnecting from:", @@ -126,6 +141,12 @@ public class NetworkRunner implements AutoCloseable { message.getConnection().disconnect(DisconnectReason.BREACH_OF_PROTOCOL); return; } + inboundMessageCounter + .labels( + cap.toString(), + protocol.messageName(cap.getVersion(), code), + Integer.toString(code)) + .inc(); protocolManager.processMessage(cap, message); }); } @@ -162,6 +183,7 @@ public class NetworkRunner implements AutoCloseable { private Function, P2PNetwork> networkProvider; List protocolManagers = new ArrayList<>(); List subProtocols = new ArrayList<>(); + MetricsSystem metricsSystem; public NetworkRunner build() { final Map subProtocolMap = new HashMap<>(); @@ -180,7 +202,7 @@ public class NetworkRunner implements AutoCloseable { } } final P2PNetwork network = networkProvider.apply(caps); - return new NetworkRunner(network, subProtocolMap, protocolManagers); + return new NetworkRunner(network, subProtocolMap, protocolManagers, metricsSystem); } public Builder protocolManagers(final List protocolManagers) { @@ -202,5 +224,10 @@ public class NetworkRunner implements AutoCloseable { this.subProtocols.addAll(subProtocols); return this; } + + public Builder metricsSystem(final MetricsSystem metricsSystem) { + this.metricsSystem = metricsSystem; + return this; + } } } diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/AbstractHandshakeHandler.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/AbstractHandshakeHandler.java index 937ea1cf79..19c9f06d36 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/AbstractHandshakeHandler.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/AbstractHandshakeHandler.java @@ -22,6 +22,8 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.HelloMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.WireMessageCodes; +import tech.pegasys.pantheon.metrics.Counter; +import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.util.List; @@ -50,17 +52,21 @@ abstract class AbstractHandshakeHandler extends SimpleChannelInboundHandler connectionFuture; private final List subProtocols; + private final LabelledMetric outboundMessagesCounter; + AbstractHandshakeHandler( final List subProtocols, final PeerInfo ourInfo, final CompletableFuture connectionFuture, final Callbacks callbacks, - final PeerConnectionRegistry peerConnectionRegistry) { + final PeerConnectionRegistry peerConnectionRegistry, + final LabelledMetric outboundMessagesCounter) { this.subProtocols = subProtocols; this.ourInfo = ourInfo; this.connectionFuture = connectionFuture; this.callbacks = callbacks; this.peerConnectionRegistry = peerConnectionRegistry; + this.outboundMessagesCounter = outboundMessagesCounter; } /** @@ -101,7 +107,8 @@ abstract class AbstractHandshakeHandler extends SimpleChannelInboundHandler subProtocols; private boolean hellosExchanged; + private final LabelledMetric outboundMessagesCounter; DeFramer( final Framer framer, final List subProtocols, final PeerInfo ourInfo, final Callbacks callbacks, - final CompletableFuture connectFuture) { + final CompletableFuture connectFuture, + final LabelledMetric outboundMessagesCounter) { this.framer = framer; this.subProtocols = subProtocols; this.ourInfo = ourInfo; this.connectFuture = connectFuture; this.callbacks = callbacks; + this.outboundMessagesCounter = outboundMessagesCounter; } @Override @@ -90,7 +95,8 @@ final class DeFramer extends ByteToMessageDecoder { new CapabilityMultiplexer( subProtocols, ourInfo.getCapabilities(), peerInfo.getCapabilities()); final PeerConnection connection = - new NettyPeerConnection(ctx, peerInfo, capabilityMultiplexer, callbacks); + new NettyPeerConnection( + ctx, peerInfo, capabilityMultiplexer, callbacks, outboundMessagesCounter); if (capabilityMultiplexer.getAgreedCapabilities().size() == 0) { LOG.debug( "Disconnecting from {} because no capabilities are shared.", peerInfo.getClientId()); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerInbound.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerInbound.java index 94f5680182..3b5e4f1425 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerInbound.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerInbound.java @@ -17,6 +17,8 @@ import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.rlpx.handshake.Handshaker; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; +import tech.pegasys.pantheon.metrics.Counter; +import tech.pegasys.pantheon.metrics.LabelledMetric; import java.util.List; import java.util.Optional; @@ -32,8 +34,15 @@ public final class HandshakeHandlerInbound extends AbstractHandshakeHandler { final PeerInfo ourInfo, final CompletableFuture connectionFuture, final Callbacks callbacks, - final PeerConnectionRegistry peerConnectionRegistry) { - super(subProtocols, ourInfo, connectionFuture, callbacks, peerConnectionRegistry); + final PeerConnectionRegistry peerConnectionRegistry, + final LabelledMetric outboundMessagesCounter) { + super( + subProtocols, + ourInfo, + connectionFuture, + callbacks, + peerConnectionRegistry, + outboundMessagesCounter); handshaker.prepareResponder(kp); } diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerOutbound.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerOutbound.java index 2e414f1fc5..70376e917e 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerOutbound.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/HandshakeHandlerOutbound.java @@ -17,6 +17,8 @@ import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.rlpx.handshake.Handshaker; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; +import tech.pegasys.pantheon.metrics.Counter; +import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.util.List; @@ -41,8 +43,15 @@ public final class HandshakeHandlerOutbound extends AbstractHandshakeHandler { final PeerInfo ourInfo, final CompletableFuture connectionFuture, final Callbacks callbacks, - final PeerConnectionRegistry peerConnectionRegistry) { - super(subProtocols, ourInfo, connectionFuture, callbacks, peerConnectionRegistry); + final PeerConnectionRegistry peerConnectionRegistry, + final LabelledMetric outboundMessagesCounter) { + super( + subProtocols, + ourInfo, + connectionFuture, + callbacks, + peerConnectionRegistry, + outboundMessagesCounter); handshaker.prepareInitiator(kp, SECP256K1.PublicKey.create(peerId)); this.first = handshaker.firstMessage(); } diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java index 5ee78d2d83..e4f2acc982 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java @@ -31,6 +31,9 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; +import tech.pegasys.pantheon.metrics.Counter; +import tech.pegasys.pantheon.metrics.LabelledMetric; +import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.Subscribers; @@ -137,6 +140,8 @@ public final class NettyP2PNetwork implements P2PNetwork { private final List subProtocols; + private final LabelledMetric outboundMessagesCounter; + /** * Creates a peer networking service for production purposes. * @@ -173,6 +178,16 @@ public final class NettyP2PNetwork implements P2PNetwork { peerRequirement, peerBlacklist, nodeWhitelistController); + + outboundMessagesCounter = + metricsSystem.createLabelledCounter( + MetricCategory.NETWORK, + "p2p_messages_outbound", + "Count of each P2P message sent outbound.", + "protocol", + "name", + "code"); + subscribeDisconnect(peerDiscoveryAgent); subscribeDisconnect(peerBlacklist); subscribeDisconnect(connections); @@ -234,7 +249,13 @@ public final class NettyP2PNetwork implements P2PNetwork { new TimeoutException( "Timed out waiting to fully establish incoming connection"))), new HandshakeHandlerInbound( - keyPair, subProtocols, ourPeerInfo, connectionFuture, callbacks, connections)); + keyPair, + subProtocols, + ourPeerInfo, + connectionFuture, + callbacks, + connections, + outboundMessagesCounter)); connectionFuture.thenAccept( connection -> { @@ -305,7 +326,8 @@ public final class NettyP2PNetwork implements P2PNetwork { ourPeerInfo, connectionFuture, callbacks, - connections)); + connections, + outboundMessagesCounter)); } }) .connect() diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnection.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnection.java index c4b4ce3509..ccb3f8c09a 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnection.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnection.java @@ -22,6 +22,9 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; +import tech.pegasys.pantheon.ethereum.p2p.wire.messages.WireMessageCodes; +import tech.pegasys.pantheon.metrics.Counter; +import tech.pegasys.pantheon.metrics.LabelledMetric; import java.net.SocketAddress; import java.util.HashMap; @@ -49,12 +52,14 @@ final class NettyPeerConnection implements PeerConnection { private final AtomicBoolean disconnected = new AtomicBoolean(false); private final Callbacks callbacks; private final CapabilityMultiplexer multiplexer; + private final LabelledMetric outboundMessagesCounter; public NettyPeerConnection( final ChannelHandlerContext ctx, final PeerInfo peerInfo, final CapabilityMultiplexer multiplexer, - final Callbacks callbacks) { + final Callbacks callbacks, + final LabelledMetric outboundMessagesCounter) { this.ctx = ctx; this.peerInfo = peerInfo; this.multiplexer = multiplexer; @@ -63,6 +68,7 @@ final class NettyPeerConnection implements PeerConnection { protocolToCapability.put(cap.getName(), cap); } this.callbacks = callbacks; + this.outboundMessagesCounter = outboundMessagesCounter; ctx.channel().closeFuture().addListener(f -> terminateConnection(TCP_SUBSYSTEM_ERROR, false)); } @@ -82,6 +88,19 @@ final class NettyPeerConnection implements PeerConnection { + ") via cap " + capability); } + outboundMessagesCounter + .labels( + capability.toString(), + subProtocol.messageName(capability.getVersion(), message.getCode()), + Integer.toString(message.getCode())) + .inc(); + } else { + outboundMessagesCounter + .labels( + "Wire", + WireMessageCodes.messageName(message.getCode()), + Integer.toString(message.getCode())) + .inc(); } LOG.trace("Writing {} to {} via protocol {}", message, peerInfo, capability); @@ -152,9 +171,7 @@ final class NettyPeerConnection implements PeerConnection { .add("nodeId", peerInfo.getNodeId()) .add( "caps", - String.join( - ", ", - agreedCapabilities.stream().map(Capability::toString).collect(Collectors.toList()))) + agreedCapabilities.stream().map(Capability::toString).collect(Collectors.joining(", "))) .toString(); } } diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/SubProtocol.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/SubProtocol.java index 5a121c0519..b278e0d15c 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/SubProtocol.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/SubProtocol.java @@ -37,4 +37,17 @@ public interface SubProtocol { * @return true if the given protocol version supports the given message code */ boolean isValidMessageCode(int protocolVersion, int code); + + /** Message name for a message code not valid within this subprotocol. */ + String INVALID_MESSAGE_NAME = "invalid"; + + /** + * Returns the name of the particular message for this protocol, suitable for human viewing. + * + * @param protocolVersion The version of the protocol for the message code. + * @param code The message code to be named. + * @return A string of the human readable name of the message, or {@link #INVALID_MESSAGE_NAME} if + * it is not a valid in the protocol. + */ + String messageName(int protocolVersion, int code); } diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/messages/WireMessageCodes.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/messages/WireMessageCodes.java index b3b8a7e0d0..34ce6d281b 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/messages/WireMessageCodes.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/wire/messages/WireMessageCodes.java @@ -19,4 +19,19 @@ public final class WireMessageCodes { public static final int PONG = 0x03; private WireMessageCodes() {} + + public static String messageName(final int code) { + switch (code) { + case HELLO: + return "Hello"; + case DISCONNECT: + return "Disconnect"; + case PING: + return "Ping"; + case PONG: + return "Pong"; + default: + return "invalid"; + } + } } diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java index 8e5efe41be..9c0455b6e5 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java @@ -411,6 +411,11 @@ public final class NettyP2PNetworkTest { public boolean isValidMessageCode(final int protocolVersion, final int code) { return true; } + + @Override + public String messageName(final int protocolVersion, final int code) { + return INVALID_MESSAGE_NAME; + } }; } @@ -430,6 +435,11 @@ public final class NettyP2PNetworkTest { public boolean isValidMessageCode(final int protocolVersion, final int code) { return true; } + + @Override + public String messageName(final int protocolVersion, final int code) { + return INVALID_MESSAGE_NAME; + } }; } diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/CapabilityMultiplexerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/CapabilityMultiplexerTest.java index 087ae94011..55df49ea01 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/CapabilityMultiplexerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/CapabilityMultiplexerTest.java @@ -105,6 +105,11 @@ public class CapabilityMultiplexerTest { public boolean isValidMessageCode(final int protocolVersion, final int code) { return true; } + + @Override + public String messageName(final int protocolVersion, final int code) { + return INVALID_MESSAGE_NAME; + } }; } } diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/DeFramerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/DeFramerTest.java index d85feed798..1b4ab447c6 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/DeFramerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/DeFramerTest.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.p2p.rlpx.framing.Framer; import tech.pegasys.pantheon.ethereum.p2p.rlpx.framing.FramingException; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; +import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.util.Collections; @@ -42,7 +43,8 @@ public class DeFramerTest { Collections.emptyList(), new PeerInfo(5, "abc", Collections.emptyList(), 0, BytesValue.fromHexString("0x01")), callbacks, - connectFuture); + connectFuture, + NoOpMetricsSystem.NO_OP_LABELLED_COUNTER); @Test public void shouldDisconnectForBreachOfProtocolWhenFramingExceptionThrown() throws Exception { diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnectionTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnectionTest.java index e3cb0154ba..c0af49ebe1 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnectionTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyPeerConnectionTest.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection.PeerNotConnected; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.HelloMessage; +import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; import io.netty.channel.Channel; @@ -47,7 +48,9 @@ public class NettyPeerConnectionTest { when(context.channel()).thenReturn(channel); when(channel.closeFuture()).thenReturn(closeFuture); when(channel.eventLoop()).thenReturn(eventLoop); - connection = new NettyPeerConnection(context, peerInfo, multiplexer, callbacks); + connection = + new NettyPeerConnection( + context, peerInfo, multiplexer, callbacks, NoOpMetricsSystem.NO_OP_LABELLED_COUNTER); } @Test diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java index 2b5d00e7e7..9640aec0c7 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java @@ -18,7 +18,8 @@ public enum MetricCategory { JVM("jvm", false), PROCESS("process", false), BLOCKCHAIN("blockchain"), - SYNCHRONIZER("synchronizer"); + SYNCHRONIZER("synchronizer"), + NETWORK("network"); private final String name; private final boolean pantheonSpecific; diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystem.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystem.java index 54e44f8f94..41da268662 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystem.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystem.java @@ -29,6 +29,7 @@ public class NoOpMetricsSystem implements MetricsSystem { private static final TimingContext NO_OP_TIMING_CONTEXT = () -> 0; private static final OperationTimer NO_OP_TIMER = () -> NO_OP_TIMING_CONTEXT; public static final LabelledMetric NO_OP_LABELLED_TIMER = label -> NO_OP_TIMER; + public static final LabelledMetric NO_OP_LABELLED_COUNTER = label -> NO_OP_COUNTER; @Override public LabelledMetric createLabelledCounter( diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index a908fdbeff..17046a3a22 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -214,6 +214,7 @@ public class RunnerBuilder { peerBlacklist, metricsSystem, nodeWhitelistController)) + .metricsSystem(metricsSystem) .build(); final Synchronizer synchronizer = pantheonController.getSynchronizer();