Skip to content

Commit

Permalink
Revert "node: remove unused error return from Attach (ethereum#27450)"
Browse files Browse the repository at this point in the history
This reverts commit 2df602a.
  • Loading branch information
devopsbo3 committed Nov 10, 2023
1 parent 8bf01cc commit 12c8a07
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 10 deletions.
6 changes: 5 additions & 1 deletion cmd/faucet/faucet.go
Expand Up @@ -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{
Expand Down
5 changes: 4 additions & 1 deletion cmd/geth/consolecmd.go
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion cmd/geth/main.go
Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion console/console_test.go
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ethclient/ethclient_test.go
Expand Up @@ -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()

Expand Down
5 changes: 4 additions & 1 deletion ethclient/gethclient/gethclient_test.go
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions node/node.go
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions p2p/simulations/adapters/inproc.go
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 12c8a07

Please sign in to comment.