11"""
22Proof of work calculation
33"""
4- # pylint: disable=import-outside-toplevel
4+ # pylint: disable=import-outside-toplevel,relative-import
55
66import ctypes
77import hashlib
2525from tr import _translate
2626
2727
28- bitmsglib = 'bitmsghash.so'
29- bmpow = None
28+ BITMSGLIB = 'bitmsghash.so'
29+ BMPOW = None
3030
3131
3232class LogOutput (object ): # pylint: disable=too-few-public-methods
@@ -173,7 +173,7 @@ def _doCPoW(target, initialHash):
173173 out_h = ctypes .pointer (ctypes .create_string_buffer (h , 64 ))
174174 out_m = ctypes .c_ulonglong (m )
175175 logger .debug ('C PoW start' )
176- nonce = bmpow (out_h , out_m )
176+ nonce = BMPOW (out_h , out_m )
177177
178178 trialValue = trial_value (nonce , initialHash )
179179 if state .shutdown != 0 :
@@ -200,7 +200,7 @@ def _doGPUPoW(target, initialHash):
200200 'Your GPUs (%s) did not calculate correctly, disabling OpenCL.'
201201 ' Please report to the developers.' , deviceNames )
202202 openclpow .enabledGpus = []
203- raise Exception ("GPU did not calculate correctly." )
203+ raise RuntimeError ("GPU did not calculate correctly." )
204204 if state .shutdown != 0 :
205205 raise StopIteration ("Interrupted" )
206206 logger .debug ('GPU PoW done' )
@@ -240,7 +240,7 @@ def getPowType():
240240
241241 if openclpow .openclEnabled ():
242242 return "OpenCL"
243- if bmpow :
243+ if BMPOW :
244244 return "C"
245245 return "python"
246246
@@ -250,7 +250,7 @@ def notifyBuild(tried=False):
250250 Notify the user of the success or otherwise of building the PoW C module
251251 """
252252
253- if bmpow :
253+ if BMPOW :
254254 queues .UISignalQueue .put (('updateStatusBar' , (_translate (
255255 "proofofwork" , "C PoW module built successfully." ), 1 )))
256256 elif tried :
@@ -264,7 +264,7 @@ def notifyBuild(tried=False):
264264
265265def buildCPoW ():
266266 """Attempt to build the PoW C module"""
267- if bmpow is not None :
267+ if BMPOW is not None :
268268 return
269269 if paths .frozen or sys .platform .startswith ('win' ):
270270 notifyBuild (False )
@@ -279,7 +279,9 @@ def buildCPoW():
279279
280280 subprocess .check_call (make_cmd ) # nosec B603
281281 if os .path .exists (
282- os .path .join (paths .codePath (), 'bitmsghash' , 'bitmsghash.so' )
282+ os .path .join (paths .codePath (),
283+ 'bitmsghash' ,
284+ 'bitmsghash.so' )
283285 ):
284286 init ()
285287 except (OSError , subprocess .CalledProcessError ):
@@ -299,7 +301,7 @@ def run(target, initialHash):
299301 target = int (target )
300302 if openclpow .openclEnabled ():
301303 return _doGPUPoW (target , initialHash )
302- if bmpow :
304+ if BMPOW :
303305 return _doCPoW (target , initialHash )
304306 if paths .frozen == "macosx_app" or not paths .frozen :
305307 # on my (Peter Surda) Windows 10, Windows Defender
@@ -323,14 +325,14 @@ def getTarget(payloadLength, ttl, nonceTrialsPerByte, payloadLengthExtraBytes):
323325
324326
325327def calculate (
326- payload , ttl ,
327- nonceTrialsPerByte = networkDefaultProofOfWorkNonceTrialsPerByte ,
328- payloadLengthExtraBytes = networkDefaultPayloadLengthExtraBytes
328+ payload , ttl ,
329+ nonceTrialsPerByte = networkDefaultProofOfWorkNonceTrialsPerByte ,
330+ payloadLengthExtraBytes = networkDefaultPayloadLengthExtraBytes
329331):
330332 """Do the PoW for the payload and TTL with optional difficulty params"""
331- return run (getTarget (
332- len ( payload ), ttl , nonceTrialsPerByte , payloadLengthExtraBytes ),
333- hashlib .sha512 (payload ).digest ())
333+ return run (getTarget (len ( payload ), ttl , nonceTrialsPerByte ,
334+ payloadLengthExtraBytes ),
335+ hashlib .sha512 (payload ).digest ())
334336
335337
336338def resetPoW ():
@@ -344,42 +346,42 @@ def resetPoW():
344346def init ():
345347 """Initialise PoW"""
346348 # pylint: disable=broad-exception-caught,global-statement
347- global bitmsglib , bmpow
349+ global BITMSGLIB , BMPOW
348350
349351 openclpow .initCL ()
350352 if sys .platform .startswith ('win' ):
351- bitmsglib = (
353+ BITMSGLIB = (
352354 'bitmsghash32.dll' if ctypes .sizeof (ctypes .c_voidp ) == 4 else
353355 'bitmsghash64.dll' )
354- libfile = os .path .join (paths .codePath (), 'bitmsghash' , bitmsglib )
356+ libfile = os .path .join (paths .codePath (), 'bitmsghash' , BITMSGLIB )
355357 try :
356358 # MSVS
357359 bso = ctypes .WinDLL (
358- os .path .join (paths .codePath (), 'bitmsghash' , bitmsglib ))
359- logger .info ('Loaded C PoW DLL (stdcall) %s' , bitmsglib )
360- bmpow = bso .BitmessagePOW
361- bmpow .restype = ctypes .c_ulonglong
360+ os .path .join (paths .codePath (), 'bitmsghash' , BITMSGLIB ))
361+ logger .info ('Loaded C PoW DLL (stdcall) %s' , BITMSGLIB )
362+ BMPOW = bso .BitmessagePOW
363+ BMPOW .restype = ctypes .c_ulonglong
362364 _doCPoW (2 ** 63 , "" )
363365 logger .info (
364- 'Successfully tested C PoW DLL (stdcall) %s' , bitmsglib )
366+ 'Successfully tested C PoW DLL (stdcall) %s' , BITMSGLIB )
365367 except ValueError :
366368 try :
367369 # MinGW
368370 bso = ctypes .CDLL (libfile )
369- logger .info ('Loaded C PoW DLL (cdecl) %s' , bitmsglib )
370- bmpow = bso .BitmessagePOW
371- bmpow .restype = ctypes .c_ulonglong
371+ logger .info ('Loaded C PoW DLL (cdecl) %s' , BITMSGLIB )
372+ BMPOW = bso .BitmessagePOW
373+ BMPOW .restype = ctypes .c_ulonglong
372374 _doCPoW (2 ** 63 , "" )
373375 logger .info (
374- 'Successfully tested C PoW DLL (cdecl) %s' , bitmsglib )
376+ 'Successfully tested C PoW DLL (cdecl) %s' , BITMSGLIB )
375377 except Exception as e :
376378 logger .error ('Error: %s' , e , exc_info = True )
377379 except Exception as e :
378380 logger .error ('Error: %s' , e , exc_info = True )
379381 else :
380382 try :
381383 bso = ctypes .CDLL (
382- os .path .join (paths .codePath (), 'bitmsghash' , bitmsglib ))
384+ os .path .join (paths .codePath (), 'bitmsghash' , BITMSGLIB ))
383385 except OSError :
384386 import glob
385387 try :
@@ -391,15 +393,15 @@ def init():
391393 except Exception :
392394 bso = None
393395 else :
394- logger .info ('Loaded C PoW DLL %s' , bitmsglib )
396+ logger .info ('Loaded C PoW DLL %s' , BITMSGLIB )
395397 if bso :
396398 try :
397- bmpow = bso .BitmessagePOW
398- bmpow .restype = ctypes .c_ulonglong
399+ BMPOW = bso .BitmessagePOW
400+ BMPOW .restype = ctypes .c_ulonglong
399401 except Exception :
400402 logger .warning (
401- 'Failed to setup bmpow lib %s' , bso , exc_info = True )
403+ 'Failed to setup BMPOW lib %s' , bso , exc_info = True )
402404 return
403405
404- if bmpow is None :
406+ if BMPOW is None :
405407 buildCPoW ()
0 commit comments