Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions hathor/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BuildArtifacts(NamedTuple):


_VertexVerifiersBuilder: TypeAlias = Callable[
[HathorSettingsType, DifficultyAdjustmentAlgorithm, FeatureService],
[HathorSettingsType, DifficultyAdjustmentAlgorithm],
VertexVerifiers
]

Expand Down Expand Up @@ -493,7 +493,13 @@ def _get_or_create_bit_signaling_service(self) -> BitSignalingService:
def _get_or_create_verification_service(self) -> VerificationService:
if self._verification_service is None:
verifiers = self._get_or_create_vertex_verifiers()
self._verification_service = VerificationService(verifiers=verifiers)
daa = self._get_or_create_daa()
feature_service = self._get_or_create_feature_service()
self._verification_service = VerificationService(
verifiers=verifiers,
daa=daa,
feature_service=feature_service
)

return self._verification_service

Expand All @@ -509,17 +515,12 @@ def _get_or_create_feature_storage(self) -> FeatureActivationStorage | None:
def _get_or_create_vertex_verifiers(self) -> VertexVerifiers:
if self._vertex_verifiers is None:
settings = self._get_or_create_settings()
feature_service = self._get_or_create_feature_service()
daa = self._get_or_create_daa()

if self._vertex_verifiers_builder:
self._vertex_verifiers = self._vertex_verifiers_builder(settings, daa, feature_service)
self._vertex_verifiers = self._vertex_verifiers_builder(settings, daa)
else:
self._vertex_verifiers = VertexVerifiers.create_defaults(
settings=settings,
daa=daa,
feature_service=feature_service,
)
self._vertex_verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa)

return self._vertex_verifiers

Expand Down
6 changes: 3 additions & 3 deletions hathor/builder/cli_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ def create_manager(self, reactor: Reactor) -> HathorManager:

daa = DifficultyAdjustmentAlgorithm(settings=settings, test_mode=test_mode)

vertex_verifiers = VertexVerifiers.create_defaults(
settings=settings,
vertex_verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa)
verification_service = VerificationService(
verifiers=vertex_verifiers,
daa=daa,
feature_service=self.feature_service
)
verification_service = VerificationService(verifiers=vertex_verifiers)

cpu_mining_service = CpuMiningService()

Expand Down
6 changes: 2 additions & 4 deletions hathor/cli/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,14 @@ def execute(args: Namespace) -> None:
block.nonce, block.weight))

try:
from unittest.mock import Mock

from hathor.conf.get_settings import get_global_settings
from hathor.daa import DifficultyAdjustmentAlgorithm
from hathor.verification.verification_service import VerificationService
from hathor.verification.vertex_verifiers import VertexVerifiers
settings = get_global_settings()
daa = DifficultyAdjustmentAlgorithm(settings=settings)
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa, feature_service=Mock())
verification_service = VerificationService(verifiers=verifiers)
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa)
verification_service = VerificationService(verifiers=verifiers, daa=daa)
verification_service.verify_without_storage(block)
except HathorError:
print('[{}] ERROR: Block has not been pushed because it is not valid.'.format(datetime.datetime.now()))
Expand Down
2 changes: 1 addition & 1 deletion hathor/feature_activation/bit_signaling_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _log_signal_bits(self, feature: Feature, enable_bit: bool, support: bool, no

def _get_signaling_features(self, block: Block) -> dict[Feature, Criteria]:
"""Given a specific block, return all features that are in a signaling state for that block."""
feature_descriptions = self._feature_service.get_bits_description(block=block)
feature_descriptions = self._feature_service.get_feature_info(block=block)
signaling_features = {
feature: description.criteria
for feature, description in feature_descriptions.items()
Expand Down
8 changes: 4 additions & 4 deletions hathor/feature_activation/feature_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import TYPE_CHECKING, Optional, TypeAlias

from hathor.feature_activation.feature import Feature
from hathor.feature_activation.model.feature_description import FeatureDescription
from hathor.feature_activation.model.feature_description import FeatureInfo
from hathor.feature_activation.model.feature_state import FeatureState
from hathor.feature_activation.settings import Settings as FeatureSettings

Expand Down Expand Up @@ -64,7 +64,7 @@ def is_signaling_mandatory_features(self, block: 'Block') -> BlockSignalingState
height = block.get_height()
offset_to_boundary = height % self._feature_settings.evaluation_interval
remaining_blocks = self._feature_settings.evaluation_interval - offset_to_boundary - 1
descriptions = self.get_bits_description(block=block)
descriptions = self.get_feature_info(block=block)

must_signal_features = (
feature for feature, description in descriptions.items()
Expand Down Expand Up @@ -194,10 +194,10 @@ def _calculate_new_state(

raise ValueError(f'Unknown previous state: {previous_state}')

def get_bits_description(self, *, block: 'Block') -> dict[Feature, FeatureDescription]:
def get_feature_info(self, *, block: 'Block') -> dict[Feature, FeatureInfo]:
"""Returns the criteria definition and feature state for all features at a certain block."""
return {
feature: FeatureDescription(
feature: FeatureInfo(
criteria=criteria,
state=self.get_state(block=block, feature=feature)
)
Expand Down
2 changes: 1 addition & 1 deletion hathor/feature_activation/model/feature_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from hathor.feature_activation.model.feature_state import FeatureState


class FeatureDescription(NamedTuple):
class FeatureInfo(NamedTuple):
"""Represents all information related to one feature, that is, its criteria and state."""
criteria: Criteria
state: FeatureState
4 changes: 4 additions & 0 deletions hathor/feature_activation/model/feature_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ def get_signaling_states() -> set['FeatureState']:
support it or not through bit signals is valid during those states.
"""
return {FeatureState.STARTED, FeatureState.MUST_SIGNAL, FeatureState.LOCKED_IN}

def is_active(self) -> bool:
"""Return whether the state is active."""
return self is FeatureState.ACTIVE
2 changes: 1 addition & 1 deletion hathor/feature_activation/resources/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_block_features(self, request: Request) -> bytes:
return error.json_dumpb()

signal_bits = []
feature_descriptions = self._feature_service.get_bits_description(block=block)
feature_descriptions = self._feature_service.get_feature_info(block=block)

for feature, description in feature_descriptions.items():
if description.state not in FeatureState.get_signaling_states():
Expand Down
10 changes: 7 additions & 3 deletions hathor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _initialize_components_full_verification(self) -> None:
tx.calculate_height()
tx._update_parents_children_metadata()

if tx.can_validate_full():
if self.tx_storage.can_validate_full(tx):
tx.update_initial_metadata()
tx.calculate_min_height()
if tx.is_genesis:
Expand Down Expand Up @@ -944,7 +944,8 @@ def propagate_tx(self, tx: BaseTransaction, fails_silently: bool = True) -> bool
@cpu.profiler('on_new_tx')
def on_new_tx(self, tx: BaseTransaction, *, conn: Optional[HathorProtocol] = None,
quiet: bool = False, fails_silently: bool = True, propagate_to_peers: bool = True,
skip_block_weight_verification: bool = False, reject_locked_reward: bool = True) -> bool:
skip_block_weight_verification: bool = False, reject_locked_reward: bool = True,
is_sync_v2: bool = False) -> bool:
""" New method for adding transactions or blocks that steps the validation state machine.

:param tx: transaction to be added
Expand All @@ -957,6 +958,9 @@ def on_new_tx(self, tx: BaseTransaction, *, conn: Optional[HathorProtocol] = Non
assert self.tx_storage.is_only_valid_allowed()
assert tx.hash is not None

# if is_sync_v2:
# assert tx.storage is None

already_exists = False
if self.tx_storage.transaction_exists(tx.hash):
self.tx_storage.compare_bytes_with_local_tx(tx)
Expand Down Expand Up @@ -1077,7 +1081,7 @@ def _log_feature_states(self, vertex: BaseTransaction) -> None:
if not isinstance(vertex, Block):
return

feature_descriptions = self._feature_service.get_bits_description(block=vertex)
feature_descriptions = self._feature_service.get_feature_info(block=vertex)
state_by_feature = {
feature.value: description.state.value
for feature, description in feature_descriptions.items()
Expand Down
Loading