Skip to content

Commit e862cbf

Browse files
authored
internal/web3ext, node: migrate node admin API (Start|Stop)RPC->HTTP (#22461)
* internal/web3ext,node: migrate node admin API (Start|Stop)RPC->HTTP Corresponding CLI flags --rpc have been moved to --http. This moves the admin module HTTP RPC start/stop methods to an equivalent namespace. Rel ethereum/go-ethereum#22263 Date: 2021-03-08 08:00:11-06:00 Signed-off-by: meows <b5c6@protonmail.com> * internal/web3ext: fix startRPC/HTTP param count (4->5) Date: 2021-03-16 06:13:23-05:00 Signed-off-by: meows <b5c6@protonmail.com>
1 parent 477ec75 commit e862cbf

3 files changed

Lines changed: 43 additions & 16 deletions

File tree

‎internal/web3ext/web3ext.go‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,24 @@ web3._extend({
186186
call: 'admin_sleepBlocks',
187187
params: 2
188188
}),
189+
new web3._extend.Method({
190+
name: 'startHTTP',
191+
call: 'admin_startHTTP',
192+
params: 5,
193+
inputFormatter: [null, null, null, null, null]
194+
}),
195+
new web3._extend.Method({
196+
name: 'stopHTTP',
197+
call: 'admin_stopHTTP'
198+
}),
199+
// This method is deprecated.
189200
new web3._extend.Method({
190201
name: 'startRPC',
191202
call: 'admin_startRPC',
192-
params: 4,
193-
inputFormatter: [null, null, null, null]
203+
params: 5,
204+
inputFormatter: [null, null, null, null, null]
194205
}),
206+
// This method is deprecated.
195207
new web3._extend.Method({
196208
name: 'stopRPC',
197209
call: 'admin_stopRPC'

‎node/api.go‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/ethereum/go-ethereum/common/hexutil"
2525
"github.com/ethereum/go-ethereum/crypto"
2626
"github.com/ethereum/go-ethereum/internal/debug"
27+
"github.com/ethereum/go-ethereum/log"
2728
"github.com/ethereum/go-ethereum/p2p"
2829
"github.com/ethereum/go-ethereum/p2p/enode"
2930
"github.com/ethereum/go-ethereum/rpc"
@@ -162,8 +163,8 @@ func (api *privateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription,
162163
return rpcSub, nil
163164
}
164165

165-
// StartRPC starts the HTTP RPC API server.
166-
func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
166+
// StartHTTP starts the HTTP RPC API server.
167+
func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
167168
api.node.lock.Lock()
168169
defer api.node.lock.Unlock()
169170

@@ -216,12 +217,26 @@ func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis
216217
return true, nil
217218
}
218219

219-
// StopRPC shuts down the HTTP server.
220-
func (api *privateAdminAPI) StopRPC() (bool, error) {
220+
// StartRPC starts the HTTP RPC API server.
221+
// This method is deprecated. Use StartHTTP instead.
222+
func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
223+
log.Warn("Deprecation warning", "method", "admin.StartRPC", "use-instead", "admin.StartHTTP")
224+
return api.StartHTTP(host, port, cors, apis, vhosts)
225+
}
226+
227+
// StopHTTP shuts down the HTTP server.
228+
func (api *privateAdminAPI) StopHTTP() (bool, error) {
221229
api.node.http.stop()
222230
return true, nil
223231
}
224232

233+
// StopRPC shuts down the HTTP server.
234+
// This method is deprecated. Use StopHTTP instead.
235+
func (api *privateAdminAPI) StopRPC() (bool, error) {
236+
log.Warn("Deprecation warning", "method", "admin.StopRPC", "use-instead", "admin.StopHTTP")
237+
return api.StopHTTP()
238+
}
239+
225240
// StartWS starts the websocket RPC API server.
226241
func (api *privateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error) {
227242
api.node.lock.Lock()

‎node/api_test.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestStartRPC(t *testing.T) {
6969
name: "rpc enabled through API",
7070
cfg: Config{},
7171
fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
72-
_, err := api.StartRPC(sp("127.0.0.1"), ip(0), nil, nil, nil)
72+
_, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil)
7373
assert.NoError(t, err)
7474
},
7575
wantReachable: true,
@@ -90,14 +90,14 @@ func TestStartRPC(t *testing.T) {
9090
port := listener.Addr().(*net.TCPAddr).Port
9191

9292
// Now try to start RPC on that port. This should fail.
93-
_, err = api.StartRPC(sp("127.0.0.1"), ip(port), nil, nil, nil)
93+
_, err = api.StartHTTP(sp("127.0.0.1"), ip(port), nil, nil, nil)
9494
if err == nil {
95-
t.Fatal("StartRPC should have failed on port", port)
95+
t.Fatal("StartHTTP should have failed on port", port)
9696
}
9797

9898
// Try again after unblocking the port. It should work this time.
9999
listener.Close()
100-
_, err = api.StartRPC(sp("127.0.0.1"), ip(port), nil, nil, nil)
100+
_, err = api.StartHTTP(sp("127.0.0.1"), ip(port), nil, nil, nil)
101101
assert.NoError(t, err)
102102
},
103103
wantReachable: true,
@@ -109,7 +109,7 @@ func TestStartRPC(t *testing.T) {
109109
name: "rpc stopped through API",
110110
cfg: Config{HTTPHost: "127.0.0.1"},
111111
fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
112-
_, err := api.StopRPC()
112+
_, err := api.StopHTTP()
113113
assert.NoError(t, err)
114114
},
115115
wantReachable: false,
@@ -121,10 +121,10 @@ func TestStartRPC(t *testing.T) {
121121
name: "rpc stopped twice",
122122
cfg: Config{HTTPHost: "127.0.0.1"},
123123
fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
124-
_, err := api.StopRPC()
124+
_, err := api.StopHTTP()
125125
assert.NoError(t, err)
126126

127-
_, err = api.StopRPC()
127+
_, err = api.StopHTTP()
128128
assert.NoError(t, err)
129129
},
130130
wantReachable: false,
@@ -211,14 +211,14 @@ func TestStartRPC(t *testing.T) {
211211
{
212212
name: "rpc stopped with ws enabled",
213213
fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
214-
_, err := api.StartRPC(sp("127.0.0.1"), ip(0), nil, nil, nil)
214+
_, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil)
215215
assert.NoError(t, err)
216216

217217
wsport := n.http.port
218218
_, err = api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil)
219219
assert.NoError(t, err)
220220

221-
_, err = api.StopRPC()
221+
_, err = api.StopHTTP()
222222
assert.NoError(t, err)
223223
},
224224
wantReachable: false,
@@ -233,7 +233,7 @@ func TestStartRPC(t *testing.T) {
233233
assert.NoError(t, err)
234234

235235
wsport := n.http.port
236-
_, err = api.StartRPC(sp("127.0.0.1"), ip(wsport), nil, nil, nil)
236+
_, err = api.StartHTTP(sp("127.0.0.1"), ip(wsport), nil, nil, nil)
237237
assert.NoError(t, err)
238238
},
239239
wantReachable: true,

0 commit comments

Comments
 (0)