From a3900113bb946a3a6b31678a2dc385684f57a70f Mon Sep 17 00:00:00 2001 From: Wizz Wallet <153743376+wizz-wallet-dev@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:22:05 +0800 Subject: [PATCH] Fix RPC endpoint calls (#226) RPC handlers were accidentally dropped during the session refactoring. Fixes #223 --- electrumx/server/session/rpc_session.py | 29 +++++++++++++++++++++ electrumx/server/session/session_base.py | 17 +++--------- electrumx/server/session/session_manager.py | 7 +++-- electrumx_rpc | 3 ++- 4 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 electrumx/server/session/rpc_session.py diff --git a/electrumx/server/session/rpc_session.py b/electrumx/server/session/rpc_session.py new file mode 100644 index 00000000..7685fd60 --- /dev/null +++ b/electrumx/server/session/rpc_session.py @@ -0,0 +1,29 @@ +from electrumx.server.session.session_base import SessionBase + + +class LocalRPC(SessionBase): + """A local TCP RPC server session.""" + + processing_timeout = 10**9 # disable timeouts + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.client = "RPC" + self.connection.max_response_size = 0 + self.request_handlers = { + "getinfo": self.session_mgr.rpc_getinfo, + "groups": self.session_mgr.rpc_groups, + "peers": self.session_mgr.rpc_peers, + "sessions": self.session_mgr.rpc_sessions, + "stop": self.session_mgr.rpc_stop, + "disconnect": self.session_mgr.rpc_disconnect, + "add_peer": self.session_mgr.rpc_add_peer, + "daemon_url": self.session_mgr.rpc_daemon_url, + "query": self.session_mgr.rpc_query, + "reorg": self.session_mgr.rpc_reorg, + "debug_memusage_list_all_objects": self.session_mgr.rpc_debug_memusage_list_all_objects, + "debug_memusage_get_random_backref_chain": self.session_mgr.rpc_debug_memusage_get_random_backref_chain, + } + + def protocol_version_string(self): + return "RPC" diff --git a/electrumx/server/session/session_base.py b/electrumx/server/session/session_base.py index 0a6dae68..5991c805 100644 --- a/electrumx/server/session/session_base.py +++ b/electrumx/server/session/session_base.py @@ -73,6 +73,9 @@ def __init__( maybe_bump_cost=self.bump_cost, ) + def protocol_version_string(self): + raise NotImplementedError + async def notify(self, touched, height_changed): pass @@ -138,17 +141,3 @@ async def handle_request(self, request): return await coro else: return coro - - -class LocalRPC(SessionBase): - """A local TCP RPC server session.""" - - processing_timeout = 10**9 # disable timeouts - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.client = "RPC" - self.connection.max_response_size = 0 - - def protocol_version_string(self): - return "RPC" diff --git a/electrumx/server/session/session_manager.py b/electrumx/server/session/session_manager.py index b077649d..87dd33dd 100644 --- a/electrumx/server/session/session_manager.py +++ b/electrumx/server/session/session_manager.py @@ -1,5 +1,4 @@ import asyncio -import copy import math import os import ssl @@ -8,7 +7,7 @@ from collections import defaultdict from functools import partial from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network -from typing import TYPE_CHECKING, Dict, List, Optional, Type +from typing import TYPE_CHECKING, Dict, List, Optional import attr import pylru @@ -46,7 +45,7 @@ from electrumx.server.peers import PeerManager from electrumx.server.session import BAD_REQUEST, DAEMON_ERROR from electrumx.server.session.http_session import HttpSession -from electrumx.server.session.session_base import LocalRPC +from electrumx.server.session.rpc_session import LocalRPC from electrumx.server.session.util import SESSION_PROTOCOL_MAX, non_negative_integer from electrumx.version import electrumx_version @@ -174,7 +173,7 @@ async def _start_servers(self, services): else: sslc = None if service.protocol == "rpc": - session_class = Type["LocalRPC"] + session_class = LocalRPC else: session_class = self.env.coin.SESSIONCLS if service.protocol in ("ws", "wss"): diff --git a/electrumx_rpc b/electrumx_rpc index 73f6a5ce..09205a6f 100755 --- a/electrumx_rpc +++ b/electrumx_rpc @@ -34,7 +34,6 @@ simple_commands = { session_commands = { "disconnect": "Disconnect sessions", - "log": "Control logging of sessions", } other_commands = { @@ -132,6 +131,8 @@ def main(): if port is None: port = int(environ.get("RPC_PORT", 8000)) method = args.pop("command") + if not method: + raise Exception("Must specify a method") timeout = args.pop("timeout") # aiorpcX makes this so easy...