1919
2020from hathor .feature_activation .feature import Feature
2121from hathor .feature_activation .model .feature_state import FeatureState
22+ from hathor .nanocontracts .nano_runtime_version import NanoRuntimeVersion
2223from hathor .transaction .scripts .opcode import OpcodesVersion
2324
2425if TYPE_CHECKING :
@@ -36,6 +37,7 @@ class Features:
3637 nanocontracts : bool
3738 fee_tokens : bool
3839 opcodes_version : OpcodesVersion
40+ nano_runtime_version : NanoRuntimeVersion
3941
4042 @staticmethod
4143 def from_vertex (* , settings : HathorSettings , feature_service : FeatureService , vertex : Vertex ) -> Features :
@@ -47,6 +49,7 @@ def from_vertex(*, settings: HathorSettings, feature_service: FeatureService, ve
4749 Feature .NANO_CONTRACTS : settings .ENABLE_NANO_CONTRACTS ,
4850 Feature .FEE_TOKENS : settings .ENABLE_FEE_BASED_TOKENS ,
4951 Feature .OPCODES_V2 : settings .ENABLE_OPCODES_V2 ,
52+ Feature .NANO_RUNTIME_V2 : settings .ENABLE_NANO_RUNTIME_V2 ,
5053 }
5154
5255 feature_is_active : dict [Feature , bool ] = {
@@ -55,12 +58,16 @@ def from_vertex(*, settings: HathorSettings, feature_service: FeatureService, ve
5558 }
5659
5760 opcodes_version = OpcodesVersion .V2 if feature_is_active [Feature .OPCODES_V2 ] else OpcodesVersion .V1
61+ nano_runtime_version = (
62+ NanoRuntimeVersion .V2 if feature_is_active [Feature .NANO_RUNTIME_V2 ] else NanoRuntimeVersion .V1
63+ )
5864
5965 return Features (
6066 count_checkdatasig_op = feature_is_active [Feature .COUNT_CHECKDATASIG_OP ],
6167 nanocontracts = feature_is_active [Feature .NANO_CONTRACTS ],
6268 fee_tokens = feature_is_active [Feature .FEE_TOKENS ],
6369 opcodes_version = opcodes_version ,
70+ nano_runtime_version = nano_runtime_version ,
6471 )
6572
6673 @staticmethod
@@ -69,20 +76,23 @@ def for_mempool(*, settings: HathorSettings, feature_service: FeatureService, be
6976 Used for mempool verification.
7077
7178 Features can either be more restrictive (for example, `count_checkdatasig_op`) or more permissive
72- (for example, `nanocontracts`).
79+ (for example, `nanocontracts`) in relation to vertex verification. When a feature doesn't affect
80+ verification, such as changes to the Nano runtime only (`nano_runtime_version`), it is indifferent.
7381
7482 Returns information about each feature where permissive features come from the state in the provided
7583 block, and restrictive features are always enabled. This means restrictive features are applied in
7684 mempool verification regardless of features states in the current best block.
7785 """
7886 features = Features .from_vertex (settings = settings , feature_service = feature_service , vertex = best_block )
7987 return Features (
80- # Permissive features (come from the block state):
81- nanocontracts = features .nanocontracts ,
82- fee_tokens = features .fee_tokens ,
8388 # Restrictive features (hardcoded as enabled):
8489 count_checkdatasig_op = True ,
8590 opcodes_version = OpcodesVersion .V2 ,
91+ # Permissive features (come from the block state):
92+ nanocontracts = features .nanocontracts ,
93+ fee_tokens = features .fee_tokens ,
94+ # Indifferent features (come from the block state):
95+ nano_runtime_version = features .nano_runtime_version ,
8696 )
8797
8898 @staticmethod
@@ -91,14 +101,19 @@ def all_enabled() -> Features:
91101 Used mostly for APIs and tests, it disregards the actual state of the blockchain
92102 and hardcodes all features as enabled.
93103
94- For restrictive features, this means they're restricted on APIs just like in the mempool. For permissive
95- features, they're allowed on APIs, which is fine since they may be blocked during verification anyway.
104+ - For restrictive features, this means they're restricted on APIs just like in the mempool.
105+ - For permissive features, they're allowed on APIs, which is fine since they may be blocked
106+ during verification anyway.
107+ - For indifferent features, it doesn't matter.
108+
109+ Read the `Features.for_mempool` docstring for more details on these types of features.
96110 """
97111 return Features (
98112 count_checkdatasig_op = True ,
99113 nanocontracts = True ,
100114 fee_tokens = True ,
101115 opcodes_version = OpcodesVersion .V2 ,
116+ nano_runtime_version = NanoRuntimeVersion .V2 ,
102117 )
103118
104119
0 commit comments