Skip to content

Commit

Permalink
Add protocol version in response
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed Apr 17, 2024
1 parent 2a5158f commit bb10b8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 30 additions & 3 deletions cmd/soroban-rpc/internal/methods/get_version_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
})
}
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/test/get_version_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit bb10b8f

Please sign in to comment.