mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-19 07:04:27 +01:00
Bug fix and moves update condition to update_state
The tip update was performed in the wrong order, so tips never made it to last_tips
This commit is contained in:
@@ -103,13 +103,22 @@ class ChainMonitor:
|
|||||||
Args:
|
Args:
|
||||||
block_hash (:obj:`block_hash`): the new best tip.
|
block_hash (:obj:`block_hash`): the new best tip.
|
||||||
max_block_window_size (:obj:`int`): the maximum length of the ``last_tips`` list.
|
max_block_window_size (:obj:`int`): the maximum length of the ``last_tips`` list.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(:obj:`bool`): ``True`` is the state was successfully updated, ``False`` otherwise.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.best_tip = block_hash
|
if block_hash != self.best_tip and block_hash not in self.last_tips:
|
||||||
self.last_tips.append(block_hash)
|
self.last_tips.append(self.best_tip)
|
||||||
|
self.best_tip = block_hash
|
||||||
|
|
||||||
if len(self.last_tips) > max_block_window_size:
|
if len(self.last_tips) > max_block_window_size:
|
||||||
self.last_tips.pop(0)
|
self.last_tips.pop(0)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def monitor_chain_polling(self, polling_delta=POLLING_DELTA):
|
def monitor_chain_polling(self, polling_delta=POLLING_DELTA):
|
||||||
"""
|
"""
|
||||||
@@ -126,8 +135,7 @@ class ChainMonitor:
|
|||||||
current_tip = BlockProcessor.get_best_block_hash()
|
current_tip = BlockProcessor.get_best_block_hash()
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if current_tip != self.best_tip:
|
if self.update_state(current_tip):
|
||||||
self.update_state(current_tip)
|
|
||||||
self.notify_subscribers(current_tip)
|
self.notify_subscribers(current_tip)
|
||||||
logger.info("New block received via polling", block_hash=current_tip)
|
logger.info("New block received via polling", block_hash=current_tip)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
@@ -151,8 +159,7 @@ class ChainMonitor:
|
|||||||
block_hash = binascii.hexlify(body).decode("utf-8")
|
block_hash = binascii.hexlify(body).decode("utf-8")
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if block_hash != self.best_tip and block_hash not in self.last_tips:
|
if self.update_state(block_hash):
|
||||||
self.update_state(block_hash)
|
|
||||||
self.notify_subscribers(block_hash)
|
self.notify_subscribers(block_hash)
|
||||||
logger.info("New block received via zmq", block_hash=block_hash)
|
logger.info("New block received via zmq", block_hash=block_hash)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|||||||
Reference in New Issue
Block a user