work on using dynamic/configurable POW
parent
4e86604692
commit
34aa892b65
|
@ -269,7 +269,8 @@ class OnionrCrypto:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
difficulty = math.floor(dataLen / 1000000)
|
difficulty = math.floor(dataLen / 1000000)
|
||||||
|
if difficulty < int(config.get('general.minimum_block_pow')):
|
||||||
|
difficulty = int(config.get('general.minimum_block_pow'))
|
||||||
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
||||||
puzzle = mainHash[:difficulty]
|
puzzle = mainHash[:difficulty]
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
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
|
import core, config
|
||||||
|
|
||||||
class DataPOW:
|
class DataPOW:
|
||||||
def __init__(self, data, forceDifficulty=0, threadCount = 5):
|
def __init__(self, data, forceDifficulty=0, threadCount = 5):
|
||||||
|
@ -27,6 +27,7 @@ class DataPOW:
|
||||||
self.difficulty = 0
|
self.difficulty = 0
|
||||||
self.data = data
|
self.data = data
|
||||||
self.threadCount = threadCount
|
self.threadCount = threadCount
|
||||||
|
config.reload()
|
||||||
|
|
||||||
if forceDifficulty == 0:
|
if forceDifficulty == 0:
|
||||||
dataLen = sys.getsizeof(data)
|
dataLen = sys.getsizeof(data)
|
||||||
|
@ -128,7 +129,7 @@ class POW:
|
||||||
dataLen = len(data) + len(json.dumps(metadata))
|
dataLen = len(data) + len(json.dumps(metadata))
|
||||||
self.difficulty = math.floor(dataLen / 1000000)
|
self.difficulty = math.floor(dataLen / 1000000)
|
||||||
if self.difficulty <= 2:
|
if self.difficulty <= 2:
|
||||||
self.difficulty = 4
|
self.difficulty = int(config.get('general.minimum_block_pow'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.data = self.data.encode()
|
self.data = self.data.encode()
|
||||||
|
@ -144,7 +145,7 @@ class POW:
|
||||||
for i in range(max(1, threadCount)):
|
for i in range(max(1, threadCount)):
|
||||||
t = threading.Thread(name = 'thread%s' % i, target = self.pow, args = (True,myCore))
|
t = threading.Thread(name = 'thread%s' % i, target = self.pow, args = (True,myCore))
|
||||||
t.start()
|
t.start()
|
||||||
|
self.myCore = myCore
|
||||||
return
|
return
|
||||||
|
|
||||||
def pow(self, reporting = False, myCore = None):
|
def pow(self, reporting = False, myCore = None):
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"general" : {
|
"general" : {
|
||||||
"dev_mode": true,
|
"dev_mode": true,
|
||||||
"display_header" : true,
|
"display_header" : true,
|
||||||
|
"minimum_block_pow": 5,
|
||||||
|
|
||||||
"direct_connect" : {
|
"direct_connect" : {
|
||||||
"respond" : true,
|
"respond" : true,
|
||||||
|
|
Loading…
Reference in New Issue