Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metadata): actually use None for unset height #671

Merged
merged 1 commit into from
Jun 15, 2023
Merged
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
5 changes: 4 additions & 1 deletion hathor/transaction/base_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def get_metadata(self, *, force_reload: bool = False, use_storage: bool = True)
# FIXME: there is code that set use_storage=False but relies on correct height being calculated
# which requires the use of a storage, this is a workaround that should be fixed, places where this
# happens include generating new mining blocks and some tests
height = self.calculate_height() if self.storage else 0
height = self.calculate_height() if self.storage else None
score = self.weight if self.is_genesis else 0
kwargs: dict[str, Any] = {}

Expand Down Expand Up @@ -913,6 +913,9 @@ def reset_metadata(self) -> None:
self._metadata.validation = ValidationState.INITIAL
self._metadata.voided_by = {settings.PARTIALLY_VALIDATED_ID}
self._metadata._tx_ref = weakref.ref(self)

self._update_height_metadata()

self.storage.save_transaction(self, only_metadata=True)

def update_accumulated_weight(self, *, stop_value: float = inf, save_file: bool = True) -> TransactionMetadata:
Expand Down
7 changes: 7 additions & 0 deletions hathor/transaction/storage/transaction_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def pre_save_validation(self, tx: BaseTransaction, tx_meta: TransactionMetadata)
assert tx.hash == tx_meta.hash, f'{tx.hash.hex()} != {tx_meta.hash.hex()}'
self._validate_partial_marker_consistency(tx_meta)
self._validate_transaction_in_scope(tx)
self._validate_block_height_metadata(tx)

def post_get_validation(self, tx: BaseTransaction) -> None:
""" Must be run before every save, will raise AssertionError or TransactionNotInAllowedScopeError
Expand All @@ -433,6 +434,7 @@ def post_get_validation(self, tx: BaseTransaction) -> None:
tx_meta = tx.get_metadata()
self._validate_partial_marker_consistency(tx_meta)
self._validate_transaction_in_scope(tx)
self._validate_block_height_metadata(tx)

def _validate_partial_marker_consistency(self, tx_meta: TransactionMetadata) -> None:
voided_by = tx_meta.get_frozen_voided_by()
Expand All @@ -447,6 +449,11 @@ def _validate_transaction_in_scope(self, tx: BaseTransaction) -> None:
tx_meta = tx.get_metadata()
raise TransactionNotInAllowedScopeError(tx.hash_hex, self.get_allow_scope().name, tx_meta.validation.name)

def _validate_block_height_metadata(self, tx: BaseTransaction) -> None:
if tx.is_block:
tx_meta = tx.get_metadata()
assert tx_meta.height is not None

@abstractmethod
def remove_transaction(self, tx: BaseTransaction) -> None:
"""Remove the tx.
Expand Down