Skip to content

Commit

Permalink
refactor(static-metadata): undo migration of feature_states to static…
Browse files Browse the repository at this point in the history
… metadata (#1146)
  • Loading branch information
glevco authored Oct 14, 2024
1 parent daf12e7 commit 6a4c562
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 253 deletions.
2 changes: 1 addition & 1 deletion hathor/transaction/static_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def create(
height=height,
min_height=min_height,
feature_activation_bit_counts=feature_activation_bit_counts,
feature_states={}, # This will be populated in the next PR
feature_states={}, # This will be populated in a future PR
)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion hathor/transaction/storage/rocksdb_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def migrate_static_metadata(self, log: BoundLogger) -> None:
height=height,
min_height=min_height,
feature_activation_bit_counts=bit_counts,
feature_states={}, # This will be populated in the next PR
feature_states={}, # This will be populated in a future PR
)
else:
assert bit_counts is None or bit_counts == []
Expand Down
2 changes: 1 addition & 1 deletion hathor/transaction/transaction_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def to_bytes(self) -> bytes:
del json_dict['min_height']
if 'feature_activation_bit_counts' in json_dict:
del json_dict['feature_activation_bit_counts']
# TODO: This one has not been migrated yet, but will be in the next PR
# TODO: This one has not been migrated yet, but will be in a future PR
# if 'feature_states' in json_dict:
# del json_dict['feature_states']

Expand Down
34 changes: 34 additions & 0 deletions tests/feature_activation/test_feature_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,40 @@ def test_get_state_from_active(block_height: int) -> None:
assert result == FeatureState.ACTIVE


@pytest.mark.parametrize('block_height', [16, 17, 18, 19])
def test_caching_mechanism(block_height: int) -> None:
features = {
Feature.NOP_FEATURE_1: Criteria.construct(
bit=3,
start_height=0,
timeout_height=8,
lock_in_on_timeout=True,
version=Mock()
)
}
settings = get_settings(features=features)
storage = get_storage(settings, up_to_height=block_height)
service = FeatureService(
settings=settings,
tx_storage=storage
)
service.bit_signaling_service = Mock()
block = not_none(storage.get_block_by_height(block_height))
calculate_new_state_mock = Mock(wraps=service._calculate_new_state)

with patch.object(FeatureService, '_calculate_new_state', calculate_new_state_mock):
result1 = service.get_state(block=block, feature=Feature.NOP_FEATURE_1)

assert result1 == FeatureState.ACTIVE
assert calculate_new_state_mock.call_count == 4

calculate_new_state_mock.reset_mock()
result2 = service.get_state(block=block, feature=Feature.NOP_FEATURE_1)

assert result2 == FeatureState.ACTIVE
assert calculate_new_state_mock.call_count == 0


@pytest.mark.parametrize('block_height', [16, 17, 18, 19])
def test_is_feature_active(block_height: int) -> None:
features = {
Expand Down
Loading

0 comments on commit 6a4c562

Please sign in to comment.