Skip to content
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

feat: add flag to enable price-feeder on node start #157

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 28 additions & 3 deletions cmd/exocored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"fmt"
"io"
"os"
"path"
"path/filepath"
"time"

Expand Down Expand Up @@ -49,11 +50,17 @@
srvflags "github.com/evmos/evmos/v14/server/flags"

cmdcfg "github.com/ExocoreNetwork/exocore/cmd/config"
pricefeeder "github.com/ExocoreNetwork/price-feeder/external"
evmoskr "github.com/evmos/evmos/v14/crypto/keyring"
)

const (
EnvPrefix = "EXOCORE"
EnvPrefix = "EXOCORE"
flagOracle = "oracle"
flagMnemonic = "mnemonic"
confPath = "config"
confOracle = "oracle_feeder.yaml"
cmdStartName = "start"
)

// NewRootCmd creates a new root command for exocored. It is called once in the
Expand Down Expand Up @@ -96,7 +103,6 @@
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}

// override the app and tendermint configuration
customAppTemplate, customAppConfig := initAppConfig()
customTMConfig := initTendermintConfig()
Expand Down Expand Up @@ -132,7 +138,26 @@
a.appExport,
addModuleInitFlags,
)

startCmd, _, _ := rootCmd.Find([]string{cmdStartName})
startCmd.Flags().Bool(flagOracle, false, "enable oracle feeder")
startCmd.Flags().String(flagMnemonic, "", "set validator consensus key's mnemonic")
preRunE := startCmd.PreRunE
// add preRun to run price-feeder first before starting the node
startCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if enableFeeder, _ := cmd.Flags().GetBool(flagOracle); enableFeeder {
clientCtx := cmd.Context().Value(client.ClientContextKey).(*client.Context)
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
Comment on lines +149 to +157

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
}
return preRunE(cmd, args)
}
Comment on lines +144 to +160
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error handling within the goroutine.

Spawning a goroutine can introduce non-determinism. Ensure that any panic is logged appropriately to aid in debugging.

go func() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("price-feeder failed", err)
+			// Log the error with more context
+			log.Printf("price-feeder panic: %v", err)
		}
	}()
	mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
	pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
preRunE := startCmd.PreRunE
// add preRun to run price-feeder first before starting the node
startCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if enableFeeder, _ := cmd.Flags().GetBool(flagOracle); enableFeeder {
clientCtx := cmd.Context().Value(client.ClientContextKey).(*client.Context)
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
}
return preRunE(cmd, args)
}
preRunE := startCmd.PreRunE
// add preRun to run price-feeder first before starting the node
startCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if enableFeeder, _ := cmd.Flags().GetBool(flagOracle); enableFeeder {
clientCtx := cmd.Context().Value(client.ClientContextKey).(*client.Context)
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
// Log the error with more context
log.Printf("price-feeder panic: %v", err)
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
}
return preRunE(cmd, args)
}
Tools
GitHub Check: CodeQL

[notice] 149-157: Spawning a Go routine
Spawning a Go routine may be a possible source of non-determinism

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
rpc.StatusCommand(),
Expand Down
38 changes: 22 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
cosmossdk.io/math v1.2.0
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d
cosmossdk.io/tools/rosetta v0.2.1
github.com/ExocoreNetwork/price-feeder v0.0.0-20240804171932-9ca244b6618d
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/armon/go-metrics v0.4.1
github.com/cometbft/cometbft v0.37.4
Expand All @@ -17,7 +18,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/v7 v7.4.0
github.com/ethereum/go-ethereum v1.13.5-0.20231027145059-2d7dba024d76
github.com/ethereum/go-ethereum v1.13.15
github.com/evmos/evmos/v14 v14.0.0-rc4
github.com/golang/protobuf v1.5.4
github.com/gorilla/mux v1.8.0
Expand All @@ -29,10 +30,10 @@ require (
github.com/prysmaticlabs/prysm/v4 v4.2.1
github.com/rakyll/statik v0.1.7
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
go.opencensus.io v0.24.0
go.uber.org/mock v0.4.0
Expand All @@ -50,7 +51,7 @@ require (
cosmossdk.io/api v0.3.1
github.com/btcsuite/btcd v0.23.3 // indirect
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand All @@ -67,7 +68,7 @@ require (
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cloud.google.com/go/storage v1.35.1 // indirect
cosmossdk.io/core v0.6.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.0 // indirect
Expand Down Expand Up @@ -111,7 +112,7 @@ require (
github.com/dvsekhvalnov/jose2go v1.5.1-0.20231206184617-48ba0b76bc88 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
Expand All @@ -120,7 +121,7 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
Expand Down Expand Up @@ -152,7 +153,7 @@ require (
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down Expand Up @@ -182,9 +183,9 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20230518223814-80aa455d8761 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
Expand All @@ -197,14 +198,16 @@ require (
github.com/rjeczalik/notify v0.9.3 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand All @@ -223,13 +226,16 @@ require (
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/api v0.149.0 // indirect
google.golang.org/api v0.153.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
Expand Down
Loading
Loading