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 https://github.com/ethereum/go-ethereum/pull/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>
pull/22564/head^2
meowsbits 4 years ago committed by GitHub
parent 477ec75323
commit e862cbff95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      internal/web3ext/web3ext.go
  2. 23
      node/api.go
  3. 20
      node/api_test.go

@ -186,12 +186,24 @@ web3._extend({
call: 'admin_sleepBlocks', call: 'admin_sleepBlocks',
params: 2 params: 2
}), }),
new web3._extend.Method({
name: 'startHTTP',
call: 'admin_startHTTP',
params: 5,
inputFormatter: [null, null, null, null, null]
}),
new web3._extend.Method({
name: 'stopHTTP',
call: 'admin_stopHTTP'
}),
// This method is deprecated.
new web3._extend.Method({ new web3._extend.Method({
name: 'startRPC', name: 'startRPC',
call: 'admin_startRPC', call: 'admin_startRPC',
params: 4, params: 5,
inputFormatter: [null, null, null, null] inputFormatter: [null, null, null, null, null]
}), }),
// This method is deprecated.
new web3._extend.Method({ new web3._extend.Method({
name: 'stopRPC', name: 'stopRPC',
call: 'admin_stopRPC' call: 'admin_stopRPC'

@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
@ -162,8 +163,8 @@ func (api *privateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription,
return rpcSub, nil return rpcSub, nil
} }
// StartRPC starts the HTTP RPC API server. // StartHTTP starts the HTTP RPC API server.
func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) { func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
api.node.lock.Lock() api.node.lock.Lock()
defer api.node.lock.Unlock() defer api.node.lock.Unlock()
@ -216,12 +217,26 @@ func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis
return true, nil return true, nil
} }
// StopRPC shuts down the HTTP server. // StartRPC starts the HTTP RPC API server.
func (api *privateAdminAPI) StopRPC() (bool, error) { // This method is deprecated. Use StartHTTP instead.
func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
log.Warn("Deprecation warning", "method", "admin.StartRPC", "use-instead", "admin.StartHTTP")
return api.StartHTTP(host, port, cors, apis, vhosts)
}
// StopHTTP shuts down the HTTP server.
func (api *privateAdminAPI) StopHTTP() (bool, error) {
api.node.http.stop() api.node.http.stop()
return true, nil return true, nil
} }
// StopRPC shuts down the HTTP server.
// This method is deprecated. Use StopHTTP instead.
func (api *privateAdminAPI) StopRPC() (bool, error) {
log.Warn("Deprecation warning", "method", "admin.StopRPC", "use-instead", "admin.StopHTTP")
return api.StopHTTP()
}
// StartWS starts the websocket RPC API server. // StartWS starts the websocket RPC API server.
func (api *privateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error) { func (api *privateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error) {
api.node.lock.Lock() api.node.lock.Lock()

@ -69,7 +69,7 @@ func TestStartRPC(t *testing.T) {
name: "rpc enabled through API", name: "rpc enabled through API",
cfg: Config{}, cfg: Config{},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
_, err := api.StartRPC(sp("127.0.0.1"), ip(0), nil, nil, nil) _, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
}, },
wantReachable: true, wantReachable: true,
@ -90,14 +90,14 @@ func TestStartRPC(t *testing.T) {
port := listener.Addr().(*net.TCPAddr).Port port := listener.Addr().(*net.TCPAddr).Port
// Now try to start RPC on that port. This should fail. // Now try to start RPC on that port. This should fail.
_, err = api.StartRPC(sp("127.0.0.1"), ip(port), nil, nil, nil) _, err = api.StartHTTP(sp("127.0.0.1"), ip(port), nil, nil, nil)
if err == nil { if err == nil {
t.Fatal("StartRPC should have failed on port", port) t.Fatal("StartHTTP should have failed on port", port)
} }
// Try again after unblocking the port. It should work this time. // Try again after unblocking the port. It should work this time.
listener.Close() listener.Close()
_, err = api.StartRPC(sp("127.0.0.1"), ip(port), nil, nil, nil) _, err = api.StartHTTP(sp("127.0.0.1"), ip(port), nil, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
}, },
wantReachable: true, wantReachable: true,
@ -109,7 +109,7 @@ func TestStartRPC(t *testing.T) {
name: "rpc stopped through API", name: "rpc stopped through API",
cfg: Config{HTTPHost: "127.0.0.1"}, cfg: Config{HTTPHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
_, err := api.StopRPC() _, err := api.StopHTTP()
assert.NoError(t, err) assert.NoError(t, err)
}, },
wantReachable: false, wantReachable: false,
@ -121,10 +121,10 @@ func TestStartRPC(t *testing.T) {
name: "rpc stopped twice", name: "rpc stopped twice",
cfg: Config{HTTPHost: "127.0.0.1"}, cfg: Config{HTTPHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
_, err := api.StopRPC() _, err := api.StopHTTP()
assert.NoError(t, err) assert.NoError(t, err)
_, err = api.StopRPC() _, err = api.StopHTTP()
assert.NoError(t, err) assert.NoError(t, err)
}, },
wantReachable: false, wantReachable: false,
@ -211,14 +211,14 @@ func TestStartRPC(t *testing.T) {
{ {
name: "rpc stopped with ws enabled", name: "rpc stopped with ws enabled",
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *privateAdminAPI) {
_, err := api.StartRPC(sp("127.0.0.1"), ip(0), nil, nil, nil) _, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
wsport := n.http.port wsport := n.http.port
_, err = api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil) _, err = api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
_, err = api.StopRPC() _, err = api.StopHTTP()
assert.NoError(t, err) assert.NoError(t, err)
}, },
wantReachable: false, wantReachable: false,
@ -233,7 +233,7 @@ func TestStartRPC(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
wsport := n.http.port wsport := n.http.port
_, err = api.StartRPC(sp("127.0.0.1"), ip(wsport), nil, nil, nil) _, err = api.StartHTTP(sp("127.0.0.1"), ip(wsport), nil, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
}, },
wantReachable: true, wantReachable: true,

Loading…
Cancel
Save