Skip to content

Commit

Permalink
Services/horizon: Skip querying stellar-core on 127.0.0.1 when Horizo…
Browse files Browse the repository at this point in the history
…n is in build state
  • Loading branch information
urvisavla committed Jul 25, 2023
1 parent 95c2976 commit 4b05f7b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -196,6 +197,13 @@ func (a *App) Paths() paths.Finder {
return a.paths
}

func isLocalAddress(url string, port uint) bool {
localHostURL := fmt.Sprintf("http://localhost:%d", port)
localIPURL := fmt.Sprintf("http://127.0.0.1:%d", port)

return strings.HasPrefix(url, localHostURL) || strings.HasPrefix(url, localIPURL)
}

// UpdateCoreLedgerState triggers a refresh of Stellar-Core ledger state.
// This is done separately from Horizon ledger state update to prevent issues
// in case Stellar-Core query timeout.
Expand All @@ -205,7 +213,7 @@ func (a *App) UpdateCoreLedgerState(ctx context.Context) {
// #4446 If the ingestion state machine is in the build state, the query can time out
// because the captive-core buffer may be full. In this case, skip the check.
if a.config.CaptiveCoreToml != nil &&
a.config.StellarCoreURL == fmt.Sprintf("http://localhost:%d", a.config.CaptiveCoreToml.HTTPPort) &&
isLocalAddress(a.config.StellarCoreURL, a.config.CaptiveCoreToml.HTTPPort) &&
a.ingester != nil && a.ingester.GetCurrentState() == ingest.Build {
return
}
Expand Down

0 comments on commit 4b05f7b

Please sign in to comment.