Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Got rid of OrderedDict #233
  • Loading branch information
ritikramuka committed Feb 24, 2022
commit ca5ab76de94cebbf3b90d6159c6354ddcd667524
9 changes: 4 additions & 5 deletions teos/watcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from queue import Queue
from threading import Thread
from collections import OrderedDict
from readerwriterlock import rwlock

from teos.logger import get_logger
Expand Down Expand Up @@ -44,7 +43,7 @@ class LocatorCache:
logger (:obj:`Logger <teos.logger.Logger>`): The logger for this component.
cache (:obj:`dict`): A dictionary of ``locator:dispute_txid`` pairs that received appointments are checked
against.
blocks (:obj:`OrderedDict`): An ordered dictionary of the last ``blocks_in_cache`` blocks
blocks (:obj:`dict`): An ordered dictionary of the last ``blocks_in_cache`` blocks
(``block_hash:locators``). Used to keep track of what data belongs to what block, so data can be pruned
accordingly. Also needed to rebuild the cache in case of reorgs.
cache_size (:obj:`int`): The size of the cache in blocks.
Expand All @@ -54,7 +53,7 @@ class LocatorCache:
def __init__(self, blocks_in_cache):
self.logger = get_logger(component=LocatorCache.__name__)
self.cache = dict()
self.blocks = OrderedDict()
self.blocks = dict()
self.cache_size = blocks_in_cache
self.rw_lock = rwlock.RWLockWrite()

Expand Down Expand Up @@ -85,7 +84,7 @@ def init(self, last_known_block, block_processor):
self.blocks[target_block_hash] = list(locator_txid_map.keys())
target_block_hash = target_block.get("previousblockhash")

self.blocks = OrderedDict(reversed((list(self.blocks.items()))))
self.blocks = dict(reversed((list(self.blocks.items()))))

def get_txid(self, locator):
"""
Expand Down Expand Up @@ -159,7 +158,7 @@ def fix(self, last_known_block, block_processor):
target_block_hash = target_block.get("previousblockhash")

with self.rw_lock.gen_wlock():
self.blocks = OrderedDict(reversed((list(tmp_cache.blocks.items()))))
self.blocks = dict(reversed((list(tmp_cache.blocks.items()))))
self.cache = tmp_cache.cache


Expand Down