Skip to content

Commit

Permalink
update: enable to overwrite KYVE pool endpoints.
Browse files Browse the repository at this point in the history
* update: opt-out state-pruning.

* update: enable to overwrite KYVE pool endpoints.

* chore: GetPoolSettings error & endpoint handling.
  • Loading branch information
christopherbrumm authored Jan 25, 2024
1 parent c37a488 commit dfa0960
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 57 deletions.
8 changes: 4 additions & 4 deletions cmd/supervysor/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {

initCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")

initCmd.Flags().StringVar(&fallbackEndpoints, "fallback-endpoints", "", "additional endpoints to query KYVE pool height")
initCmd.Flags().StringVar(&poolEndpoints, "endpoints", "", "overwrite endpoints to query KYVE pool height")

initCmd.Flags().IntVar(&pruningInterval, "pruning-interval", 24, "block-pruning interval (hours)")

Expand All @@ -61,7 +61,7 @@ var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize supervysor",
RunE: func(cmd *cobra.Command, args []string) error {
supportedChains := []string{"kyve-1", "kaon-1", "korellia", "korellia-2"}
supportedChains := []string{"kyve-1", "kaon-1", "korellia-2"}
if !slices.Contains(supportedChains, chainId) {
logger.Error("specified chain-id is not supported", "chain-id", chainId)
return fmt.Errorf("not supported chain-id")
Expand All @@ -78,7 +78,7 @@ var initCmd = &cobra.Command{

utils.TrackInitEvent(chainId, optOut)

if err := settings.InitializeSettings(binary, home, poolId, false, seeds, chainId, fallbackEndpoints); err != nil {
if err := settings.InitializeSettings(binary, home, poolId, false, seeds, chainId, poolEndpoints); err != nil {
logger.Error("could not initialize settings", "err", err)
return err
}
Expand Down Expand Up @@ -110,13 +110,13 @@ var initCmd = &cobra.Command{
ABCIEndpoint: abciEndpoint,
BinaryPath: binary,
ChainId: chainId,
FallbackEndpoints: fallbackEndpoints,
HeightDifferenceMax: settings.Settings.MaxDifference,
HeightDifferenceMin: settings.Settings.MaxDifference / 2,
HomePath: home,
Interval: 10,
Metrics: metrics,
MetricsPort: metricsPort,
PoolEndpoints: poolEndpoints,
PoolId: poolId,
PruningInterval: pruningInterval,
Seeds: seeds,
Expand Down
32 changes: 16 additions & 16 deletions cmd/supervysor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ import (
)

var (
abciEndpoint string
binary string
binaryFlags string
cfgFlag string
chainId string
config string
fallbackEndpoints string
home string
metrics bool
metricsPort int
optOut bool
poolId int
pruningInterval int
seeds string
statePruning bool
untilHeight int64
abciEndpoint string
binary string
binaryFlags string
cfgFlag string
chainId string
config string
home string
metrics bool
metricsPort int
optOut bool
poolEndpoints string
poolId int
pruningInterval int
seeds string
statePruning bool
untilHeight int64

cfg types.SupervysorConfig

Expand Down
2 changes: 1 addition & 1 deletion cmd/supervysor/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var startCmd = &cobra.Command{
m.NodeHeight.Set(float64(nodeHeight))
}

poolHeight, err := pool.GetPoolHeight(supervysorConfig.ChainId, supervysorConfig.PoolId, supervysorConfig.FallbackEndpoints)
poolHeight, err := pool.GetPoolHeight(supervysorConfig.ChainId, supervysorConfig.PoolId, supervysorConfig.PoolEndpoints)
if err != nil {
logger.Error("could not get pool height", "err", err)
if shutdownErr := e.Shutdown(); shutdownErr != nil {
Expand Down
35 changes: 20 additions & 15 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,33 @@ import (

// GetPoolHeight retrieves the KYVE pool height by using a list of endpoints (& optionally fallback endpoints)
// based on the provided chain and pool ID.
func GetPoolHeight(chainId string, poolId int, fallbackEndpoints string) (int, error) {
func GetPoolHeight(chainId string, poolId int, poolEndpoints string) (int, error) {
var endpoints []string
var err error

if chainId == "korellia" {
endpoints = types.KorelliaEndpoints
} else if chainId == "kaon-1" {
endpoints = types.KaonEndpoints
} else if chainId == "kyve-1" {
endpoints = types.MainnetEndpoints
if poolEndpoints != "" {
endpoints = strings.Split(poolEndpoints, ",")
} else {
return 0, fmt.Errorf("unknown chainId")
if chainId == "korellia-2" {
endpoints = types.KorelliaEndpoints
} else if chainId == "kaon-1" {
endpoints = types.KaonEndpoints
} else if chainId == "kyve-1" {
endpoints = types.MainnetEndpoints
} else {
return 0, fmt.Errorf("unknown chainId")
}
}

for _, endpoint := range append(endpoints, strings.Split(fallbackEndpoints, ",")...) {
if endpoint != "" {
if height, err := requestPoolHeight(poolId, endpoint); err == nil {
return height, err
}
for _, endpoint := range endpoints {
height, err := requestPoolHeight(poolId, endpoint)
if err == nil {
return height, nil
} else {
fmt.Printf("failed to request pool height from %v: %v", endpoint, err)
}
}
return 0, err

return 0, fmt.Errorf("failed to get pool height from all endpoints")
}

// requestPoolHeight retrieves KYVE pool height by making an GET request to the given endpoint.
Expand Down
38 changes: 20 additions & 18 deletions settings/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,33 @@ func CalculateMaxDifference(maxBundleSize int, uploadInterval int) int {

// GetPoolSettings retrieves KYVE pool settings by using a list of endpoints (& optionally fallback endpoints)
// based on the provided chain and pool ID.
func GetPoolSettings(poolId int, chainId string, fallbackEndpoints string) ([2]int, error) {
func GetPoolSettings(poolId int, chainId string, poolEndpoints string) ([2]int, error) {
var endpoints []string
var err error

if chainId == "korellia" {
endpoints = types.KorelliaEndpoints
} else if chainId == "kaon-1" {
endpoints = types.KaonEndpoints
} else if chainId == "kyve-1" {
endpoints = types.MainnetEndpoints

if poolEndpoints != "" {
endpoints = strings.Split(poolEndpoints, ",")
} else {
return [2]int{}, fmt.Errorf("unknown chainId")
if chainId == "korellia-2" {
endpoints = types.KorelliaEndpoints
} else if chainId == "kaon-1" {
endpoints = types.KaonEndpoints
} else if chainId == "kyve-1" {
endpoints = types.MainnetEndpoints
} else {
return [2]int{}, fmt.Errorf("unknown chainId")
}
}

for _, endpoint := range append(endpoints, strings.Split(fallbackEndpoints, ",")...) {
if endpoint != "" {
if height, err := requestPoolSettings(poolId, endpoint); err == nil {
return height, err
}
for _, endpoint := range endpoints {
height, err := requestPoolSettings(poolId, endpoint)
if err == nil {
return height, err
} else {
fmt.Printf("failed to request pool settings from %v: %v", endpoint, err)
}
}

return [2]int{}, err
return [2]int{}, fmt.Errorf("failed to get pool settings from all endpoints")
}

// SetPruningSettings updates the pruning settings in the app.toml file of the given home directory.
Expand Down Expand Up @@ -143,8 +147,6 @@ func SetPruningSettings(homePath string, stateRequests bool, keepRecent int, int
func requestPoolSettings(poolId int, endpoint string) ([2]int, error) {
poolEndpoint := endpoint + "/kyve/query/v1beta1/pool/" + strconv.FormatInt(int64(poolId), 10)

fmt.Println(poolEndpoint)

response, err := http.Get(poolEndpoint)
if err != nil {
logger.Error("API is not available", err.Error())
Expand Down
4 changes: 2 additions & 2 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var Settings = types.SettingsType{
// and homePath and sets the seeds value required for the node. It retrieves the pool settings, calculates the
// keepRecent and maxDifference values, and sets the pruning settings based on these calculated values.
// If any step encounters an error, it returns the corresponding error message.
func InitializeSettings(binaryPath string, homePath string, poolId int, stateRequests bool, seeds string, chainId string, fallbackEndpoints string) error {
func InitializeSettings(binaryPath string, homePath string, poolId int, stateRequests bool, seeds string, chainId string, poolEndpoints string) error {
if err := helpers.CheckBinaryPath(binaryPath); err != nil {
return fmt.Errorf("could not resolve binary path: %s", err)
}
Expand All @@ -38,7 +38,7 @@ func InitializeSettings(binaryPath string, homePath string, poolId int, stateReq
return fmt.Errorf("seeds are not defined")
}

settings, err := helpers.GetPoolSettings(poolId, chainId, fallbackEndpoints)
settings, err := helpers.GetPoolSettings(poolId, chainId, poolEndpoints)
if err != nil {
return fmt.Errorf("could not get pool settings: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ type SupervysorConfig struct {
ABCIEndpoint string
BinaryPath string
ChainId string
FallbackEndpoints string
HeightDifferenceMax int
HeightDifferenceMin int
HomePath string
Interval int
Metrics bool
MetricsPort int
PoolEndpoints string
PoolId int
PruningInterval int
Seeds string
Expand Down

0 comments on commit dfa0960

Please sign in to comment.