multi: update GetInfoResponse response

Add the `commit_hash` field to the GetInfoResponse. The `commit_hash`
field will contain the most recent commit_hash that the build was based
on. If the build had uncommitted changes, this field will contain the
most recent commit hash, suffixed by "-dirty".

The semantics of the `version` field is also updated to always contain
the most recent semantic version of the litd node, following the
semantic versioning 2.0.0 spec (http://semver.org/).
This commit is contained in:
Viktor Tigerström 2025-04-11 21:23:45 +02:00
parent 2d3efee7df
commit e30ac3d0a8
No known key found for this signature in database
GPG key ID: B984570980684DCC
12 changed files with 130 additions and 36 deletions

View file

@ -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
@ -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') \
-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)

View file

@ -99,6 +99,9 @@ export class GetInfoResponse extends jspb.Message {
getVersion(): string;
setVersion(value: string): void;
getCommitHash(): string;
setCommitHash(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): GetInfoResponse.AsObject;
static toObject(includeInstance: boolean, msg: GetInfoResponse): GetInfoResponse.AsObject;
@ -112,6 +115,7 @@ export class GetInfoResponse extends jspb.Message {
export namespace GetInfoResponse {
export type AsObject = {
version: string,
commitHash: string,
}
}

View file

@ -781,7 +781,8 @@ proto.litrpc.GetInfoResponse.prototype.toObject = function(opt_includeInstance)
*/
proto.litrpc.GetInfoResponse.toObject = function(includeInstance, msg) {
var f, obj = {
version: jspb.Message.getFieldWithDefault(msg, 1, "")
version: jspb.Message.getFieldWithDefault(msg, 1, ""),
commitHash: jspb.Message.getFieldWithDefault(msg, 2, "")
};
if (includeInstance) {
@ -822,6 +823,10 @@ proto.litrpc.GetInfoResponse.deserializeBinaryFromReader = function(msg, reader)
var value = /** @type {string} */ (reader.readString());
msg.setVersion(value);
break;
case 2:
var value = /** @type {string} */ (reader.readString());
msg.setCommitHash(value);
break;
default:
reader.skipField();
break;
@ -858,6 +863,13 @@ proto.litrpc.GetInfoResponse.serializeBinaryToWriter = function(message, writer)
f
);
}
f = message.getCommitHash();
if (f.length > 0) {
writer.writeString(
2,
f
);
}
};
@ -879,4 +891,22 @@ proto.litrpc.GetInfoResponse.prototype.setVersion = function(value) {
};
/**
* optional string commit_hash = 2;
* @return {string}
*/
proto.litrpc.GetInfoResponse.prototype.getCommitHash = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ""));
};
/**
* @param {string} value
* @return {!proto.litrpc.GetInfoResponse} returns this
*/
proto.litrpc.GetInfoResponse.prototype.setCommitHash = function(value) {
return jspb.Message.setProto3StringField(this, 2, value);
};
goog.object.extend(exports, proto.litrpc);

View file

@ -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{

View file

@ -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 {

View file

@ -245,8 +245,14 @@ type GetInfoResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// 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/).
Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
// 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".
CommitHash string `protobuf:"bytes,2,opt,name=commit_hash,json=commitHash,proto3" json:"commit_hash,omitempty"`
}
func (x *GetInfoResponse) Reset() {
@ -288,6 +294,13 @@ func (x *GetInfoResponse) GetVersion() string {
return ""
}
func (x *GetInfoResponse) GetCommitHash() string {
if x != nil {
return x.CommitHash
}
return ""
}
var File_proxy_proto protoreflect.FileDescriptor
var file_proxy_proto_rawDesc = []byte{
@ -306,28 +319,30 @@ var file_proxy_proto_rawDesc = []byte{
0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x53, 0x74, 0x6f,
0x70, 0x44, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x10, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x22, 0x2b, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70,
0x74, 0x22, 0x4c, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x32, 0xe2,
0x01, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x3a, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x49,
0x6e, 0x66, 0x6f, 0x12, 0x16, 0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74,
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x6c, 0x69,
0x74, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, 0x0a, 0x0a, 0x53, 0x74, 0x6f, 0x70, 0x44, 0x61, 0x65, 0x6d,
0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x74, 0x6f, 0x70,
0x44, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e,
0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x44, 0x61, 0x65, 0x6d, 0x6f,
0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x58, 0x0a, 0x11, 0x42, 0x61, 0x6b,
0x65, 0x53, 0x75, 0x70, 0x65, 0x72, 0x4d, 0x61, 0x63, 0x61, 0x72, 0x6f, 0x6f, 0x6e, 0x12, 0x20,
0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x61, 0x6b, 0x65, 0x53, 0x75, 0x70, 0x65,
0x72, 0x4d, 0x61, 0x63, 0x61, 0x72, 0x6f, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x21, 0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x61, 0x6b, 0x65, 0x53, 0x75,
0x70, 0x65, 0x72, 0x4d, 0x61, 0x63, 0x61, 0x72, 0x6f, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f,
0x6d, 0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, 0x6c, 0x61, 0x62, 0x73, 0x2f,
0x6c, 0x69, 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, 0x2d, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e,
0x61, 0x6c, 0x2f, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f,
0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x48, 0x61, 0x73, 0x68, 0x32,
0xe2, 0x01, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x3a, 0x0a, 0x07, 0x47, 0x65, 0x74,
0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65,
0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x6c,
0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, 0x0a, 0x0a, 0x53, 0x74, 0x6f, 0x70, 0x44, 0x61, 0x65,
0x6d, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x74, 0x6f,
0x70, 0x44, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a,
0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x44, 0x61, 0x65, 0x6d,
0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x58, 0x0a, 0x11, 0x42, 0x61,
0x6b, 0x65, 0x53, 0x75, 0x70, 0x65, 0x72, 0x4d, 0x61, 0x63, 0x61, 0x72, 0x6f, 0x6f, 0x6e, 0x12,
0x20, 0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x61, 0x6b, 0x65, 0x53, 0x75, 0x70,
0x65, 0x72, 0x4d, 0x61, 0x63, 0x61, 0x72, 0x6f, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x21, 0x2e, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x61, 0x6b, 0x65, 0x53,
0x75, 0x70, 0x65, 0x72, 0x4d, 0x61, 0x63, 0x61, 0x72, 0x6f, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, 0x6c, 0x61, 0x62, 0x73,
0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, 0x2d, 0x74, 0x65, 0x72, 0x6d, 0x69,
0x6e, 0x61, 0x6c, 0x2f, 0x6c, 0x69, 0x74, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
}
var (

View file

@ -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;
}

View file

@ -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\"."
}
}
},

View file

@ -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;
}

View file

@ -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
}

View file

@ -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
@ -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
}

View file

@ -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-."
@ -33,6 +44,21 @@ 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 it
// was built on.
func RichVersion() string {
// Append git tag of current build to version.
return fmt.Sprintf(
"%s commit=%s", semanticVersion(), Commit,
)
}
// 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)
@ -45,9 +71,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
}