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, stew/shims/net as stewNet, json_rpc/rpcserver,
libp2p/errors, libp2p/errors,
libp2p/peerstore, libp2p/peerstore,
# Waku v1 imports eth/[keys, p2p],
eth/[keys, p2p], eth/common/utils, eth/common/utils,
eth/p2p/[enode, peer_pool], eth/p2p/[enode, peer_pool],
eth/p2p/discoveryv5/random2, eth/p2p/discoveryv5/random2
import
# Waku v1 imports
../../waku/v1/protocol/waku_protocol, ../../waku/v1/protocol/waku_protocol,
# Waku v2 imports # Waku v2 imports
libp2p/crypto/crypto, libp2p/crypto/crypto,
@ -24,6 +26,10 @@ import
../../waku/v2/protocol/waku_message, ../../waku/v2/protocol/waku_message,
../../waku/v2/node/waku_node, ../../waku/v2/node/waku_node,
../../waku/v2/node/peer_manager/peer_manager, ../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/node/jsonrpc/[debug_api,
filter_api,
relay_api,
store_api],
# Common cli config # Common cli config
./config_bridge ./config_bridge
@ -321,6 +327,23 @@ proc stop*(bridge: WakuBridge) {.async.} =
bridge.started = false bridge.started = false
await bridge.nodev2.stop() 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 {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
when isMainModule: when isMainModule:
import import
@ -329,28 +352,7 @@ when isMainModule:
../../waku/whisper/whispernodes, ../../waku/whisper/whispernodes,
../../waku/v1/node/rpc/wakusim, ../../waku/v1/node/rpc/wakusim,
../../waku/v1/node/rpc/waku, ../../waku/v1/node/rpc/waku,
../../waku/v1/node/rpc/key_storage, ../../waku/v1/node/rpc/key_storage
../../waku/v2/node/jsonrpc/[debug_api,
filter_api,
relay_api,
store_api]
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 let
rng = keys.newRng() rng = keys.newRng()
@ -443,21 +445,25 @@ when isMainModule:
waitFor connectToNodes(bridge.nodev2, conf.staticnodesV2) waitFor connectToNodes(bridge.nodev2, conf.staticnodesV2)
if conf.storenode != "": if conf.storenode != "":
mountStoreClient(bridge.nodev2, store=nil)
setStorePeer(bridge.nodev2, conf.storenode) setStorePeer(bridge.nodev2, conf.storenode)
if conf.filternode != "": if conf.filternode != "":
waitFor mountFilterClient(bridge.nodev2)
setFilterPeer(bridge.nodev2, conf.filternode) setFilterPeer(bridge.nodev2, conf.filternode)
if conf.rpc: if conf.rpc:
let ta = initTAddress(conf.rpcAddress, let ta = initTAddress(conf.rpcAddress,
Port(conf.rpcPort + conf.portsShift)) Port(conf.rpcPort + conf.portsShift))
var rpcServer = newRpcHttpServer([ta]) var rpcServer = newRpcHttpServer([ta])
# Waku v1 RPC # Waku v1 RPC
let keys = newKeyStorage() let keys = newKeyStorage()
setupWakuRPC(bridge.nodev1, keys, rpcServer, rng) setupWakuRPC(bridge.nodev1, keys, rpcServer, rng)
setupWakuSimRPC(bridge.nodev1, rpcServer) setupWakuSimRPC(bridge.nodev1, rpcServer)
# Waku v2 rpc # Waku v2 rpc
startV2Rpc(bridge.nodev2, rpcServer, conf) setupV2Rpc(bridge.nodev2, rpcServer, conf)
rpcServer.start() rpcServer.start()

View File

@ -25,7 +25,7 @@ logScope:
proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf) proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf)
{.raises: [Defect, RpcBindError].} = {.raises: [RpcBindError].} =
let let
ta = initTAddress(rpcIp, rpcPort) ta = initTAddress(rpcIp, rpcPort)
@ -33,8 +33,9 @@ proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf:
installDebugApiHandlers(node, rpcServer) installDebugApiHandlers(node, rpcServer)
# TODO: Move to setup protocols proc
if conf.relay: if conf.relay:
let topicCache = newTable[string, seq[WakuMessage]]() let topicCache = newTable[PubsubTopic, seq[WakuMessage]]()
installRelayApiHandlers(node, rpcServer, topicCache) installRelayApiHandlers(node, rpcServer, topicCache)
if conf.rpcPrivate: if conf.rpcPrivate:
@ -42,15 +43,17 @@ proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf:
# is backwards compatible with Waku v1. # is backwards compatible with Waku v1.
installPrivateApiHandlers(node, rpcServer, topicCache) installPrivateApiHandlers(node, rpcServer, topicCache)
if conf.filter: # TODO: Move to setup protocols proc
if conf.filternode != "":
let messageCache = newTable[ContentTopic, seq[WakuMessage]]() let messageCache = newTable[ContentTopic, seq[WakuMessage]]()
installFilterApiHandlers(node, rpcServer, messageCache) installFilterApiHandlers(node, rpcServer, messageCache)
if conf.store: # TODO: Move to setup protocols proc
if conf.storenode != "":
installStoreApiHandlers(node, rpcServer) installStoreApiHandlers(node, rpcServer)
if conf.rpcAdmin: if conf.rpcAdmin:
installAdminApiHandlers(node, rpcServer) installAdminApiHandlers(node, rpcServer)
rpcServer.start() rpcServer.start()
info "RPC Server started", ta info "RPC Server started", address=ta