Skip to content

Commit dfb7c66

Browse files
committed
review changes
1 parent ffa58f7 commit dfb7c66

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

hathor/builder/builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ def build(self) -> BuildArtifacts:
177177
feature_service = self._get_or_create_feature_service()
178178
bit_signaling_service = self._get_or_create_bit_signaling_service()
179179
verification_service = self._get_or_create_verification_service()
180-
feature_storage = self._get_or_create_feature_storage()
181180
daa = self._get_or_create_daa()
182181
cpu_mining_service = self._get_or_create_cpu_mining_service()
183182

@@ -216,7 +215,6 @@ def build(self) -> BuildArtifacts:
216215
environment_info=get_environment_info(self._cmdline, peer_id.id),
217216
feature_service=feature_service,
218217
bit_signaling_service=bit_signaling_service,
219-
feature_storage=feature_storage,
220218
verification_service=verification_service,
221219
cpu_mining_service=cpu_mining_service,
222220
**kwargs
@@ -464,12 +462,14 @@ def _get_or_create_bit_signaling_service(self) -> BitSignalingService:
464462
settings = self._get_or_create_settings()
465463
tx_storage = self._get_or_create_tx_storage()
466464
feature_service = self._get_or_create_feature_service()
465+
feature_storage = self._get_or_create_feature_storage()
467466
self._bit_signaling_service = BitSignalingService(
468467
feature_settings=settings.FEATURE_ACTIVATION,
469468
feature_service=feature_service,
470469
tx_storage=tx_storage,
471470
support_features=self._support_features,
472471
not_support_features=self._not_support_features,
472+
feature_storage=feature_storage,
473473
)
474474

475475
return self._bit_signaling_service

hathor/builder/cli_builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
214214
feature_service=self.feature_service,
215215
tx_storage=tx_storage,
216216
support_features=self._args.signal_support,
217-
not_support_features=self._args.signal_not_support
217+
not_support_features=self._args.signal_not_support,
218+
feature_storage=feature_storage,
218219
)
219220

220221
test_mode = TestMode.DISABLED
@@ -271,7 +272,6 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
271272
bit_signaling_service=bit_signaling_service,
272273
verification_service=verification_service,
273274
cpu_mining_service=cpu_mining_service,
274-
feature_storage=feature_storage,
275275
)
276276

277277
p2p_manager.set_manager(self.manager)

hathor/cli/reset_feature_settings.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
from structlog import get_logger
1818

19-
from hathor.conf.get_settings import get_settings
20-
from hathor.feature_activation.storage.feature_activation_storage import FeatureActivationStorage
21-
2219
logger = get_logger()
2320

2421

@@ -32,6 +29,8 @@ def create_parser() -> ArgumentParser:
3229

3330

3431
def execute(args: Namespace) -> None:
32+
from hathor.conf.get_settings import get_settings
33+
from hathor.feature_activation.storage.feature_activation_storage import FeatureActivationStorage
3534
from hathor.storage import RocksDBStorage
3635

3736
assert args.data is not None, '--data is required'

hathor/feature_activation/bit_signaling_service.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from hathor.feature_activation.model.criteria import Criteria
2020
from hathor.feature_activation.model.feature_state import FeatureState
2121
from hathor.feature_activation.settings import Settings as FeatureSettings
22+
from hathor.feature_activation.storage.feature_activation_storage import FeatureActivationStorage
2223
from hathor.transaction import Block
2324
from hathor.transaction.storage import TransactionStorage
2425

@@ -32,7 +33,8 @@ class BitSignalingService:
3233
'_feature_service',
3334
'_tx_storage',
3435
'_support_features',
35-
'_not_support_features'
36+
'_not_support_features',
37+
'_feature_storage',
3638
)
3739

3840
def __init__(
@@ -42,14 +44,16 @@ def __init__(
4244
feature_service: FeatureService,
4345
tx_storage: TransactionStorage,
4446
support_features: set[Feature],
45-
not_support_features: set[Feature]
47+
not_support_features: set[Feature],
48+
feature_storage: FeatureActivationStorage | None,
4649
) -> None:
4750
self._log = logger.new()
4851
self._feature_settings = feature_settings
4952
self._feature_service = feature_service
5053
self._tx_storage = tx_storage
5154
self._support_features = support_features
5255
self._not_support_features = not_support_features
56+
self._feature_storage = feature_storage
5357

5458
self._validate_support_intersection()
5559

@@ -58,6 +62,9 @@ def start(self) -> None:
5862
Log information related to bit signaling. Must be called after the storage is ready and migrations have
5963
been applied.
6064
"""
65+
if self._feature_storage:
66+
self._feature_storage.validate_settings()
67+
6168
best_block = self._tx_storage.get_best_block()
6269

6370
self._warn_non_signaling_features(best_block)

hathor/feature_activation/storage/feature_activation_storage.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ def __init__(self, *, settings: HathorSettings, rocksdb_storage: RocksDBStorage)
3535
self._db = rocksdb_storage.get_db()
3636
self._cf_meta = rocksdb_storage.get_or_create_column_family(_CF_NAME_META)
3737

38-
def start(self) -> None:
39-
"""Start the storage."""
40-
self._validate_settings()
41-
4238
def reset_settings(self) -> None:
4339
"""Reset feature settings from the database."""
4440
self._db.delete((self._cf_meta, _KEY_SETTINGS))
4541

46-
def _validate_settings(self) -> None:
42+
def validate_settings(self) -> None:
4743
"""Validate new feature settings against the previous configuration from the database."""
4844
new_settings = self._settings.FEATURE_ACTIVATION
4945
db_settings_bytes: bytes | None = self._db.get((self._cf_meta, _KEY_SETTINGS))

hathor/manager.py

-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from hathor.feature_activation.bit_signaling_service import BitSignalingService
4444
from hathor.feature_activation.feature import Feature
4545
from hathor.feature_activation.feature_service import FeatureService
46-
from hathor.feature_activation.storage.feature_activation_storage import FeatureActivationStorage
4746
from hathor.mining import BlockTemplate, BlockTemplates
4847
from hathor.mining.cpu_mining_service import CpuMiningService
4948
from hathor.p2p.manager import ConnectionsManager
@@ -100,7 +99,6 @@ def __init__(self,
10099
event_manager: EventManager,
101100
feature_service: FeatureService,
102101
bit_signaling_service: BitSignalingService,
103-
feature_storage: FeatureActivationStorage | None,
104102
verification_service: VerificationService,
105103
cpu_mining_service: CpuMiningService,
106104
network: str,
@@ -180,7 +178,6 @@ def __init__(self,
180178

181179
self._feature_service = feature_service
182180
self._bit_signaling_service = bit_signaling_service
183-
self._feature_storage = feature_storage
184181
self.verification_service = verification_service
185182
self.cpu_mining_service = cpu_mining_service
186183

@@ -283,9 +280,6 @@ def start(self) -> None:
283280
self._event_manager.load_started()
284281
self.pow_thread_pool.start()
285282

286-
if self._feature_storage:
287-
self._feature_storage.start()
288-
289283
# Disable get transaction lock when initializing components
290284
self.tx_storage.disable_lock()
291285
# Open scope for initialization.

tests/feature_activation/test_bit_signaling_service.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def _test_generate_signal_bits(
173173
feature_service=feature_service,
174174
tx_storage=Mock(),
175175
support_features=support_features,
176-
not_support_features=not_support_features
176+
not_support_features=not_support_features,
177+
feature_storage=Mock(),
177178
)
178179

179180
return service.generate_signal_bits(block=Mock())
@@ -216,6 +217,7 @@ def test_support_intersection_validation(
216217
tx_storage=Mock(),
217218
support_features=support_features,
218219
not_support_features=not_support_features,
220+
feature_storage=Mock(),
219221
)
220222

221223
message = str(e.value)
@@ -270,6 +272,7 @@ def get_bits_description_mock(block):
270272
tx_storage=tx_storage,
271273
support_features=support_features,
272274
not_support_features=not_support_features,
275+
feature_storage=Mock(),
273276
)
274277
logger_mock = Mock()
275278
service._log = logger_mock

0 commit comments

Comments
 (0)