Sensible default maximum difficulty

Fixes #144
This commit is contained in:
mailchuck 2015-12-15 12:14:21 +01:00
parent 0c817755f2
commit ce764b6c95
Signed by untrusted user who does not match committer: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 36 additions and 1 deletions

View File

@ -326,7 +326,13 @@ class sqlThread(threading.Thread):
shared.config.set('bitmessagesettings', 'maxdownloadrate', '0')
shared.config.set('bitmessagesettings', 'maxuploadrate', '0')
shared.config.set('bitmessagesettings', 'settingsversion', '10')
shared.writeKeysFile()
shared.writeKeysFile()
# sanity check
if shared.config.getint('bitmessagesettings', 'maxacceptablenoncetrialsperbyte') == 0:
shared.config.set('bitmessagesettings','maxacceptablenoncetrialsperbyte', str(shared.ridiculousDifficulty * shared.networkDefaultProofOfWorkNonceTrialsPerByte))
if shared.config.getint('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0:
shared.config.set('bitmessagesettings','maxacceptablepayloadlengthextrabytes', str(shared.ridiculousDifficulty * shared.networkDefaultPayloadLengthExtraBytes))
# The format of data stored in the pubkeys table has changed. Let's
# clear it, and the pubkeys from inventory, so that they'll be re-downloaded.

View File

@ -133,6 +133,31 @@ def _doGPUPoW(target, initialHash):
raise Exception("GPU did not calculate correctly.")
logger.debug("GPU PoW done")
return [trialValue, nonce]
def estimate(difficulty, format = False):
ret = difficulty / 10
if ret < 1:
ret = 1
if format:
out = str(int(ret)) + " seconds"
if ret > 60:
ret /= 60
out = str(int(ret)) + " minutes"
if ret > 60:
ret /= 60
out = str(int(ret)) + " hours"
if ret > 24:
ret /= 24
out = str(int(ret)) + " days"
if ret > 7:
out = str(int(ret)) + " weeks"
if ret > 31:
out = str(int(ret)) + " months"
if ret > 366:
ret /= 366
out = str(int(ret)) + " years"
else:
return ret
def run(target, initialHash):
target = int(target)

View File

@ -91,6 +91,10 @@ objectProcessorQueue = Queue.Queue(
) # receiveDataThreads dump objects they hear on the network into this queue to be processed.
streamsInWhichIAmParticipating = {}
# sanity check, prevent doing ridiculous PoW
# 20 million PoWs equals approximately 2 days on dev's dual R9 290
ridiculousDifficulty = 20000000
#If changed, these values will cause particularly unexpected behavior: You won't be able to either send or receive messages because the proof of work you do (or demand) won't match that done or demanded by others. Don't change them!
networkDefaultProofOfWorkNonceTrialsPerByte = 1000 #The amount of work that should be performed (and demanded) per byte of the payload.
networkDefaultPayloadLengthExtraBytes = 1000 #To make sending short messages a little more difficult, this value is added to the payload length for use in calculating the proof of work target.