mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 06:04:21 +01:00
Updates teos to work with the new conf file format and redefines how objects are built
Configuration parameters are now load from a .conf file (see template.conf as an example). The code has 3 config levels: default (teos/__init__.py), config file (<data_dir>/teos.conf) and command line. Most of the config parameters are only modificable trough the config file for now. The priority order is: command line, config file, default. Objects that need config parameters are now built in teosd instead of inside other classes. Therefore teosd acts like a factory and config parameters don't have to be passed around between objects. This also implies that a lot of the object creation logic has been changed. This should simplify unit testing.
This commit is contained in:
@@ -5,8 +5,6 @@ from threading import Thread
|
||||
from teos import LOG_PREFIX
|
||||
from common.logger import Logger
|
||||
from teos.cleaner import Cleaner
|
||||
from teos.carrier import Carrier
|
||||
from teos.block_processor import BlockProcessor
|
||||
|
||||
CONFIRMATIONS_BEFORE_RETRY = 6
|
||||
MIN_CONFIRMATIONS = 6
|
||||
@@ -125,17 +123,22 @@ class Responder:
|
||||
is populated by the :obj:`ChainMonitor <teos.chain_monitor.ChainMonitor>`.
|
||||
db_manager (:obj:`DBManager <teos.db_manager.DBManager>`): A ``DBManager`` instance to interact with the
|
||||
database.
|
||||
carrier (:obj:`Carrier <teos.carrier.Carrier>`): a ``Carrier`` instance to send transactions to bitcoind.
|
||||
block_processor (:obj:`DBManager <teos.block_processor.BlockProcessor>`): a ``BlockProcessor`` instance to get
|
||||
data from bitcoind.
|
||||
last_known_block (:obj:`str`): the last block known by the ``Responder``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, db_manager):
|
||||
def __init__(self, db_manager, carrier, block_processor):
|
||||
self.trackers = dict()
|
||||
self.tx_tracker_map = dict()
|
||||
self.unconfirmed_txs = []
|
||||
self.missed_confirmations = dict()
|
||||
self.block_queue = Queue()
|
||||
self.db_manager = db_manager
|
||||
self.carrier = Carrier()
|
||||
self.carrier = carrier
|
||||
self.block_processor = block_processor
|
||||
self.last_known_block = db_manager.load_last_block_hash_responder()
|
||||
|
||||
def awake(self):
|
||||
@@ -144,8 +147,7 @@ class Responder:
|
||||
|
||||
return responder_thread
|
||||
|
||||
@staticmethod
|
||||
def on_sync(block_hash):
|
||||
def on_sync(self, block_hash):
|
||||
"""
|
||||
Whether the :obj:`Responder` is on sync with ``bitcoind`` or not. Used when recovering from a crash.
|
||||
|
||||
@@ -165,8 +167,7 @@ class Responder:
|
||||
:obj:`bool`: Whether or not the :obj:`Responder` and ``bitcoind`` are on sync.
|
||||
"""
|
||||
|
||||
block_processor = BlockProcessor()
|
||||
distance_from_tip = block_processor.get_distance_to_tip(block_hash)
|
||||
distance_from_tip = self.block_processor.get_distance_to_tip(block_hash)
|
||||
|
||||
if distance_from_tip is not None and distance_from_tip > 1:
|
||||
synchronized = False
|
||||
@@ -266,11 +267,11 @@ class Responder:
|
||||
|
||||
# Distinguish fresh bootstraps from bootstraps from db
|
||||
if self.last_known_block is None:
|
||||
self.last_known_block = BlockProcessor.get_best_block_hash()
|
||||
self.last_known_block = self.block_processor.get_best_block_hash()
|
||||
|
||||
while True:
|
||||
block_hash = self.block_queue.get()
|
||||
block = BlockProcessor.get_block(block_hash)
|
||||
block = self.block_processor.get_block(block_hash)
|
||||
logger.info("New block received", block_hash=block_hash, prev_block_hash=block.get("previousblockhash"))
|
||||
|
||||
if len(self.trackers) > 0 and block is not None:
|
||||
@@ -377,7 +378,7 @@ class Responder:
|
||||
if appointment_end <= height and penalty_txid not in self.unconfirmed_txs:
|
||||
|
||||
if penalty_txid not in checked_txs:
|
||||
tx = Carrier.get_transaction(penalty_txid)
|
||||
tx = self.carrier.get_transaction(penalty_txid)
|
||||
else:
|
||||
tx = checked_txs.get(penalty_txid)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user