Skip to content

Commit

Permalink
feat: validation service (#724)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler <[email protected]>
  • Loading branch information
aljo242 and technicallyty committed Sep 10, 2024
1 parent fc4879a commit 2c68728
Show file tree
Hide file tree
Showing 15 changed files with 510 additions and 243 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ Lcng
ldflags
Lenmapkey
Lenmapvalue
libhttp
Linting
llc
logtostderr
Expand Down
54 changes: 52 additions & 2 deletions cmd/connect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"errors"
"fmt"
"net/http"

//nolint: gosec
_ "net/http/pprof"
"os"
"os/signal"
"path/filepath"
"syscall"

_ "net/http/pprof" //nolint: gosec
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -28,6 +30,7 @@ import (
mmservicetypes "github.com/skip-mev/connect/v2/service/clients/marketmap/types"
oracleserver "github.com/skip-mev/connect/v2/service/servers/oracle"
promserver "github.com/skip-mev/connect/v2/service/servers/prometheus"
"github.com/skip-mev/connect/v2/service/validation"
mmtypes "github.com/skip-mev/connect/v2/x/marketmap/types"
)

Expand Down Expand Up @@ -58,6 +61,8 @@ var (
flagPort = "port"
flagUpdateInterval = "update-interval"
flagMaxPriceAge = "max-price-age"
flagMode = "mode"
flagValidationPeriod = "validation-period"

// flag-bound values.
oracleCfgPath string
Expand All @@ -75,12 +80,21 @@ var (
maxAge int
disableCompressLogs bool
disableRotatingLogs bool
mode string
validationPeriod time.Duration
)

const (
DefaultLegacyConfigPath = "./oracle.json"
)

type runMode string

const (
modeExec runMode = "exec"
modeValidate runMode = "validate"
)

func init() {
rootCmd.Flags().StringVarP(
&marketMapProvider,
Expand Down Expand Up @@ -187,6 +201,19 @@ func init() {
"",
"Use a custom listen-to endpoint for market-map (overwrites what is provided in oracle-config).",
)
rootCmd.Flags().StringVarP(
&mode,
flagMode,
"m",
string(modeExec),
"Select the mode to run the oracle in. Default is \"exec\" which will fetch prices as configured. \"validate\" mode will run the oracle for a set period of time to validate the configuration.",
)
rootCmd.Flags().DurationVar(
&validationPeriod,
flagValidationPeriod,
validation.DefaultValidationPeriod,
"Duration to run in validation mode. Note: this flag is only used if mode == \"validate\"",
)

// these flags are connected to the OracleConfig.
rootCmd.Flags().Bool(
Expand Down Expand Up @@ -316,6 +343,8 @@ func runOracle() error {
nodeClient, _ = oraclemetrics.NewNodeClient(nodeEndpoint)
}

isValidateMode := runMode(mode) == modeValidate

metrics := oraclemetrics.NewMetricsFromConfig(cfg.Metrics, nodeClient)

aggregator, err := oraclemath.NewIndexPriceAggregator(
Expand Down Expand Up @@ -395,6 +424,27 @@ func runOracle() error {
}()
}

// run validation service if enabled and tear down if completed successfully
if isValidateMode {
valCfg := validation.DefaultConfig()
valCfg.ValidationPeriod = validationPeriod
validatorService := validation.NewValidator(logger, metrics, valCfg)

go func(c context.CancelFunc) {
defer c()

_, err := validatorService.Run(ctx)
if err != nil {
logger.Error("failed to validate metrics", zap.Error(err))

// kill the process
os.Exit(1)
}

logger.Info("shutting down gracefully after validation")
}(cancel)
}

// start server (blocks).
if err := srv.StartServer(ctx, cfg.Host, cfg.Port); err != nil {
logger.Error("stopping server", zap.Error(err))
Expand Down
190 changes: 0 additions & 190 deletions cmd/constants/marketmaps/markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,6 @@ var (
}
]
},
"AGIX/USD": {
"ticker": {
"currency_pair": {
"Base": "AGIX",
"Quote": "USD"
},
"decimals": 10,
"min_provider_count": 1,
"enabled": true
},
"provider_configs": [
{
"name": "coinmarketcap_api",
"off_chain_ticker": "2424"
}
]
},
"ALGO/USD": {
"ticker": {
"currency_pair": {
Expand Down Expand Up @@ -1309,23 +1292,6 @@ var (
}
]
},
"RNDR/USD": {
"ticker": {
"currency_pair": {
"Base": "RNDR",
"Quote": "USD"
},
"decimals": 9,
"min_provider_count": 1,
"enabled": true
},
"provider_configs": [
{
"name": "coinmarketcap_api",
"off_chain_ticker": "5690"
}
]
},
"RUNE/USD": {
"ticker": {
"currency_pair": {
Expand Down Expand Up @@ -3437,67 +3403,6 @@ var (
}
]
},
"AGIX/USD": {
"ticker": {
"currency_pair": {
"Base": "AGIX",
"Quote": "USD"
},
"decimals": 10,
"min_provider_count": 3,
"enabled": true
},
"provider_configs": [
{
"name": "binance_ws",
"off_chain_ticker": "AGIXUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "bybit_ws",
"off_chain_ticker": "AGIXUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "gate_ws",
"off_chain_ticker": "AGIX_USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "kucoin_ws",
"off_chain_ticker": "AGIX-USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "okx_ws",
"off_chain_ticker": "AGIX-USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "mexc_ws",
"off_chain_ticker": "AGIXUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
}
]
},
"ALGO/USD": {
"ticker": {
"currency_pair": {
Expand Down Expand Up @@ -6354,67 +6259,6 @@ var (
}
]
},
"RNDR/USD": {
"ticker": {
"currency_pair": {
"Base": "RNDR",
"Quote": "USD"
},
"decimals": 9,
"min_provider_count": 3,
"enabled": true
},
"provider_configs": [
{
"name": "binance_ws",
"off_chain_ticker": "RNDRUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "coinbase_ws",
"off_chain_ticker": "RNDR-USD"
},
{
"name": "kraken_api",
"off_chain_ticker": "RNDRUSD"
},
{
"name": "kucoin_ws",
"off_chain_ticker": "RNDR-USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "okx_ws",
"off_chain_ticker": "RNDR-USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "mexc_ws",
"off_chain_ticker": "RNDRUSDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
},
{
"name": "crypto_dot_com_ws",
"off_chain_ticker": "RNDR_USDT",
"normalize_by_pair": {
"Base": "USDT",
"Quote": "USD"
}
}
]
},
"RUNE/USD": {
"ticker": {
"currency_pair": {
Expand Down Expand Up @@ -7982,23 +7826,6 @@ var (
}
]
},
"AGIX/USD": {
"ticker": {
"currency_pair": {
"Base": "AGIX",
"Quote": "USD"
},
"decimals": 10,
"min_provider_count": 1,
"enabled": true
},
"provider_configs": [
{
"name": "coingecko_api",
"off_chain_ticker": "singularitynet/usd"
}
]
},
"ALGO/USD": {
"ticker": {
"currency_pair": {
Expand Down Expand Up @@ -9308,23 +9135,6 @@ var (
}
]
},
"RNDR/USD": {
"ticker": {
"currency_pair": {
"Base": "RNDR",
"Quote": "USD"
},
"decimals": 9,
"min_provider_count": 1,
"enabled": true
},
"provider_configs": [
{
"name": "coingecko_api",
"off_chain_ticker": "render-token/usd"
}
]
},
"RUNE/USD": {
"ticker": {
"currency_pair": {
Expand Down
1 change: 1 addition & 0 deletions contrib/compose/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ services:
"--market-config-path", "/data/markets.json",
"--pprof-port", "6060",
"--run-pprof",
# "-m", "validate" # uncomment to run in validation mode with default config
]
ports:
- "8080:8080" # main oracle port
Expand Down
Loading

0 comments on commit 2c68728

Please sign in to comment.