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

ETCM-365: Version info in Hello.clientId #794

Merged
merged 12 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ val root = {
val root = project
.in(file("."))
.configs(Integration, Benchmark, Evm, Ets, Snappy, Rpc)
.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoKeys := Seq[BuildInfoKey](name, version, git.gitHeadCommit),
buildInfoPackage := "io.iohk.ethereum.utils"
)
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= dep
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.5")
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "3.0.0")
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.25")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")

libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.6.6"
4 changes: 2 additions & 2 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mantis {
# Identifier used when connecting to other clients
client-id = "mantis"
# Optionally override the client ID sent in Hello messages.
client-id = null
ntallar marked this conversation as resolved.
Show resolved Hide resolved

# Version string (reported by an RPC method)
client-version = "mantis/v2.0"
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/io/iohk/ethereum/utils/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ object Config {

val testmode: Boolean = config.getBoolean("testmode")

val clientId: String = config.getString("client-id")
val clientId =
ConfigUtils
.getOptionalValue(config, "client-id", _.getString("client-id"))
.getOrElse(VersionInfo.clientId)

val clientVersion: String = config.getString("client-version")

Expand Down
34 changes: 34 additions & 0 deletions src/main/scala/io/iohk/ethereum/utils/VersionInfo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.iohk.ethereum.utils

object VersionInfo {

/** Produce a node name that get sent in `WireProtocol.Hello.clientId` according to Ethereum conventions.
*
* Check out examples on https://etcnodes.org
*
* e.g.
* - mantis/v3.0-cd5ae33/linux-amd64/ubuntu-openjdk64bitservervm-java-11.0.9
* - besu/v20.10.0/linux-x86_64/oracle_openjdk-java-11
* - coregeth/v1.11.8-stable-305b5089/linux-amd64/go1.14.4
*/
val clientId = {
val appName = BuildInfo.name
val appVersion = BuildInfo.version
val appCommit = BuildInfo.gitHeadCommit.map("-" + _.take(7)).getOrElse("")

val osName = norm(prop("os.name"))
val osArch = norm(prop("os.arch"))

val javaVendor = norm(prop("java.vendor"))
val javaVmName = norm(prop("java.vm.name"))
val javaVersion = prop("java.version")

s"$appName/v$appVersion$appCommit/$osName-$osArch/$javaVendor-$javaVmName-java-$javaVersion"
}

private def prop(name: String) =
System.getProperty(name)

private def norm(value: String) =
value.toLowerCase.replaceAll("[^a-z0-9]+", "")
}
2 changes: 0 additions & 2 deletions src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mantis {

client-id = "mantis"

datadir = "/tmp/mantis-test/"

secure-random-algo = "NativePRNGNonBlocking"
Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/io/iohk/ethereum/utils/ConfigSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.iohk.ethereum.utils

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class ConfigSpec extends AnyFlatSpec with Matchers {
"clientId" should "by default come from VersionInfo" in {
Config.clientId shouldBe VersionInfo.clientId
}
}
12 changes: 12 additions & 0 deletions src/test/scala/io/iohk/ethereum/utils/VersionInfoSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.iohk.ethereum.utils

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class VersionInfoSpec extends AnyFlatSpec with Matchers {
behavior of "clientId"

it should "preserve major and minor Java version" in {
VersionInfo.clientId should fullyMatch regex """.+/v\d.*-[a-z0-9]{7}/.+-.+/.+-.+-java-\d+\.\d+.*"""
}
}