Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Got rid of OrderedDict #233
Browse files Browse the repository at this point in the history
  • Loading branch information
ritikramuka committed Feb 23, 2022
1 parent 66bc075 commit 71e1926
Showing 1 changed file with 4 additions and 5 deletions.
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

0 comments on commit 71e1926

Please sign in to comment.