From 08fa23fc1a01ad9809fc5dd82202fbe85497f46b Mon Sep 17 00:00:00 2001 From: pritsheth Date: Wed, 3 Apr 2024 08:40:08 -0700 Subject: [PATCH 01/13] Add get_version endpoint --- .../internal/methods/get_version.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 cmd/soroban-rpc/internal/methods/get_version.go diff --git a/cmd/soroban-rpc/internal/methods/get_version.go b/cmd/soroban-rpc/internal/methods/get_version.go new file mode 100644 index 00000000..7389889d --- /dev/null +++ b/cmd/soroban-rpc/internal/methods/get_version.go @@ -0,0 +1,31 @@ +package methods + +import ( + "context" + "github.com/creachadair/jrpc2" + "github.com/creachadair/jrpc2/handler" + "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" +) + +type GetVersionRequest struct { +} + +type GetVersionResponse struct { + Version string `json:"version"` + XDRVersion string `json:"xdr_version"` + ContractVersion string `json:"contract_version"` +} + +func NewGetVersionHandler(daemon interfaces.Daemon) jrpc2.Handler { + coreClient := daemon.CoreClient() + return handler.New(func(ctx context.Context, request GetVersionRequest) (GetVersionResponse, error) { + _, err := coreClient.Info(ctx) + if err != nil { + return GetVersionResponse{}, &jrpc2.Error{ + Code: jrpc2.InternalError, + Message: err.Error(), + } + } + return GetVersionResponse{}, nil + }) +} From 689c724057161dc4447d6306b6bab0696d664b2b Mon Sep 17 00:00:00 2001 From: pritsheth Date: Wed, 10 Apr 2024 12:46:13 -0700 Subject: [PATCH 02/13] Add CaptiveCoreVersion Info --- Makefile | 6 ++- cmd/soroban-rpc/internal/config/config.go | 2 + cmd/soroban-rpc/internal/config/options.go | 13 ++++++ cmd/soroban-rpc/internal/config/version.go | 2 + cmd/soroban-rpc/internal/jsonrpc.go | 7 ++++ .../internal/methods/get_version.go | 31 -------------- .../internal/methods/get_version_info.go | 42 +++++++++++++++++++ 7 files changed, 71 insertions(+), 32 deletions(-) delete mode 100644 cmd/soroban-rpc/internal/methods/get_version.go create mode 100644 cmd/soroban-rpc/internal/methods/get_version_info.go diff --git a/Makefile b/Makefile index 278f6713..1e102922 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ all: check build test export RUSTFLAGS=-Dwarnings -Dclippy::all -Dclippy::pedantic + +CAPTIVE_CORE_VERSION_INFO := $(shell stellar-core version) + REPOSITORY_COMMIT_HASH := "$(shell git rev-parse HEAD)" ifeq (${REPOSITORY_COMMIT_HASH},"") $(error failed to retrieve git head commit hash) @@ -17,7 +20,8 @@ BUILD_TIMESTAMP ?= $(shell date '+%Y-%m-%dT%H:%M:%S') GOLDFLAGS := -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.Version=${REPOSITORY_VERSION}' \ -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.CommitHash=${REPOSITORY_COMMIT_HASH}' \ -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.BuildTimestamp=${BUILD_TIMESTAMP}' \ - -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.Branch=${REPOSITORY_BRANCH}' + -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.Branch=${REPOSITORY_BRANCH}' \ + -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.CaptiveCoreVersionInfo=${CAPTIVE_CORE_VERSION_INFO}' # The following works around incompatibility between the rust and the go linkers - diff --git a/cmd/soroban-rpc/internal/config/config.go b/cmd/soroban-rpc/internal/config/config.go index 15e69f6b..5d753b45 100644 --- a/cmd/soroban-rpc/internal/config/config.go +++ b/cmd/soroban-rpc/internal/config/config.go @@ -44,6 +44,7 @@ type Config struct { RequestBacklogGetHealthQueueLimit uint RequestBacklogGetEventsQueueLimit uint RequestBacklogGetNetworkQueueLimit uint + RequestBacklogGetVersionInfoQueueLimit uint RequestBacklogGetLatestLedgerQueueLimit uint RequestBacklogGetLedgerEntriesQueueLimit uint RequestBacklogGetTransactionQueueLimit uint @@ -54,6 +55,7 @@ type Config struct { MaxGetHealthExecutionDuration time.Duration MaxGetEventsExecutionDuration time.Duration MaxGetNetworkExecutionDuration time.Duration + MaxGetVersionInfoExecutionDuration time.Duration MaxGetLatestLedgerExecutionDuration time.Duration MaxGetLedgerEntriesExecutionDuration time.Duration MaxGetTransactionExecutionDuration time.Duration diff --git a/cmd/soroban-rpc/internal/config/options.go b/cmd/soroban-rpc/internal/config/options.go index df503200..edef7968 100644 --- a/cmd/soroban-rpc/internal/config/options.go +++ b/cmd/soroban-rpc/internal/config/options.go @@ -302,6 +302,13 @@ func (cfg *Config) options() ConfigOptions { DefaultValue: uint(1000), Validate: positive, }, + { + TomlKey: strutils.KebabToConstantCase("request-backlog-get-version-info-queue-limit"), + Usage: "Maximum number of outstanding GetVersionInfo requests", + ConfigKey: &cfg.RequestBacklogGetVersionInfoQueueLimit, + DefaultValue: uint(1000), + Validate: positive, + }, { TomlKey: strutils.KebabToConstantCase("request-backlog-get-latest-ledger-queue-limit"), Usage: "Maximum number of outstanding GetLatestsLedger requests", @@ -367,6 +374,12 @@ func (cfg *Config) options() ConfigOptions { ConfigKey: &cfg.MaxGetNetworkExecutionDuration, DefaultValue: 5 * time.Second, }, + { + TomlKey: strutils.KebabToConstantCase("max-get-version-info-execution-duration"), + Usage: "The maximum duration of time allowed for processing a getVersionInfo request. When that time elapses, the rpc server would return -32001 and abort the request's execution", + ConfigKey: &cfg.MaxGetVersionInfoExecutionDuration, + DefaultValue: 5 * time.Second, + }, { TomlKey: strutils.KebabToConstantCase("max-get-latest-ledger-execution-duration"), Usage: "The maximum duration of time allowed for processing a getLatestLedger request. When that time elapses, the rpc server would return -32001 and abort the request's execution", diff --git a/cmd/soroban-rpc/internal/config/version.go b/cmd/soroban-rpc/internal/config/version.go index 909fdaea..ec60c4fa 100644 --- a/cmd/soroban-rpc/internal/config/version.go +++ b/cmd/soroban-rpc/internal/config/version.go @@ -12,4 +12,6 @@ var ( // Branch is the git branch from which the soroban-rpc was built, injected during build time. Branch = "" + + CaptiveCoreVersionInfo = "" ) diff --git a/cmd/soroban-rpc/internal/jsonrpc.go b/cmd/soroban-rpc/internal/jsonrpc.go index d122b9a0..84d20e3d 100644 --- a/cmd/soroban-rpc/internal/jsonrpc.go +++ b/cmd/soroban-rpc/internal/jsonrpc.go @@ -162,6 +162,13 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler { queueLimit: cfg.RequestBacklogGetNetworkQueueLimit, requestDurationLimit: cfg.MaxGetNetworkExecutionDuration, }, + { + methodName: "getVersionInfo", + underlyingHandler: methods.NewGetVersionInfoHandler(params.Daemon), + longName: "get_version_info", + queueLimit: cfg.RequestBacklogGetVersionInfoQueueLimit, + requestDurationLimit: cfg.MaxGetVersionInfoExecutionDuration, + }, { methodName: "getLatestLedger", underlyingHandler: methods.NewGetLatestLedgerHandler(params.LedgerEntryReader, params.LedgerReader), diff --git a/cmd/soroban-rpc/internal/methods/get_version.go b/cmd/soroban-rpc/internal/methods/get_version.go deleted file mode 100644 index 7389889d..00000000 --- a/cmd/soroban-rpc/internal/methods/get_version.go +++ /dev/null @@ -1,31 +0,0 @@ -package methods - -import ( - "context" - "github.com/creachadair/jrpc2" - "github.com/creachadair/jrpc2/handler" - "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" -) - -type GetVersionRequest struct { -} - -type GetVersionResponse struct { - Version string `json:"version"` - XDRVersion string `json:"xdr_version"` - ContractVersion string `json:"contract_version"` -} - -func NewGetVersionHandler(daemon interfaces.Daemon) jrpc2.Handler { - coreClient := daemon.CoreClient() - return handler.New(func(ctx context.Context, request GetVersionRequest) (GetVersionResponse, error) { - _, err := coreClient.Info(ctx) - if err != nil { - return GetVersionResponse{}, &jrpc2.Error{ - Code: jrpc2.InternalError, - Message: err.Error(), - } - } - return GetVersionResponse{}, nil - }) -} diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go new file mode 100644 index 00000000..db11b55b --- /dev/null +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -0,0 +1,42 @@ +package methods + +import ( + "context" + "github.com/creachadair/jrpc2" + "github.com/creachadair/jrpc2/handler" + "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config" + "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" +) + +type GetVersionRequest struct { +} + +type GetVersionResponse struct { + Version string `json:"version"` + CommitHash string `json:"commit_hash"` + BuildTimestamp string `json:"build_time_stamp"` + ProtocolVersion int `json:"protocol_version"` + XDRVersion string `json:"xdr_version"` + CaptiveCoreVersionInfo string `json:"captive_core_version"` +} + +func NewGetVersionInfoHandler(daemon interfaces.Daemon) jrpc2.Handler { + coreClient := daemon.CoreClient() + return handler.New(func(ctx context.Context, request GetVersionRequest) (GetVersionResponse, error) { + info, err := coreClient.Info(ctx) + if err != nil { + return GetVersionResponse{}, &jrpc2.Error{ + Code: jrpc2.InternalError, + Message: err.Error(), + } + } + + return GetVersionResponse{ + Version: config.Version, + CommitHash: config.CommitHash, + BuildTimestamp: config.BuildTimestamp, + CaptiveCoreVersionInfo: config.CaptiveCoreVersionInfo, + ProtocolVersion: info.Info.ProtocolVersion, + }, nil + }) +} From a95ce3dde30c965548a8690e1c5ac8df928755d1 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Fri, 12 Apr 2024 11:46:07 -0700 Subject: [PATCH 03/13] Add integration tests --- .../internal/methods/get_version_info.go | 11 ++++---- .../internal/test/get_version_info_test.go | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 cmd/soroban-rpc/internal/test/get_version_info_test.go diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index db11b55b..d4493e60 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -8,30 +8,29 @@ import ( "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" ) -type GetVersionRequest struct { +type GetVersionInfoRequest struct { } -type GetVersionResponse struct { +type GetVersionInfoResponse struct { Version string `json:"version"` CommitHash string `json:"commit_hash"` BuildTimestamp string `json:"build_time_stamp"` ProtocolVersion int `json:"protocol_version"` - XDRVersion string `json:"xdr_version"` CaptiveCoreVersionInfo string `json:"captive_core_version"` } func NewGetVersionInfoHandler(daemon interfaces.Daemon) jrpc2.Handler { coreClient := daemon.CoreClient() - return handler.New(func(ctx context.Context, request GetVersionRequest) (GetVersionResponse, error) { + return handler.New(func(ctx context.Context, request GetVersionInfoRequest) (GetVersionInfoResponse, error) { info, err := coreClient.Info(ctx) if err != nil { - return GetVersionResponse{}, &jrpc2.Error{ + return GetVersionInfoResponse{}, &jrpc2.Error{ Code: jrpc2.InternalError, Message: err.Error(), } } - return GetVersionResponse{ + return GetVersionInfoResponse{ Version: config.Version, CommitHash: config.CommitHash, BuildTimestamp: config.BuildTimestamp, diff --git a/cmd/soroban-rpc/internal/test/get_version_info_test.go b/cmd/soroban-rpc/internal/test/get_version_info_test.go new file mode 100644 index 00000000..ba4f4b09 --- /dev/null +++ b/cmd/soroban-rpc/internal/test/get_version_info_test.go @@ -0,0 +1,26 @@ +package test + +import ( + "context" + "testing" + + "github.com/creachadair/jrpc2" + "github.com/creachadair/jrpc2/jhttp" + "github.com/stretchr/testify/assert" + + "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/methods" +) + +func TestGetVersionInfoSucceeds(t *testing.T) { + test := NewTest(t, nil) + + ch := jhttp.NewChannel(test.sorobanRPCURL(), nil) + client := jrpc2.NewClient(ch, nil) + + request := methods.GetVersionInfoRequest{} + + var result methods.GetVersionInfoResponse + err := client.CallResult(context.Background(), "getVersionInfo", request, &result) + assert.NoError(t, err) + assert.Equal(t, stellarCoreProtocolVersion, result.ProtocolVersion) +} From 68cd9d0546c430ef91d29d42d14838f2c3ed7ea8 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Tue, 16 Apr 2024 03:22:34 +0530 Subject: [PATCH 04/13] update integration tests --- .../internal/test/get_version_info_test.go | 7 ++++-- cmd/soroban-rpc/internal/test/integration.go | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cmd/soroban-rpc/internal/test/get_version_info_test.go b/cmd/soroban-rpc/internal/test/get_version_info_test.go index ba4f4b09..597e4047 100644 --- a/cmd/soroban-rpc/internal/test/get_version_info_test.go +++ b/cmd/soroban-rpc/internal/test/get_version_info_test.go @@ -16,11 +16,14 @@ func TestGetVersionInfoSucceeds(t *testing.T) { ch := jhttp.NewChannel(test.sorobanRPCURL(), nil) client := jrpc2.NewClient(ch, nil) - request := methods.GetVersionInfoRequest{} var result methods.GetVersionInfoResponse err := client.CallResult(context.Background(), "getVersionInfo", request, &result) assert.NoError(t, err) - assert.Equal(t, stellarCoreProtocolVersion, result.ProtocolVersion) + + assert.NotEmpty(t, result.CaptiveCoreVersionInfo) + assert.NotEmpty(t, result.Version) + assert.NotEmpty(t, result.BuildTimestamp) + assert.NotEmpty(t, result.CommitHash) } diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index 8680a1cd..e3b94e93 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -98,6 +98,7 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test { })) i.runComposeCommand("up", "--detach", "--quiet-pull", "--no-color") + i.populateVersionInfo() i.prepareShutdownHandlers() i.coreClient = &stellarcore.Client{URL: "http://localhost:" + strconv.Itoa(stellarCorePort)} i.waitForCore() @@ -224,6 +225,30 @@ func (i *Test) runComposeCommand(args ...string) { } } +// Runs git commands to fetch version information +func (i *Test) populateVersionInfo() { + + execFunction := func(command string, args ...string) string { + cmd := exec.Command(command, args...) + i.t.Log("Running", cmd.Env, cmd.Args) + out, innerErr := cmd.Output() + if exitErr, ok := innerErr.(*exec.ExitError); ok { + fmt.Printf("stdout:\n%s\n", string(out)) + fmt.Printf("stderr:\n%s\n", string(exitErr.Stderr)) + } + + if innerErr != nil { + i.t.Fatalf("Command %s failed: %v", cmd.Env, innerErr) + } + return string(out) + } + + config.CaptiveCoreVersionInfo = execFunction("stellar-core", "version") + config.Version = execFunction("git", "describe", "--tags", "--always", "--abbrev=0", "--match='v[0-9]*.[0-9]*.[0-9]*'") + config.CommitHash = execFunction("git", "rev-parse", "HEAD") + config.BuildTimestamp = execFunction("date", "+%Y-%m-%dT%H:%M:%S") +} + func (i *Test) prepareShutdownHandlers() { i.shutdownCalls = append(i.shutdownCalls, func() { From 1010049eb2e713f511168213e036801967e092cb Mon Sep 17 00:00:00 2001 From: pritsheth Date: Tue, 16 Apr 2024 03:24:06 +0530 Subject: [PATCH 05/13] remove protocol version --- cmd/soroban-rpc/internal/jsonrpc.go | 2 +- .../internal/methods/get_version_info.go | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/cmd/soroban-rpc/internal/jsonrpc.go b/cmd/soroban-rpc/internal/jsonrpc.go index 84d20e3d..84585510 100644 --- a/cmd/soroban-rpc/internal/jsonrpc.go +++ b/cmd/soroban-rpc/internal/jsonrpc.go @@ -164,7 +164,7 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler { }, { methodName: "getVersionInfo", - underlyingHandler: methods.NewGetVersionInfoHandler(params.Daemon), + underlyingHandler: methods.NewGetVersionInfoHandler(), longName: "get_version_info", queueLimit: cfg.RequestBacklogGetVersionInfoQueueLimit, requestDurationLimit: cfg.MaxGetVersionInfoExecutionDuration, diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index d4493e60..f926ac68 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -5,7 +5,6 @@ import ( "github.com/creachadair/jrpc2" "github.com/creachadair/jrpc2/handler" "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config" - "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" ) type GetVersionInfoRequest struct { @@ -15,27 +14,17 @@ type GetVersionInfoResponse struct { Version string `json:"version"` CommitHash string `json:"commit_hash"` BuildTimestamp string `json:"build_time_stamp"` - ProtocolVersion int `json:"protocol_version"` CaptiveCoreVersionInfo string `json:"captive_core_version"` } -func NewGetVersionInfoHandler(daemon interfaces.Daemon) jrpc2.Handler { - coreClient := daemon.CoreClient() +func NewGetVersionInfoHandler() jrpc2.Handler { return handler.New(func(ctx context.Context, request GetVersionInfoRequest) (GetVersionInfoResponse, error) { - info, err := coreClient.Info(ctx) - if err != nil { - return GetVersionInfoResponse{}, &jrpc2.Error{ - Code: jrpc2.InternalError, - Message: err.Error(), - } - } return GetVersionInfoResponse{ Version: config.Version, CommitHash: config.CommitHash, BuildTimestamp: config.BuildTimestamp, CaptiveCoreVersionInfo: config.CaptiveCoreVersionInfo, - ProtocolVersion: info.Info.ProtocolVersion, }, nil }) } From d1120e4545f11ad21e0529349f6dd6b565d1951a Mon Sep 17 00:00:00 2001 From: pritsheth Date: Wed, 17 Apr 2024 19:00:46 +0530 Subject: [PATCH 06/13] fetch captive core version from info endpoint --- cmd/soroban-rpc/internal/config/version.go | 2 -- cmd/soroban-rpc/internal/jsonrpc.go | 2 +- .../internal/methods/get_version_info.go | 29 +++++++++++++------ .../internal/test/get_version_info_test.go | 2 +- cmd/soroban-rpc/internal/test/integration.go | 1 - 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cmd/soroban-rpc/internal/config/version.go b/cmd/soroban-rpc/internal/config/version.go index ec60c4fa..909fdaea 100644 --- a/cmd/soroban-rpc/internal/config/version.go +++ b/cmd/soroban-rpc/internal/config/version.go @@ -12,6 +12,4 @@ var ( // Branch is the git branch from which the soroban-rpc was built, injected during build time. Branch = "" - - CaptiveCoreVersionInfo = "" ) diff --git a/cmd/soroban-rpc/internal/jsonrpc.go b/cmd/soroban-rpc/internal/jsonrpc.go index 825a2093..99027a96 100644 --- a/cmd/soroban-rpc/internal/jsonrpc.go +++ b/cmd/soroban-rpc/internal/jsonrpc.go @@ -173,7 +173,7 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler { }, { methodName: "getVersionInfo", - underlyingHandler: methods.NewGetVersionInfoHandler(), + underlyingHandler: methods.NewGetVersionInfoHandler(params.Logger, params.Daemon), longName: "get_version_info", queueLimit: cfg.RequestBacklogGetVersionInfoQueueLimit, requestDurationLimit: cfg.MaxGetVersionInfoExecutionDuration, diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index f926ac68..241e3e26 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -4,27 +4,38 @@ import ( "context" "github.com/creachadair/jrpc2" "github.com/creachadair/jrpc2/handler" + "github.com/stellar/go/support/log" "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config" + "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" ) type GetVersionInfoRequest struct { } type GetVersionInfoResponse struct { - Version string `json:"version"` - CommitHash string `json:"commit_hash"` - BuildTimestamp string `json:"build_time_stamp"` - CaptiveCoreVersionInfo string `json:"captive_core_version"` + Version string `json:"version"` + CommitHash string `json:"commit_hash"` + BuildTimestamp string `json:"build_time_stamp"` + CaptiveCoreVersion string `json:"captive_core_version"` } -func NewGetVersionInfoHandler() jrpc2.Handler { +func NewGetVersionInfoHandler(logger *log.Entry, daemon interfaces.Daemon) jrpc2.Handler { + coreClient := daemon.CoreClient() return handler.New(func(ctx context.Context, request GetVersionInfoRequest) (GetVersionInfoResponse, error) { + info, err := coreClient.Info(ctx) + var captiveCoreVersion string + if err != nil { + logger.WithError(err).WithField("request", request). + Infof("error occurred while calling Info endpoint of core") + } else { + captiveCoreVersion = info.Info.Build + } return GetVersionInfoResponse{ - Version: config.Version, - CommitHash: config.CommitHash, - BuildTimestamp: config.BuildTimestamp, - CaptiveCoreVersionInfo: config.CaptiveCoreVersionInfo, + Version: config.Version, + CommitHash: config.CommitHash, + BuildTimestamp: config.BuildTimestamp, + CaptiveCoreVersion: captiveCoreVersion, }, nil }) } diff --git a/cmd/soroban-rpc/internal/test/get_version_info_test.go b/cmd/soroban-rpc/internal/test/get_version_info_test.go index 597e4047..61849b0d 100644 --- a/cmd/soroban-rpc/internal/test/get_version_info_test.go +++ b/cmd/soroban-rpc/internal/test/get_version_info_test.go @@ -22,8 +22,8 @@ func TestGetVersionInfoSucceeds(t *testing.T) { err := client.CallResult(context.Background(), "getVersionInfo", request, &result) assert.NoError(t, err) - assert.NotEmpty(t, result.CaptiveCoreVersionInfo) assert.NotEmpty(t, result.Version) assert.NotEmpty(t, result.BuildTimestamp) assert.NotEmpty(t, result.CommitHash) + assert.NotEmpty(t, result.CaptiveCoreVersion) } diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index e3b94e93..3d84a1e7 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -243,7 +243,6 @@ func (i *Test) populateVersionInfo() { return string(out) } - config.CaptiveCoreVersionInfo = execFunction("stellar-core", "version") config.Version = execFunction("git", "describe", "--tags", "--always", "--abbrev=0", "--match='v[0-9]*.[0-9]*.[0-9]*'") config.CommitHash = execFunction("git", "rev-parse", "HEAD") config.BuildTimestamp = execFunction("date", "+%Y-%m-%dT%H:%M:%S") From bb10b8f6414678debfd34da7d091fb5654901604 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Wed, 17 Apr 2024 19:29:29 +0530 Subject: [PATCH 07/13] Add protocol version in response --- cmd/soroban-rpc/internal/jsonrpc.go | 2 +- .../internal/methods/get_version_info.go | 33 +++++++++++++++++-- .../internal/test/get_version_info_test.go | 1 + 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cmd/soroban-rpc/internal/jsonrpc.go b/cmd/soroban-rpc/internal/jsonrpc.go index 11532e67..3b302aa7 100644 --- a/cmd/soroban-rpc/internal/jsonrpc.go +++ b/cmd/soroban-rpc/internal/jsonrpc.go @@ -173,7 +173,7 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler { }, { methodName: "getVersionInfo", - underlyingHandler: methods.NewGetVersionInfoHandler(params.Logger, params.Daemon), + underlyingHandler: methods.NewGetVersionInfoHandler(params.Logger, params.LedgerEntryReader, params.LedgerReader, params.Daemon), longName: "get_version_info", queueLimit: cfg.RequestBacklogGetVersionInfoQueueLimit, requestDurationLimit: cfg.MaxGetVersionInfoExecutionDuration, diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index 241e3e26..ab2a38a1 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -7,6 +7,7 @@ import ( "github.com/stellar/go/support/log" "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config" "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/daemon/interfaces" + "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/db" ) type GetVersionInfoRequest struct { @@ -17,25 +18,51 @@ type GetVersionInfoResponse struct { CommitHash string `json:"commit_hash"` BuildTimestamp string `json:"build_time_stamp"` CaptiveCoreVersion string `json:"captive_core_version"` + ProtocolVersion uint32 `json:"protocol_version"` } -func NewGetVersionInfoHandler(logger *log.Entry, daemon interfaces.Daemon) jrpc2.Handler { +func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntryReader, ledgerReader db.LedgerReader, daemon interfaces.Daemon) jrpc2.Handler { coreClient := daemon.CoreClient() return handler.New(func(ctx context.Context, request GetVersionInfoRequest) (GetVersionInfoResponse, error) { - info, err := coreClient.Info(ctx) + var captiveCoreVersion string + info, err := coreClient.Info(ctx) if err != nil { logger.WithError(err).WithField("request", request). - Infof("error occurred while calling Info endpoint of core") + Info("error occurred while calling Info endpoint of core") } else { captiveCoreVersion = info.Info.Build } + // Fetch Protocol version + var protocolVersion uint32 + readTx, err := ledgerEntryReader.NewCachedTx(ctx) + if err != nil { + logger.WithError(err).WithField("request", request). + Info("Cannot create read transaction") + } + defer func() { + _ = readTx.Done() + }() + + latestLedger, err := readTx.GetLatestLedgerSequence() + if err != nil { + logger.WithError(err).WithField("request", request). + Info("error occurred while getting latest ledger") + } + + _, protocolVersion, err = getBucketListSizeAndProtocolVersion(ctx, ledgerReader, latestLedger) + if err != nil { + logger.WithError(err).WithField("request", request). + Info("error occurred while fetching protocol version") + } + return GetVersionInfoResponse{ Version: config.Version, CommitHash: config.CommitHash, BuildTimestamp: config.BuildTimestamp, CaptiveCoreVersion: captiveCoreVersion, + ProtocolVersion: protocolVersion, }, nil }) } diff --git a/cmd/soroban-rpc/internal/test/get_version_info_test.go b/cmd/soroban-rpc/internal/test/get_version_info_test.go index 61849b0d..53d6367a 100644 --- a/cmd/soroban-rpc/internal/test/get_version_info_test.go +++ b/cmd/soroban-rpc/internal/test/get_version_info_test.go @@ -26,4 +26,5 @@ func TestGetVersionInfoSucceeds(t *testing.T) { assert.NotEmpty(t, result.BuildTimestamp) assert.NotEmpty(t, result.CommitHash) assert.NotEmpty(t, result.CaptiveCoreVersion) + assert.NotEmpty(t, result.ProtocolVersion) } From a9a869c48de77bdce8e7df7629f92a667f22fc30 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Wed, 17 Apr 2024 20:11:31 +0530 Subject: [PATCH 08/13] Remove captive-core-info from makefile --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 1e102922..1c401fdb 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,6 @@ all: check build test export RUSTFLAGS=-Dwarnings -Dclippy::all -Dclippy::pedantic -CAPTIVE_CORE_VERSION_INFO := $(shell stellar-core version) - REPOSITORY_COMMIT_HASH := "$(shell git rev-parse HEAD)" ifeq (${REPOSITORY_COMMIT_HASH},"") $(error failed to retrieve git head commit hash) @@ -21,7 +19,6 @@ GOLDFLAGS := -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config. -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.CommitHash=${REPOSITORY_COMMIT_HASH}' \ -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.BuildTimestamp=${BUILD_TIMESTAMP}' \ -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.Branch=${REPOSITORY_BRANCH}' \ - -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.CaptiveCoreVersionInfo=${CAPTIVE_CORE_VERSION_INFO}' # The following works around incompatibility between the rust and the go linkers - From 8684abeb3eed84e17c576443d76c491231b1b3e7 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Thu, 18 Apr 2024 17:24:09 +0530 Subject: [PATCH 09/13] Cache captive core version during bootup and add retry logic --- Makefile | 3 +-- cmd/soroban-rpc/internal/config/version.go | 3 +++ cmd/soroban-rpc/internal/daemon/daemon.go | 19 +++++++++++++++++++ .../internal/methods/get_version_info.go | 13 ++----------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 1c401fdb..278f6713 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ all: check build test export RUSTFLAGS=-Dwarnings -Dclippy::all -Dclippy::pedantic - REPOSITORY_COMMIT_HASH := "$(shell git rev-parse HEAD)" ifeq (${REPOSITORY_COMMIT_HASH},"") $(error failed to retrieve git head commit hash) @@ -18,7 +17,7 @@ BUILD_TIMESTAMP ?= $(shell date '+%Y-%m-%dT%H:%M:%S') GOLDFLAGS := -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.Version=${REPOSITORY_VERSION}' \ -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.CommitHash=${REPOSITORY_COMMIT_HASH}' \ -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.BuildTimestamp=${BUILD_TIMESTAMP}' \ - -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.Branch=${REPOSITORY_BRANCH}' \ + -X 'github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config.Branch=${REPOSITORY_BRANCH}' # The following works around incompatibility between the rust and the go linkers - diff --git a/cmd/soroban-rpc/internal/config/version.go b/cmd/soroban-rpc/internal/config/version.go index 909fdaea..5c334b36 100644 --- a/cmd/soroban-rpc/internal/config/version.go +++ b/cmd/soroban-rpc/internal/config/version.go @@ -12,4 +12,7 @@ var ( // Branch is the git branch from which the soroban-rpc was built, injected during build time. Branch = "" + + // CaptiveCoreVersion is the Build value from /Info endpoint of core, injected during daemon.run() + CaptiveCoreVersion = "" ) diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index c2c224de..b3d7eb89 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -3,6 +3,7 @@ package daemon import ( "context" "errors" + "github.com/cenkalti/backoff/v4" "net/http" "net/http/pprof" //nolint:gosec "os" @@ -185,6 +186,24 @@ func MustNew(cfg *config.Config) *Daemon { }, metricsRegistry), } + fetchCaptiveCoreVersion := func() error { + coreClient := daemon.CoreClient() + info, err := coreClient.Info(context.Background()) + if err != nil { + return err + } + config.CaptiveCoreVersion = info.Info.Build + return nil + } + + backoffStrategy := backoff.NewExponentialBackOff() + backoffStrategy.MaxElapsedTime = 4 * time.Second + err = backoff.Retry(fetchCaptiveCoreVersion, backoffStrategy) + if err != nil { + logger.WithError(err). + Info("error occurred while calling Info endpoint of core") + } + eventStore := events.NewMemoryStore( daemon, cfg.NetworkPassphrase, diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index ab2a38a1..0aa42fb4 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -22,18 +22,9 @@ type GetVersionInfoResponse struct { } func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntryReader, ledgerReader db.LedgerReader, daemon interfaces.Daemon) jrpc2.Handler { - coreClient := daemon.CoreClient() + //coreClient := daemon.CoreClient() return handler.New(func(ctx context.Context, request GetVersionInfoRequest) (GetVersionInfoResponse, error) { - var captiveCoreVersion string - info, err := coreClient.Info(ctx) - if err != nil { - logger.WithError(err).WithField("request", request). - Info("error occurred while calling Info endpoint of core") - } else { - captiveCoreVersion = info.Info.Build - } - // Fetch Protocol version var protocolVersion uint32 readTx, err := ledgerEntryReader.NewCachedTx(ctx) @@ -61,7 +52,7 @@ func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntr Version: config.Version, CommitHash: config.CommitHash, BuildTimestamp: config.BuildTimestamp, - CaptiveCoreVersion: captiveCoreVersion, + CaptiveCoreVersion: config.CaptiveCoreVersion, ProtocolVersion: protocolVersion, }, nil }) From ca90d9f214984a86412eb5dae1978fbf76be830d Mon Sep 17 00:00:00 2001 From: pritsheth Date: Mon, 29 Apr 2024 11:08:03 -0700 Subject: [PATCH 10/13] Revert retry logic in daemon and call /info endpoint directly in handler --- cmd/soroban-rpc/internal/config/version.go | 3 --- cmd/soroban-rpc/internal/daemon/daemon.go | 19 ------------------- .../internal/methods/get_version_info.go | 13 +++++++++++-- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/cmd/soroban-rpc/internal/config/version.go b/cmd/soroban-rpc/internal/config/version.go index 5c334b36..909fdaea 100644 --- a/cmd/soroban-rpc/internal/config/version.go +++ b/cmd/soroban-rpc/internal/config/version.go @@ -12,7 +12,4 @@ var ( // Branch is the git branch from which the soroban-rpc was built, injected during build time. Branch = "" - - // CaptiveCoreVersion is the Build value from /Info endpoint of core, injected during daemon.run() - CaptiveCoreVersion = "" ) diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index b3d7eb89..c2c224de 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -3,7 +3,6 @@ package daemon import ( "context" "errors" - "github.com/cenkalti/backoff/v4" "net/http" "net/http/pprof" //nolint:gosec "os" @@ -186,24 +185,6 @@ func MustNew(cfg *config.Config) *Daemon { }, metricsRegistry), } - fetchCaptiveCoreVersion := func() error { - coreClient := daemon.CoreClient() - info, err := coreClient.Info(context.Background()) - if err != nil { - return err - } - config.CaptiveCoreVersion = info.Info.Build - return nil - } - - backoffStrategy := backoff.NewExponentialBackOff() - backoffStrategy.MaxElapsedTime = 4 * time.Second - err = backoff.Retry(fetchCaptiveCoreVersion, backoffStrategy) - if err != nil { - logger.WithError(err). - Info("error occurred while calling Info endpoint of core") - } - eventStore := events.NewMemoryStore( daemon, cfg.NetworkPassphrase, diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index 0aa42fb4..ab2a38a1 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -22,9 +22,18 @@ type GetVersionInfoResponse struct { } func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntryReader, ledgerReader db.LedgerReader, daemon interfaces.Daemon) jrpc2.Handler { - //coreClient := daemon.CoreClient() + coreClient := daemon.CoreClient() return handler.New(func(ctx context.Context, request GetVersionInfoRequest) (GetVersionInfoResponse, error) { + var captiveCoreVersion string + info, err := coreClient.Info(ctx) + if err != nil { + logger.WithError(err).WithField("request", request). + Info("error occurred while calling Info endpoint of core") + } else { + captiveCoreVersion = info.Info.Build + } + // Fetch Protocol version var protocolVersion uint32 readTx, err := ledgerEntryReader.NewCachedTx(ctx) @@ -52,7 +61,7 @@ func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntr Version: config.Version, CommitHash: config.CommitHash, BuildTimestamp: config.BuildTimestamp, - CaptiveCoreVersion: config.CaptiveCoreVersion, + CaptiveCoreVersion: captiveCoreVersion, ProtocolVersion: protocolVersion, }, nil }) From dd12dedc9b38ecb652eacb6450683cad7bb77a72 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Wed, 1 May 2024 05:32:21 -0700 Subject: [PATCH 11/13] Fix integration tests --- cmd/soroban-rpc/internal/test/get_version_info_test.go | 2 +- cmd/soroban-rpc/internal/test/integration.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/soroban-rpc/internal/test/get_version_info_test.go b/cmd/soroban-rpc/internal/test/get_version_info_test.go index 53d6367a..bce5f338 100644 --- a/cmd/soroban-rpc/internal/test/get_version_info_test.go +++ b/cmd/soroban-rpc/internal/test/get_version_info_test.go @@ -13,7 +13,7 @@ import ( func TestGetVersionInfoSucceeds(t *testing.T) { test := NewTest(t, nil) - + test.populateVersionInfo() ch := jhttp.NewChannel(test.sorobanRPCURL(), nil) client := jrpc2.NewClient(ch, nil) request := methods.GetVersionInfoRequest{} diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index 62fb58e2..d9109663 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -108,7 +108,6 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test { })) i.runComposeCommand("up", "--detach", "--quiet-pull", "--no-color") - i.populateVersionInfo() i.prepareShutdownHandlers() i.coreClient = &stellarcore.Client{URL: "http://localhost:" + strconv.Itoa(stellarCorePort)} i.waitForCore() From 80059d03a8019308ae26db8350a9acc6291891ee Mon Sep 17 00:00:00 2001 From: pritsheth Date: Wed, 1 May 2024 06:31:59 -0700 Subject: [PATCH 12/13] Isolate version population in its own test --- .../internal/test/get_version_info_test.go | 40 ++++++++++++++++++- cmd/soroban-rpc/internal/test/integration.go | 23 ----------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/cmd/soroban-rpc/internal/test/get_version_info_test.go b/cmd/soroban-rpc/internal/test/get_version_info_test.go index bce5f338..d8d9097a 100644 --- a/cmd/soroban-rpc/internal/test/get_version_info_test.go +++ b/cmd/soroban-rpc/internal/test/get_version_info_test.go @@ -2,6 +2,9 @@ package test import ( "context" + "fmt" + "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config" + "os/exec" "testing" "github.com/creachadair/jrpc2" @@ -13,7 +16,10 @@ import ( func TestGetVersionInfoSucceeds(t *testing.T) { test := NewTest(t, nil) - test.populateVersionInfo() + + populateVersionInfo(test) + defer resetVersionInfo(test) + ch := jhttp.NewChannel(test.sorobanRPCURL(), nil) client := jrpc2.NewClient(ch, nil) request := methods.GetVersionInfoRequest{} @@ -28,3 +34,35 @@ func TestGetVersionInfoSucceeds(t *testing.T) { assert.NotEmpty(t, result.CaptiveCoreVersion) assert.NotEmpty(t, result.ProtocolVersion) } + +// Runs git commands to fetch version information +func populateVersionInfo(test *Test) { + + execFunction := func(command string, args ...string) string { + cmd := exec.Command(command, args...) + test.t.Log("Running", cmd.Env, cmd.Args) + out, innerErr := cmd.Output() + if exitErr, ok := innerErr.(*exec.ExitError); ok { + fmt.Printf("stdout:\n%s\n", string(out)) + fmt.Printf("stderr:\n%s\n", string(exitErr.Stderr)) + } + + if innerErr != nil { + test.t.Fatalf("Command %s failed: %v", cmd.Env, innerErr) + } + return string(out) + } + + config.Version = execFunction("git", "describe", "--tags", "--always", "--abbrev=0", "--match='v[0-9]*.[0-9]*.[0-9]*'") + config.CommitHash = execFunction("git", "rev-parse", "HEAD") + config.BuildTimestamp = execFunction("date", "+%Y-%m-%dT%H:%M:%S") +} + +func resetVersionInfo(test *Test) { + + test.t.Log("Reset version information to default values") + + config.Version = "0.0.0" + config.CommitHash = "" + config.BuildTimestamp = "" +} diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index d9109663..882e2250 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -241,29 +241,6 @@ func (i *Test) runComposeCommand(args ...string) { } } -// Runs git commands to fetch version information -func (i *Test) populateVersionInfo() { - - execFunction := func(command string, args ...string) string { - cmd := exec.Command(command, args...) - i.t.Log("Running", cmd.Env, cmd.Args) - out, innerErr := cmd.Output() - if exitErr, ok := innerErr.(*exec.ExitError); ok { - fmt.Printf("stdout:\n%s\n", string(out)) - fmt.Printf("stderr:\n%s\n", string(exitErr.Stderr)) - } - - if innerErr != nil { - i.t.Fatalf("Command %s failed: %v", cmd.Env, innerErr) - } - return string(out) - } - - config.Version = execFunction("git", "describe", "--tags", "--always", "--abbrev=0", "--match='v[0-9]*.[0-9]*.[0-9]*'") - config.CommitHash = execFunction("git", "rev-parse", "HEAD") - config.BuildTimestamp = execFunction("date", "+%Y-%m-%dT%H:%M:%S") -} - func (i *Test) prepareShutdownHandlers() { i.shutdownCalls = append(i.shutdownCalls, func() { From 754b77fb12846398fadcb2837e7c0a663d41de30 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Thu, 2 May 2024 03:13:16 -0700 Subject: [PATCH 13/13] Fix review comments --- .../internal/methods/get_version_info.go | 17 +++------- .../internal/test/get_version_info_test.go | 31 +++++++++---------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index ab2a38a1..9aa562a1 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -10,9 +10,6 @@ import ( "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/db" ) -type GetVersionInfoRequest struct { -} - type GetVersionInfoResponse struct { Version string `json:"version"` CommitHash string `json:"commit_hash"` @@ -23,13 +20,12 @@ type GetVersionInfoResponse struct { func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntryReader, ledgerReader db.LedgerReader, daemon interfaces.Daemon) jrpc2.Handler { coreClient := daemon.CoreClient() - return handler.New(func(ctx context.Context, request GetVersionInfoRequest) (GetVersionInfoResponse, error) { + return handler.New(func(ctx context.Context) (GetVersionInfoResponse, error) { var captiveCoreVersion string info, err := coreClient.Info(ctx) if err != nil { - logger.WithError(err).WithField("request", request). - Info("error occurred while calling Info endpoint of core") + logger.WithError(err).Info("error occurred while calling Info endpoint of core") } else { captiveCoreVersion = info.Info.Build } @@ -38,8 +34,7 @@ func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntr var protocolVersion uint32 readTx, err := ledgerEntryReader.NewCachedTx(ctx) if err != nil { - logger.WithError(err).WithField("request", request). - Info("Cannot create read transaction") + logger.WithError(err).Info("Cannot create read transaction") } defer func() { _ = readTx.Done() @@ -47,14 +42,12 @@ func NewGetVersionInfoHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntr latestLedger, err := readTx.GetLatestLedgerSequence() if err != nil { - logger.WithError(err).WithField("request", request). - Info("error occurred while getting latest ledger") + logger.WithError(err).Info("error occurred while getting latest ledger") } _, protocolVersion, err = getBucketListSizeAndProtocolVersion(ctx, ledgerReader, latestLedger) if err != nil { - logger.WithError(err).WithField("request", request). - Info("error occurred while fetching protocol version") + logger.WithError(err).Info("error occurred while fetching protocol version") } return GetVersionInfoResponse{ diff --git a/cmd/soroban-rpc/internal/test/get_version_info_test.go b/cmd/soroban-rpc/internal/test/get_version_info_test.go index d8d9097a..9f406b8d 100644 --- a/cmd/soroban-rpc/internal/test/get_version_info_test.go +++ b/cmd/soroban-rpc/internal/test/get_version_info_test.go @@ -17,22 +17,30 @@ import ( func TestGetVersionInfoSucceeds(t *testing.T) { test := NewTest(t, nil) + version, commitHash, buildTimeStamp := config.Version, config.CommitHash, config.BuildTimestamp + populateVersionInfo(test) - defer resetVersionInfo(test) + + // reset to previous config values + t.Cleanup(func() { + config.Version = version + config.CommitHash = commitHash + config.BuildTimestamp = buildTimeStamp + }) ch := jhttp.NewChannel(test.sorobanRPCURL(), nil) client := jrpc2.NewClient(ch, nil) - request := methods.GetVersionInfoRequest{} var result methods.GetVersionInfoResponse - err := client.CallResult(context.Background(), "getVersionInfo", request, &result) + err := client.CallResult(context.Background(), "getVersionInfo", nil, &result) assert.NoError(t, err) - assert.NotEmpty(t, result.Version) - assert.NotEmpty(t, result.BuildTimestamp) - assert.NotEmpty(t, result.CommitHash) + assert.Equal(t, config.Version, result.Version) + assert.Equal(t, config.BuildTimestamp, result.BuildTimestamp) + assert.Equal(t, config.CommitHash, result.CommitHash) + assert.Equal(t, test.protocolVersion, result.ProtocolVersion) assert.NotEmpty(t, result.CaptiveCoreVersion) - assert.NotEmpty(t, result.ProtocolVersion) + } // Runs git commands to fetch version information @@ -57,12 +65,3 @@ func populateVersionInfo(test *Test) { config.CommitHash = execFunction("git", "rev-parse", "HEAD") config.BuildTimestamp = execFunction("date", "+%Y-%m-%dT%H:%M:%S") } - -func resetVersionInfo(test *Test) { - - test.t.Log("Reset version information to default values") - - config.Version = "0.0.0" - config.CommitHash = "" - config.BuildTimestamp = "" -}