mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
teos - additional docs
This commit is contained in:
@@ -62,7 +62,7 @@ class LocatorCache:
|
||||
target_block_hash = last_known_block
|
||||
for _ in range(self.cache_size):
|
||||
# In some setups, like regtest, it could be the case that there are no enough previous blocks.
|
||||
# In those cases we pull as many as we can (up to ``cache_size``).
|
||||
# In those cases we pull as many as we can (up to cache_size).
|
||||
if target_block_hash:
|
||||
target_block = block_processor.get_block(target_block_hash)
|
||||
if not target_block:
|
||||
@@ -78,10 +78,18 @@ class LocatorCache:
|
||||
self.blocks = OrderedDict(reversed((list(self.blocks.items()))))
|
||||
|
||||
def fix_cache(self, last_known_block, block_processor):
|
||||
"""
|
||||
Fixes an existing cache after a reorg has been detected by feeding the last ``cache_size`` blocks to it.
|
||||
|
||||
Args:
|
||||
last_known_block (:obj:`str`): the last known block hash after the reorg.
|
||||
block_processor (:obj:`teos.block_processor.BlockProcessor`): a ``BlockProcessor`` instance.
|
||||
"""
|
||||
|
||||
tmp_cache = LocatorCache(self.cache_size)
|
||||
|
||||
# We assume there are no reorgs back to genesis. If so, this would raise some log warnings. And the cache will
|
||||
# be filled with less than ``cache_size`` blocks.`
|
||||
# be filled with less than cache_size blocks.
|
||||
target_block_hash = last_known_block
|
||||
for _ in range(tmp_cache.cache_size):
|
||||
target_block = block_processor.get_block(target_block_hash)
|
||||
@@ -463,8 +471,10 @@ class Watcher:
|
||||
breaches (:obj:`dict`): a dictionary containing channel breaches (``locator:txid``).
|
||||
|
||||
Returns:
|
||||
:obj:`dict`: A dictionary containing all the breaches flagged either as valid or invalid.
|
||||
The structure is as follows:
|
||||
:obj:`tuple`: A dictionary and a list. The former contains the valid breaches, while the latter contain the
|
||||
invalid ones.
|
||||
|
||||
The valid breaches dictionary has the following structure:
|
||||
|
||||
``{locator, dispute_txid, penalty_txid, penalty_rawtx}``
|
||||
"""
|
||||
|
||||
@@ -382,7 +382,7 @@ def test_add_appointment_in_cache(api, client):
|
||||
r = add_appointment(client, {"appointment": appointment.to_dict(), "signature": appointment_signature}, user_id)
|
||||
assert r.status_code == HTTP_BAD_REQUEST and r.json.get("error_code") == errors.APPOINTMENT_ALREADY_TRIGGERED
|
||||
|
||||
# The appointment would be rejected even if the data is not in the cache provided we've it has been triggered
|
||||
# The appointment would be rejected even if the data is not in the cache provided it has been triggered
|
||||
del api.watcher.locator_cache.cache[appointment.locator]
|
||||
r = add_appointment(client, {"appointment": appointment.to_dict(), "signature": appointment_signature}, user_id)
|
||||
assert r.status_code == HTTP_BAD_REQUEST and r.json.get("error_code") == errors.APPOINTMENT_ALREADY_TRIGGERED
|
||||
|
||||
Reference in New Issue
Block a user