From 2cec613ae2040bdb9b280e6f3fb7737eaa2e9222 Mon Sep 17 00:00:00 2001 From: christopherbrumm Date: Mon, 28 Aug 2023 11:20:48 +0200 Subject: [PATCH] update: support custom ABCI Endpoint. --- cmd/supervysor/init.go | 4 ++++ executor/executor.go | 4 +--- node/node.go | 8 ++++---- types/constants.go | 4 ---- types/types.go | 3 ++- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/supervysor/init.go b/cmd/supervysor/init.go index b7ddb4c..cec21df 100644 --- a/cmd/supervysor/init.go +++ b/cmd/supervysor/init.go @@ -16,6 +16,7 @@ import ( ) var ( + abciEndpoint string binaryPath string chainId string fallbackEndpoints string @@ -59,6 +60,8 @@ func init() { initCmd.Flags().IntVar(&pruningInterval, "pruning-interval", 24, "block-pruning interval (hours)") initCmd.Flags().StringVar(&metrics, "metrics", "true", "exposing Prometheus metrics (true or false)") + + initCmd.Flags().StringVar(&abciEndpoint, "abci-endpoint", "http://127.0.0.1:26657", "ABCI Endpoint to request node information") } var initCmd = &cobra.Command{ @@ -110,6 +113,7 @@ func InitializeSupervysor() error { } config := types.SupervysorConfig{ + ABCIEndpoint: abciEndpoint, ChainId: chainId, BinaryPath: binaryPath, HomePath: homePath, diff --git a/executor/executor.go b/executor/executor.go index 2c5dda3..41c91f6 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -38,8 +38,6 @@ func (e *Executor) InitialStart(flags []string) error { return nil } -// TODO: Create one generic StartNode function which gets a mode as input. Mode is managed in start.go. - // EnableGhostMode activates the Ghost Mode by starting the node in GhostMode if it is not already enabled. // If not, it shuts down the node running in NormalMode, initiates the GhostMode and updates the process ID // and GhostMode upon success. @@ -137,7 +135,7 @@ func (e *Executor) PruneBlocks(homePath string, pruneHeight int, flags []string) } func (e *Executor) GetHeight() (int, error) { - return node.GetNodeHeight(e.Logger, &e.Process, 0) + return node.GetNodeHeight(e.Logger, &e.Process, e.Cfg.ABCIEndpoint, 0) } func (e *Executor) Shutdown() error { diff --git a/node/node.go b/node/node.go index 5bfc899..9c5aa28 100644 --- a/node/node.go +++ b/node/node.go @@ -23,22 +23,22 @@ import ( // The GetNodeHeight function retrieves the height of the node by querying the ABCI endpoint. // It uses recursion with a maximum depth of 10 to handle delays or failures. // It returns the nodeHeight if successful or an error message if the recursion depth reaches the limit (200s). -func GetNodeHeight(log log.Logger, p *types.ProcessType, recursionDepth int) (int, error) { +func GetNodeHeight(log log.Logger, p *types.ProcessType, abciEndpoint string, recursionDepth int) (int, error) { if recursionDepth < 10 { if p.Id == -1 { log.Error(fmt.Sprintf("node hasn't started yet. Try again in 20s ... (%d/10)", recursionDepth+1)) time.Sleep(time.Second * 20) - return GetNodeHeight(log, p, recursionDepth+1) + return GetNodeHeight(log, p, abciEndpoint, recursionDepth+1) } - response, err := http.Get(types.ABCIEndpoint) + response, err := http.Get(abciEndpoint + "/abci_info?") if err != nil { log.Error(fmt.Sprintf("failed to query height. Try again in 20s ... (%d/10)", recursionDepth+1)) time.Sleep(time.Second * 20) - return GetNodeHeight(log, p, recursionDepth+1) + return GetNodeHeight(log, p, abciEndpoint, recursionDepth+1) } else { responseData, err := io.ReadAll(response.Body) if err != nil { diff --git a/types/constants.go b/types/constants.go index 37a9fb9..e1be5e9 100644 --- a/types/constants.go +++ b/types/constants.go @@ -1,9 +1,5 @@ package types -const ( - ABCIEndpoint = "http://127.0.0.1:26657/abci_info?" -) - var ( KaonEndpoints = []string{ "https://api-eu-1.kaon.kyve.network", diff --git a/types/types.go b/types/types.go index 7cac4f0..b2119f6 100644 --- a/types/types.go +++ b/types/types.go @@ -7,8 +7,9 @@ import ( ) type SupervysorConfig struct { - ChainId string + ABCIEndpoint string BinaryPath string + ChainId string HomePath string PoolId int Seeds string