Skip to content

Commit

Permalink
feat: add cosmos-sdk Version (#9429)
Browse files Browse the repository at this point in the history
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰
v    Before smashing the submit button please review the checkboxes.
v    If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

## Description

Add CosmosSDKVersion to nodeInfo.

closes: #9420
  • Loading branch information
tac0turtle authored Jun 18, 2021
1 parent e4673ad commit 105ad99
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 110 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if input key is empty, or input data contains empty key.
* [\#9133](https://github.com/cosmos/cosmos-sdk/pull/9133) Added hooks for governance actions.
* (x/staking) [\#9214](https://github.com/cosmos/cosmos-sdk/pull/9214) Added `new_shares` attribute inside `EventTypeDelegate` event.
* [\#9382](https://github.com/cosmos/cosmos-sdk/pull/9382) feat: add Dec.Float64() function.
* [\#9429](https://github.com/cosmos/cosmos-sdk/pull/9429) Add `cosmos_sdk_version` to node_info
* [\#9457](https://github.com/cosmos/cosmos-sdk/pull/9457) Add amino support for x/authz and x/feegrant Msgs.
* [\#9498](https://github.com/cosmos/cosmos-sdk/pull/9498) Added `Codec: codec.Codec` attribute to `client/Context` structure.

Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ of how these are written refer to the current [ADRs](https://github.com/cosmos/c
PRs should be categorically broken up based on the type of changes being made (i.e. `fix`, `feat`,
`refactor`, `docs`, etc.). The *type* must be included in the PR title as a prefix (e.g.
`fix: <description>`). This ensures that all changes committed to the base branch follow the
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
Additionally, each PR should only address a single issue.

### Pull Request Templates

There are currently three PR templates. The [default template](./.github/PULL_REQUEST_TEMPLATE.md) is for types `fix`, `feat`, and `refactor`. We also have a [docs template](./.github/PULL_REQUEST_TEMPLATE/docs.md) for documentation changes and an [other template](./.github/PULL_REQUEST_TEMPLATE/other.md) for changes that do not affect production code. When previewing a PR before it has been opened, you can change the template by adding one of the following parameters to the url:

- `template=docs.md`
- `template=other.md`

Expand Down
202 changes: 127 additions & 75 deletions client/grpc/tmservice/query.pb.go

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions client/grpc/tmservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ func (s queryServer) GetNodeInfo(ctx context.Context, req *GetNodeInfoRequest) (
resp := GetNodeInfoResponse{
DefaultNodeInfo: protoNodeInfo,
ApplicationVersion: &VersionInfo{
AppName: nodeInfo.AppName,
Name: nodeInfo.Name,
GitCommit: nodeInfo.GitCommit,
GoVersion: nodeInfo.GoVersion,
Version: nodeInfo.Version,
BuildTags: nodeInfo.BuildTags,
BuildDeps: deps,
AppName: nodeInfo.AppName,
Name: nodeInfo.Name,
GitCommit: nodeInfo.GitCommit,
GoVersion: nodeInfo.GoVersion,
Version: nodeInfo.Version,
BuildTags: nodeInfo.BuildTags,
BuildDeps: deps,
CosmosSdkVersion: nodeInfo.CosmosSdkVersion,
},
}
return &resp, nil
Expand Down
1 change: 1 addition & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,7 @@ VersionInfo is the type for the GetNodeInfoResponse message.
| `build_tags` | [string](#string) | | |
| `go_version` | [string](#string) | | |
| `build_deps` | [Module](#cosmos.base.tendermint.v1beta1.Module) | repeated | |
| `cosmos_sdk_version` | [string](#string) | | |



Expand Down
15 changes: 8 additions & 7 deletions proto/cosmos/base/tendermint/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ message GetNodeInfoResponse {

// VersionInfo is the type for the GetNodeInfoResponse message.
message VersionInfo {
string name = 1;
string app_name = 2;
string version = 3;
string git_commit = 4;
string build_tags = 5;
string go_version = 6;
repeated Module build_deps = 7;
string name = 1;
string app_name = 2;
string version = 3;
string git_commit = 4;
string build_tags = 5;
string go_version = 6;
repeated Module build_deps = 7;
string cosmos_sdk_version = 8;
}

// Module is the type for VersionInfo
Expand Down
46 changes: 32 additions & 14 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,44 @@ var (
BuildTags = ""
)

func getSDKVersion() string {
deps, ok := debug.ReadBuildInfo()
if !ok {
return "unable to read deps"
}
var sdkVersion string
for _, dep := range deps.Deps {
if dep.Path == "github.com/cosmos/cosmos-sdk" {
sdkVersion = dep.Version
}
}

return sdkVersion
}

// Info defines the application version information.
type Info struct {
Name string `json:"name" yaml:"name"`
AppName string `json:"server_name" yaml:"server_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
BuildDeps []buildDep `json:"build_deps" yaml:"build_deps"`
Name string `json:"name" yaml:"name"`
AppName string `json:"server_name" yaml:"server_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
BuildDeps []buildDep `json:"build_deps" yaml:"build_deps"`
CosmosSdkVersion string `json:"cosmos_sdk_version" yaml:"cosmos_sdk_version"`
}

func NewInfo() Info {
sdkVersion := getSDKVersion()
return Info{
Name: Name,
AppName: AppName,
Version: Version,
GitCommit: Commit,
BuildTags: BuildTags,
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
BuildDeps: depsFromBuildInfo(),
Name: Name,
AppName: AppName,
Version: Version,
GitCommit: Commit,
BuildTags: BuildTags,
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
BuildDeps: depsFromBuildInfo(),
CosmosSdkVersion: sdkVersion,
}
}

Expand Down
13 changes: 7 additions & 6 deletions version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ build tags:

func TestInfo_String(t *testing.T) {
info := version.Info{
Name: "testapp",
AppName: "testappd",
Version: "1.0.0",
GitCommit: "1b78457135a4104bc3af97f20654d49e2ea87454",
BuildTags: "netgo,ledger",
GoVersion: "go version go1.14 linux/amd64",
Name: "testapp",
AppName: "testappd",
Version: "1.0.0",
GitCommit: "1b78457135a4104bc3af97f20654d49e2ea87454",
BuildTags: "netgo,ledger",
GoVersion: "go version go1.14 linux/amd64",
CosmosSdkVersion: "0.42.5",
}
want := `testapp: 1.0.0
git commit: 1b78457135a4104bc3af97f20654d49e2ea87454
Expand Down

0 comments on commit 105ad99

Please sign in to comment.