Skip to content
Open
Changes from 1 commit
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
26 changes: 23 additions & 3 deletions pkg/arkd-wallet/core/infrastructure/nbxplorer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ type nbxplorer struct {
groupID string
}

const (
nbxplorerMaxRetries = 30
nbxplorerRetryInterval = 5 * time.Second
)
Comment thread
s373nZ marked this conversation as resolved.

func New(rawURL string) (ports.Nbxplorer, error) {
rawURL = strings.TrimSuffix(rawURL, "/")

Expand All @@ -67,9 +72,24 @@ func New(rawURL string) (ports.Nbxplorer, error) {
groupID: "",
}

status, err := svc.GetBitcoinStatus(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to connect to nbxplorer: %s", err)
var status *ports.BitcoinStatus

for attempt := 1; attempt <= nbxplorerMaxRetries; attempt++ {
status, err = svc.GetBitcoinStatus(context.Background())
if err == nil {
break
}

if attempt == nbxplorerMaxRetries {
return nil, fmt.Errorf("failed to connect to nbxplorer after %d attempts: %s", nbxplorerMaxRetries, err)
}

log.WithFields(log.Fields{
"attempt": attempt,
"error": err.Error(),
}).Warn("nbxplorer not ready, retrying")

time.Sleep(nbxplorerRetryInterval)
}

svc.minRelayTxFee = status.MinRelayTxFee
Expand Down
Loading