15
15
from dataclasses import dataclass
16
16
from typing import TYPE_CHECKING , Optional , TypeAlias
17
17
18
+ from hathor .conf .settings import HathorSettings
18
19
from hathor .feature_activation .feature import Feature
19
- from hathor .feature_activation .model .feature_description import FeatureDescription
20
+ from hathor .feature_activation .model .feature_info import FeatureInfo
20
21
from hathor .feature_activation .model .feature_state import FeatureState
21
- from hathor .feature_activation .settings import Settings as FeatureSettings
22
22
23
23
if TYPE_CHECKING :
24
24
from hathor .feature_activation .bit_signaling_service import BitSignalingService
@@ -44,8 +44,8 @@ class BlockIsMissingSignal:
44
44
class FeatureService :
45
45
__slots__ = ('_feature_settings' , '_tx_storage' , 'bit_signaling_service' )
46
46
47
- def __init__ (self , * , feature_settings : FeatureSettings , tx_storage : 'TransactionStorage' ) -> None :
48
- self ._feature_settings = feature_settings
47
+ def __init__ (self , * , settings : HathorSettings , tx_storage : 'TransactionStorage' ) -> None :
48
+ self ._feature_settings = settings . FEATURE_ACTIVATION
49
49
self ._tx_storage = tx_storage
50
50
self .bit_signaling_service : Optional ['BitSignalingService' ] = None
51
51
@@ -64,11 +64,11 @@ def is_signaling_mandatory_features(self, block: 'Block') -> BlockSignalingState
64
64
height = block .static_metadata .height
65
65
offset_to_boundary = height % self ._feature_settings .evaluation_interval
66
66
remaining_blocks = self ._feature_settings .evaluation_interval - offset_to_boundary - 1
67
- descriptions = self .get_bits_description (block = block )
67
+ feature_infos = self .get_feature_infos (block = block )
68
68
69
69
must_signal_features = (
70
- feature for feature , description in descriptions .items ()
71
- if description .state is FeatureState .MUST_SIGNAL
70
+ feature for feature , feature_info in feature_infos .items ()
71
+ if feature_info .state is FeatureState .MUST_SIGNAL
72
72
)
73
73
74
74
for feature in must_signal_features :
@@ -192,12 +192,12 @@ def _calculate_new_state(
192
192
if previous_state is FeatureState .FAILED :
193
193
return FeatureState .FAILED
194
194
195
- raise ValueError (f'Unknown previous state: { previous_state } ' )
195
+ raise NotImplementedError (f'Unknown previous state: { previous_state } ' )
196
196
197
- def get_bits_description (self , * , block : 'Block' ) -> dict [Feature , FeatureDescription ]:
197
+ def get_feature_infos (self , * , block : 'Block' ) -> dict [Feature , FeatureInfo ]:
198
198
"""Returns the criteria definition and feature state for all features at a certain block."""
199
199
return {
200
- feature : FeatureDescription (
200
+ feature : FeatureInfo (
201
201
criteria = criteria ,
202
202
state = self .get_state (block = block , feature = feature )
203
203
)
@@ -223,9 +223,11 @@ def _get_ancestor_at_height(self, *, block: 'Block', ancestor_height: int) -> 'B
223
223
if parent_block .static_metadata .height == ancestor_height :
224
224
return parent_block
225
225
226
- if not parent_metadata .voided_by and (ancestor := self ._tx_storage .get_block_by_height (ancestor_height )):
227
- from hathor .transaction import Block
228
- assert isinstance (ancestor , Block )
226
+ if not parent_metadata .voided_by :
227
+ ancestor = self ._tx_storage .get_block_by_height (ancestor_height )
228
+ assert ancestor is not None , (
229
+ 'it is guaranteed that the ancestor of a fully connected and non-voided block is in the height index'
230
+ )
229
231
return ancestor
230
232
231
233
return self ._get_ancestor_iteratively (block = parent_block , ancestor_height = ancestor_height )
0 commit comments