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 6fa79cec1023395810599f8d8fced18b30bb8610
parent c6b4b370e7ea0bb3643bc679dd1a6dc4625da48e
Author: chris-belcher <chris-belcher@users.noreply.github.com>
Date:   Fri,  8 May 2020 17:34:48 +0100

Change logs to reduce spam and keep logfile small

The aim is to make the debug log file not grow as quickly. Now
there wont be messages printed every heartbeat. Also address_history
and the list of all imported addresses wont be written as they are
really huge and dont add much value.

The info log is also reduced with the aim to make it more useful
for users to watch. They will see incoming transactions.

Diffstat:
Melectrumpersonalserver/server/common.py | 15++++++---------
Melectrumpersonalserver/server/peertopeer.py | 4++--
Melectrumpersonalserver/server/transactionmonitor.py | 20++++----------------
3 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/electrumpersonalserver/server/common.py b/electrumpersonalserver/server/common.py @@ -30,12 +30,10 @@ bestblockhash = [None] def on_heartbeat_listening(txmonitor): logger = logging.getLogger('ELECTRUMPERSONALSERVER') - logger.debug("on heartbeat listening") txmonitor.check_for_updated_txes() def on_heartbeat_connected(rpc, txmonitor, protocol): logger = logging.getLogger('ELECTRUMPERSONALSERVER') - logger.debug("on heartbeat connected") is_tip_updated, header = check_for_new_blockchain_tip(rpc, protocol.are_headers_raw) if is_tip_updated: @@ -61,7 +59,7 @@ def create_server_socket(hostport): def run_electrum_server(rpc, txmonitor, config): logger = logging.getLogger('ELECTRUMPERSONALSERVER') - logger.info("Starting electrum server") + logger.debug("Starting electrum server") hostport = (config.get("electrum-server", "host"), int(config.get("electrum-server", "port"))) @@ -78,7 +76,7 @@ def run_electrum_server(rpc, txmonitor, config): poll_interval_connected = int(config.get("bitcoin-rpc", "poll_interval_connected")) certfile, keyfile = get_certs(config) - logger.info('using cert: {}, key: {}'.format(certfile, keyfile)) + logger.debug('using cert: {}, key: {}'.format(certfile, keyfile)) disable_mempool_fee_histogram = config.getboolean("electrum-server", "disable_mempool_fee_histogram", fallback=False) broadcast_method = config.get("electrum-server", "broadcast_method", @@ -110,7 +108,7 @@ def run_electrum_server(rpc, txmonitor, config): except (ConnectionRefusedError, ssl.SSLError): sock.close() sock = None - logger.info('Electrum connected from ' + str(addr[0])) + logger.debug('Electrum connected from ' + str(addr[0])) def send_reply_fun(reply): line = json.dumps(reply) @@ -144,9 +142,9 @@ def run_electrum_server(rpc, txmonitor, config): on_heartbeat_connected(rpc, txmonitor, protocol) except (IOError, EOFError) as e: if isinstance(e, (EOFError, ConnectionRefusedError)): - logger.info("Electrum wallet disconnected") + logger.debug("Electrum wallet disconnected") else: - logger.error("IOError: " + repr(e)) + logger.debug("IOError: " + repr(e)) try: if sock != None: sock.close() @@ -171,7 +169,6 @@ def get_scriptpubkeys_to_monitor(rpc, config): else: #no label, no addresses imported at all imported_addresses = set() - logger.debug("already-imported addresses = " + str(imported_addresses)) deterministic_wallets = [] for key in config.options("master-public-keys"): @@ -348,7 +345,7 @@ def main(): return logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger, logfilename = logger_config(logger, config) - logger.info('Starting Electrum Personal Server v{}'.format( + logger.info('Starting Electrum Personal Server ' + str( SERVER_VERSION_NUMBER)) logger.info('Logging to ' + logfilename) try: diff --git a/electrumpersonalserver/server/peertopeer.py b/electrumpersonalserver/server/peertopeer.py @@ -92,7 +92,7 @@ class P2PMessageHandler(object): if ((datetime.now() - self.last_message).total_seconds() < KEEPALIVE_TIMEOUT): return - self.logger.info('keepalive timed out, closing') + self.logger.debug('keepalive timed out, closing') p2p.sock.close() else: if ((datetime.now() - self.last_message).total_seconds() @@ -334,7 +334,7 @@ class P2PBroadcastTx(P2PMessageHandler): if hash_id == self.txid: p2p.sock.sendall(p2p.create_message('tx', self.txhex)) self.uploaded_tx = True - self.logger.info("Uploaded transaction via tor to peer at " + self.logger.debug("Uploaded transaction via tor to peer at " + str(p2p.remote_hostport)) ##make sure the packets really got through by sleeping ##some kernels seem to send a RST packet on close() even diff --git a/electrumpersonalserver/server/transactionmonitor.py b/electrumpersonalserver/server/transactionmonitor.py @@ -188,7 +188,6 @@ class TransactionMonitor(object): self.last_known_wallet_txid)) et = time.time() - logger.debug("address_history =\n" + pprint.pformat(address_history)) logger.info("Found " + str(count) + " txes. History built in " + str(et - st) + "sec") self.address_history = address_history @@ -284,8 +283,6 @@ class TransactionMonitor(object): his = self.address_history[ush] self.sort_address_history_list(his) if len(updated_scrhashes) > 0: - logger.debug("new tx address_history =\n" - + pprint.pformat(self.address_history)) logger.debug("unconfirmed txes = " + pprint.pformat(self.unconfirmed_txes)) logger.debug("reorganizable_txes = " @@ -300,7 +297,6 @@ class TransactionMonitor(object): elements_removed = [] elements_added = [] updated_scrhashes = set() - logger.debug("reorganizable_txes = " + str(self.reorganizable_txes)) for reorgable_tx in self.reorganizable_txes: txid, blockhash, height, scrhashes = reorgable_tx tx = self.rpc.call("gettransaction", [txid]) @@ -312,7 +308,7 @@ class TransactionMonitor(object): updated_scrhashes.update(scrhashes) if tx["confirmations"] == 0: #transaction became unconfirmed in a reorg - logger.warning("A transaction was reorg'd out: " + txid) + logger.info("A transaction was reorg'd out: " + txid) elements_removed.append(reorgable_tx) self.unconfirmed_txes[txid].extend(scrhashes) @@ -328,17 +324,17 @@ class TransactionMonitor(object): elif tx["confirmations"] < 0: #tx became conflicted in reorg i.e. a double spend - logger.error("A transaction was double spent! " + txid) + logger.info("A transaction was double spent! " + txid) elements_removed.append(reorgable_tx) elif tx["blockhash"] != blockhash: block = self.rpc.call("getblockheader", [tx["blockhash"]]) if block["height"] == height: #reorg but height is the same - logger.warning("A transaction was reorg'd but still " + + logger.debug("A transaction was reorg'd but still " + "confirmed at same height: " + txid) continue #reorged but still confirmed at a different height updated_scrhashes.update(scrhashes) - logger.warning("A transaction was reorg'd but still confirmed" + logger.debug("A transaction was reorg'd but still confirmed" + " to a new block and different height: " + txid) #update history with the new height for scrhash in scrhashes: @@ -368,8 +364,6 @@ class TransactionMonitor(object): def check_for_confirmations(self): logger = self.logger tx_scrhashes_removed_from_mempool = [] - logger.debug("unconfirmed_txes = " - + pprint.pformat(self.unconfirmed_txes)) for uc_txid, scrhashes in self.unconfirmed_txes.items(): tx = self.rpc.call("gettransaction", [uc_txid]) logger.debug("uc_txid=" + uc_txid + " => " + str(tx)) @@ -406,8 +400,6 @@ class TransactionMonitor(object): tx_request_count = 2 max_attempts = int(math.log(MAX_TX_REQUEST_COUNT, 2)) for i in range(max_attempts): - logger.debug("listtransactions tx_request_count=" - + str(tx_request_count)) ##how listtransactions works ##skip and count parameters take most-recent txes first ## so skip=0 count=1 will return the most recent tx @@ -433,13 +425,9 @@ class TransactionMonitor(object): #TODO low priority: handle a user getting more than 255 new # transactions in 15 seconds - logger.debug("recent tx index = " + str(recent_tx_index) + " ret = " + - str([(t["txid"], t.get("address", None)) for t in ret])) if len(ret) > 0: self.last_known_wallet_txid = (ret[0]["txid"], ret[0].get("address", None)) - logger.debug("last_known_wallet_txid = " + str( - self.last_known_wallet_txid)) assert(recent_tx_index != -1) if recent_tx_index == 0: return set()