pow changes
This commit is contained in:
		
							parent
							
								
									3fc623b8ee
								
							
						
					
					
						commit
						950883dc5d
					
				
					 3 changed files with 10 additions and 4 deletions
				
			
		|  | @ -18,10 +18,11 @@ | ||||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. |     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||||
| ''' | ''' | ||||||
| 
 | 
 | ||||||
| import onionrexceptions, onionrpeers, onionrproofs, logger, onionrusers | import onionrexceptions, onionrpeers, onionrproofs, logger | ||||||
| import base64, sqlite3, os | import base64, sqlite3, os | ||||||
| from dependencies import secrets | from dependencies import secrets | ||||||
| from utils import netutils | from utils import netutils | ||||||
|  | from onionrusers import onionrusers | ||||||
| 
 | 
 | ||||||
| class DaemonTools: | class DaemonTools: | ||||||
|     ''' |     ''' | ||||||
|  |  | ||||||
|  | @ -44,6 +44,10 @@ class PasswordStrengthError(Exception): | ||||||
|     pass |     pass | ||||||
| 
 | 
 | ||||||
| # block exceptions | # block exceptions | ||||||
|  | 
 | ||||||
|  | class DifficultyTooLarge(Exception): | ||||||
|  |     pass | ||||||
|  | 
 | ||||||
| class InvalidMetadata(Exception): | class InvalidMetadata(Exception): | ||||||
|     pass |     pass | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -69,6 +69,7 @@ def getDifficultyForNewBlock(data, ourBlock=True): | ||||||
|         minDifficulty = config.get('general.minimum_block_pow', 4) |         minDifficulty = config.get('general.minimum_block_pow', 4) | ||||||
| 
 | 
 | ||||||
|     retData = max(minDifficulty, math.floor(dataSize / 100000)) + getDifficultyModifier() |     retData = max(minDifficulty, math.floor(dataSize / 100000)) + getDifficultyModifier() | ||||||
|  | 
 | ||||||
|     return retData |     return retData | ||||||
| 
 | 
 | ||||||
| def getHashDifficulty(h): | def getHashDifficulty(h): | ||||||
|  | @ -245,11 +246,10 @@ class POW: | ||||||
|         answer = '' |         answer = '' | ||||||
|         heartbeat = 200000 |         heartbeat = 200000 | ||||||
|         hbCount = 0 |         hbCount = 0 | ||||||
|          |         nonce = int(binascii.hexlify(nacl.utils.random(2)), 16) | ||||||
|         while self.hashing: |         while self.hashing: | ||||||
|             rand = nacl.utils.random() |  | ||||||
|             #token = nacl.hash.blake2b(rand + self.data).decode() |             #token = nacl.hash.blake2b(rand + self.data).decode() | ||||||
|             self.metadata['powRandomToken'] = base64.b64encode(rand).decode() |             self.metadata['powRandomToken'] = nonce | ||||||
|             payload = json.dumps(self.metadata).encode() + b'\n' + self.data |             payload = json.dumps(self.metadata).encode() + b'\n' + self.data | ||||||
|             token = myCore._crypto.sha3Hash(payload) |             token = myCore._crypto.sha3Hash(payload) | ||||||
|             try: |             try: | ||||||
|  | @ -262,6 +262,7 @@ class POW: | ||||||
|                 iFound = True |                 iFound = True | ||||||
|                 self.result = payload |                 self.result = payload | ||||||
|                 break |                 break | ||||||
|  |             nonce += 1 | ||||||
|                  |                  | ||||||
|         if iFound: |         if iFound: | ||||||
|             endTime = math.floor(time.time()) |             endTime = math.floor(time.time()) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue