Skip to content

Commit

Permalink
Cache captive core version during bootup and add retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed Apr 18, 2024
1 parent a9a869c commit 8684abe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 -
Expand Down
3 changes: 3 additions & 0 deletions cmd/soroban-rpc/internal/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
)
19 changes: 19 additions & 0 deletions cmd/soroban-rpc/internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package daemon
import (
"context"
"errors"
"github.com/cenkalti/backoff/v4"
"net/http"
"net/http/pprof" //nolint:gosec
"os"
Expand Down Expand Up @@ -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()

Check failure on line 199 in cmd/soroban-rpc/internal/daemon/daemon.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: backoff (typecheck)
backoffStrategy.MaxElapsedTime = 4 * time.Second
err = backoff.Retry(fetchCaptiveCoreVersion, backoffStrategy)

Check failure on line 201 in cmd/soroban-rpc/internal/daemon/daemon.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: backoff (typecheck)
if err != nil {
logger.WithError(err).
Info("error occurred while calling Info endpoint of core")
}

eventStore := events.NewMemoryStore(
daemon,
cfg.NetworkPassphrase,
Expand Down
13 changes: 2 additions & 11 deletions cmd/soroban-rpc/internal/methods/get_version_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
Expand Down

0 comments on commit 8684abe

Please sign in to comment.