16
16
17
17
from structlog import get_logger
18
18
19
- from hathor .conf import HathorSettings
19
+ from hathor .conf . get_settings import get_settings
20
20
from hathor .profiler import get_cpu_profiler
21
21
from hathor .transaction import BaseTransaction , Block , Transaction , TxInput , sum_weights
22
22
from hathor .util import classproperty
25
25
from hathor .consensus .context import ConsensusAlgorithmContext
26
26
27
27
logger = get_logger ()
28
- settings = HathorSettings ()
29
28
cpu = get_cpu_profiler ()
30
29
31
30
_base_transaction_log = logger .new ()
@@ -35,6 +34,7 @@ class TransactionConsensusAlgorithm:
35
34
"""Implement the consensus algorithm for transactions."""
36
35
37
36
def __init__ (self , context : 'ConsensusAlgorithmContext' ) -> None :
37
+ self ._settings = get_settings ()
38
38
self .context = context
39
39
40
40
@classproperty
@@ -180,7 +180,7 @@ def update_voided_info(self, tx: Transaction) -> None:
180
180
parent_meta = parent .get_metadata ()
181
181
if parent_meta .voided_by :
182
182
voided_by .update (self .context .consensus .filter_out_soft_voided_entries (parent , parent_meta .voided_by ))
183
- assert settings .SOFT_VOIDED_ID not in voided_by
183
+ assert self . _settings .SOFT_VOIDED_ID not in voided_by
184
184
assert not (self .context .consensus .soft_voided_tx_ids & voided_by )
185
185
186
186
# Union of voided_by of inputs
@@ -189,13 +189,13 @@ def update_voided_info(self, tx: Transaction) -> None:
189
189
spent_meta = spent_tx .get_metadata ()
190
190
if spent_meta .voided_by :
191
191
voided_by .update (spent_meta .voided_by )
192
- voided_by .discard (settings .SOFT_VOIDED_ID )
193
- assert settings .SOFT_VOIDED_ID not in voided_by
192
+ voided_by .discard (self . _settings .SOFT_VOIDED_ID )
193
+ assert self . _settings .SOFT_VOIDED_ID not in voided_by
194
194
195
195
# Update accumulated weight of the transactions voiding us.
196
196
assert tx .hash not in voided_by
197
197
for h in voided_by :
198
- if h == settings .SOFT_VOIDED_ID :
198
+ if h == self . _settings .SOFT_VOIDED_ID :
199
199
continue
200
200
tx2 = tx .storage .get_transaction (h )
201
201
tx2_meta = tx2 .get_metadata ()
@@ -207,7 +207,7 @@ def update_voided_info(self, tx: Transaction) -> None:
207
207
assert not meta .voided_by or meta .voided_by == {tx .hash }
208
208
assert meta .accumulated_weight == tx .weight
209
209
if tx .hash in self .context .consensus .soft_voided_tx_ids :
210
- voided_by .add (settings .SOFT_VOIDED_ID )
210
+ voided_by .add (self . _settings .SOFT_VOIDED_ID )
211
211
voided_by .add (tx .hash )
212
212
if meta .conflict_with :
213
213
voided_by .add (tx .hash )
@@ -221,7 +221,7 @@ def update_voided_info(self, tx: Transaction) -> None:
221
221
222
222
# Check conflicts of the transactions voiding us.
223
223
for h in voided_by :
224
- if h == settings .SOFT_VOIDED_ID :
224
+ if h == self . _settings .SOFT_VOIDED_ID :
225
225
continue
226
226
if h == tx .hash :
227
227
continue
@@ -300,7 +300,7 @@ def check_conflicts(self, tx: Transaction) -> None:
300
300
candidate .update_accumulated_weight (stop_value = meta .accumulated_weight )
301
301
tx_meta = candidate .get_metadata ()
302
302
d = tx_meta .accumulated_weight - meta .accumulated_weight
303
- if abs (d ) < settings .WEIGHT_TOL :
303
+ if abs (d ) < self . _settings .WEIGHT_TOL :
304
304
tie_list .append (candidate )
305
305
elif d > 0 :
306
306
is_highest = False
0 commit comments