Skip to content

Add commit_hash field to GetInfo response #1034

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GOIMPORTS_BIN := $(GO_BIN)/gosimports

COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
COMMIT_HASH := $(shell git rev-parse HEAD)
DIRTY := $(shell git diff-index --quiet HEAD -- || echo -dirty)
PUBLIC_URL :=

# GO_VERSION is the Go version used for the release build, docker files, and
Expand Down Expand Up @@ -69,6 +70,8 @@ make_ldflags = $(2) -X $(LND_PKG)/build.Commit=lightning-terminal-$(COMMIT) \
-X $(LND_PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g') \
Copy link
Contributor Author

@ViktorTigerstrom ViktorTigerstrom May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we do not change the:
$(LND_PKG)/build.Commit=lightning-terminal-$(COMMIT)

above here, so that the Commit in the getinfo response through lncli remains the same. I think it doesn't make sense to change this until we also change the output of getinfo in lnd.

-X $(PKG).appFilesPrefix=$(PUBLIC_URL) \
-X $(PKG).Commit=$(COMMIT) \
-X $(PKG).CommitHash=$(COMMIT_HASH) \
-X $(PKG).Dirty=$(DIRTY) \
-X $(LOOP_PKG).Commit=$(LOOP_COMMIT) \
-X $(POOL_PKG).Commit=$(POOL_COMMIT) \
-X $(TAP_PKG).Commit=$(TAP_COMMIT)
Expand Down
4 changes: 4 additions & 0 deletions app/src/types/generated/proxy_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion app/src/types/generated/proxy_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/litcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var (
func main() {
app := cli.NewApp()

app.Version = terminal.Version()
app.Version = terminal.RichVersion()
app.Name = "litcli"
app.Usage = "control plane for your Lightning Terminal (lit) daemon"
app.Flags = []cli.Flag{
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
appName := filepath.Base(os.Args[0])
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
if preCfg.ShowVersion {
fmt.Println(appName, "version", Version())
fmt.Println(appName, "version", RichVersion())
os.Exit(0)
}
if preCfg.Lnd.ShowVersion {
Expand Down
15 changes: 15 additions & 0 deletions docs/release-notes/release-notes-0.14.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
`supermacaroon:write` permission to disable access to the
`bakesupermacaroon` endpoint.

* [A `commit_hash` field has been added to the `GetInfo`
response](https://github.com/lightninglabs/lightning-terminal/pull/1034).
The `commit_hash` field will contain the full commit hash of the commit that
LiT release binary build was based on. If the build had uncommitted changes,
the `commit_hash` field will contain the most recent commit hash, suffixed by
"-dirty".
The contents of the `version` field in the `GetInfo` response has also been
updated to only include the semantic version number of the LiT release,
following the semantic versioning 2.0.0 spec (http://semver.org/).

* [A `commit_hash` field has been added to the `--version`
output](https://github.com/lightninglabs/lightning-terminal/pull/1034).
The `commit_hash` field will contain the full commit hash of the commit that
LiT release binary build was based on.

## Integrated Binary Updates

### LND
Expand Down
59 changes: 37 additions & 22 deletions litrpc/proxy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion litrpc/proxy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ message GetInfoRequest {
}

message GetInfoResponse {
// The version of the LiTd software that the node is running.
// The application version of the LiTd software running on the node,
// following the Semantic Versioning 2.0.0 specification
// (http://semver.org/).
string version = 1;

// The Git commit hash the LiTd binary build was based on. If the build had
// uncommited changes, this field will contain the most recent commit hash,
// suffixed by "-dirty".
string commit_hash = 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you think commit would be a more suitable name for this, as the contents may be the tag rather than a commit hash. But opted for this naming as it then mimics the loop getinfo response :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staying consistent is probably better, I would have chosen "revision" I guess.

}
6 changes: 5 additions & 1 deletion litrpc/proxy.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@
"properties": {
"version": {
"type": "string",
"description": "The version of the LiTd software that the node is running."
"description": "The application version of the LiTd software running on the node,\nfollowing the Semantic Versioning 2.0.0 specification\n(http://semver.org/)."
},
"commit_hash": {
"type": "string",
"description": "The Git commit hash the LiTd binary build was based on. If the build had\nuncommited changes, this field will contain the most recent commit hash,\nsuffixed by \"-dirty\"."
}
}
},
Expand Down
9 changes: 8 additions & 1 deletion proto/proxy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ message GetInfoRequest {
}

message GetInfoResponse {
// The version of the LiTd software that the node is running.
// The application version of the LiTd software running on the node,
// following the Semantic Versioning 2.0.0 specification
// (http://semver.org/).
string version = 1;

// The Git commit hash the LiTd binary build was based on. If the build had
// uncommited changes, this field will contain the most recent commit hash,
// suffixed by "-dirty".
string commit_hash = 2;
}
3 changes: 2 additions & 1 deletion rpc_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ func (p *rpcProxy) GetInfo(_ context.Context, _ *litrpc.GetInfoRequest) (
*litrpc.GetInfoResponse, error) {

return &litrpc.GetInfoResponse{
Version: Version(),
Version: Version(),
CommitHash: CommitHash + Dirty,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (g *LightningTerminal) Run(ctx context.Context) error {
g.defaultImplCfg = g.cfg.Lnd.ImplementationConfig(shutdownInterceptor)

// Show version at startup.
log.Infof("LiT version: %s", Version())
log.Infof("LiT version: %s", RichVersion())

// This concurrent error queue can be used by every component that can
// raise runtime errors. Using a queue will prevent us from blocking on
Expand Down Expand Up @@ -2010,7 +2010,7 @@ func (g *LightningTerminal) showStartupInfo(ctx context.Context) error {
" Web interface %s \n" +
"----------------------------------------------------------\n"
fmt.Printf(str, info.mode, info.status, info.alias, info.version,
Version(), webInterfaceString)
RichVersion(), webInterfaceString)

return nil
}
Expand Down
34 changes: 29 additions & 5 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ import (
"strings"
)

// Commit stores the current commit hash of this build, this should be set
// using the -ldflags during compilation.
// Commit stores the current git tag of this build, when the build is based on
// a tagged commit. If the build is based on an untagged commit or is a dirty
// build, the Commit field stores the most recent tag suffixed by the commit
// hash, and/or "-dirty". This should be set using the -ldflags during
// compilation.
var Commit string

// CommitHash stores the current git commit hash of this build. This should be
// set using the -ldflags during compilation.
var CommitHash string

// Dirty stores a "-dirty" string, if the build had uncommitted changes when
// being built. This should be set using the -ldflags during compilation.
var Dirty string

// semanticAlphabet
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-."

Expand All @@ -33,6 +44,22 @@ const (
// Version returns the application version as a properly formed string per the
// semantic versioning 2.0.0 spec (http://semver.org/).
func Version() string {
return semanticVersion()
}

// RichVersion returns the application version as a properly formed string
// per the semantic versioning 2.0.0 spec (http://semver.org/), the git tag and
// commit hash it was built on.
func RichVersion() string {
// Append git tag and commit hash of current build to version.
return fmt.Sprintf(
"%s commit=%s commit_hash=%s", semanticVersion(), Commit,
CommitHash,
)
}

// semanticVersion returns the SemVer part of the version.
func semanticVersion() string {
// Start with the major, minor, and patch versions.
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)

Expand All @@ -45,9 +72,6 @@ func Version() string {
version = fmt.Sprintf("%s-%s", version, preRelease)
}

// Append commit hash of current build to version.
version = fmt.Sprintf("%s commit=%s", version, Commit)

return version
}

Expand Down
Loading