-
Notifications
You must be signed in to change notification settings - Fork 574
New POW calculation module #1284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v0.6
Are you sure you want to change the base?
Conversation
Have you tried frozen mode on Windows? |
No, but |
@@ -0,0 +1,42 @@ | |||
Please keep this module independent from the outside code, so that it can be reused in other applications. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case why can't we make it a separate package and import it where required ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a Python package with the __init__.py
file, and it's intended to be imported like import workprover
. It could be moved to a separate repository, but I think, it's easier and safer to keep it in the same file tree.
src/workprover/__init__.py
Outdated
try: | ||
self.availableSolvers["fast"] = fastsolver.FastSolver(codePath) | ||
except: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass is the dangerous statement, please log it or please write a print statement atleast...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.availableSolvers
is visible to the outside code, so it can log or print if fast
is missing. It should show a message in GUI status bar like the current code does.
src/workprover/__init__.py
Outdated
if self.statusUpdated is None: | ||
return | ||
|
||
if self.solver is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parallelism = self.solver.parallelism if self.solver else 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's less readable.
self.currentTaskID = None | ||
|
||
def notifyStatus(self): | ||
if self.statusUpdated is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not self.statusUpdated:
return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's less acurate.
self.statusUpdated
must be either a function or a None
. If it's 0 or an empty string, it would be a programming error and further call would rise an exception making the error noticable.
src/workprover/__init__.py
Outdated
self.statusUpdated((self.solverName, parallelism, self.speed)) | ||
|
||
def setSolver(self, name, parallelism): | ||
if name is None and self.solverName is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not name and not self.solverName
src/workprover/fastsolver.py
Outdated
import ctypes | ||
|
||
def loadFastSolver(codePath): | ||
if hasattr(sys, "winver"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc type required here
|
||
if platform.architecture()[0] == "64bit": | ||
suffix = "-64" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8 validation
src/workprover/fastsolver.py
Outdated
self.parallelism = 0 | ||
|
||
def search(self, initialHash, target, seed, timeout): | ||
found = self.libfastsolver.fastsolver_search( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation required here
@@ -0,0 +1,106 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8 validation for the file
src/workprover/forkingsolver.py
Outdated
def setIdle(): | ||
try: | ||
import psutil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove un necessary spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work for me: two "singleWorker" threads appear when doing PoW. Oh, I realized it's not connected so far :(
@Kleshni |
Some tests are failing. It seems to be expected for |
|
It seems to be specific to ubuntu:trusty or Travis-CI. Nevertheless could you please add |
I have registered in Travis-CI and debugged the issue. It was a very stupid mistake, shared libraries like Travis-CI also gives an OS X environment, so I tested the module there. |
|
src/workprover/gpusolver.py
Outdated
|
||
try: | ||
import numpy | ||
import pyopencl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please comment #1283 and maybe change the import order too if you agree?
@@ -54,6 +54,8 @@ else: | |||
a.binaries += [('libeay32.dll', openSSLPath + 'libeay32.dll', 'BINARY'), | |||
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'), | |||
(os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'), | |||
("workprover/fastsolver/libfastsolver-{}.dll".format(arch), os.path.join(srcPath, "workprover/fastsolver/libfastsolver-{}.dll".format(arch)), "BINARY"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 validation required here.
|
||
# This thread, of which there is only one, runs the API. | ||
class singleAPI(threading.Thread, helper_threading.StoppableThread): | ||
def __init__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add doc string to the class.
self.initStop() | ||
|
||
def stopThread(self): | ||
super(singleAPI, self).stopThread() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add doc string to the class
@@ -502,10 +384,85 @@ def main(): | |||
mainprogram = Main() | |||
mainprogram.start() | |||
|
|||
# See "workprover/Readme.md" | |||
|
|||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please write all the imports on the starting of the file.
|
||
if __name__ == "__main__": | ||
main() | ||
import multiprocessing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please place all the imports in the starting the file...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These imports must be conditional.
|
||
# Update status values inherited from old versions | ||
|
||
self.cur.execute("""UPDATE "sent" SET "status" = 'msgsent' WHERE "status" == 'sentmessage';""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8 validation here.
@@ -0,0 +1,253 @@ | |||
import Queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please place all the imports in a alphabetic order.
src/workprover/__init__.py
Outdated
self.statusUpdated(Status(self.solverName, status, self.speed, len(self.tasks), self.totalDifficulty)) | ||
|
||
def setSolver(self, name, configuration): | ||
if name is None and self.solverName is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not name and not self.solverName:
pass
src/workprover/__init__.py
Outdated
elif name == self.solverName: | ||
self.solver.setConfiguration(configuration) | ||
else: | ||
if self.solver is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.solver:
….
src/workprover/__init__.py
Outdated
self.solverName = None | ||
self.solver = None | ||
|
||
if name is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if name:
….
Added API methods for dealing with raw objects in the inventory, solving #1225 and superseding #1226.
|
I deleted the The same for |
src/workprover/__init__.py
Outdated
self.solverName = name | ||
self.solver = self.availableSolvers[name] | ||
self.solver.setConfiguration(configuration) | ||
except GPUSolverError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined name 'GPUSolverError'
I got 3 additional threads ( This patch helped: diff --git a/src/singleworker.py b/src/singleworker.py
index 9fa1391c..e1eeda3f 100644
--- a/src/singleworker.py
+++ b/src/singleworker.py
@@ -270,17 +270,19 @@ def setBestSolver():
setBestSolver()
+
class singleWorker(threading.Thread, helper_threading.StoppableThread):
name = "singleWorker"
def __init__(self):
- super(self.__class__, self).__init__()
+ super(self.__class__, self).__init__(name="singleWorker")
self.initStop()
def stopThread(self):
queues.workerQueue.put(("stopThread", "data"))
+ workProver.commandsQueue.put(("shutdown", ))
super(self.__class__, self).stopThread()
def run(self): |
Any plans on merging? |
your POW branch works nicely here ! great job ! |
@Kleshni I haven't looked at it yet, but it first needs to pass all the code quality checks and all commits need to be signed (you can squash commits if it helps). However, others gave good feedback so chances are good. |
Also, please split this into multiple patches. The PoW, the API and the other changes should be separate. You'll have better chances of getting it merged that way too. |
@Kleshni would it be ok if I assigned someone else to the task to help you with cleaning it up? You'd have to give them write access to your repo. |
OK. |
@Kleshni please give @omkar1117 write access to the POW branch. this way your commits will be preserved and you can still get paid through tip4commit. |
I have sent him an invite yesterday but forgot to notify you 👀 |
@Kleshni could you please resolve the conflicts please. |
@Kleshni Omkar says he doesn't have write access. He could fork it into his own repo, but since this PR is already open I would prefer to continue this way. Can you check and let me know? |
For #1227. It's currently not connected to the PyBitmessage code, I'm going to get it done sooner or later.
It provides the
WorkProver
thread class which manages tasks and schedules them to solvers. There are 4 possible solvers:Single-threaded
DumbSolver
in Python. I optimised it so it now works ~2 times faster. In particular, I replacedhashlib.sha512
withSHA512
from OpenSSL. Since you need OpenSSL to assemble a message anyway, I think it's safe to use it in a fallback solver.Multiprocess based
ForkingSolver
in Python. It works faster too, because it relies onDumbSolver
.Multithreaded
FastSolver
in C. I tried to utilize SIMD, but it gave very little speed up of 7 %, so it still calls OpenSSL.And
GPUSolver
in OpenCL.The library was tested on a 4-core AMD64 Linux with integrated GPU and 45-CPU virtual machines with hyperthreading enabled:
bsd.mp
kernel;I failed to install Hackintosh on QEMU, so somebody else has to test it there.