add new block to hash db in communicator

master
Kevin Froman 2018-06-21 19:57:12 -05:00
parent 232bc4932a
commit a7d0d73b5b
2 changed files with 8 additions and 5 deletions

View File

@ -19,7 +19,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
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 sys, os, core, config, onionrblockapi as block, requests, time, logger, threading, onionrplugins as plugins, base64 import sys, os, core, config, json, onionrblockapi as block, requests, time, logger, threading, onionrplugins as plugins, base64
import onionrexceptions import onionrexceptions
from defusedxml import minidom from defusedxml import minidom
@ -114,9 +114,10 @@ class OnionrCommunicatorDaemon:
metas = self._core._utils.getBlockMetadataFromData(content) metas = self._core._utils.getBlockMetadataFromData(content)
metadata = metas[0] metadata = metas[0]
meta = metas[1] meta = metas[1]
if self._core._crypto.verifyPow(metas[2], metadata['meta']): if self._core._crypto.verifyPow(metas[2], metadata):
logger.info('Block passed proof, saving.') logger.info('Block passed proof, saving.')
self._core.setData(content) self._core.setData(content)
self._core.addToBlockDB(blockHash, dataSaved=True)
self.blockQueue.remove(blockHash) self.blockQueue.remove(blockHash)
else: else:
logger.warn('POW failed for block ' + blockHash) logger.warn('POW failed for block ' + blockHash)
@ -152,9 +153,11 @@ class OnionrCommunicatorDaemon:
def clearOfflinePeer(self): def clearOfflinePeer(self):
'''Removes the longest offline peer to retry later''' '''Removes the longest offline peer to retry later'''
try: try:
self.offlinePeers.pop(0) removed = self.offlinePeers.pop(0)
except IndexError: except IndexError:
pass pass
else:
logger.debug('removed ' + removed + ' from offline list to try them again.')
self.decrementThreadCount('clearOfflinePeer') self.decrementThreadCount('clearOfflinePeer')
def getOnlinePeers(self): def getOnlinePeers(self):

View File

@ -273,7 +273,7 @@ class OnionrCrypto:
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode() mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
puzzle = mainHash[:difficulty] puzzle = mainHash[:difficulty]
if metadata['powHash'][:difficulty] == puzzle: if metadata['powRandomToken'][:difficulty] == puzzle:
# logger.debug('Validated block pow') # logger.debug('Validated block pow')
retData = True retData = True
else: else: