From c5485a28ecf35d9a36ab7ab86cee92c8d7566889 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Tue, 30 Jun 2020 10:48:03 +0100 Subject: [PATCH] Return string for failed rpc connections --- background/background.go | 4 ++-- rpc/dcrwallet.go | 18 +++++++++--------- webapi/middleware.go | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/background/background.go b/background/background.go index bdcd62c..9cee958 100644 --- a/background/background.go +++ b/background/background.go @@ -159,9 +159,9 @@ func blockConnected() { log.Errorf("%s: Could not connect to any wallets", funcName) return } - if failedConnections > 0 { + if len(failedConnections) > 0 { log.Errorf("%s: Failed to connect to %d wallet(s), proceeding with only %d", - funcName, failedConnections, len(walletClients)) + funcName, len(failedConnections), len(walletClients)) } for _, ticket := range unconfirmedFees { diff --git a/rpc/dcrwallet.go b/rpc/dcrwallet.go index e0b690e..15ff018 100644 --- a/rpc/dcrwallet.go +++ b/rpc/dcrwallet.go @@ -42,16 +42,16 @@ func (w *WalletConnect) Close() { // Clients loops over each wallet and tries to establish a connection. It // increments a count of failed connections if a connection cannot be // established, or if the wallet is misconfigured. -func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) ([]*WalletRPC, int) { +func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) ([]*WalletRPC, []string) { walletClients := make([]*WalletRPC, 0) - failedConnections := 0 + failedConnections := make([]string, 0) for _, connect := range []*client(*w) { c, newConnection, err := connect.dial(ctx) if err != nil { log.Errorf("dcrwallet connection error: %v", err) - failedConnections++ + failedConnections = append(failedConnections, connect.addr) continue } @@ -67,20 +67,20 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) err = c.Call(ctx, "version", &verMap) if err != nil { log.Errorf("version check on dcrwallet '%s' failed: %v", c.String(), err) - failedConnections++ + failedConnections = append(failedConnections, connect.addr) continue } walletVersion, exists := verMap["dcrwalletjsonrpcapi"] if !exists { log.Errorf("version response on dcrwallet '%s' missing 'dcrwalletjsonrpcapi'", c.String()) - failedConnections++ + failedConnections = append(failedConnections, connect.addr) continue } if walletVersion.VersionString != requiredWalletVersion { log.Errorf("dcrwallet '%s' has wrong RPC version: got %s, expected %s", c.String(), walletVersion.VersionString, requiredWalletVersion) - failedConnections++ + failedConnections = append(failedConnections, connect.addr) continue } @@ -89,12 +89,12 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) err = c.Call(ctx, "getcurrentnet", &netID) if err != nil { log.Errorf("getcurrentnet check on dcrwallet '%s' failed: %v", c.String(), err) - failedConnections++ + failedConnections = append(failedConnections, connect.addr) continue } if netID != netParams.Net { log.Errorf("dcrwallet '%s' running on %s, expected %s", c.String(), netID, netParams.Net) - failedConnections++ + failedConnections = append(failedConnections, connect.addr) continue } @@ -103,7 +103,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) walletInfo, err := walletRPC.WalletInfo() if err != nil { log.Errorf("walletinfo check on dcrwallet '%s' failed: %v", c.String(), err) - failedConnections++ + failedConnections = append(failedConnections, connect.addr) continue } diff --git a/webapi/middleware.go b/webapi/middleware.go index 3facc95..f7ba06d 100644 --- a/webapi/middleware.go +++ b/webapi/middleware.go @@ -100,9 +100,9 @@ func withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc { sendError(errInternalError, c) return } - if failedConnections > 0 { + if len(failedConnections) > 0 { log.Errorf("Failed to connect to %d wallet(s), proceeding with only %d", - failedConnections, len(clients)) + len(failedConnections), len(clients)) } c.Set("WalletClients", clients) }