electrum-personal-server

Maximally lightweight electrum server for a single user
git clone https://git.parazyd.org/electrum-personal-server
Log | Files | Refs | README

commit f6613b86f0745a1f00047c971d5fdeb6c54ef351
parent 4a9f39dd8f28c7928f82d92d82b5694038b172d8
Author: chris-belcher <chris-belcher@users.noreply.github.com>
Date:   Wed, 10 Apr 2019 19:46:45 +0100

Suggest disabling mempool feature if load too large

Diffstat:
Mconfig.cfg_sample | 8+++++---
Melectrumpersonalserver/server/common.py | 22+++++++++++++++-------
2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/config.cfg_sample b/config.cfg_sample @@ -12,6 +12,7 @@ #my_second_wallet = xpubanotherkey # Multisig wallets use format `required-signatures [list of master pub keys]` +# this example is a 2-of-3 multisig wallet #multisig_wallet = 2 xpub661MyMwAqRbcFseXCwRdRVkhVuzEiskg4QUp5XpUdNf2uGXvQmnD4zcofZ1MN6Fo8PjqQ5cemJQ39f7RTwDVVputHMFjPUn8VRp2pJQMgEF xpub661MyMwAqRbcFseXCwRdRVkhVuzEiskg4QUp5XpUdNf2uGXvQmnD4zcofZ1MN6Fo8PjqQ5cemJQ39f7RTwDVVputHMFjPUn8VRp2pJQMgEF xpub661MyMwAqRbcFseXCwRdRVkhVuzEiskg4QUp5XpUdNf2uGXvQmnD4zcofZ1MN6Fo8PjqQ5cemJQ39f7RTwDVVputHMFjPUn8VRp2pJQMgEF [watch-only-addresses] @@ -71,6 +72,7 @@ ip_whitelist = * certfile = certs/cert.crt keyfile = certs/cert.key -# Option for disabling the fee histogram -# This is useful on low powered devices at times when the mempool is large -disable_fee_histogram = false +# Option for disabling the fee histogram calculation +# It improves server responsiveness but stops mempool-based Electrum features +# This is useful on low powered devices at times when the node mempool is large +disable_mempool_fee_histogram = false diff --git a/electrumpersonalserver/server/common.py b/electrumpersonalserver/server/common.py @@ -105,7 +105,7 @@ def on_disconnect(txmonitor): subscribed_to_headers[0] = False txmonitor.unsubscribe_all_addresses() -def handle_query(sock, line, rpc, txmonitor, disable_fee_histogram): +def handle_query(sock, line, rpc, txmonitor, disable_mempool_fee_histogram): logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger.debug("=> " + line) try: @@ -241,6 +241,7 @@ def handle_query(sock, line, rpc, txmonitor, disable_fee_histogram): elif method == "blockchain.transaction.broadcast": if not rpc.call("getnetworkinfo", [])["localrelay"]: result = "Broadcast disabled when using blocksonly" + logger.info("Transaction broadcasting disabled when blocksonly") else: try: result = rpc.call("sendrawtransaction", [query["params"][0]]) @@ -248,11 +249,18 @@ def handle_query(sock, line, rpc, txmonitor, disable_fee_histogram): result = str(e) send_response(sock, query, result) elif method == "mempool.get_fee_histogram": - if disable_fee_histogram: + if disable_mempool_fee_histogram: result = [[0, 0]] logger.debug("fee histogram disabled, sending back empty mempool") else: + st = time.time() mempool = rpc.call("getrawmempool", [True]) + et = time.time() + MEMPOOL_WARNING_DURATION = 10 #seconds + if et - st > MEMPOOL_WARNING_DURATION: + logger.warning("Mempool very large resulting in slow response" + + " by server. Consider setting " + + "`disable_mempool_fee_histogram = true`") #algorithm copied from the relevant place in ElectrumX #https://github.com/kyuupichan/electrumx/blob/e92c9bd4861c1e35989ad2773d33e01219d33280/server/mempool.py fee_hist = defaultdict(int) @@ -414,7 +422,7 @@ def create_server_socket(hostport): def run_electrum_server(rpc, txmonitor, hostport, ip_whitelist, poll_interval_listening, poll_interval_connected, certfile, keyfile, - disable_fee_histogram): + disable_mempool_fee_histogram): logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger.info("Starting electrum server") server_sock = create_server_socket(hostport) @@ -455,7 +463,7 @@ def run_electrum_server(rpc, txmonitor, hostport, ip_whitelist, recv_buffer = recv_buffer[lb + 1:] lb = recv_buffer.find(b'\n') handle_query(sock, line.decode("utf-8"), rpc, - txmonitor, disable_fee_histogram) + txmonitor, disable_mempool_fee_histogram) except socket.timeout: on_heartbeat_connected(sock, rpc, txmonitor) except (IOError, EOFError) as e: @@ -709,13 +717,13 @@ def main(): poll_interval_connected = int(config.get("bitcoin-rpc", "poll_interval_connected")) certfile, keyfile = get_certs(config) - disable_fee_histogram = config.getboolean("electrum-server", - "disable_fee_histogram", fallback=False) + disable_mempool_fee_histogram = config.getboolean("electrum-server", + "disable_mempool_fee_histogram", fallback=False) try: run_electrum_server(rpc, txmonitor, hostport, ip_whitelist, poll_interval_listening, poll_interval_connected, certfile, keyfile, - disable_fee_histogram) + disable_mempool_fee_histogram) except KeyboardInterrupt: logger.info('Received KeyboardInterrupt, quitting')