Skip to content

Commit

Permalink
fix: Call price feeder tick inside of oracle endblocker (#501)
Browse files Browse the repository at this point in the history
* fix: Call price feeder tick inside of oracle endblocker

* .golangci.yml depecrated updates

* revert .golangci.yml

* e2e fix

* pf import

* upgrade handler
  • Loading branch information
rbajollari authored Sep 13, 2024
1 parent f5192a3 commit 7b7daca
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 439 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ make install
Example command structure for running a node with a price feeder config file located at `./price-feeder.example.config` (See [price-feeder](https://github.com/ojo-network/price-feeder) repo for more information on configuring an Ojo price feeder)

```shell
$ ojod start --pricefeeder.config_path=./price-feeder.example.config --pricefeeder.log_level="INFO" --pricefeeder.chain_config=TRUE --pricefeeder.oracle_tick_time=5s
$ ojod start --pricefeeder.config_path=./price-feeder.example.config --pricefeeder.log_level="INFO"
```

## Networks
Expand Down
6 changes: 0 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ import (
airdropkeeper "github.com/ojo-network/ojo/x/airdrop/keeper"
airdroptypes "github.com/ojo-network/ojo/x/airdrop/types"

"github.com/ojo-network/ojo/pricefeeder"
oracleabci "github.com/ojo-network/ojo/x/oracle/abci"

customante "github.com/ojo-network/ojo/ante"
Expand Down Expand Up @@ -221,8 +220,6 @@ type App struct {

// module configurator
configurator module.Configurator

PriceFeeder *pricefeeder.PriceFeeder
}

// New returns a reference to an initialized blockchain app
Expand Down Expand Up @@ -738,12 +735,9 @@ func New(
app.SetPrepareProposal(proposalHandler.PrepareProposalHandler())
app.SetProcessProposal(proposalHandler.ProcessProposalHandler())

// initialize empty price feeder object to pass reference into vote extension handler
app.PriceFeeder = &pricefeeder.PriceFeeder{}
voteExtensionsHandler := oracleabci.NewVoteExtensionHandler(
app.Logger(),
app.OracleKeeper,
app.PriceFeeder,
)
app.SetExtendVoteHandler(voteExtensionsHandler.ExtendVoteHandler())
app.SetVerifyVoteExtensionHandler(voteExtensionsHandler.VerifyVoteExtensionHandler())
Expand Down
13 changes: 13 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (app App) RegisterUpgradeHandlers() {
app.registerUpgrade0_3_1(upgradeInfo)
app.registerUpgrade0_3_2(upgradeInfo)
app.registerUpgrade0_4_0(upgradeInfo)
app.registerUpgrade0_4_1(upgradeInfo)
}

// performs upgrade from v0.1.3 to v0.1.4
Expand Down Expand Up @@ -284,6 +285,18 @@ func (app *App) registerUpgrade0_4_0(upgradeInfo upgradetypes.Plan) {
})
}

func (app *App) registerUpgrade0_4_1(_ upgradetypes.Plan) {
const planName = "v0.4.1"

app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.Logger().Info("Upgrade handler execution", "name", planName)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
}

// helper function to check if the store loader should be upgraded
func (app *App) storeUpgrade(planName string, ui upgradetypes.Plan, stores storetypes.StoreUpgrades) {
if ui.Name == planName && !app.UpgradeKeeper.IsSkipHeight(ui.Height) {
Expand Down
30 changes: 4 additions & 26 deletions cmd/ojod/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"io"
"os"
"time"

"cosmossdk.io/log"
"cosmossdk.io/tools/confix/cmd"
Expand Down Expand Up @@ -32,7 +31,6 @@ import (

app "github.com/ojo-network/ojo/app"
"github.com/ojo-network/ojo/pricefeeder"
oracletypes "github.com/ojo-network/ojo/x/oracle/types"
)

// initCometBFTConfig helps to override default CometBFT Config values.
Expand Down Expand Up @@ -71,10 +69,8 @@ func initAppConfig() (string, interface{}) {
QueryGasLimit: 300000,
},
PriceFeeder: pricefeeder.AppConfig{
ConfigPath: "",
ChainConfig: true,
LogLevel: "info",
OracleTickTime: time.Second * 5,
ConfigPath: "",
LogLevel: "info",
},
}

Expand Down Expand Up @@ -131,17 +127,7 @@ func initRootCmd(

// add price feeder flags
rootCmd.PersistentFlags().String(pricefeeder.FlagConfigPath, "", "Path to price feeder config file")
rootCmd.PersistentFlags().Bool(
pricefeeder.FlagChainConfig,
true,
"Specifies whether the currency pair providers and currency deviation threshold values should",
)
rootCmd.PersistentFlags().String(pricefeeder.FlagLogLevel, "", "Log level of price feeder process")
rootCmd.PersistentFlags().Duration(
pricefeeder.FlagOracleTickTime,
time.Second*5,
"Time interval that the price feeder's oracle process waits before fetching for new prices",
)
}

// genesisCommand builds genesis-related `simd genesis` command. Users may
Expand Down Expand Up @@ -226,20 +212,12 @@ func newApp(
baseappOptions...,
)

// start price feeder
// load app config into oracle keeper price feeder
appConfig, err := pricefeeder.ReadConfigFromAppOpts(appOpts)
if err != nil {
panic(err)
}

var oracleGenState oracletypes.GenesisState
app.AppCodec().MustUnmarshalJSON(app.DefaultGenesis()[oracletypes.ModuleName], &oracleGenState)
go func() {
err := app.PriceFeeder.Start(oracleGenState.Params, appConfig)
if err != nil {
panic(err)
}
}()
app.OracleKeeper.PriceFeeder.AppConfig = appConfig

return app
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/mgechev/revive v1.3.9
github.com/mitchellh/mapstructure v1.5.0
github.com/ojo-network/price-feeder v0.2.0
github.com/ojo-network/price-feeder v0.2.1-rc1
github.com/ory/dockertest/v3 v3.10.0
github.com/rs/zerolog v1.32.0
github.com/spf13/cast v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
github.com/ojo-network/price-feeder v0.2.0 h1:1D+0K19xUlmEPUxAeyG0W+CWjBvSOSdwoMYcQ2+u9dM=
github.com/ojo-network/price-feeder v0.2.0/go.mod h1:2xHrCcUMPoozsvst9785vToD7/U05OOAAl0NvnMYaTg=
github.com/ojo-network/price-feeder v0.2.1-rc1 h1:m9vgR9DYuXhM5f2DQX/wewihzkPVAVdVjZgtr/gB6bs=
github.com/ojo-network/price-feeder v0.2.1-rc1/go.mod h1:CSdgh7XiOMLGQwRW8OqbL5FlkE5Mc3+fDZEMRN8JkYY=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
Expand Down
35 changes: 4 additions & 31 deletions pricefeeder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pricefeeder

import (
"fmt"
"time"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/spf13/cast"
Expand All @@ -14,30 +13,20 @@ const (
# Path to price feeder config file.
config_path = ""
# Specifies whether to use the on chain price feeder provider pair and deviation threshold values or the config file.
chain_config = true
# Log level of price feeder process.
log_level = "info"
# Time interval that the price feeder's oracle process waits before fetching for new prices.
oracle_tick_time = "5s"
`
)

const (
FlagConfigPath = "pricefeeder.config_path"
FlagChainConfig = "pricefeeder.chain_config"
FlagLogLevel = "pricefeeder.log_level"
FlagOracleTickTime = "pricefeeder.oracle_tick_time"
FlagConfigPath = "pricefeeder.config_path"
FlagLogLevel = "pricefeeder.log_level"
)

// 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"`
ChainConfig bool `mapstructure:"chain_config"`
LogLevel string `mapstructure:"log_level"`
OracleTickTime time.Duration `mapstructure:"oracle_tick_time"`
ConfigPath string `mapstructure:"config_path"`
LogLevel string `mapstructure:"log_level"`
}

// ValidateBasic performs basic validation of the price feeder app config.
Expand All @@ -46,10 +35,6 @@ func (c *AppConfig) ValidateBasic() error {
return fmt.Errorf("path to price feeder config must be set")
}

if c.OracleTickTime <= 0 {
return fmt.Errorf("oracle tick time must be greater than 0")
}

return nil
}

Expand All @@ -66,24 +51,12 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (AppConfig, error) {
}
}

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

if v := opts.Get(FlagLogLevel); v != nil {
if cfg.LogLevel, err = cast.ToStringE(v); err != nil {
return cfg, err
}
}

if v := opts.Get(FlagOracleTickTime); v != nil {
if cfg.OracleTickTime, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}

if err := cfg.ValidateBasic(); err != nil {
return cfg, err
}
Expand Down
Loading

0 comments on commit 7b7daca

Please sign in to comment.