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

cleanup relay-status check #335

Merged
merged 1 commit into from
Sep 20, 2022
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
8 changes: 4 additions & 4 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ func Main() {
lvl, err := logrus.ParseLevel(*logLevel)
if err != nil {
flag.Usage()
log.Fatalf("Invalid loglevel: %s", *logLevel)
log.Fatalf("invalid loglevel: %s", *logLevel)
}
logrus.SetLevel(lvl)
}
@@ -110,14 +110,14 @@ func Main() {
genesisForkVersionHex = genesisForkVersionGoerli
} else {
flag.Usage()
log.Fatal("Please specify a genesis fork version (eg. -mainnet / -kiln / -ropsten / -sepolia / -goerli / -genesis-fork-version flags)")
log.Fatal("please specify a genesis fork version (eg. -mainnet / -sepolia / -goerli / -genesis-fork-version flags)")
}
log.Infof("Using genesis fork version: %s", genesisForkVersionHex)
log.Infof("using genesis fork version: %s", genesisForkVersionHex)

relays := parseRelayURLs(*relayURLs)
if len(relays) == 0 {
flag.Usage()
log.Fatal("No relays specified")
log.Fatal("no relays specified")
}
log.WithField("relays", relaysToStrings(relays)).Infof("using %d relays", len(relays))

14 changes: 6 additions & 8 deletions server/service.go
Original file line number Diff line number Diff line change
@@ -538,31 +538,29 @@ func (m *BoostService) CheckRelays() int {
var wg sync.WaitGroup
var numSuccessRequestsToRelay uint32

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

for _, r := range m.relays {
wg.Add(1)

go func(relay RelayEntry) {
defer wg.Done()
url := relay.GetURI(pathStatus)
log := m.log.WithField("url", url)
log.Debug("Checking relay status")
log.Debug("checking relay status")

code, err := SendHTTPRequest(ctx, m.httpClientGetHeader, http.MethodGet, url, "", nil, nil)
if err != nil && ctx.Err() != context.Canceled {
code, err := SendHTTPRequest(context.Background(), m.httpClientGetHeader, http.MethodGet, url, "", nil, nil)
if err != nil {
log.WithError(err).Error("relay status error - request failed")
return
}
if code != http.StatusOK {
if code == http.StatusOK {
log.Debug("relay status OK")
} else {
log.Errorf("relay status error - unexpected status code %d", code)
return
}

// Success: increase counter and cancel all pending requests to other relays
atomic.AddUint32(&numSuccessRequestsToRelay, 1)
cancel()
}(r)
}