Skip to content

Commit

Permalink
make oracle tick time env var
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Mar 1, 2024
1 parent a3cedae commit adf259c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 1 addition & 2 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 @@ -209,7 +208,7 @@ func newApp(
var oracleGenState oracletypes.GenesisState
app.AppCodec().MustUnmarshalJSON(app.DefaultGenesis()[oracletypes.ModuleName], &oracleGenState)
go func() {
err := pricefeeder.Start(oracleGenState.Params, time.Second * 5)
err := pricefeeder.Start(oracleGenState.Params)
if err != nil {
panic(err)
}
Expand Down
18 changes: 12 additions & 6 deletions pricefeeder/pricefeeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import (
)

const (
envConfig = "PRICE_FEEDER_CONFIG"
envChainConfig = "PRICE_FEEDER_CHAIN_CONFIG"
envDebugLevel = "PRICE_FEEDER_LOG_LEVEL"
envVariablePass = "PRICE_FEEDER_PASS"
envConfig = "PRICE_FEEDER_CONFIG"
envChainConfig = "PRICE_FEEDER_CHAIN_CONFIG"
envDebugLevel = "PRICE_FEEDER_LOG_LEVEL"
envVariablePass = "PRICE_FEEDER_PASS"
envOracleTickTime = "PRICE_FEEDER_ORACLE_TICK_TIME"
)

func Start(oracleParams types.Params, blockTime time.Duration) error {
func Start(oracleParams types.Params) error {
logWriter := zerolog.ConsoleWriter{Out: os.Stderr}
logLevel, err := zerolog.ParseLevel(os.Getenv(envDebugLevel))
if err != nil {
Expand Down Expand Up @@ -97,13 +98,18 @@ func Start(oracleParams types.Params, blockTime time.Duration) error {
return err
}

oracleTickTime, err := time.ParseDuration(os.Getenv(envOracleTickTime))
if err != nil {
return err
}

g.Go(func() error {
// start the process that observes and publishes exchange prices
return startPriceFeeder(ctx, logger, cfg, oracle, metrics)
})
g.Go(func() error {
// start the process that calculates oracle prices
return startPriceOracle(ctx, logger, oracle, oracleParams, blockTime)
return startPriceOracle(ctx, logger, oracle, oracleParams, oracleTickTime)
})

// Block main process until all spawned goroutines have gracefully exited and
Expand Down
1 change: 1 addition & 0 deletions scripts/single-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PRICE_FEEDER_CONFIG_PATH="${CWD}/../pricefeeder/price-feeder.example.toml"
export PRICE_FEEDER_CONFIG=$(realpath "$PRICE_FEEDER_CONFIG_PATH")
export PRICE_FEEDER_CHAIN_CONFIG="TRUE"
export PRICE_FEEDER_LOG_LEVEL="DEBUG"
export PRICE_FEEDER_ORACLE_TICK_TIME="5s"

NODE_BIN="${1:-$CWD/../build/ojod}"

Expand Down

0 comments on commit adf259c

Please sign in to comment.