Skip to content

Commit

Permalink
refactor(feature-activation): remove enable_usage
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Jan 12, 2024
1 parent 64d0a86 commit 12992a0
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 39 deletions.
4 changes: 3 additions & 1 deletion hathor/cli/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ def execute(args: Namespace) -> None:
block.nonce, block.weight))

try:
from unittest.mock import Mock

from hathor.conf.get_settings import get_settings
from hathor.daa import DifficultyAdjustmentAlgorithm
from hathor.verification.verification_service import VerificationService, VertexVerifiers
settings = get_settings()
daa = DifficultyAdjustmentAlgorithm(settings=settings)
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa)
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa, feature_service=Mock())
verification_service = VerificationService(verifiers=verifiers)
verification_service.verify_without_storage(block)
except HathorError:
Expand Down
1 change: 0 additions & 1 deletion hathor/conf/mainnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@
'000045ecbab77c9a8d819ff6d26893b9da2774eee5539f17d8fc2394f82b758e',
])),
FEATURE_ACTIVATION=FeatureActivationSettings(
enable_usage=True,
features={
Feature.NOP_FEATURE_1: Criteria(
bit=0,
Expand Down
1 change: 0 additions & 1 deletion hathor/conf/mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ SOFT_VOIDED_TX_IDS:
- 000045ecbab77c9a8d819ff6d26893b9da2774eee5539f17d8fc2394f82b758e

FEATURE_ACTIVATION:
enable_usage: true
features:
#### First Phased Testing features on mainnet ####

Expand Down
1 change: 0 additions & 1 deletion hathor/conf/testnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
],
FEATURE_ACTIVATION=FeatureActivationSettings(
evaluation_interval=40_320,
enable_usage=True,
default_threshold=30240,
features={
Feature.NOP_FEATURE_4: Criteria(
Expand Down
1 change: 0 additions & 1 deletion hathor/conf/testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ CHECKPOINTS:

FEATURE_ACTIVATION:
evaluation_interval: 40_320
enable_usage: true
default_threshold: 30_240 # 30240 = 75% of evaluation_interval (40320)
features:
#### Second Phased Testing features ####
Expand Down
3 changes: 0 additions & 3 deletions hathor/feature_activation/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class Settings(BaseModel, validate_all=True):
# neither their values changed, to preserve history.
features: dict[Feature, Criteria] = {}

# Boolean indicating whether feature activation can be used.
enable_usage: bool = False

@validator('default_threshold')
def _validate_default_threshold(cls, default_threshold: int, values: dict[str, Any]) -> int:
"""Validates that the default_threshold is not greater than the evaluation_interval."""
Expand Down
2 changes: 1 addition & 1 deletion hathor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ def tx_fully_validated(self, tx: BaseTransaction, *, quiet: bool) -> None:

def _log_feature_states(self, vertex: BaseTransaction) -> None:
"""Log features states for a block. Used as part of the Feature Activation Phased Testing."""
if not self._settings.FEATURE_ACTIVATION.enable_usage or not isinstance(vertex, Block):
if not isinstance(vertex, Block):
return

feature_descriptions = self._feature_service.get_bits_description(block=vertex)
Expand Down
7 changes: 1 addition & 6 deletions hathor/verification/block_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
*,
settings: HathorSettings,
daa: DifficultyAdjustmentAlgorithm,
feature_service: FeatureService | None = None
feature_service: FeatureService,
) -> None:
self._settings = settings
self._daa = daa
Expand Down Expand Up @@ -82,11 +82,6 @@ def verify_data(self, block: Block) -> None:

def verify_mandatory_signaling(self, block: Block) -> None:
"""Verify whether this block is missing mandatory signaling for any feature."""
if not self._settings.FEATURE_ACTIVATION.enable_usage:
return

assert self._feature_service is not None

signaling_state = self._feature_service.is_signaling_mandatory_features(block)

match signaling_state:
Expand Down
4 changes: 2 additions & 2 deletions hathor/verification/vertex_verifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create_defaults(
*,
settings: HathorSettings,
daa: DifficultyAdjustmentAlgorithm,
feature_service: FeatureService | None = None,
feature_service: FeatureService,
) -> 'VertexVerifiers':
"""
Create a VertexVerifiers instance using the default verifier for each vertex type,
Expand All @@ -60,7 +60,7 @@ def create(
settings: HathorSettings,
vertex_verifier: VertexVerifier,
daa: DifficultyAdjustmentAlgorithm,
feature_service: FeatureService | None = None,
feature_service: FeatureService,
) -> 'VertexVerifiers':
"""
Create a VertexVerifiers instance using a custom vertex_verifier.
Expand Down
3 changes: 0 additions & 3 deletions tests/feature_activation/test_feature_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def test_feature(self) -> None:
method calls to make sure we're executing it in the intended, most performatic way.
"""
feature_settings = FeatureSettings(
enable_usage=True,
evaluation_interval=4,
max_signal_bits=4,
default_threshold=3,
Expand Down Expand Up @@ -336,7 +335,6 @@ def test_feature(self) -> None:

def test_reorg(self) -> None:
feature_settings = FeatureSettings(
enable_usage=True,
evaluation_interval=4,
max_signal_bits=4,
default_threshold=3,
Expand Down Expand Up @@ -551,7 +549,6 @@ def test_feature_from_existing_storage(self) -> None:
Tests that feature states are correctly retrieved from an existing storage, so no recalculation is required.
"""
feature_settings = FeatureSettings(
enable_usage=True,
evaluation_interval=4,
max_signal_bits=4,
default_threshold=3,
Expand Down
17 changes: 0 additions & 17 deletions tests/tx/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,8 @@ def test_get_feature_activation_bit_value() -> None:
assert block.get_feature_activation_bit_value(3) == 0


@pytest.mark.parametrize(
'is_signaling_mandatory_features',
[BlockIsSignaling(), BlockIsMissingSignal(feature=Feature.NOP_FEATURE_1)]
)
def test_verify_must_signal_when_feature_activation_is_disabled(is_signaling_mandatory_features: bool) -> None:
settings = Mock(spec_set=HathorSettings)
settings.FEATURE_ACTIVATION.enable_usage = False
feature_service = Mock(spec_set=FeatureService)
feature_service.is_signaling_mandatory_features = Mock(return_value=is_signaling_mandatory_features)
verifier = BlockVerifier(settings=settings, feature_service=feature_service, daa=Mock())
block = Block()

verifier.verify_mandatory_signaling(block)


def test_verify_must_signal() -> None:
settings = Mock(spec_set=HathorSettings)
settings.FEATURE_ACTIVATION.enable_usage = True
feature_service = Mock(spec_set=FeatureService)
feature_service.is_signaling_mandatory_features = Mock(
return_value=BlockIsMissingSignal(feature=Feature.NOP_FEATURE_1)
Expand All @@ -171,7 +155,6 @@ def test_verify_must_signal() -> None:

def test_verify_must_not_signal() -> None:
settings = Mock(spec_set=HathorSettings)
settings.FEATURE_ACTIVATION.enable_usage = True
feature_service = Mock(spec_set=FeatureService)
feature_service.is_signaling_mandatory_features = Mock(return_value=BlockIsSignaling())
verifier = BlockVerifier(settings=settings, feature_service=feature_service, daa=Mock())
Expand Down
4 changes: 3 additions & 1 deletion tests/tx/test_genesis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import Mock

from hathor.conf import HathorSettings
from hathor.daa import DifficultyAdjustmentAlgorithm, TestMode
from hathor.transaction.storage import TransactionMemoryStorage
Expand Down Expand Up @@ -30,7 +32,7 @@ class GenesisTest(unittest.TestCase):
def setUp(self):
super().setUp()
self._daa = DifficultyAdjustmentAlgorithm(settings=self._settings)
verifiers = VertexVerifiers.create_defaults(settings=self._settings, daa=self._daa)
verifiers = VertexVerifiers.create_defaults(settings=self._settings, daa=self._daa, feature_service=Mock())
self._verification_service = VerificationService(verifiers=verifiers)
self.storage = TransactionMemoryStorage()

Expand Down
4 changes: 3 additions & 1 deletion tests/tx/test_tx_deserialization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import Mock

from hathor.daa import DifficultyAdjustmentAlgorithm
from hathor.transaction import Block, MergeMinedBlock, Transaction, TxVersion
from hathor.transaction.token_creation_tx import TokenCreationTransaction
Expand All @@ -11,7 +13,7 @@ class _DeserializationTest(unittest.TestCase):
def setUp(self) -> None:
super().setUp()
daa = DifficultyAdjustmentAlgorithm(settings=self._settings)
verifiers = VertexVerifiers.create_defaults(settings=self._settings, daa=daa)
verifiers = VertexVerifiers.create_defaults(settings=self._settings, daa=daa, feature_service=Mock())
self._verification_service = VerificationService(verifiers=verifiers)

def test_deserialize(self):
Expand Down

0 comments on commit 12992a0

Please sign in to comment.