From 440f9346ff68e6d2a5881704422daf463db29f03 Mon Sep 17 00:00:00 2001 From: Matthew Whitehead Date: Tue, 21 May 2024 13:44:45 +0100 Subject: [PATCH 1/2] Include currently active EVM version in node info response Signed-off-by: Matthew Whitehead --- .../internal/methods/AdminNodeInfo.java | 11 ++++++++++- .../jsonrpc/methods/AdminJsonRpcMethods.java | 9 +++++++-- .../jsonrpc/methods/JsonRpcMethodsFactory.java | 3 ++- .../internal/methods/AdminNodeInfoTest.java | 18 ++++++++++++++++-- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java index 8515f9ba1bb..552d8f471c7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.ChainHead; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; import org.hyperledger.besu.nat.NatService; import org.hyperledger.besu.nat.core.domain.NatPortMapping; @@ -47,6 +48,7 @@ public class AdminNodeInfo implements JsonRpcMethod { private final P2PNetwork peerNetwork; private final BlockchainQueries blockchainQueries; private final NatService natService; + private final ProtocolSchedule protocolSchedule; public AdminNodeInfo( final String clientVersion, @@ -54,13 +56,15 @@ public AdminNodeInfo( final GenesisConfigOptions genesisConfigOptions, final P2PNetwork peerNetwork, final BlockchainQueries blockchainQueries, - final NatService natService) { + final NatService natService, + final ProtocolSchedule protocolSchedule) { this.peerNetwork = peerNetwork; this.clientVersion = clientVersion; this.genesisConfigOptions = genesisConfigOptions; this.blockchainQueries = blockchainQueries; this.networkId = networkId; this.natService = natService; + this.protocolSchedule = protocolSchedule; } @Override @@ -73,6 +77,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Map response = new HashMap<>(); final Map ports = new HashMap<>(); + System.out.println("MRW: Returning node info"); + if (!peerNetwork.isP2pEnabled()) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.P2P_DISABLED); @@ -126,6 +132,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { "network", networkId))); + response.put( + "activeFork", protocolSchedule.getByBlockHeader(chainHead.getBlockHeader()).getName()); + return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java index 286758cb762..437f64f1df2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.PluginsReloadConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; import org.hyperledger.besu.ethereum.p2p.peers.EnodeDnsConfiguration; import org.hyperledger.besu.nat.NatService; @@ -48,6 +49,7 @@ public class AdminJsonRpcMethods extends ApiGroupJsonRpcMethods { private final Map namedPlugins; private final EthPeers ethPeers; private final Optional enodeDnsConfiguration; + private final ProtocolSchedule protocolSchedule; public AdminJsonRpcMethods( final String clientVersion, @@ -58,7 +60,8 @@ public AdminJsonRpcMethods( final Map namedPlugins, final NatService natService, final EthPeers ethPeers, - final Optional enodeDnsConfiguration) { + final Optional enodeDnsConfiguration, + final ProtocolSchedule protocolSchedule) { this.clientVersion = clientVersion; this.networkId = networkId; this.genesisConfigOptions = genesisConfigOptions; @@ -68,6 +71,7 @@ public AdminJsonRpcMethods( this.natService = natService; this.ethPeers = ethPeers; this.enodeDnsConfiguration = enodeDnsConfiguration; + this.protocolSchedule = protocolSchedule; } @Override @@ -86,7 +90,8 @@ protected Map create() { genesisConfigOptions, p2pNetwork, blockchainQueries, - natService), + natService, + protocolSchedule), new AdminPeers(ethPeers), new AdminChangeLogLevel(), new AdminGenerateLogBloomCache(blockchainQueries), diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java index c4cfd226905..924889ef47a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java @@ -97,7 +97,8 @@ public Map methods( namedPlugins, natService, ethPeers, - enodeDnsConfiguration), + enodeDnsConfiguration, + protocolSchedule), new DebugJsonRpcMethods( blockchainQueries, protocolContext, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java index 20284cb5de3..07fc060655b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; @@ -33,6 +34,8 @@ import org.hyperledger.besu.ethereum.chain.ChainHead; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; import org.hyperledger.besu.ethereum.p2p.peers.DefaultPeer; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; @@ -67,6 +70,8 @@ public class AdminNodeInfoTest { @Mock private BlockchainQueries blockchainQueries; @Mock private NatService natService; @Mock private BlockHeader blockHeader; + @Mock private ProtocolSchedule protocolSchedule; + @Mock private ProtocolSpec protocolSpec; private AdminNodeInfo method; @@ -93,6 +98,8 @@ public void setup() { when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.EMPTY)); when(blockchain.getChainHead()).thenReturn(testChainHead); when(natService.queryExternalIPAddress(anyString())).thenReturn("1.2.3.4"); + when(protocolSpec.getName()).thenReturn("London"); + when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec); method = new AdminNodeInfo( "testnet/1.0/this/that", @@ -100,7 +107,8 @@ public void setup() { genesisConfigOptions, p2pNetwork, blockchainQueries, - natService); + natService, + protocolSchedule); } @Test @@ -110,6 +118,7 @@ public void shouldReturnCorrectResult() { final JsonRpcRequestContext request = adminNodeInfo(); final Map expected = new HashMap<>(); + expected.put("activeFork", "London"); expected.put( "enode", "enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:30303?discport=7890"); @@ -161,6 +170,7 @@ public void shouldReturnCorrectResultWhenIsNatEnvironment() { final JsonRpcRequestContext request = adminNodeInfo(); final Map expected = new HashMap<>(); + expected.put("activeFork", "London"); expected.put( "enode", "enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@3.4.5.6:8081?discport=8080"); @@ -207,6 +217,7 @@ public void handlesLocalEnodeWithListeningAndDiscoveryDisabled() { final JsonRpcRequestContext request = adminNodeInfo(); final Map expected = new HashMap<>(); + expected.put("activeFork", "London"); expected.put( "enode", "enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:0"); @@ -253,6 +264,7 @@ public void handlesLocalEnodeWithListeningDisabled() { final JsonRpcRequestContext request = adminNodeInfo(); final Map expected = new HashMap<>(); + expected.put("activeFork", "London"); expected.put( "enode", "enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:0?discport=7890"); @@ -299,6 +311,7 @@ public void handlesLocalEnodeWithDiscoveryDisabled() { final JsonRpcRequestContext request = adminNodeInfo(); final Map expected = new HashMap<>(); + expected.put("activeFork", "London"); expected.put( "enode", "enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:7890?discport=0"); @@ -387,7 +400,8 @@ public void returnsClassicForkBlocks() { genesisClassicConfigOptions, p2pNetwork, blockchainQueries, - natService); + natService, + protocolSchedule); final JsonRpcRequestContext request = adminNodeInfo(); From 4737810bbe22a30641a036b1383b065480bd4285 Mon Sep 17 00:00:00 2001 From: Matthew Whitehead Date: Mon, 3 Jun 2024 10:09:27 +0100 Subject: [PATCH 2/2] Remove println, add changelog entry Signed-off-by: Matthew Whitehead --- CHANGELOG.md | 1 + .../ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebe02cc0a55..7da419e86a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Additions and Improvements - Add two counters to DefaultBlockchain in order to be able to calculate TPS and Mgas/s [#7105](https://github.com/hyperledger/besu/pull/7105) +- `admin_nodeInfo` JSON/RPC call returns the currently active EVM version [#7127](https://github.com/hyperledger/besu/pull/7127) ### Bug fixes - Make `eth_gasPrice` aware of the base fee market [#7102](https://github.com/hyperledger/besu/pull/7102) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java index 552d8f471c7..f1633db7841 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfo.java @@ -77,8 +77,6 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Map response = new HashMap<>(); final Map ports = new HashMap<>(); - System.out.println("MRW: Returning node info"); - if (!peerNetwork.isP2pEnabled()) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.P2P_DISABLED);