From f1ab1475dbce5d49b9164ef5597167900280ed2e Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Tue, 15 Nov 2022 22:03:06 +0100 Subject: [PATCH] fix: store clients with `--store=false` does not install Store Client JSON-RPC API handlers --- apps/wakubridge/wakubridge.nim | 58 ++++++++++++++------------ apps/wakunode2/wakunode2_setup_rpc.nim | 13 +++--- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/apps/wakubridge/wakubridge.nim b/apps/wakubridge/wakubridge.nim index fc208b0d0..2258d2880 100644 --- a/apps/wakubridge/wakubridge.nim +++ b/apps/wakubridge/wakubridge.nim @@ -11,10 +11,12 @@ import stew/shims/net as stewNet, json_rpc/rpcserver, libp2p/errors, libp2p/peerstore, - # Waku v1 imports - eth/[keys, p2p], eth/common/utils, + eth/[keys, p2p], + eth/common/utils, eth/p2p/[enode, peer_pool], - eth/p2p/discoveryv5/random2, + eth/p2p/discoveryv5/random2 +import + # Waku v1 imports ../../waku/v1/protocol/waku_protocol, # Waku v2 imports libp2p/crypto/crypto, @@ -24,6 +26,10 @@ import ../../waku/v2/protocol/waku_message, ../../waku/v2/node/waku_node, ../../waku/v2/node/peer_manager/peer_manager, + ../../waku/v2/node/jsonrpc/[debug_api, + filter_api, + relay_api, + store_api], # Common cli config ./config_bridge @@ -320,6 +326,23 @@ proc start*(bridge: WakuBridge) {.async.} = proc stop*(bridge: WakuBridge) {.async.} = bridge.started = false await bridge.nodev2.stop() + + +proc setupV2Rpc(node: WakuNode, rpcServer: RpcHttpServer, conf: WakuNodeConf) = + installDebugApiHandlers(node, rpcServer) + + # Install enabled API handlers: + if conf.relay: + let topicCache = newTable[PubsubTopic, seq[WakuMessage]]() + installRelayApiHandlers(node, rpcServer, topicCache) + + if conf.filternode != "": + let messageCache = newTable[ContentTopic, seq[WakuMessage]]() + installFilterApiHandlers(node, rpcServer, messageCache) + + if conf.storenode != "": + installStoreApiHandlers(node, rpcServer) + {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError when isMainModule: @@ -329,29 +352,8 @@ when isMainModule: ../../waku/whisper/whispernodes, ../../waku/v1/node/rpc/wakusim, ../../waku/v1/node/rpc/waku, - ../../waku/v1/node/rpc/key_storage, - ../../waku/v2/node/jsonrpc/[debug_api, - filter_api, - relay_api, - store_api] + ../../waku/v1/node/rpc/key_storage - proc startV2Rpc(node: WakuNode, rpcServer: RpcHttpServer, conf: WakuNodeConf) = - installDebugApiHandlers(node, rpcServer) - - # Install enabled API handlers: - if conf.relay: - let topicCache = newTable[string, seq[WakuMessage]]() - installRelayApiHandlers(node, rpcServer, topicCache) - - if conf.filter: - let messageCache = newTable[ContentTopic, seq[WakuMessage]]() - installFilterApiHandlers(node, rpcServer, messageCache) - - if conf.store: - installStoreApiHandlers(node, rpcServer) - - rpcServer.start() - let rng = keys.newRng() conf = WakuNodeConf.load() @@ -443,21 +445,25 @@ when isMainModule: waitFor connectToNodes(bridge.nodev2, conf.staticnodesV2) if conf.storenode != "": + mountStoreClient(bridge.nodev2, store=nil) setStorePeer(bridge.nodev2, conf.storenode) if conf.filternode != "": + waitFor mountFilterClient(bridge.nodev2) setFilterPeer(bridge.nodev2, conf.filternode) if conf.rpc: let ta = initTAddress(conf.rpcAddress, Port(conf.rpcPort + conf.portsShift)) var rpcServer = newRpcHttpServer([ta]) + # Waku v1 RPC let keys = newKeyStorage() setupWakuRPC(bridge.nodev1, keys, rpcServer, rng) setupWakuSimRPC(bridge.nodev1, rpcServer) + # Waku v2 rpc - startV2Rpc(bridge.nodev2, rpcServer, conf) + setupV2Rpc(bridge.nodev2, rpcServer, conf) rpcServer.start() diff --git a/apps/wakunode2/wakunode2_setup_rpc.nim b/apps/wakunode2/wakunode2_setup_rpc.nim index 04173ff8e..7eaa320a0 100644 --- a/apps/wakunode2/wakunode2_setup_rpc.nim +++ b/apps/wakunode2/wakunode2_setup_rpc.nim @@ -25,7 +25,7 @@ logScope: proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf) - {.raises: [Defect, RpcBindError].} = + {.raises: [RpcBindError].} = let ta = initTAddress(rpcIp, rpcPort) @@ -33,8 +33,9 @@ proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: installDebugApiHandlers(node, rpcServer) + # TODO: Move to setup protocols proc if conf.relay: - let topicCache = newTable[string, seq[WakuMessage]]() + let topicCache = newTable[PubsubTopic, seq[WakuMessage]]() installRelayApiHandlers(node, rpcServer, topicCache) if conf.rpcPrivate: @@ -42,15 +43,17 @@ proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: # is backwards compatible with Waku v1. installPrivateApiHandlers(node, rpcServer, topicCache) - if conf.filter: + # TODO: Move to setup protocols proc + if conf.filternode != "": let messageCache = newTable[ContentTopic, seq[WakuMessage]]() installFilterApiHandlers(node, rpcServer, messageCache) - if conf.store: + # TODO: Move to setup protocols proc + if conf.storenode != "": installStoreApiHandlers(node, rpcServer) if conf.rpcAdmin: installAdminApiHandlers(node, rpcServer) rpcServer.start() - info "RPC Server started", ta \ No newline at end of file + info "RPC Server started", address=ta \ No newline at end of file