Skip to content

Commit

Permalink
Implement engine_getClientVersionV1 (#2233)
Browse files Browse the repository at this point in the history
* Implement engine_getClientVersionV1

* full git revision string

* Limit GitRevisionString to 8 chars

* Fixes

* Debug windows CI

* debug windows ci

* produce git revision using -C

* try not to delete .git folder in windows ci

* Harden GitRevision procuration

* Add double quotes to git -C param

* Escape sourcePath

* Remove double quotes from git -C param
  • Loading branch information
jangko committed May 29, 2024
1 parent abf1e58 commit 74cc3b6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ jobs:
mingw32-make ${DEFAULT_MAKE_FLAGS}
build/nimbus.exe --help
# give us more space
find . -type d -name ".git" -exec rm -rf {} +
# find . -type d -name ".git" -exec rm -rf {} +
find . -type d -name "nimcache" -exec rm -rf {} +
mingw32-make ${DEFAULT_MAKE_FLAGS} test
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
Expand Down
14 changes: 13 additions & 1 deletion nimbus/rpc/engine_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import
web3/[conversions, execution_types],
../beacon/api_handler,
../beacon/beacon_engine,
../beacon/web3_eth_conv
../beacon/web3_eth_conv,
../version

{.push raises: [].}

Expand All @@ -33,6 +34,7 @@ const supportedMethods: HashSet[string] =
"engine_forkchoiceUpdatedV3",
"engine_getPayloadBodiesByHashV1",
"engine_getPayloadBodiesByRangeV1",
"engine_getClientVersionV1",
])

# I'm trying to keep the handlers below very thin, and move the
Expand Down Expand Up @@ -94,3 +96,13 @@ proc setupEngineAPI*(engine: BeaconEngineRef, server: RpcServer) =
server.rpc("engine_getPayloadBodiesByRangeV1") do(
start: Quantity, count: Quantity) -> seq[Option[ExecutionPayloadBodyV1]]:
return engine.getPayloadBodiesByRange(start.uint64, count.uint64)

server.rpc("engine_getClientVersionV1") do(version: ClientVersionV1) ->
seq[ClientVersionV1]:
# TODO: what should we do with the `version` parameter?
return @[ClientVersionV1(
code: "NB",
name: NimbusName,
version: NimbusVersion,
commit: FixedBytes[4](GitRevisionBytes),
)]
44 changes: 38 additions & 6 deletions nimbus/version.nim
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# Copyright (c) 2018-2022 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.

import strutils
import
std/[strutils, os, sequtils],
stew/byteutils

const
sourcePath = currentSourcePath.rsplit({DirSep, AltSep}, 1)[0]
nimbusRevision {.strdefine.} = "00000000"

static:
doAssert(nimbusRevision.len == 8, "nimbusRevision must consist of 8 characters")
doAssert(nimbusRevision.allIt(it in HexDigits), "nimbusRevision should contains only hex chars")

proc gitFolderExists(path: string): bool {.compileTime.} =
# walk up parent folder to find `.git` folder
var currPath = sourcePath
while true:
if dirExists(currPath & "/.git"):
return true
let parts = splitPath(currPath)
if parts.tail.len == 0: break
currPath = parts.head
false

const
NimbusName* = "nimbus-eth1"
Expand All @@ -24,7 +45,18 @@ const
NimbusVersion* = $NimbusMajor & "." & $NimbusMinor & "." & $NimbusPatch
## is the version of Nimbus as a string.

GitRevision* = strip(staticExec("git rev-parse --short HEAD"))[0..5]

NimVersion* = staticExec("nim --version | grep Version")

# strip: remove spaces
# --short=8: ensure we get 8 chars of commit hash
# -C sourcePath: get the correct git hash no matter where the current dir is.
GitRevision* = if gitFolderExists(sourcePath):
# only using git if the parent dir is a git repo.
strip(staticExec("git -C " & strutils.escape(sourcePath) &
" rev-parse --short=8 HEAD"))
else:
# otherwise we use revision number given by build system.
# e.g. user download from release tarball, or Github zip download.
nimbusRevision

GitRevisionBytes* = hexToByteArray[4](GitRevision)

NimVersion* = "Nim version " & $NimMajor & "." & $NimMinor & "." & $NimPatch
2 changes: 1 addition & 1 deletion vendor/nim-web3

0 comments on commit 74cc3b6

Please sign in to comment.