Skip to content

Commit

Permalink
feat: option to disable price feeder ticks for full nodes (#522)
Browse files Browse the repository at this point in the history
* feat: option to disable price feeder ticks for full nodes

* enable price feeder appconfig setting in e2e tests

* e2e typo

* price feeder cmd fix
  • Loading branch information
adamewozniak authored Sep 27, 2024
1 parent aa3f85a commit 1dc2b32
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/ojod/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func initRootCmd(
// add price feeder flags
rootCmd.PersistentFlags().String(pricefeeder.FlagConfigPath, "", "Path to price feeder config file")
rootCmd.PersistentFlags().String(pricefeeder.FlagLogLevel, "", "Log level of price feeder process")
rootCmd.PersistentFlags().Bool(pricefeeder.FlagEnablePriceFeeder, false, "Enable the price feeder")
}

// genesisCommand builds genesis-related `simd genesis` command. Users may
Expand Down
15 changes: 13 additions & 2 deletions pricefeeder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ config_path = ""
# Log level of price feeder process.
log_level = "info"
# Enable the price feeder.
enable = false
`
)

const (
FlagConfigPath = "pricefeeder.config_path"
FlagLogLevel = "pricefeeder.log_level"
FlagConfigPath = "pricefeeder.config_path"
FlagLogLevel = "pricefeeder.log_level"
FlagEnablePriceFeeder = "pricefeeder.enable"
)

// AppConfig defines the app configuration for the price feeder that must be set in the app.toml file.
type AppConfig struct {
ConfigPath string `mapstructure:"config_path"`
LogLevel string `mapstructure:"log_level"`
Enable bool `mapstructure:"enable"`
}

// ValidateBasic performs basic validation of the price feeder app config.
Expand Down Expand Up @@ -57,6 +62,12 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (AppConfig, error) {
}
}

if v := opts.Get(FlagEnablePriceFeeder); v != nil {
if cfg.Enable, err = cast.ToBoolE(v); err != nil {
return cfg, err
}
}

if err := cfg.ValidateBasic(); err != nil {
return cfg, err
}
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ func (o *Orchestrator) runValidators(t *testing.T) {
"start",
"--pricefeeder.config_path=/root/pricefeeder/price-feeder.example.toml",
"--pricefeeder.log_level=info",
"--pricefeeder.enable=true",
}

runOpts := &dockertest.RunOptions{
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/abci/endblocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func EndBlocker(ctx context.Context, k keeper.Keeper) error {

params := k.GetParams(sdkCtx)

// Start price feeder if it hasn't been started.
if k.PriceFeeder.Oracle == nil {
// Start price feeder if it hasn't been started, and it is enabled.
if k.PriceFeeder.Oracle == nil && k.PriceFeeder.AppConfig.Enable {
go func() {
err := k.PriceFeeder.Start(sdkCtx.BlockHeight(), params)
if err != nil {
Expand All @@ -51,7 +51,7 @@ func EndBlocker(ctx context.Context, k keeper.Keeper) error {
}

if k.IsPeriodLastBlock(sdkCtx, params.VotePeriod) {
if k.PriceFeeder.Oracle != nil {
if k.PriceFeeder.Oracle != nil && k.PriceFeeder.AppConfig.Enable {
// Update price feeder oracle with latest params.
k.PriceFeeder.Oracle.ParamCache.UpdateParamCache(sdkCtx.BlockHeight(), k.GetParams(sdkCtx), nil)

Expand Down

0 comments on commit 1dc2b32

Please sign in to comment.