From 12c8a07cdfad33d22d237d5d8a63189ae349dafa Mon Sep 17 00:00:00 2001 From: devopsbo3 <69951731+devopsbo3@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:21:03 -0600 Subject: [PATCH] Revert "node: remove unused error return from Attach (#27450)" This reverts commit 2df602a33274ea21843ad2bb848b2d43d94d4f22. --- cmd/faucet/faucet.go | 6 +++++- cmd/geth/consolecmd.go | 5 ++++- cmd/geth/main.go | 5 ++++- console/console_test.go | 5 ++++- ethclient/ethclient_test.go | 2 +- ethclient/gethclient/gethclient_test.go | 5 ++++- node/node.go | 4 ++-- p2p/simulations/adapters/inproc.go | 7 +++++-- 8 files changed, 29 insertions(+), 10 deletions(-) diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index e4d6ad6977508..581629da5e1cb 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -268,7 +268,11 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*enode.Node, network ui } } // Attach to the client and retrieve and interesting metadatas - api := stack.Attach() + api, err := stack.Attach() + if err != nil { + stack.Close() + return nil, err + } client := ethclient.NewClient(api) return &faucet{ diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go index 526ede96192fa..aeee6f9c9e404 100644 --- a/cmd/geth/consolecmd.go +++ b/cmd/geth/consolecmd.go @@ -75,7 +75,10 @@ func localConsole(ctx *cli.Context) error { defer stack.Close() // Attach to the newly started node and create the JavaScript console. - client := stack.Attach() + client, err := stack.Attach() + if err != nil { + return fmt.Errorf("failed to attach to the inproc geth: %v", err) + } config := console.Config{ DataDir: utils.MakeDataDir(ctx), DocRoot: ctx.String(utils.JSpathFlag.Name), diff --git a/cmd/geth/main.go b/cmd/geth/main.go index dcdf0045ce25e..2794e37e380d1 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -346,7 +346,10 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon stack.AccountManager().Subscribe(events) // Create a client to interact with local geth node. - rpcClient := stack.Attach() + rpcClient, err := stack.Attach() + if err != nil { + utils.Fatalf("Failed to attach to self: %v", err) + } ethClient := ethclient.NewClient(rpcClient) go func() { diff --git a/console/console_test.go b/console/console_test.go index a2550d8ca8ae6..cc61f021ce1d4 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -110,7 +110,10 @@ func newTester(t *testing.T, confOverride func(*ethconfig.Config)) *tester { if err = stack.Start(); err != nil { t.Fatalf("failed to start test stack: %v", err) } - client := stack.Attach() + client, err := stack.Attach() + if err != nil { + t.Fatalf("failed to attach to node: %v", err) + } prompter := &hookedPrompter{scheduler: make(chan string)} printer := new(bytes.Buffer) diff --git a/ethclient/ethclient_test.go b/ethclient/ethclient_test.go index d2f3710936611..3856760756553 100644 --- a/ethclient/ethclient_test.go +++ b/ethclient/ethclient_test.go @@ -250,7 +250,7 @@ func generateTestChain() []*types.Block { func TestEthClient(t *testing.T) { backend, chain := newTestBackend(t) - client := backend.Attach() + client, _ := backend.Attach() defer backend.Close() defer client.Close() diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index 7ff5836f81df7..296d328484513 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -94,7 +94,10 @@ func generateTestChain() (*core.Genesis, []*types.Block) { func TestGethClient(t *testing.T) { backend, _ := newTestBackend(t) - client := backend.Attach() + client, err := backend.Attach() + if err != nil { + t.Fatal(err) + } defer backend.Close() defer client.Close() diff --git a/node/node.go b/node/node.go index da41169c52b86..553d451ab8608 100644 --- a/node/node.go +++ b/node/node.go @@ -616,8 +616,8 @@ func (n *Node) RegisterHandler(name, path string, handler http.Handler) { } // Attach creates an RPC client attached to an in-process API handler. -func (n *Node) Attach() *rpc.Client { - return rpc.DialInProc(n.inprocHandler) +func (n *Node) Attach() (*rpc.Client, error) { + return rpc.DialInProc(n.inprocHandler), nil } // RPCHandler returns the in-process RPC request handler. diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index c52917fd0ae59..36b5286517ae7 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -147,7 +147,7 @@ func (s *SimAdapter) DialRPC(id enode.ID) (*rpc.Client, error) { if !ok { return nil, fmt.Errorf("unknown node: %s", id) } - return node.node.Attach(), nil + return node.node.Attach() } // GetNode returns the node with the given ID if it exists @@ -274,7 +274,10 @@ func (sn *SimNode) Start(snapshots map[string][]byte) error { } // create an in-process RPC client - client := sn.node.Attach() + client, err := sn.node.Attach() + if err != nil { + return err + } sn.lock.Lock() sn.client = client sn.lock.Unlock()