From 8c63d6c205242d732d818931fba95b9921a9b806 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 28 Oct 2018 14:01:57 -0500 Subject: [PATCH] work on improving block sync --- onionr/communicator2.py | 1 + onionr/onionrcrypto.py | 2 ++ onionr/onionrproofs.py | 23 +++++++++++++++++++++++ onionr/static-data/default_config.json | 3 ++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 19b4db31..fe4fb1ef 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -180,6 +180,7 @@ class OnionrCommunicatorDaemon: if not i in existingBlocks: # if block does not exist on disk and is not already in block queue if i not in self.blockQueue and not self._core._blacklist.inBlacklist(i): + # TODO ensure block starts with minimum difficulty before adding to queue self.blockQueue.append(i) # add blocks to download queue self.decrementThreadCount('lookupBlocks') return diff --git a/onionr/onionrcrypto.py b/onionr/onionrcrypto.py index c717935c..1105d844 100644 --- a/onionr/onionrcrypto.py +++ b/onionr/onionrcrypto.py @@ -24,6 +24,8 @@ if sys.version_info[0] == 3 and sys.version_info[1] < 6: from dependencies import secrets elif sys.version_info[0] == 3 and sys.version_info[1] >= 6: import secrets +import config +config.reload() class OnionrCrypto: def __init__(self, coreInstance): diff --git a/onionr/onionrproofs.py b/onionr/onionrproofs.py index 0288343b..6c5045d0 100644 --- a/onionr/onionrproofs.py +++ b/onionr/onionrproofs.py @@ -20,6 +20,29 @@ import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger, sys, base64, json import core, config +config.reload() + +def getHashDifficulty(h): + ''' + Return the amount of leading zeroes in a hex hash string (h) + ''' + difficulty = 0 + assert type(h) is str + for character in h: + if character == '0': + difficulty += 1 + return difficulty + +def hashMeetsDifficulty(h): + ''' + Return bool for a hash string to see if it meets pow difficulty defined in config + ''' + hashDifficulty = getHashDifficulty(h) + expected = int(config.get('minimum_block_pow')) + if hashDifficulty >= expected: + return True + else: + return False class DataPOW: def __init__(self, data, forceDifficulty=0, threadCount = 5): diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 3841b05c..768bb8ce 100644 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -2,7 +2,8 @@ "general" : { "dev_mode": true, "display_header" : true, - "minimum_block_pow": 5, + "minimum_block_pow": 6, + "minimum_send_pow": 6, "direct_connect" : { "respond" : true,