Skip to content

Commit 713ed89

Browse files
committed
Bugfix: infinite loop if our max acceptable difficulty is too low
1 parent fdb0d1e commit 713ed89

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/bitmessageqt/__init__.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,12 +2347,31 @@ def click_actionSettings(self):
23472347
if float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) >= 1:
23482348
shared.config.set('bitmessagesettings', 'defaultpayloadlengthextrabytes', str(int(float(
23492349
self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes)))
2350+
2351+
acceptableDifficultyChanged = False
2352+
23502353
if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) == 0:
2351-
shared.config.set('bitmessagesettings', 'maxacceptablenoncetrialsperbyte', str(int(float(
2352-
self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) * shared.networkDefaultProofOfWorkNonceTrialsPerByte)))
2354+
if shared.config.get('bitmessagesettings','maxacceptablenoncetrialsperbyte') != str(int(float(
2355+
self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) * shared.networkDefaultProofOfWorkNonceTrialsPerByte)):
2356+
# the user changed the max acceptable total difficulty
2357+
acceptableDifficultyChanged = True
2358+
shared.config.set('bitmessagesettings', 'maxacceptablenoncetrialsperbyte', str(int(float(
2359+
self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) * shared.networkDefaultProofOfWorkNonceTrialsPerByte)))
23532360
if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0:
2354-
shared.config.set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float(
2355-
self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes)))
2361+
if shared.config.get('bitmessagesettings','maxacceptablepayloadlengthextrabytes') != str(int(float(
2362+
self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes)):
2363+
# the user changed the max acceptable small message difficulty
2364+
acceptableDifficultyChanged = True
2365+
shared.config.set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float(
2366+
self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes)))
2367+
if acceptableDifficultyChanged:
2368+
# It might now be possible to send msgs which were previously marked as toodifficult.
2369+
# Let us change them to 'msgqueued'. The singleWorker will try to send them and will again
2370+
# mark them as toodifficult if the receiver's required difficulty is still higher than
2371+
# we are willing to do.
2372+
sqlExecute('''UPDATE sent SET status='msgqueued' WHERE status='toodifficult' ''')
2373+
shared.workerQueue.put(('sendmessage', ''))
2374+
23562375
#start:UI setting to stop trying to send messages after X days/months
23572376
# I'm open to changing this UI to something else if someone has a better idea.
23582377
if ((self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')):#We need to handle this special case. Bitmessage has its default behavior. The input is blank/blank

src/class_singleWorker.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,9 @@ def sendBroadcast(self):
515515
def sendMsg(self):
516516
while True: # while we have a msg that needs some work
517517

518-
# Select just one msg that needs work. We'll get a msg
519-
# which is ready to be sent or a msg which we have sent in
520-
# the last 28 days which were previously marked
521-
# as 'toodifficult'. If the user has raised the maximum acceptable
522-
# difficulty then those msgs may now be sendable.
518+
# Select just one msg that needs work.
523519
queryreturn = sqlQuery(
524-
'''SELECT toaddress, toripe, fromaddress, subject, message, ackdata, status FROM sent WHERE (status='msgqueued' or status='doingmsgpow' or status='forcepow' or (status='toodifficult' and lastactiontime>?)) and folder='sent' LIMIT 1''',
525-
int(time.time()) - 2419200)
520+
'''SELECT toaddress, toripe, fromaddress, subject, message, ackdata, status FROM sent WHERE (status='msgqueued' or status='doingmsgpow' or status='forcepow') and folder='sent' LIMIT 1''')
526521
if len(queryreturn) == 0: # if there is no work to do then
527522
break # break out of this sendMsg loop and
528523
# wait for something to get put in the shared.workerQueue.
@@ -717,7 +712,7 @@ def sendMsg(self):
717712
sqlExecute(
718713
'''UPDATE sent SET status='toodifficult' WHERE ackdata=? ''',
719714
ackdata)
720-
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, tr.translateText("MainWindow", "Problem: The work demanded by the recipient (%1 and %2) is more difficult than you are willing to do.").arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte) / shared.networkDefaultProofOfWorkNonceTrialsPerByte)).arg(str(float(
715+
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (ackdata, tr.translateText("MainWindow", "Problem: The work demanded by the recipient (%1 and %2) is more difficult than you are willing to do. %3").arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte) / shared.networkDefaultProofOfWorkNonceTrialsPerByte)).arg(str(float(
721716
requiredPayloadLengthExtraBytes) / shared.networkDefaultPayloadLengthExtraBytes)).arg(l10n.formatTimestamp()))))
722717
continue
723718
else: # if we are sending a message to ourselves or a chan..

0 commit comments

Comments
 (0)