From ce0db1f2d77ad0eed86fd174a3fa9666b16f03ba Mon Sep 17 00:00:00 2001 From: Jasmina Malicevic Date: Thu, 26 Jan 2023 16:06:42 +0100 Subject: [PATCH] config v0.34: use a different source of versioning (#204) * config: use a different source of versioning (#9486) * Changed version generation * Fixed comment describing the versioning Co-authored-by: Callum Waters --- Makefile | 9 ++------- abci/example/kvstore/kvstore.go | 2 +- abci/version/version.go | 2 +- cmd/tendermint/commands/version.go | 11 ++++++++--- node/node.go | 2 ++ version/version.go | 12 ++++++++---- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 3d623a4fef..fbfcd147c8 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,9 @@ OUTPUT?=build/cometbft BUILD_TAGS?=cometbft -# If building a release, please checkout the version tag to get the correct version setting -ifneq ($(shell git symbolic-ref -q --short HEAD),) -VERSION := unreleased-$(shell git symbolic-ref -q --short HEAD)-$(shell git rev-parse HEAD) -else -VERSION := $(shell git describe --tags) -endif +COMMIT_HASH := $(shell git rev-parse --short HEAD) -LD_FLAGS = -X github.com/cometbft/cometbft/version.TMCoreSemVer=$(VERSION) +LD_FLAGS = -X github.com/cometbft/cometbft/version.TMGitCommitHash=$(COMMIT_HASH) BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)" HTTPS_GIT := https://github.com/cometbft/cometbft.git CGO_ENABLED ?= 0 diff --git a/abci/example/kvstore/kvstore.go b/abci/example/kvstore/kvstore.go index 42b1011013..1a15d04571 100644 --- a/abci/example/kvstore/kvstore.go +++ b/abci/example/kvstore/kvstore.go @@ -85,7 +85,7 @@ func (app *Application) SetGenBlockEvents() { func (app *Application) Info(req types.RequestInfo) (resInfo types.ResponseInfo) { return types.ResponseInfo{ Data: fmt.Sprintf("{\"size\":%v}", app.state.Size), - Version: version.ABCIVersion, + Version: version.ABCISemVer, AppVersion: ProtocolVersion, LastBlockHeight: app.state.Height, LastBlockAppHash: app.state.AppHash, diff --git a/abci/version/version.go b/abci/version/version.go index 1b1b7a31d0..96f27e03b7 100644 --- a/abci/version/version.go +++ b/abci/version/version.go @@ -6,4 +6,4 @@ import ( // TODO: eliminate this after some version refactor -const Version = version.ABCIVersion +const Version = version.ABCISemVer diff --git a/cmd/tendermint/commands/version.go b/cmd/tendermint/commands/version.go index 7f84c2be9f..45eca20b93 100644 --- a/cmd/tendermint/commands/version.go +++ b/cmd/tendermint/commands/version.go @@ -14,6 +14,11 @@ var VersionCmd = &cobra.Command{ Use: "version", Short: "Show version info", Run: func(cmd *cobra.Command, args []string) { + tmVersion := version.TMCoreSemVer + if version.TMGitCommitHash != "" { + tmVersion += "+" + version.TMGitCommitHash + } + if verbose { values, _ := json.MarshalIndent(struct { Tendermint string `json:"tendermint"` @@ -21,14 +26,14 @@ var VersionCmd = &cobra.Command{ BlockProtocol uint64 `json:"block_protocol"` P2PProtocol uint64 `json:"p2p_protocol"` }{ - Tendermint: version.TMCoreSemVer, - ABCI: version.ABCIVersion, + Tendermint: tmVersion, + ABCI: version.ABCISemVer, BlockProtocol: version.BlockProtocol, P2PProtocol: version.P2PProtocol, }, "", " ") fmt.Println(string(values)) } else { - fmt.Println(version.TMCoreSemVer) + fmt.Println(tmVersion) } }, } diff --git a/node/node.go b/node/node.go index 2c74338669..371b2dd007 100644 --- a/node/node.go +++ b/node/node.go @@ -336,8 +336,10 @@ func logNodeStartupInfo(state sm.State, pubKey crypto.PubKey, logger, consensusL // Log the version info. logger.Info("Version info", "tendermint_version", version.TMCoreSemVer, + "abci", version.ABCISemVer, "block", version.BlockProtocol, "p2p", version.P2PProtocol, + "commit_hash", version.TMGitCommitHash, ) // If the state and software differ in block version, at least log it. diff --git a/version/version.go b/version/version.go index d376c79254..f6147b3dec 100644 --- a/version/version.go +++ b/version/version.go @@ -1,11 +1,9 @@ package version -var TMCoreSemVer = TMVersionDefault - const ( - // TMVersionDefault is the used as the fallback version of Tendermint Core + // TMCoreSemVer is the used as the fallback version of Tendermint Core // when not using git describe. It is formatted with semantic versioning. - TMVersionDefault = "0.34.24" + TMCoreSemVer = "0.34.24" // ABCISemVer is the semantic version of the ABCI library ABCISemVer = "0.17.0" @@ -21,3 +19,9 @@ var ( // This includes validity of blocks and state updates. BlockProtocol uint64 = 11 ) + +var ( + // TMGitCommitHash uses git rev-parse HEAD to find commit hash which is helpful + // for the engineering team when working with the tendermint binary. See Makefile + TMGitCommitHash = "" +)