-
Notifications
You must be signed in to change notification settings - Fork 841
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
add engine_getClientVersionV1 #7512
Changes from 7 commits
c5f151e
caebd5a
060d6db
93f37de
7f53348
10ee3ba
df8434c
7cb6dcc
24ed389
09f97e1
c3bf4c9
c370aae
0fd5509
f83cccf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
import org.hyperledger.besu.util.platform.PlatformDetector; | ||
|
||
import java.util.Optional; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Represent Besu information such as version, OS etc. Used with --version option and during Besu | ||
|
@@ -27,6 +29,21 @@ 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 { | ||
if (VERSION == null) { | ||
COMMIT = null; | ||
} else { | ||
Pattern pattern = Pattern.compile("v?\\d*\\.\\d*\\.\\d*-\\w+-(?<commit>[0-9a-fA-F]{8})"); | ||
Matcher matcher = pattern.matcher(VERSION); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only the develop builds include the commit hash in the version at the moment, so this won't work for github release versions. I tested locally using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not sure how else to get the commit hash. The purpose of the field is to give a specific commit at which the application was run, and for github releases there seems to be an accompanying tag, so the version itself can be used to find the exact commit if desired. Do you think it would be worthwhile finding some other way to get the commit field populated? |
||
if (matcher.find()) { | ||
COMMIT = matcher.group("commit"); | ||
} else { | ||
COMMIT = null; | ||
} | ||
} | ||
} | ||
|
||
private BesuInfo() {} | ||
|
||
|
@@ -60,4 +77,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, or null if this is a full release version | ||
* | ||
* @return the commit hash for this besu version, or null if this is a full release version | ||
*/ | ||
public static String commit() { | ||
return COMMIT; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renaming this to better match its source in BesuInfo |
||
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; | ||
|
@@ -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, | ||
|
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of NULL, would it be better to return empty String
""
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is there a test that covers NULL commit? How would it be reported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it's difficult to test the value of COMMIT because BesuInfo pulls data from the class' package which isn't typically set outside of a proper build.
As for null vs empty String, philosophically I'd rather it be null. The api doesn't really specify what should be supplied if a value isn't available.