Skip to content

Commit

Permalink
update: support custom ABCI Endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherbrumm committed Aug 28, 2023
1 parent df04524 commit 2cec613
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
4 changes: 4 additions & 0 deletions cmd/supervysor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

var (
abciEndpoint string
binaryPath string
chainId string
fallbackEndpoints string
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -110,6 +113,7 @@ func InitializeSupervysor() error {
}

config := types.SupervysorConfig{
ABCIEndpoint: abciEndpoint,
ChainId: chainId,
BinaryPath: binaryPath,
HomePath: homePath,
Expand Down
4 changes: 1 addition & 3 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions types/constants.go
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
)

type SupervysorConfig struct {
ChainId string
ABCIEndpoint string
BinaryPath string
ChainId string
HomePath string
PoolId int
Seeds string
Expand Down

0 comments on commit 2cec613

Please sign in to comment.