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

feat(feature-activation): implement closest_block metadata and Feature Activation for Transactions #933

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

glevco
Copy link
Contributor

@glevco glevco commented Jan 23, 2024

Depends on #927

Motivation

Implement the new closest_block metadata that will enable Feature Activation for Transactions.

Acceptance Criteria

  • Rename FeatureService.is_feature_active() to is_feature_active_for_block().
  • Implement FeatureService.is_feature_active_for_transaction().
  • Create new closest_block metadata, with a migration for it.
  • Implement BaseTransaction._update_closest_block_metadata().
  • Tests will be implemented in a separate PR.

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@glevco glevco force-pushed the feat/feature-activation/txs-closest-block branch from cfe1640 to d3d069c Compare January 23, 2024 17:56
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (9ef629f) 85.30% compared to head (d3d069c) 85.32%.

Files Patch % Lines
...n/storage/migrations/add_closest_block_metadata.py 68.75% 5 Missing ⚠️
hathor/feature_activation/feature_service.py 50.00% 3 Missing ⚠️
hathor/manager.py 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                               Coverage Diff                                @@
##           fix/feature-activation/add-missing-migration     #933      +/-   ##
================================================================================
+ Coverage                                         85.30%   85.32%   +0.02%     
================================================================================
  Files                                               289      290       +1     
  Lines                                             22411    22465      +54     
  Branches                                           3373     3381       +8     
================================================================================
+ Hits                                              19117    19168      +51     
- Misses                                             2620     2623       +3     
  Partials                                            674      674              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"""Returns whether a Feature is active at a certain block."""
def is_feature_active_for_transaction(self, *, tx: 'Transaction', feature: Feature) -> bool:
"""Return whether a Feature is active for a certain Transaction."""
metadata = tx.get_metadata()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert that isinstance(tx, Transaction) to prevent bugs if mypy fails to detect wrong call types.

this_closest_block = vertex
elif isinstance(vertex, Transaction):
this_closest_block_id = (
self._settings.GENESIS_BLOCK_HASH if vertex.is_genesis else not_none(vertex_meta.closest_block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can safely do not_none(vertex_meta.closest_block).

return
assert isinstance(self, Transaction)
assert self.storage is not None
metadata = self.get_metadata()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if metadata.closest_block is not None and returns if true.


if isinstance(vertex, Block):
assert vertex_meta.closest_block is None
this_closest_block = vertex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name it candidate_block.

# For Blocks, this is None. For Transactions, this is the Block with the greatest height that is a direct or
# indirect dependency (ancestor) of the transaction, including both funds and confirmation DAGs.
# It's used by Feature Activation for Transactions.
closest_block: VertexId | None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name it closest_ancestor_block.

@glevco glevco force-pushed the fix/feature-activation/add-missing-migration branch 2 times, most recently from d5306f4 to bbcd88a Compare January 29, 2024 02:17
Base automatically changed from fix/feature-activation/add-missing-migration to master January 29, 2024 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

None yet

2 participants