Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include currently active EVM version in admin_nodeInfo response #7127

Merged
merged 3 commits into from
Jun 4, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,20 +48,23 @@ 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,
final BigInteger networkId,
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
Expand Down Expand Up @@ -126,6 +130,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
"network",
networkId)));

response.put(
"activeFork", protocolSchedule.getByBlockHeader(chainHead.getBlockHeader()).getName());

return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +49,7 @@ public class AdminJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final Map<String, BesuPlugin> namedPlugins;
private final EthPeers ethPeers;
private final Optional<EnodeDnsConfiguration> enodeDnsConfiguration;
private final ProtocolSchedule protocolSchedule;

public AdminJsonRpcMethods(
final String clientVersion,
Expand All @@ -58,7 +60,8 @@ public AdminJsonRpcMethods(
final Map<String, BesuPlugin> namedPlugins,
final NatService natService,
final EthPeers ethPeers,
final Optional<EnodeDnsConfiguration> enodeDnsConfiguration) {
final Optional<EnodeDnsConfiguration> enodeDnsConfiguration,
final ProtocolSchedule protocolSchedule) {
this.clientVersion = clientVersion;
this.networkId = networkId;
this.genesisConfigOptions = genesisConfigOptions;
Expand All @@ -68,6 +71,7 @@ public AdminJsonRpcMethods(
this.natService = natService;
this.ethPeers = ethPeers;
this.enodeDnsConfiguration = enodeDnsConfiguration;
this.protocolSchedule = protocolSchedule;
}

@Override
Expand All @@ -86,7 +90,8 @@ protected Map<String, JsonRpcMethod> create() {
genesisConfigOptions,
p2pNetwork,
blockchainQueries,
natService),
natService,
protocolSchedule),
new AdminPeers(ethPeers),
new AdminChangeLogLevel(),
new AdminGenerateLogBloomCache(blockchainQueries),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public Map<String, JsonRpcMethod> methods(
namedPlugins,
natService,
ethPeers,
enodeDnsConfiguration),
enodeDnsConfiguration,
protocolSchedule),
new DebugJsonRpcMethods(
blockchainQueries,
protocolContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -93,14 +98,17 @@ 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",
BigInteger.valueOf(2018),
genesisConfigOptions,
p2pNetwork,
blockchainQueries,
natService);
natService,
protocolSchedule);
}

@Test
Expand All @@ -110,6 +118,7 @@ public void shouldReturnCorrectResult() {
final JsonRpcRequestContext request = adminNodeInfo();

final Map<String, Object> expected = new HashMap<>();
expected.put("activeFork", "London");
expected.put(
"enode",
"enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:30303?discport=7890");
Expand Down Expand Up @@ -161,6 +170,7 @@ public void shouldReturnCorrectResultWhenIsNatEnvironment() {
final JsonRpcRequestContext request = adminNodeInfo();

final Map<String, Object> expected = new HashMap<>();
expected.put("activeFork", "London");
expected.put(
"enode",
"enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@3.4.5.6:8081?discport=8080");
Expand Down Expand Up @@ -207,6 +217,7 @@ public void handlesLocalEnodeWithListeningAndDiscoveryDisabled() {
final JsonRpcRequestContext request = adminNodeInfo();

final Map<String, Object> expected = new HashMap<>();
expected.put("activeFork", "London");
expected.put(
"enode",
"enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:0");
Expand Down Expand Up @@ -253,6 +264,7 @@ public void handlesLocalEnodeWithListeningDisabled() {
final JsonRpcRequestContext request = adminNodeInfo();

final Map<String, Object> expected = new HashMap<>();
expected.put("activeFork", "London");
expected.put(
"enode",
"enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:0?discport=7890");
Expand Down Expand Up @@ -299,6 +311,7 @@ public void handlesLocalEnodeWithDiscoveryDisabled() {
final JsonRpcRequestContext request = adminNodeInfo();

final Map<String, Object> expected = new HashMap<>();
expected.put("activeFork", "London");
expected.put(
"enode",
"enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:7890?discport=0");
Expand Down Expand Up @@ -387,7 +400,8 @@ public void returnsClassicForkBlocks() {
genesisClassicConfigOptions,
p2pNetwork,
blockchainQueries,
natService);
natService,
protocolSchedule);

final JsonRpcRequestContext request = adminNodeInfo();

Expand Down
Loading