github.com/decred/dcrlnd@v0.7.6/chainreg/dcrlnd_checks.go (about) 1 package chainreg 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/decred/dcrd/rpcclient/v8" 9 "github.com/decred/dcrd/wire" 10 ) 11 12 // checkDcrdNode checks whether the dcrd node reachable using the provided 13 // config is usable as source of chain information, given the requirements of a 14 // dcrlnd node. 15 func checkDcrdNode(wantNet wire.CurrencyNet, rpcConfig rpcclient.ConnConfig) error { 16 connectTimeout := 30 * time.Second 17 ctx, cancel := context.WithTimeout(context.Background(), connectTimeout) 18 defer cancel() 19 20 rpcConfig.DisableConnectOnNew = true 21 rpcConfig.DisableAutoReconnect = false 22 chainConn, err := rpcclient.New(&rpcConfig, nil) 23 if err != nil { 24 return err 25 } 26 27 // Try to connect to the given node. 28 if err := chainConn.Connect(ctx, true); err != nil { 29 return err 30 } 31 defer chainConn.Shutdown() 32 33 // Verify whether the node is on the correct network. 34 net, err := chainConn.GetCurrentNet(ctx) 35 if err != nil { 36 return err 37 } 38 if net != wantNet { 39 return fmt.Errorf("dcrd node network mismatch") 40 } 41 42 return nil 43 }