From bc3dfcae656127b4ff6abffd9632b57c9f60e804 Mon Sep 17 00:00:00 2001 From: Gabriel Levcovitz Date: Mon, 22 Jan 2024 21:30:13 -0300 Subject: [PATCH] chore(feature-activation): phased testing adjustments --- hathor/conf/testnet.py | 34 +----------- hathor/conf/testnet.yml | 32 +---------- hathor/feature_activation/feature.py | 5 +- hathor/manager.py | 2 +- .../migrations/remove_second_nop_features.py | 54 +++++++++++++++++++ .../storage/transaction_storage.py | 2 + 6 files changed, 62 insertions(+), 67 deletions(-) create mode 100644 hathor/transaction/storage/migrations/remove_second_nop_features.py diff --git a/hathor/conf/testnet.py b/hathor/conf/testnet.py index fdfa7ab616..bfde279dcb 100644 --- a/hathor/conf/testnet.py +++ b/hathor/conf/testnet.py @@ -14,8 +14,6 @@ from hathor.checkpoint import Checkpoint as cp from hathor.conf.settings import HathorSettings -from hathor.feature_activation.feature import Feature -from hathor.feature_activation.model.criteria import Criteria from hathor.feature_activation.settings import Settings as FeatureActivationSettings SETTINGS = HathorSettings( @@ -55,36 +53,6 @@ cp(1_600_000, bytes.fromhex('00000000060adfdfd7d488d4d510b5779cf35a3c50df7bcff941fbb6957be4d2')), ], FEATURE_ACTIVATION=FeatureActivationSettings( - evaluation_interval=40_320, - default_threshold=30240, - features={ - Feature.NOP_FEATURE_4: Criteria( - bit=0, - start_height=3_386_880, # N (right now the best block is 3_346_600 on testnet) - timeout_height=3_467_520, # N + 2 * 40320 (4 weeks after the start) - minimum_activation_height=3_507_840, # N + 3 * 40320 (6 weeks after the start) - lock_in_on_timeout=False, - version='0.57.0', - signal_support_by_default=True - ), - Feature.NOP_FEATURE_5: Criteria( - bit=1, - start_height=3_386_880, # N (right now the best block is 3_346_600 on testnet) - timeout_height=3_467_520, # N + 2 * 40320 (4 weeks after the start) - minimum_activation_height=0, - lock_in_on_timeout=True, - version='0.57.0', - signal_support_by_default=False - ), - Feature.NOP_FEATURE_6: Criteria( - bit=2, - start_height=3_386_880, # N (right now the best block is 3_346_600 on testnet) - timeout_height=3_467_520, # N + 2 * 40320 (4 weeks after the start) - minimum_activation_height=0, - lock_in_on_timeout=False, - version='0.57.0', - signal_support_by_default=False - ) - } + default_threshold=15_120, # 15120 = 75% of evaluation_interval (20160) ) ) diff --git a/hathor/conf/testnet.yml b/hathor/conf/testnet.yml index 2fd1abf96f..d3be15dde7 100644 --- a/hathor/conf/testnet.yml +++ b/hathor/conf/testnet.yml @@ -37,34 +37,4 @@ CHECKPOINTS: 1_600_000: 00000000060adfdfd7d488d4d510b5779cf35a3c50df7bcff941fbb6957be4d2 FEATURE_ACTIVATION: - evaluation_interval: 40_320 - default_threshold: 30_240 # 30240 = 75% of evaluation_interval (40320) - features: - #### Second Phased Testing features #### - - NOP_FEATURE_4: - bit: 0 - start_height: 3_386_880 # N (right now the best block is 3_346_600 on testnet) - timeout_height: 3_467_520 # N + 2 * 40320 (4 weeks after the start) - minimum_activation_height: 3_507_840 # N + 3 * 40320 (6 weeks after the start) - lock_in_on_timeout: false - version: 0.57.0 - signal_support_by_default: true - - NOP_FEATURE_5: - bit: 1 - start_height: 3_386_880 # N (right now the best block is 3_346_600 on testnet) - timeout_height: 3_467_520 # N + 2 * 40320 (4 weeks after the start) - minimum_activation_height: 0 - lock_in_on_timeout: true - version: 0.57.0 - signal_support_by_default: false - - NOP_FEATURE_6: - bit: 2 - start_height: 3_386_880 # N (right now the best block is 3_346_600 on testnet) - timeout_height: 3_467_520 # N + 2 * 40320 (4 weeks after the start) - minimum_activation_height: 0 - lock_in_on_timeout: false - version: 0.57.0 - signal_support_by_default: false + default_threshold: 15_120 # 15120 = 75% of evaluation_interval (20160) diff --git a/hathor/feature_activation/feature.py b/hathor/feature_activation/feature.py index c056b21d15..eb6a6e8976 100644 --- a/hathor/feature_activation/feature.py +++ b/hathor/feature_activation/feature.py @@ -23,12 +23,13 @@ class Feature(Enum): should NOT be changed either, as configuration uses them for setting feature activation criteria. """ - # First Phased Testing features + # Mainnet Phased Testing features NOP_FEATURE_1 = 'NOP_FEATURE_1' NOP_FEATURE_2 = 'NOP_FEATURE_2' NOP_FEATURE_3 = 'NOP_FEATURE_3' - # Second Phased Testing features + # TODO: Those can be removed in a future PR + # Testnet Phased Testing features NOP_FEATURE_4 = 'NOP_FEATURE_4' NOP_FEATURE_5 = 'NOP_FEATURE_5' NOP_FEATURE_6 = 'NOP_FEATURE_6' diff --git a/hathor/manager.py b/hathor/manager.py index 731e70c0a2..10af61697a 100644 --- a/hathor/manager.py +++ b/hathor/manager.py @@ -1077,7 +1077,7 @@ def _log_feature_states(self, vertex: BaseTransaction) -> None: features_states=state_by_feature ) - features = [Feature.NOP_FEATURE_4, Feature.NOP_FEATURE_5, Feature.NOP_FEATURE_6] + features = [Feature.NOP_FEATURE_1, Feature.NOP_FEATURE_2] for feature in features: self._log_if_feature_is_active(vertex, feature) diff --git a/hathor/transaction/storage/migrations/remove_second_nop_features.py b/hathor/transaction/storage/migrations/remove_second_nop_features.py new file mode 100644 index 0000000000..dd322b1f71 --- /dev/null +++ b/hathor/transaction/storage/migrations/remove_second_nop_features.py @@ -0,0 +1,54 @@ +# Copyright 2023 Hathor Labs +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from typing import TYPE_CHECKING + +from structlog import get_logger + +from hathor.conf.get_settings import get_global_settings +from hathor.transaction.storage.migrations import BaseMigration +from hathor.util import progress + +if TYPE_CHECKING: + from hathor.transaction.storage import TransactionStorage + +logger = get_logger() + + +class Migration(BaseMigration): + def skip_empty_db(self) -> bool: + return True + + def get_db_name(self) -> str: + return 'remove_second_nop_features' + + def run(self, storage: 'TransactionStorage') -> None: + """ + This migration clears the Feature Activation metadata related to the second Phased Testing on testnet. + """ + settings = get_global_settings() + log = logger.new() + + if settings.NETWORK_NAME != 'testnet-golf': + # If it's not testnet, we don't have to clear anything. + log.info('Skipping testnet-only migration.') + return + + topological_iterator = storage.topological_iterator() + + for vertex in progress(topological_iterator, log=log, total=None): + if vertex.is_block: + meta = vertex.get_metadata() + meta.feature_states = None + storage.save_transaction(vertex, only_metadata=True) diff --git a/hathor/transaction/storage/transaction_storage.py b/hathor/transaction/storage/transaction_storage.py index 4a94f98f90..5b56431cb5 100644 --- a/hathor/transaction/storage/transaction_storage.py +++ b/hathor/transaction/storage/transaction_storage.py @@ -42,6 +42,7 @@ add_feature_activation_bit_counts_metadata2, add_min_height_metadata, remove_first_nop_features, + remove_second_nop_features, ) from hathor.transaction.storage.tx_allow_scope import TxAllowScope, tx_allow_context from hathor.transaction.transaction import Transaction @@ -92,6 +93,7 @@ class TransactionStorage(ABC): add_feature_activation_bit_counts_metadata.Migration, remove_first_nop_features.Migration, add_feature_activation_bit_counts_metadata2.Migration, + remove_second_nop_features.Migration, ] _migrations: list[BaseMigration]