22
22
from itertools import chain
23
23
from math import inf , isfinite , log
24
24
from struct import error as StructError , pack
25
- from typing import TYPE_CHECKING , Any , ClassVar , Generic , Iterator , Optional , TypeAlias , TypeVar , cast
25
+ from typing import TYPE_CHECKING , Any , ClassVar , Generic , Iterator , Optional , TypeAlias , TypeVar
26
26
27
27
from structlog import get_logger
28
28
29
29
from hathor .checkpoint import Checkpoint
30
30
from hathor .conf .get_settings import get_global_settings
31
+ from hathor .conf .settings import HathorSettings
31
32
from hathor .transaction .exceptions import InvalidOutputValue , WeightError
32
33
from hathor .transaction .static_metadata import VertexStaticMetadata
33
34
from hathor .transaction .transaction_metadata import TransactionMetadata
@@ -272,14 +273,6 @@ def __bytes__(self) -> bytes:
272
273
def __hash__ (self ) -> int :
273
274
return hash (self .hash )
274
275
275
- @abstractmethod
276
- def calculate_height (self ) -> int :
277
- raise NotImplementedError
278
-
279
- @abstractmethod
280
- def calculate_min_height (self ) -> int :
281
- raise NotImplementedError
282
-
283
276
@property
284
277
def hash (self ) -> VertexId :
285
278
assert self ._hash is not None , 'Vertex hash must be initialized.'
@@ -624,19 +617,11 @@ def get_metadata(self, *, force_reload: bool = False, use_storage: bool = True)
624
617
metadata = self .storage .get_metadata (self .hash )
625
618
self ._metadata = metadata
626
619
if not metadata :
627
- # FIXME: there is code that set use_storage=False but relies on correct height being calculated
628
- # which requires the use of a storage, this is a workaround that should be fixed, places where this
629
- # happens include generating new mining blocks and some tests
630
- height = self .calculate_height () if self .storage else None
631
620
score = self .weight if self .is_genesis else 0
632
- min_height = 0 if self .is_genesis else None
633
-
634
621
metadata = TransactionMetadata (
635
622
hash = self ._hash ,
636
623
accumulated_weight = self .weight ,
637
- height = height ,
638
624
score = score ,
639
- min_height = min_height
640
625
)
641
626
self ._metadata = metadata
642
627
if not metadata .hash :
@@ -662,8 +647,6 @@ def reset_metadata(self) -> None:
662
647
self ._metadata .voided_by = {self ._settings .PARTIALLY_VALIDATED_ID }
663
648
self ._metadata ._tx_ref = weakref .ref (self )
664
649
665
- self ._update_height_metadata ()
666
-
667
650
self .storage .save_transaction (self , only_metadata = True )
668
651
669
652
def update_accumulated_weight (self , * , stop_value : float = inf , save_file : bool = True ) -> TransactionMetadata :
@@ -717,28 +700,12 @@ def update_initial_metadata(self, *, save: bool = True) -> None:
717
700
718
701
It is called when a new transaction/block is received by HathorManager.
719
702
"""
720
- self ._update_height_metadata ()
721
703
self ._update_parents_children_metadata ()
722
- self .update_reward_lock_metadata ()
723
- self ._update_feature_activation_bit_counts ()
724
704
self ._update_initial_accumulated_weight ()
725
705
if save :
726
706
assert self .storage is not None
727
707
self .storage .save_transaction (self , only_metadata = True )
728
708
729
- def _update_height_metadata (self ) -> None :
730
- """Update the vertice height metadata."""
731
- meta = self .get_metadata ()
732
- meta .height = self .calculate_height ()
733
-
734
- def update_reward_lock_metadata (self ) -> None :
735
- """Update the txs/block min_height metadata."""
736
- metadata = self .get_metadata ()
737
- min_height = self .calculate_min_height ()
738
- if metadata .min_height is not None :
739
- assert metadata .min_height == min_height
740
- metadata .min_height = min_height
741
-
742
709
def _update_parents_children_metadata (self ) -> None :
743
710
"""Update the txs/block parent's children metadata."""
744
711
assert self ._hash is not None
@@ -750,15 +717,6 @@ def _update_parents_children_metadata(self) -> None:
750
717
metadata .children .append (self .hash )
751
718
self .storage .save_transaction (parent , only_metadata = True )
752
719
753
- def _update_feature_activation_bit_counts (self ) -> None :
754
- """Update the block's feature_activation_bit_counts."""
755
- if not self .is_block :
756
- return
757
- from hathor .transaction import Block
758
- assert isinstance (self , Block )
759
- # This method lazily calculates and stores the value in metadata
760
- cast (Block , self ).get_feature_activation_bit_counts ()
761
-
762
720
def _update_initial_accumulated_weight (self ) -> None :
763
721
"""Update the vertex initial accumulated_weight."""
764
722
metadata = self .get_metadata ()
@@ -901,7 +859,7 @@ def static_metadata(self) -> StaticMetadataT:
901
859
return self ._static_metadata
902
860
903
861
@abstractmethod
904
- def init_static_metadata_from_storage (self , storage : 'TransactionStorage' ) -> None :
862
+ def init_static_metadata_from_storage (self , settings : HathorSettings , storage : 'TransactionStorage' ) -> None :
905
863
"""Initialize this vertex's static metadata using dependencies from a storage. This can be called multiple
906
864
times, provided the dependencies didn't change."""
907
865
raise NotImplementedError
@@ -916,7 +874,8 @@ def set_static_metadata(self, static_metadata: StaticMetadataT | None) -> None:
916
874
917
875
"""
918
876
Type aliases for easily working with `GenericVertex`. A `Vertex` is a superclass that includes all specific
919
- vertex subclasses, and a `BaseTransaction` is simply an alias to `Vertex` for backwards compatibility.
877
+ vertex subclasses, and a `BaseTransaction` is simply an alias to `Vertex` for backwards compatibility (it can be
878
+ removed in the future).
920
879
"""
921
880
Vertex : TypeAlias = GenericVertex [VertexStaticMetadata ]
922
881
BaseTransaction : TypeAlias = Vertex
0 commit comments