fix: store clients with `--store=false` does not install Store Client JSON-RPC API handlers

This commit is contained in:
Lorenzo Delgado 2022-11-15 22:03:06 +01:00 committed by GitHub
parent 36adfa85fc
commit f1ab1475db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 31 deletions

View File

@ -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()

View File

@ -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
info "RPC Server started", address=ta