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

Reintroduce engine get client version v1 with commit in manifest #7548

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert "Revert engine_getClientVersionV1 changes"
This reverts commit f855091

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
  • Loading branch information
Matilda-Clerke committed Aug 30, 2024
commit 2541a66ed004bc6aa89fb734159b8f4afea9ed78
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Add 'inbound' field to admin_peers JSON-RPC Call [#7461](https://github.com/hyperledger/besu/pull/7461)
- Add pending block header to `TransactionEvaluationContext` plugin API [#7483](https://github.com/hyperledger/besu/pull/7483)
- Add bootnode to holesky config [#7500](https://github.com/hyperledger/besu/pull/7500)
- Implement engine_getClientVersionV1 [#7512](https://github.com/hyperledger/besu/pull/7512)
- Performance optimzation for ECMUL (1 of 2) [#7509](https://github.com/hyperledger/besu/pull/7509)
- Performance optimzation for ECMUL (2 of 2) [#7543](https://github.com/hyperledger/besu/pull/7543)

Expand Down
2 changes: 2 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,8 @@ private Map<String, JsonRpcMethod> jsonRpcMethods(
new JsonRpcMethodsFactory()
.methods(
BesuInfo.nodeName(identityString),
BesuInfo.shortVersion(),
BesuInfo.commit(),
ethNetworkConfig.networkId(),
besuController.getGenesisConfigOptions(),
network,
Expand Down
7 changes: 4 additions & 3 deletions besu/src/test/java/org/hyperledger/besu/BesuInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public final class BesuInfoTest {
*/
@Test
public void versionStringIsEthstatsFriendly() {
assertThat(BesuInfo.version()).matches("[^/]+/v(\\d+\\.\\d+\\.\\d+[^/]*|null)/[^/]+/[^/]+");
assertThat(BesuInfo.version())
.matches("[^/]+/v(\\d+\\.\\d+\\.\\d+[^/]*|null-null)/[^/]+/[^/]+");
}

/**
Expand All @@ -45,7 +46,7 @@ public void versionStringIsEthstatsFriendly() {
@Test
public void noIdentityNodeNameIsEthstatsFriendly() {
assertThat(BesuInfo.nodeName(Optional.empty()))
.matches("[^/]+/v(\\d+\\.\\d+\\.\\d+[^/]*|null)/[^/]+/[^/]+");
.matches("[^/]+/v(\\d+\\.\\d+\\.\\d+[^/]*|null-null)/[^/]+/[^/]+");
}

/**
Expand All @@ -58,6 +59,6 @@ public void noIdentityNodeNameIsEthstatsFriendly() {
@Test
public void userIdentityNodeNameIsEthstatsFriendly() {
assertThat(BesuInfo.nodeName(Optional.of("TestUserIdentity")))
.matches("[^/]+/[^/]+/v(\\d+\\.\\d+\\.\\d+[^/]*|null)/[^/]+/[^/]+");
.matches("[^/]+/[^/]+/v(\\d+\\.\\d+\\.\\d+[^/]*|null-null)/[^/]+/[^/]+");
}
}
14 changes: 5 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ task distDocker {
dockerPlatform = "--platform ${project.getProperty('docker-platform')}"
println "Building for platform ${project.getProperty('docker-platform')}"
}
def gitDetails = getGitCommitDetails(7)
def gitDetails = getGitCommitDetails()
Copy link
Contributor

@garyschulte garyschulte Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 seems fine, but if we are going to generate commit sha metadata that is different from the build artifact name, we may as well use all 40 here

executable shell
workingDir dockerBuildDir
args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ."
Expand Down Expand Up @@ -991,17 +991,13 @@ def buildTime() {
def calculateVersion() {
// Regex pattern for basic calendar versioning, with provision to omit patch rev
def calVerPattern = ~/\d+\.\d+(\.\d+)?(-.*)?/

def gitDetails = getGitCommitDetails() // Adjust length as needed
if (project.hasProperty('version') && (project.version =~ calVerPattern)) {
if (project.hasProperty('versionappendcommit') && project.versionappendcommit == "true") {
def gitDetails = getGitCommitDetails(7) // Adjust length as needed
return "${project.version}-${gitDetails.hash}"
}
return "${project.version}"
println("Generating project version using supplied version: ${project.version}-${gitDetails.hash}")
return "${project.version}-${gitDetails.hash}"
} else {
// If no version is supplied or it doesn't match the semantic versioning, calculate from git
println("Generating project version as supplied is version not semver: ${project.version}")
def gitDetails = getGitCommitDetails(7) // Adjust length as needed
println("Generating project version using date (${gitDetails.date}-develop-${gitDetails.hash}), as supplied version is not semver: ${project.version}")
return "${gitDetails.date}-develop-${gitDetails.hash}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
/** Provides a facade to construct the JSON-RPC component. */
public class JsonRpcTestMethodsFactory {

private static final String CLIENT_VERSION = "TestClientVersion/0.1.0";
private static final String CLIENT_NODE_NAME = "TestClientVersion/0.1.0";
private static final String CLIENT_VERSION = "0.1.0";
private static final String CLIENT_COMMIT = "12345678";
private static final BigInteger NETWORK_ID = BigInteger.valueOf(123);

private final BlockchainImporter importer;
Expand Down Expand Up @@ -175,7 +177,9 @@ public Map<String, JsonRpcMethod> methods() {

return new JsonRpcMethodsFactory()
.methods(
CLIENT_NODE_NAME,
CLIENT_VERSION,
CLIENT_COMMIT,
NETWORK_ID,
new StubGenesisConfigOptions(),
peerDiscovery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum RpcMethod {
ENGINE_FORKCHOICE_UPDATED_V2("engine_forkchoiceUpdatedV2"),
ENGINE_FORKCHOICE_UPDATED_V3("engine_forkchoiceUpdatedV3"),
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION("engine_exchangeTransitionConfigurationV1"),
ENGINE_GET_CLIENT_VERSION_V1("engine_getClientVersionV1"),
ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V1("engine_getPayloadBodiesByHashV1"),
ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V1("engine_getPayloadBodiesByRangeV1"),
ENGINE_EXCHANGE_CAPABILITIES("engine_exchangeCapabilities"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineGetClientVersionResultV1;

import io.vertx.core.Vertx;

public class EngineGetClientVersionV1 extends ExecutionEngineJsonRpcMethod {
private static final String ENGINE_CLIENT_CODE = "BU";
private static final String ENGINE_CLIENT_NAME = "Besu";

private final String clientVersion;
private final String commit;

public EngineGetClientVersionV1(
final Vertx vertx,
final ProtocolContext protocolContext,
final EngineCallListener engineCallListener,
final String clientVersion,
final String commit) {
super(vertx, protocolContext, engineCallListener);
this.clientVersion = clientVersion;
this.commit = commit;
}

@Override
public String getName() {
return RpcMethod.ENGINE_GET_CLIENT_VERSION_V1.getMethodName();
}

@Override
public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) {
return new JsonRpcSuccessResponse(
request.getRequest().getId(),
new EngineGetClientVersionResultV1(
ENGINE_CLIENT_CODE, ENGINE_CLIENT_NAME, clientVersion, commit));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import com.fasterxml.jackson.annotation.JsonGetter;

public class EngineGetClientVersionResultV1 {
private final String code;
private final String name;
private final String version;
private final String commit;

public EngineGetClientVersionResultV1(
final String code, final String name, final String version, final String commit) {
this.code = code;
this.name = name;
this.version = version;
this.commit = commit;
}

@JsonGetter(value = "code")
public String getCode() {
return code;
}

@JsonGetter(value = "name")
public String getName() {
return name;
}

@JsonGetter(value = "version")
public String getVersion() {
return version;
}

@JsonGetter(value = "commit")
public String getCommit() {
return commit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineForkchoiceUpdatedV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineForkchoiceUpdatedV2;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineForkchoiceUpdatedV3;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetClientVersionV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadBodiesByHashV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadBodiesByRangeV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV1;
Expand Down Expand Up @@ -57,13 +58,17 @@ public class ExecutionEngineJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final ProtocolContext protocolContext;
private final EthPeers ethPeers;
private final Vertx consensusEngineServer;
private final String clientVersion;
private final String commit;

ExecutionEngineJsonRpcMethods(
final MiningCoordinator miningCoordinator,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final EthPeers ethPeers,
final Vertx consensusEngineServer) {
final Vertx consensusEngineServer,
final String clientVersion,
final String commit) {
this.mergeCoordinator =
Optional.ofNullable(miningCoordinator)
.filter(mc -> mc.isCompatibleWithEngineApi())
Expand All @@ -72,6 +77,8 @@ public class ExecutionEngineJsonRpcMethods extends ApiGroupJsonRpcMethods {
this.protocolContext = protocolContext;
this.ethPeers = ethPeers;
this.consensusEngineServer = consensusEngineServer;
this.clientVersion = clientVersion;
this.commit = commit;
}

@Override
Expand Down Expand Up @@ -147,7 +154,9 @@ protected Map<String, JsonRpcMethod> create() {
new EngineExchangeCapabilities(
consensusEngineServer, protocolContext, engineQosTimer),
new EnginePreparePayloadDebug(
consensusEngineServer, protocolContext, engineQosTimer, mergeCoordinator.get())));
consensusEngineServer, protocolContext, engineQosTimer, mergeCoordinator.get()),
new EngineGetClientVersionV1(
consensusEngineServer, protocolContext, engineQosTimer, clientVersion, commit)));

if (protocolSchedule.anyMatch(p -> p.spec().getName().equalsIgnoreCase("cancun"))) {
executionEngineApisSupported.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
public class JsonRpcMethodsFactory {

public Map<String, JsonRpcMethod> methods(
final String clientNodeName,
final String clientVersion,
final String commit,
final BigInteger networkId,
final GenesisConfigOptions genesisConfigOptions,
final P2PNetwork p2pNetwork,
Expand Down Expand Up @@ -89,7 +91,7 @@ public Map<String, JsonRpcMethod> methods(
final List<JsonRpcMethods> availableApiGroups =
List.of(
new AdminJsonRpcMethods(
clientVersion,
clientNodeName,
networkId,
genesisConfigOptions,
p2pNetwork,
Expand All @@ -115,7 +117,9 @@ public Map<String, JsonRpcMethod> methods(
protocolSchedule,
protocolContext,
ethPeers,
consensusEngineServer),
consensusEngineServer,
clientVersion,
commit),
new EthJsonRpcMethods(
blockchainQueries,
synchronizer,
Expand All @@ -141,7 +145,7 @@ public Map<String, JsonRpcMethod> methods(
filterManager),
new PrivxJsonRpcMethods(
blockchainQueries, protocolSchedule, transactionPool, privacyParameters),
new Web3JsonRpcMethods(clientVersion),
new Web3JsonRpcMethods(clientNodeName),
new TraceJsonRpcMethods(
blockchainQueries, protocolSchedule, protocolContext, apiConfiguration),
new TxPoolJsonRpcMethods(transactionPool),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public abstract class AbstractJsonRpcHttpServiceTest {

protected BlockchainSetupUtil blockchainSetupUtil;

protected static String CLIENT_VERSION = "TestClientVersion/0.1.0";
protected static final String CLIENT_NODE_NAME = "TestClientVersion/0.1.0";
protected static final String CLIENT_VERSION = "0.1.0";
protected static final String CLIENT_COMMIT = "12345678";
protected static final BigInteger NETWORK_ID = BigInteger.valueOf(123);
protected static final Collection<String> JSON_RPC_APIS =
Arrays.asList(
Expand Down Expand Up @@ -168,7 +170,9 @@ protected Map<String, JsonRpcMethod> getRpcMethods(

return new JsonRpcMethodsFactory()
.methods(
CLIENT_NODE_NAME,
CLIENT_VERSION,
CLIENT_COMMIT,
NETWORK_ID,
new StubGenesisConfigOptions(),
peerDiscoveryMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public void getPeers() throws Exception {
final List<EthPeer> peerList = new ArrayList<>();
final PeerInfo info1 =
new PeerInfo(
4, CLIENT_VERSION, caps, 30302, Bytes.fromHexString(String.format("%0128x", 1)));
4, CLIENT_NODE_NAME, caps, 30302, Bytes.fromHexString(String.format("%0128x", 1)));
final PeerInfo info2 =
new PeerInfo(
4, CLIENT_VERSION, caps, 60302, Bytes.fromHexString(String.format("%0128x", 2)));
4, CLIENT_NODE_NAME, caps, 60302, Bytes.fromHexString(String.format("%0128x", 2)));
final PeerInfo info3 =
new PeerInfo(
4, CLIENT_VERSION, caps, 60303, Bytes.fromHexString(String.format("%0128x", 3)));
4, CLIENT_NODE_NAME, caps, 60303, Bytes.fromHexString(String.format("%0128x", 3)));
final InetSocketAddress addr30301 = new InetSocketAddress("localhost", 30301);
final InetSocketAddress addr30302 = new InetSocketAddress("localhost", 30302);
final InetSocketAddress addr60301 = new InetSocketAddress("localhost", 60301);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public class JsonRpcHttpServiceHostAllowlistTest {
private static OkHttpClient client;
private static String baseUrl;
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private static final String CLIENT_VERSION = "TestClientVersion/0.1.0";
private static final String CLIENT_NODE_NAME = "TestClientVersion/0.1.0";
private static final String CLIENT_VERSION = "0.1.0";
private static final String CLIENT_COMMIT = "12345678";
private static final BigInteger CHAIN_ID = BigInteger.valueOf(123);

private final JsonRpcConfiguration jsonRpcConfig = createJsonRpcConfig();
Expand All @@ -100,7 +102,9 @@ public void initServerAndClient() throws Exception {
rpcMethods =
new JsonRpcMethodsFactory()
.methods(
CLIENT_NODE_NAME,
CLIENT_VERSION,
CLIENT_COMMIT,
CHAIN_ID,
new StubGenesisConfigOptions(),
peerDiscoveryMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public class JsonRpcHttpServiceLoginTest {
protected static OkHttpClient client;
protected static String baseUrl;
protected static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
protected static final String CLIENT_VERSION = "TestClientVersion/0.1.0";
protected static final String CLIENT_NODE_NAME = "TestClientVersion/0.1.0";
protected static final String CLIENT_VERSION = "0.1.0";
protected static final String CLIENT_COMMIT = "12345678";
protected static final BigInteger CHAIN_ID = BigInteger.valueOf(123);
protected static P2PNetwork peerDiscoveryMock;
protected static BlockchainQueries blockchainQueries;
Expand Down Expand Up @@ -131,7 +133,9 @@ public static void initServerAndClient() throws Exception {
rpcMethods =
new JsonRpcMethodsFactory()
.methods(
CLIENT_NODE_NAME,
CLIENT_VERSION,
CLIENT_COMMIT,
CHAIN_ID,
genesisConfigOptions,
peerDiscoveryMock,
Expand Down
Loading