Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catchup using same network logic as when starting node #25

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions tools/catch-catchpoint/catch-catchpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ import (
"log"
"math"
"net/http"
"os"
"strconv"
"strings"
"time"
)

const (
envNetworkVar = "VOINETWORK_NETWORK"
goalCmd = "/node/bin/goal"
algodDataDir = "/algod/data"
httpTimeout = 30 * time.Second
httpRetryAttempts = 10
)

var networkArgument string
var network string

func init() {
flag.StringVar(&networkArgument, "network", "testnet", "Specify the network (testnet)")
flag.StringVar(&network, "network", "testnet", "Specify the network (testnet)")
}

func getLastNodeRound(pu utils.ProcessUtils) (int, error) {
Expand All @@ -46,19 +44,21 @@ func getLastNodeRound(pu utils.ProcessUtils) (int, error) {

func main() {
flag.Parse()
envNetwork := os.Getenv(envNetworkVar)
if envNetwork != "" {
log.Printf("Using network from environment variable: %s", envNetwork)
networkArgument = envNetwork
nu := utils.NetworkUtils{}
envNetwork, networkSet := nu.GetNetworkFromEnv()
if networkSet {
network = envNetwork
Comment on lines +47 to +50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

LGTM with suggestion: Improved network initialization

The use of NetworkUtils.GetNetworkFromEnv() centralizes the network configuration logic, which is good for maintainability. However, consider adding explicit error handling for this operation to improve robustness.

Consider modifying the GetNetworkFromEnv() function to return an error, and handle it explicitly:

envNetwork, networkSet, err := nu.GetNetworkFromEnv()
if err != nil {
    log.Fatalf("Error getting network from environment: %v", err)
}
if networkSet {
    network = envNetwork
}

}

nu := utils.NetworkUtils{}
network, err := nu.NewNetwork(networkArgument)
preDefinedNetwork, err := nu.NewNetwork(network)
if err != nil {
log.Fatalf("Unsupported network: %s. Exiting.", network)
}

log.Printf("Catchup on network: %s", network.Name)
log.Printf("Catchup on network: %s", preDefinedNetwork.Name)

pu := utils.ProcessUtils{}
statusURL := network.StatusURL
statusURL := preDefinedNetwork.StatusURL
if err != nil {
log.Fatalf("Error: %v", err)
}
Expand Down
Loading