From 21559e09f18cd0cccbc229c35a9b2f521572f5ef Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Mon, 3 Jun 2013 23:14:24 -0400 Subject: [PATCH 1/2] Remove multi-core POW support --- src/bitmessagemain.py | 2 ++ src/bitmessageqt/__init__.py | 14 +++++----- src/proofofwork.py | 20 ++++++++----- src/settings.py | 34 ++--------------------- src/settings.ui | 54 ------------------------------------ 5 files changed, 24 insertions(+), 100 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index c12be4d3..df36dfc1 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -47,6 +47,7 @@ import json from subprocess import call #used when the API must execute an outside program import singleton import proofofwork +import multiprocessing.forking #For each stream to which we connect, several outgoingSynSender threads will exist and will collectively create 8 connections with peers. class outgoingSynSender(threading.Thread): @@ -3939,6 +3940,7 @@ if useVeryEasyProofOfWorkForTesting: shared.networkDefaultProofOfWorkNonceTrialsPerByte = int(shared.networkDefaultProofOfWorkNonceTrialsPerByte / 16) shared.networkDefaultPayloadLengthExtraBytes = int(shared.networkDefaultPayloadLengthExtraBytes / 7000) + if __name__ == "__main__": # is the application already running? If yes then exit. thisapp = singleton.singleinstance() diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 0179ff7f..435ebec5 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1431,10 +1431,10 @@ class MyForm(QtGui.QMainWindow): shared.config.set('bitmessagesettings', 'defaultnoncetrialsperbyte',str(int(float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text())*shared.networkDefaultProofOfWorkNonceTrialsPerByte))) if float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) >= 1: shared.config.set('bitmessagesettings', 'defaultpayloadlengthextrabytes',str(int(float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text())*shared.networkDefaultPayloadLengthExtraBytes))) - if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': - shared.config.set('bitmessagesettings', 'maxcores', '99999') - else: - shared.config.set('bitmessagesettings', 'maxcores', str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText())) + #if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': + # shared.config.set('bitmessagesettings', 'maxcores', '99999') + #else: + # shared.config.set('bitmessagesettings', 'maxcores', str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText())) with open(shared.appdata + 'keys.dat', 'wb') as configfile: shared.config.write(configfile) @@ -2140,8 +2140,8 @@ class settingsDialog(QtGui.QDialog): self.ui.lineEditTotalDifficulty.setText(str((float(shared.config.getint('bitmessagesettings', 'defaultnoncetrialsperbyte'))/shared.networkDefaultProofOfWorkNonceTrialsPerByte))) self.ui.lineEditSmallMessageDifficulty.setText(str((float(shared.config.getint('bitmessagesettings', 'defaultpayloadlengthextrabytes'))/shared.networkDefaultPayloadLengthExtraBytes))) - #On the System tab - try: + #'System' tab removed for now. + """try: maxCores = shared.config.getint('bitmessagesettings', 'maxcores') except: maxCores = 99999 @@ -2156,7 +2156,7 @@ class settingsDialog(QtGui.QDialog): elif maxCores <= 16: self.ui.comboBoxMaxCores.setCurrentIndex(4) else: - self.ui.comboBoxMaxCores.setCurrentIndex(5) + self.ui.comboBoxMaxCores.setCurrentIndex(5)""" QtGui.QWidget.resize(self,QtGui.QWidget.sizeHint(self)) diff --git a/src/proofofwork.py b/src/proofofwork.py index 8f316096..5fd7e43a 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -1,10 +1,10 @@ -import shared -import time -from multiprocessing import Pool, cpu_count +#import shared +#import time +#from multiprocessing import Pool, cpu_count import hashlib from struct import unpack, pack -import sys -import os +#import sys +#import os def _set_idle(): try: @@ -30,7 +30,13 @@ def _pool_worker(nonce, initialHash, target, pool_size): return [trialValue, nonce] def run(target, initialHash): - try: + nonce = 0 + trialValue = 99999999999999999999 + while trialValue > target: + nonce += 1 + trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8]) + return [trialValue, nonce] + """try: pool_size = cpu_count() except: pool_size = 4 @@ -56,5 +62,5 @@ def run(target, initialHash): result = result[i].get() pool.terminate() return result[0], result[1] - time.sleep(0.2) + time.sleep(0.2)""" diff --git a/src/settings.py b/src/settings.py index dac0f788..d8f86efc 100644 --- a/src/settings.py +++ b/src/settings.py @@ -2,8 +2,8 @@ # Form implementation generated from reading ui file 'settings.ui' # -# Created: Thu May 30 15:50:32 2013 -# by: PyQt4 UI code generator 4.9.4 +# Created: Mon Jun 03 23:09:01 2013 +# by: PyQt4 UI code generator 4.9.5 # # WARNING! All changes made in this file will be lost! @@ -172,28 +172,6 @@ class Ui_settingsDialog(object): self.label_10.setObjectName(_fromUtf8("label_10")) self.gridLayout_6.addWidget(self.label_10, 2, 0, 1, 3) self.tabWidgetSettings.addTab(self.tab, _fromUtf8("")) - self.tab_2 = QtGui.QWidget() - self.tab_2.setObjectName(_fromUtf8("tab_2")) - self.formLayout = QtGui.QFormLayout(self.tab_2) - self.formLayout.setObjectName(_fromUtf8("formLayout")) - self.label_13 = QtGui.QLabel(self.tab_2) - self.label_13.setObjectName(_fromUtf8("label_13")) - self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.label_13) - self.comboBoxMaxCores = QtGui.QComboBox(self.tab_2) - sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.comboBoxMaxCores.sizePolicy().hasHeightForWidth()) - self.comboBoxMaxCores.setSizePolicy(sizePolicy) - self.comboBoxMaxCores.setObjectName(_fromUtf8("comboBoxMaxCores")) - self.comboBoxMaxCores.addItem(_fromUtf8("")) - self.comboBoxMaxCores.addItem(_fromUtf8("")) - self.comboBoxMaxCores.addItem(_fromUtf8("")) - self.comboBoxMaxCores.addItem(_fromUtf8("")) - self.comboBoxMaxCores.addItem(_fromUtf8("")) - self.comboBoxMaxCores.addItem(_fromUtf8("")) - self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.comboBoxMaxCores) - self.tabWidgetSettings.addTab(self.tab_2, _fromUtf8("")) self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1) self.retranslateUi(settingsDialog) @@ -244,12 +222,4 @@ class Ui_settingsDialog(object): self.label_12.setText(QtGui.QApplication.translate("settingsDialog", "The \'Small message difficulty\' mostly only affects the difficulty of sending small messages. Doubling this value makes it almost twice as difficult to send a small message but doesn\'t really affect large messages.", None, QtGui.QApplication.UnicodeUTF8)) self.label_10.setText(QtGui.QApplication.translate("settingsDialog", "The \'Total difficulty\' affects the absolute amount of work the sender must complete. Doubling this value doubles the amount of work.", None, QtGui.QApplication.UnicodeUTF8)) self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab), QtGui.QApplication.translate("settingsDialog", "Demanded difficulty", None, QtGui.QApplication.UnicodeUTF8)) - self.label_13.setText(QtGui.QApplication.translate("settingsDialog", "Maximum number of CPU cores to use when doing work:", None, QtGui.QApplication.UnicodeUTF8)) - self.comboBoxMaxCores.setItemText(0, QtGui.QApplication.translate("settingsDialog", "1", None, QtGui.QApplication.UnicodeUTF8)) - self.comboBoxMaxCores.setItemText(1, QtGui.QApplication.translate("settingsDialog", "2", None, QtGui.QApplication.UnicodeUTF8)) - self.comboBoxMaxCores.setItemText(2, QtGui.QApplication.translate("settingsDialog", "4", None, QtGui.QApplication.UnicodeUTF8)) - self.comboBoxMaxCores.setItemText(3, QtGui.QApplication.translate("settingsDialog", "8", None, QtGui.QApplication.UnicodeUTF8)) - self.comboBoxMaxCores.setItemText(4, QtGui.QApplication.translate("settingsDialog", "16", None, QtGui.QApplication.UnicodeUTF8)) - self.comboBoxMaxCores.setItemText(5, QtGui.QApplication.translate("settingsDialog", "All", None, QtGui.QApplication.UnicodeUTF8)) - self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab_2), QtGui.QApplication.translate("settingsDialog", "System", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/src/settings.ui b/src/settings.ui index 61419bb6..971480bd 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -373,60 +373,6 @@ - - - System - - - - - - Maximum number of CPU cores to use when doing work: - - - - - - - - 0 - 0 - - - - - 1 - - - - - 2 - - - - - 4 - - - - - 8 - - - - - 16 - - - - - All - - - - - - From 55de3ad9c7e695dd8d92f42af1b376c6c45f300a Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Mon, 3 Jun 2013 23:38:10 -0400 Subject: [PATCH 2/2] Remove multi-core POW support --- src/bitmessagemain.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index df36dfc1..c12be4d3 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -47,7 +47,6 @@ import json from subprocess import call #used when the API must execute an outside program import singleton import proofofwork -import multiprocessing.forking #For each stream to which we connect, several outgoingSynSender threads will exist and will collectively create 8 connections with peers. class outgoingSynSender(threading.Thread): @@ -3940,7 +3939,6 @@ if useVeryEasyProofOfWorkForTesting: shared.networkDefaultProofOfWorkNonceTrialsPerByte = int(shared.networkDefaultProofOfWorkNonceTrialsPerByte / 16) shared.networkDefaultPayloadLengthExtraBytes = int(shared.networkDefaultPayloadLengthExtraBytes / 7000) - if __name__ == "__main__": # is the application already running? If yes then exit. thisapp = singleton.singleinstance()