From fb243dd8e974ba641fdbe7ab36fe3a76a4930d87 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Wed, 25 Sep 2024 04:05:49 +0300 Subject: [PATCH] Trying to support the PoW interruption --- minode/proofofwork.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/minode/proofofwork.py b/minode/proofofwork.py index c878b2a..4a63b0a 100644 --- a/minode/proofofwork.py +++ b/minode/proofofwork.py @@ -19,8 +19,13 @@ def _pow_worker(target, initial_hash, q): while trial_value > target: nonce += 1 - trial_value = struct.unpack('>Q', hashlib.sha512(hashlib.sha512( - struct.pack('>Q', nonce) + initial_hash).digest()).digest()[:8])[0] + try: + trial_value = struct.unpack('>Q', hashlib.sha512(hashlib.sha512( + struct.pack('>Q', nonce) + initial_hash + ).digest()).digest()[:8])[0] + except KeyboardInterrupt: + q.put(None) + return q.put(struct.pack('>Q', nonce)) @@ -36,6 +41,11 @@ def _worker(obj): nonce = q.get() p.join() + if nonce is None: + if not shared.shutting_down: + logging.warning('Got None nonce from _pow_worker!') + return + logging.debug( 'Finished doing POW, nonce: %s, time: %ss', nonce, time.time() - t) obj = structure.Object(