Remove multi-core POW support

This commit is contained in:
Jonathan Warren 2013-06-03 23:14:24 -04:00
parent 32efdca33c
commit 21559e09f1
5 changed files with 24 additions and 100 deletions

View File

@ -47,6 +47,7 @@ import json
from subprocess import call #used when the API must execute an outside program from subprocess import call #used when the API must execute an outside program
import singleton import singleton
import proofofwork 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. #For each stream to which we connect, several outgoingSynSender threads will exist and will collectively create 8 connections with peers.
class outgoingSynSender(threading.Thread): class outgoingSynSender(threading.Thread):
@ -3939,6 +3940,7 @@ if useVeryEasyProofOfWorkForTesting:
shared.networkDefaultProofOfWorkNonceTrialsPerByte = int(shared.networkDefaultProofOfWorkNonceTrialsPerByte / 16) shared.networkDefaultProofOfWorkNonceTrialsPerByte = int(shared.networkDefaultProofOfWorkNonceTrialsPerByte / 16)
shared.networkDefaultPayloadLengthExtraBytes = int(shared.networkDefaultPayloadLengthExtraBytes / 7000) shared.networkDefaultPayloadLengthExtraBytes = int(shared.networkDefaultPayloadLengthExtraBytes / 7000)
if __name__ == "__main__": if __name__ == "__main__":
# is the application already running? If yes then exit. # is the application already running? If yes then exit.
thisapp = singleton.singleinstance() thisapp = singleton.singleinstance()

View File

@ -1431,10 +1431,10 @@ class MyForm(QtGui.QMainWindow):
shared.config.set('bitmessagesettings', 'defaultnoncetrialsperbyte',str(int(float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text())*shared.networkDefaultProofOfWorkNonceTrialsPerByte))) shared.config.set('bitmessagesettings', 'defaultnoncetrialsperbyte',str(int(float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text())*shared.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) >= 1: if float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) >= 1:
shared.config.set('bitmessagesettings', 'defaultpayloadlengthextrabytes',str(int(float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text())*shared.networkDefaultPayloadLengthExtraBytes))) shared.config.set('bitmessagesettings', 'defaultpayloadlengthextrabytes',str(int(float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text())*shared.networkDefaultPayloadLengthExtraBytes)))
if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': #if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All':
shared.config.set('bitmessagesettings', 'maxcores', '99999') # shared.config.set('bitmessagesettings', 'maxcores', '99999')
else: #else:
shared.config.set('bitmessagesettings', 'maxcores', str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText())) # shared.config.set('bitmessagesettings', 'maxcores', str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()))
with open(shared.appdata + 'keys.dat', 'wb') as configfile: with open(shared.appdata + 'keys.dat', 'wb') as configfile:
shared.config.write(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.lineEditTotalDifficulty.setText(str((float(shared.config.getint('bitmessagesettings', 'defaultnoncetrialsperbyte'))/shared.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.ui.lineEditSmallMessageDifficulty.setText(str((float(shared.config.getint('bitmessagesettings', 'defaultpayloadlengthextrabytes'))/shared.networkDefaultPayloadLengthExtraBytes))) self.ui.lineEditSmallMessageDifficulty.setText(str((float(shared.config.getint('bitmessagesettings', 'defaultpayloadlengthextrabytes'))/shared.networkDefaultPayloadLengthExtraBytes)))
#On the System tab #'System' tab removed for now.
try: """try:
maxCores = shared.config.getint('bitmessagesettings', 'maxcores') maxCores = shared.config.getint('bitmessagesettings', 'maxcores')
except: except:
maxCores = 99999 maxCores = 99999
@ -2156,7 +2156,7 @@ class settingsDialog(QtGui.QDialog):
elif maxCores <= 16: elif maxCores <= 16:
self.ui.comboBoxMaxCores.setCurrentIndex(4) self.ui.comboBoxMaxCores.setCurrentIndex(4)
else: else:
self.ui.comboBoxMaxCores.setCurrentIndex(5) self.ui.comboBoxMaxCores.setCurrentIndex(5)"""
QtGui.QWidget.resize(self,QtGui.QWidget.sizeHint(self)) QtGui.QWidget.resize(self,QtGui.QWidget.sizeHint(self))

View File

@ -1,10 +1,10 @@
import shared #import shared
import time #import time
from multiprocessing import Pool, cpu_count #from multiprocessing import Pool, cpu_count
import hashlib import hashlib
from struct import unpack, pack from struct import unpack, pack
import sys #import sys
import os #import os
def _set_idle(): def _set_idle():
try: try:
@ -30,7 +30,13 @@ def _pool_worker(nonce, initialHash, target, pool_size):
return [trialValue, nonce] return [trialValue, nonce]
def run(target, initialHash): 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() pool_size = cpu_count()
except: except:
pool_size = 4 pool_size = 4
@ -56,5 +62,5 @@ def run(target, initialHash):
result = result[i].get() result = result[i].get()
pool.terminate() pool.terminate()
return result[0], result[1] return result[0], result[1]
time.sleep(0.2) time.sleep(0.2)"""

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'settings.ui' # Form implementation generated from reading ui file 'settings.ui'
# #
# Created: Thu May 30 15:50:32 2013 # Created: Mon Jun 03 23:09:01 2013
# by: PyQt4 UI code generator 4.9.4 # by: PyQt4 UI code generator 4.9.5
# #
# WARNING! All changes made in this file will be lost! # 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.label_10.setObjectName(_fromUtf8("label_10"))
self.gridLayout_6.addWidget(self.label_10, 2, 0, 1, 3) self.gridLayout_6.addWidget(self.label_10, 2, 0, 1, 3)
self.tabWidgetSettings.addTab(self.tab, _fromUtf8("")) 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.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1)
self.retranslateUi(settingsDialog) 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_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.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.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))

View File

@ -373,60 +373,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>System</string>
</attribute>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Maximum number of CPU cores to use when doing work:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxMaxCores">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>16</string>
</property>
</item>
<item>
<property name="text">
<string>All</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>