Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove json rpc #2416

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions apps/chat2bridge/chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,7 @@ proc stop*(cmb: Chat2MatterBridge) {.async: (raises: [Exception]).} =
when isMainModule:
import
../../../waku/common/utils/nat,
../../waku/waku_api/message_cache,
../../waku/waku_api/jsonrpc/debug/handlers as debug_api,
../../waku/waku_api/jsonrpc/filter/handlers as filter_api,
../../waku/waku_api/jsonrpc/relay/handlers as relay_api,
../../waku/waku_api/jsonrpc/store/handlers as store_api


proc startV2Rpc(node: WakuNode, rpcServer: RpcHttpServer, conf: Chat2MatterbridgeConf) {.raises: [Exception].} =
installDebugApiHandlers(node, rpcServer)

# Install enabled API handlers:
if conf.relay:
let cache = MessageCache.init(capacity=30)
installRelayApiHandlers(node, rpcServer, cache)

if conf.filter:
let messageCache = MessageCache.init(capacity=30)
installFilterApiHandlers(node, rpcServer, messageCache)

if conf.store:
installStoreApiHandlers(node, rpcServer)

rpcServer.start()
../../waku/waku_api/message_cache

let
rng = newRng()
Expand Down Expand Up @@ -309,15 +287,6 @@ when isMainModule:
else:
error "Error parsing conf.filternode", error = filterPeer.error

if conf.rpc:
let ta = initTAddress(conf.rpcAddress,
Port(conf.rpcPort + conf.portsShift))
var rpcServer = newRpcHttpServer([ta])
# Waku v2 rpc
startV2Rpc(bridge.nodev2, rpcServer, conf)

rpcServer.start()

if conf.metricsServer:
let
address = conf.metricsServerAddress
Expand Down
15 changes: 0 additions & 15 deletions apps/chat2bridge/config_chat2bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ type
"Must be one of: any, none, upnp, pmp, extip:<IP>"
defaultValue: "any" .}: string

rpc* {.
desc: "Enable Waku RPC server"
defaultValue: false
name: "rpc" .}: bool

rpcAddress* {.
desc: "Listening address of the RPC server",
defaultValue: parseIpAddress("127.0.0.1")
name: "rpc-address" }: IpAddress

rpcPort* {.
desc: "Listening port of the RPC server"
defaultValue: 8545
name: "rpc-port" .}: uint16

metricsServer* {.
desc: "Enable the metrics server"
defaultValue: false
Expand Down
57 changes: 0 additions & 57 deletions apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import
libp2p/protocols/pubsub/gossipsub,
libp2p/peerid,
eth/keys,
json_rpc/rpcserver,
presto,
metrics,
metrics/chronos_httpserver
Expand All @@ -42,11 +41,6 @@ import
../../waku/waku_api/rest/store/handlers as rest_store_api,
../../waku/waku_api/rest/health/handlers as rest_health_api,
../../waku/waku_api/rest/admin/handlers as rest_admin_api,
../../waku/waku_api/jsonrpc/admin/handlers as rpc_admin_api,
../../waku/waku_api/jsonrpc/debug/handlers as rpc_debug_api,
../../waku/waku_api/jsonrpc/filter/handlers as rpc_filter_api,
../../waku/waku_api/jsonrpc/relay/handlers as rpc_relay_api,
../../waku/waku_api/jsonrpc/store/handlers as rpc_store_api,
../../waku/waku_archive,
../../waku/waku_dnsdisc,
../../waku/waku_enr/sharding,
Expand Down Expand Up @@ -83,7 +77,6 @@ type

node: WakuNode

rpcServer: Option[RpcHttpServer]
restServer: Option[WakuRestServerRef]
metricsServer: Option[MetricsHttpServerRef]

Expand Down Expand Up @@ -793,46 +786,6 @@ proc startRestServer(app: App,

ok(server)

proc startRpcServer(app: App, address: IpAddress, port: Port, conf: WakuNodeConf): AppResult[RpcHttpServer] =
let ta = initTAddress(address, port)

var server: RpcHttpServer
try:
server = newRpcHttpServer([ta])
except CatchableError:
return err("failed to init JSON-RPC server: " & getCurrentExceptionMsg())

installDebugApiHandlers(app.node, server)

if conf.relay:
let cache = MessageCache.init(capacity=50)

let handler = messageCacheHandler(cache)

for pubsubTopic in conf.pubsubTopics:
cache.pubsubSubscribe(pubsubTopic)
app.node.subscribe((kind: PubsubSub, topic: pubsubTopic), some(handler))

for contentTopic in conf.contentTopics:
cache.contentSubscribe(contentTopic)
app.node.subscribe((kind: ContentSub, topic: contentTopic), some(handler))

installRelayApiHandlers(app.node, server, cache)

if conf.filternode != "":
let filterMessageCache = MessageCache.init(capacity=50)
installFilterApiHandlers(app.node, server, filterMessageCache)

installStoreApiHandlers(app.node, server)

if conf.rpcAdmin:
installAdminApiHandlers(app.node, server)

server.start()
info "RPC Server started", address=ta

ok(server)

proc startMetricsServer(serverIp: IpAddress, serverPort: Port): AppResult[MetricsHttpServerRef] =
info "Starting metrics HTTP server", serverIp= $serverIp, serverPort= $serverPort

Expand All @@ -854,13 +807,6 @@ proc startMetricsLogging(): AppResult[void] =
ok()

proc setupMonitoringAndExternalInterfaces*(app: var App): AppResult[void] =
if app.conf.rpc:
let startRpcServerRes = startRpcServer(app, app.conf.rpcAddress, Port(app.conf.rpcPort + app.conf.portsShift), app.conf)
if startRpcServerRes.isErr():
error "6/7 Starting JSON-RPC server failed. Continuing in current state.", error=startRpcServerRes.error
else:
app.rpcServer = some(startRpcServerRes.value)

if app.conf.rest:
let startRestServerRes = startRestServer(app, app.conf.restAddress, Port(app.conf.restPort + app.conf.portsShift), app.conf)
if startRestServerRes.isErr():
Expand Down Expand Up @@ -890,9 +836,6 @@ proc stop*(app: App): Future[void] {.async: (raises: [Exception]).} =
if app.restServer.isSome():
await app.restServer.get().stop()

if app.rpcServer.isSome():
await app.rpcServer.get().stop()

if app.metricsServer.isSome():
await app.metricsServer.get().stop()

Expand Down
27 changes: 0 additions & 27 deletions apps/wakunode2/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -360,33 +360,6 @@ type
defaultValue: ""
name: "lightpushnode" }: string

## JSON-RPC config

rpc* {.
desc: "Enable Waku JSON-RPC server: true|false",
defaultValue: true
name: "rpc" }: bool

rpcAddress* {.
desc: "Listening address of the JSON-RPC server.",
defaultValue: parseIpAddress("127.0.0.1")
name: "rpc-address" }: IpAddress

rpcPort* {.
desc: "Listening port of the JSON-RPC server.",
defaultValue: 8545
name: "rpc-port" }: uint16

rpcAdmin* {.
desc: "Enable access to JSON-RPC Admin API: true|false",
defaultValue: false
name: "rpc-admin" }: bool

rpcPrivate* {.
desc: "Enable access to JSON-RPC Private API: true|false",
defaultValue: false
name: "rpc-private" }: bool

## REST HTTP config

rest* {.
Expand Down
4 changes: 0 additions & 4 deletions docs/api/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ proc resume*(node: WakuNode, peerList: Option[seq[PeerInfo]]) =
##
```

## JSON RPC

TODO To specify


## REST API

Expand Down
10 changes: 1 addition & 9 deletions docs/api/rest-api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## HTTP REST API

Similar to the JSON-RPC API, the HTTP REST API consists of a set of methods operating on the Waku Node remotely over HTTP.
The HTTP REST API consists of a set of methods operating on the Waku Node remotely over HTTP.

This API is divided in different _namespaces_ which group a set of resources:

Expand Down Expand Up @@ -41,14 +41,6 @@ A particular OpenAPI spec can be easily imported into [Postman](https://www.post

#### [`get_waku_v2_debug_v1_info`](https://rfc.vac.dev/spec/16/#get_waku_v2_debug_v1_info)

JSON-RPC call:

```bash
curl -d '{"jsonrpc":"2.0","method":"get_waku_v2_debug_v1_info","params":[],"id":1}' -H 'Content-Type: application/json' localhost:8645 -s | jq
```

Equivalent call for the REST API:

```bash
curl http://localhost:8645/debug/v1/info -s | jq
```
Expand Down
2 changes: 0 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Grep for "Listening on". It should be printed at INFO level at the beginning. E.

`Oct 7, 2020 @ 23:17:00.383INF 2020-10-07 23:17:00.375+00:00 Listening on topics="wakunode" tid=1 file=wakunode2.nim:140 full=/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS`

Or use the [JSON-RPC API](https://github.com/waku-org/nwaku/blob/master/docs/tutorial/jsonrpc-api.md#perform-a-health-check).

## How do I find out node addresses at the test cluster?

The easiest way is to use `jq` and query the fleets registry that Status operates:
Expand Down
29 changes: 4 additions & 25 deletions docs/operators/how-to/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,10 @@ and websocket address
```

You can also query a running node for its listening addresses
using a [`get_waku_v2_debug_v1_info` JSON-RPC API](https://rfc.vac.dev/spec/16/#get_waku_v2_debug_v1_info) call.
using the REST API.

For example

```sh
curl -d '{"jsonrpc":"2.0","id":"id","method":"get_waku_v2_debug_v1_info", "params":[]}' --header "Content-Type: application/json" http://localhost:8545
```

returns a response similar to

```json
{
"jsonrpc": "2.0",
"id": "id",
"result": {
"listenAddresses": [
"/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmLU5Nwng9dWFZwM2DgJ5QGcUuDnefJyHJiXUCVaprhgL4"
],
"enrUri": "enr:-IO4QDxToTg86pPCK2KvMeVCXC2ADVZWrxXSvNZeaoa0JhShbM5qed69RQz1s1mWEEqJ3aoklo_7EU9iIBcPMVeKlCQBgmlkgnY0iXNlY3AyNTZrMaEDdBHK1Gx6y_zv5DVw5Qb3DtSOMmVHTZO1WSORrF2loL2DdWRwgiMohXdha3UyAw"
}
}
```bash
curl http://localhost:8645/debug/v1/info -s | jq
```

## Finding your discoverable ENR address(es)
Expand Down Expand Up @@ -210,8 +193,4 @@ See our [store configuration tutorial](./configure-store.md) for more.

## Interact with a running nwaku node

A running nwaku node can be interacted with using the [Waku v2 JSON RPC API](https://rfc.vac.dev/spec/16/).

> **Note:** Private and Admin API functionality are disabled by default.
To configure a nwaku node with these enabled,
use the `--rpc-admin:true` and `--rpc-private:true` CLI options.
A running nwaku node can be interacted with using the [REST API](https://github.com/waku-org/nwaku/blob/master/docs/api/rest-api.md).
13 changes: 1 addition & 12 deletions docs/operators/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@ or [configure](./how-to/configure.md) the node for more advanced use cases.

## 3. Interact

A running nwaku node can be interacted with using the [Waku v2 JSON RPC API](https://rfc.vac.dev/spec/16/).

> **Note:** Private and Admin API functionality are disabled by default.
To configure a nwaku node with these enabled,
use the `--rpc-admin:true` and `--rpc-private:true` CLI options.

```bash
curl -d '{"jsonrpc":"2.0","method":"get_waku_v2_debug_v1_info","params":[],"id":1}' -H 'Content-Type: application/json' localhost:8546 -s | jq
```


Or using the [Waku v2 HTTP REST API](../api/v2/rest-api.md):
A running nwaku node can be interacted with using the [REST API](../api/v2/rest-api.md).

> **Note:** REST API functionality is in ALPHA and therefore it is disabled by default. To configure a nwaku node with this enabled, use the `--rest:true` CLI option.

Expand Down
Loading
Loading