Skip to content

Commit

Permalink
Reintroduce engine get client version v1 with commit in manifest (hyp…
Browse files Browse the repository at this point in the history
…erledger#7548)

* Include Commit-Hash in manifests
* Add commit method in BesuInfo
* Use 8 character hash in EngineGetClientVersionV1 and revert calculateVersion back to original spec

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Co-authored-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
Matilda-Clerke and garyschulte authored Aug 30, 2024
1 parent 1ea1d4c commit da98fa5
Show file tree
Hide file tree
Showing 60 changed files with 372 additions and 63 deletions.
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
3 changes: 2 additions & 1 deletion acceptance-tests/test-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ task testPluginsJar(type: Jar) {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
from sourceSets.main.output
Expand Down
3 changes: 2 additions & 1 deletion besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
Expand Down
31 changes: 31 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/BesuInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

import org.hyperledger.besu.util.platform.PlatformDetector;

import java.net.JarURLConnection;
import java.net.URL;
import java.util.Optional;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

/**
* Represent Besu information such as version, OS etc. Used with --version option and during Besu
Expand All @@ -27,6 +31,24 @@ public final class BesuInfo {
private static final String VERSION = BesuInfo.class.getPackage().getImplementationVersion();
private static final String OS = PlatformDetector.getOS();
private static final String VM = PlatformDetector.getVM();
private static final String COMMIT;

static {
String className = BesuInfo.class.getSimpleName() + ".class";
String classPath = BesuInfo.class.getResource(className).toString();

String commit;
try {
URL url = new URL(classPath);
JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
Manifest manifest = jarConnection.getManifest();
Attributes attributes = manifest.getMainAttributes();
commit = attributes.getValue("Commit-Hash");
} catch (Exception e) {
commit = null;
}
COMMIT = commit;
}

private BesuInfo() {}

Expand Down Expand Up @@ -60,4 +82,13 @@ public static String nodeName(final Optional<String> maybeIdentity) {
.map(identity -> String.format("%s/%s/v%s/%s/%s", CLIENT, identity, VERSION, OS, VM))
.orElse(version());
}

/**
* Generate the commit hash for this besu version
*
* @return the commit hash for this besu version
*/
public static String commit() {
return COMMIT;
}
}
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
2 changes: 1 addition & 1 deletion 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()
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
3 changes: 2 additions & 1 deletion config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/clique/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/ibft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/merge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/qbft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
Expand Down
1 change: 1 addition & 0 deletions crypto/algorithms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jar {
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash,
'Automatic-Module-Name': 'org.hyperledger.besu.internal.crypto'
)
}
Expand Down
1 change: 1 addition & 0 deletions crypto/services/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jar {
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash,
'Automatic-Module-Name': 'org.hyperledger.besu.internal.crypto'
)
}
Expand Down
1 change: 1 addition & 0 deletions datatypes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jar {
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash,
'Automatic-Module-Name': 'org.hyperledger.besu.datatypes'
)
}
Expand Down
3 changes: 2 additions & 1 deletion ethereum/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jar {
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion()
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).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.substring(0, 8)));
}
}
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
Loading

0 comments on commit da98fa5

Please sign in to comment.