work on improving block sync

master
Kevin Froman 2018-10-28 14:01:57 -05:00
parent 34aa892b65
commit 8c63d6c205
4 changed files with 28 additions and 1 deletions

View File

@ -180,6 +180,7 @@ class OnionrCommunicatorDaemon:
if not i in existingBlocks: if not i in existingBlocks:
# if block does not exist on disk and is not already in block queue # 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): 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.blockQueue.append(i) # add blocks to download queue
self.decrementThreadCount('lookupBlocks') self.decrementThreadCount('lookupBlocks')
return return

View File

@ -24,6 +24,8 @@ if sys.version_info[0] == 3 and sys.version_info[1] < 6:
from dependencies import secrets from dependencies import secrets
elif sys.version_info[0] == 3 and sys.version_info[1] >= 6: elif sys.version_info[0] == 3 and sys.version_info[1] >= 6:
import secrets import secrets
import config
config.reload()
class OnionrCrypto: class OnionrCrypto:
def __init__(self, coreInstance): def __init__(self, coreInstance):

View File

@ -20,6 +20,29 @@
import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger, sys, base64, json import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger, sys, base64, json
import core, config 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: class DataPOW:
def __init__(self, data, forceDifficulty=0, threadCount = 5): def __init__(self, data, forceDifficulty=0, threadCount = 5):

View File

@ -2,7 +2,8 @@
"general" : { "general" : {
"dev_mode": true, "dev_mode": true,
"display_header" : true, "display_header" : true,
"minimum_block_pow": 5, "minimum_block_pow": 6,
"minimum_send_pow": 6,
"direct_connect" : { "direct_connect" : {
"respond" : true, "respond" : true,