From f89376531936f740ce91fb1802581772475a6541 Mon Sep 17 00:00:00 2001 From: Jan Segre Date: Wed, 11 Dec 2024 17:19:20 +0100 Subject: [PATCH 1/4] chore(docker): include python suffix tags on rc images --- extras/github/docker.py | 9 +++------ extras/github/test_docker.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/extras/github/docker.py b/extras/github/docker.py index 3a0c667e9..b7ee9bbf4 100644 --- a/extras/github/docker.py +++ b/extras/github/docker.py @@ -97,12 +97,9 @@ def extract_pyver(filename): tags = set() - # We don't want a tag with a python suffix for release-candidates - if is_release_candidate: - version = base_version - else: - version = base_version + '-' + suffix - tags.add(version) + # Always include -python{Version} suffix variant + version = base_version + '-' + suffix + tags.add(version) if suffix == default_python: tags.add(base_version) diff --git a/extras/github/test_docker.py b/extras/github/test_docker.py index a38060acc..b5db27e67 100644 --- a/extras/github/test_docker.py +++ b/extras/github/test_docker.py @@ -97,13 +97,14 @@ def test_release_candidate_non_default_python(self): self.assertEqual(base_version, 'v0.53.0-rc.1') output = prep_tags(os.environ, base_version, is_release_candidate) + version_with_python = f'{base_version}-python{NON_DEFAULT_PYTHON_VERSION}' self.assertNotIn('slack-notification-version', output) - self.assertEqual(output['version'], base_version) + self.assertEqual(output['version'], version_with_python) self.assertEqual(output['login-dockerhub'], 'true') self.assertEqual(output['login-ghcr'], 'false') - self.assertEqual(output['tags'], 'dont-push--local-only') - self.assertEqual(output['push'], 'false') + self.assertEqual(output['tags'], f'mock_image:{version_with_python}') + self.assertEqual(output['push'], 'true') self.assertEqual(output['dockerfile'], 'Dockerfile') def test_release_candidate_default_python(self): @@ -127,12 +128,16 @@ def test_release_candidate_default_python(self): self.assertEqual(base_version, 'v0.53.0-rc.1') output = prep_tags(os.environ, base_version, is_release_candidate) + version_with_python = f'{base_version}-python{DEFAULT_PYTHON_VERSION}' self.assertEqual(output['slack-notification-version'], base_version) - self.assertEqual(output['version'], base_version) + self.assertEqual(output['version'], version_with_python) self.assertEqual(output['login-dockerhub'], 'true') self.assertEqual(output['login-ghcr'], 'false') - self.assertEqual(output['tags'], 'mock_image:v0.53.0-rc.1') + self.assertEqual( + set(output['tags'].split(',')), + {f'mock_image:{version_with_python}', 'mock_image:v0.53.0-rc.1'}, + ) self.assertEqual(output['push'], 'true') self.assertEqual(output['dockerfile'], 'Dockerfile') From 692a74c09c8a319cb157eb3222c86d4db0916738 Mon Sep 17 00:00:00 2001 From: Gabriel Levcovitz Date: Wed, 11 Dec 2024 20:38:29 -0300 Subject: [PATCH 2/4] fix: acc weight regression (#1193) --- hathor/transaction/base_transaction.py | 19 +++++++----- .../resources/transaction_confirmation.py | 29 +++++++++++++------ .../test_transaction_confirmation.py | 5 ++-- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/hathor/transaction/base_transaction.py b/hathor/transaction/base_transaction.py index 41cbab100..a6a7b85ac 100644 --- a/hathor/transaction/base_transaction.py +++ b/hathor/transaction/base_transaction.py @@ -22,7 +22,7 @@ from abc import ABC, abstractmethod from enum import IntEnum from itertools import chain -from math import inf, isfinite, log +from math import isfinite, log from struct import error as StructError, pack from typing import TYPE_CHECKING, Any, ClassVar, Generic, Iterator, Optional, TypeAlias, TypeVar @@ -638,7 +638,12 @@ def reset_metadata(self) -> None: self.storage.save_transaction(self, only_metadata=True) - def update_accumulated_weight(self, *, stop_value: float = inf, save_file: bool = True) -> TransactionMetadata: + def update_accumulated_weight( + self, + *, + stop_value: int | None = None, + save_file: bool = True, + ) -> TransactionMetadata: """Calculates the tx's accumulated weight and update its metadata. It starts at the current transaction and does a BFS to the tips. In the @@ -656,10 +661,10 @@ def update_accumulated_weight(self, *, stop_value: float = inf, save_file: bool assert self.storage is not None metadata = self.get_metadata() - if metadata.accumulated_weight > stop_value: + if stop_value is not None and metadata.accumulated_weight > stop_value: return metadata - accumulated_weight = weight_to_work(self.weight) + work = weight_to_work(self.weight) # TODO Another optimization is that, when we calculate the acc weight of a transaction, we # also partially calculate the acc weight of its descendants. If it were a DFS, when returning @@ -674,11 +679,11 @@ def update_accumulated_weight(self, *, stop_value: float = inf, save_file: bool from hathor.transaction.storage.traversal import BFSTimestampWalk bfs_walk = BFSTimestampWalk(self.storage, is_dag_funds=True, is_dag_verifications=True, is_left_to_right=True) for tx in bfs_walk.run(self, skip_root=True): - accumulated_weight += weight_to_work(tx.weight) - if accumulated_weight > stop_value: + work += weight_to_work(tx.weight) + if stop_value is not None and work > stop_value: break - metadata.accumulated_weight = accumulated_weight + metadata.accumulated_weight = work if save_file: self.storage.save_transaction(self, only_metadata=True) diff --git a/hathor/transaction/resources/transaction_confirmation.py b/hathor/transaction/resources/transaction_confirmation.py index 153d2b8f8..62ab52208 100644 --- a/hathor/transaction/resources/transaction_confirmation.py +++ b/hathor/transaction/resources/transaction_confirmation.py @@ -12,12 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -from math import log +from math import log2 from typing import Any from hathor.api_util import Resource, get_args, get_missing_params_msg, set_cors, validate_tx_hash from hathor.cli.openapi_files.register import register_resource +from hathor.manager import HathorManager from hathor.util import json_dumpb +from hathor.utils.weight import weight_to_work, work_to_weight + +N_CONFIRMATION_BLOCKS: int = 6 @register_resource @@ -28,7 +32,7 @@ class TransactionAccWeightResource(Resource): """ isLeaf = True - def __init__(self, manager): + def __init__(self, manager: HathorManager) -> None: # Important to have the manager so we can know the tx_storage self.manager = manager @@ -48,15 +52,21 @@ def _render_GET_data(self, requested_hash: str) -> dict[str, Any]: if meta.first_block: block = self.manager.tx_storage.get_transaction(meta.first_block) - stop_value = block.weight + log(6, 2) - meta = tx.update_accumulated_weight(stop_value=stop_value) - data['accumulated_weight'] = meta.accumulated_weight - data['accumulated_bigger'] = meta.accumulated_weight > stop_value + stop_value = block.weight + log2(N_CONFIRMATION_BLOCKS) + meta = tx.update_accumulated_weight(stop_value=weight_to_work(stop_value)) + acc_weight = work_to_weight(meta.accumulated_weight) + acc_weight_raw = str(meta.accumulated_weight) + data['accumulated_weight'] = acc_weight + data['accumulated_weight_raw'] = acc_weight_raw + data['accumulated_bigger'] = acc_weight > stop_value data['stop_value'] = stop_value - data['confirmation_level'] = min(meta.accumulated_weight / stop_value, 1) + data['confirmation_level'] = min(acc_weight / stop_value, 1) else: meta = tx.update_accumulated_weight() - data['accumulated_weight'] = meta.accumulated_weight + acc_weight = work_to_weight(meta.accumulated_weight) + acc_weight_raw = str(meta.accumulated_weight) + data['accumulated_weight'] = acc_weight + data['accumulated_weight_raw'] = acc_weight_raw data['accumulated_bigger'] = False data['confirmation_level'] = 0 return data @@ -125,7 +135,8 @@ def render_GET(self, request): 'success': { 'summary': 'Success', 'value': { - 'accumulated_weight': 43237, + 'accumulated_weight': 15.4, + 'accumulated_weight_raw': '43238', 'confirmation_level': 0.88, 'stop_value': 14.5, 'accumulated_bigger': True, diff --git a/tests/resources/transaction/test_transaction_confirmation.py b/tests/resources/transaction/test_transaction_confirmation.py index 3b95f7718..a04eeb641 100644 --- a/tests/resources/transaction/test_transaction_confirmation.py +++ b/tests/resources/transaction/test_transaction_confirmation.py @@ -2,7 +2,6 @@ from hathor.simulator.utils import add_new_blocks from hathor.transaction.resources import TransactionAccWeightResource -from hathor.utils.weight import weight_to_work from tests import unittest from tests.resources.base_resource import StubSite, _BaseResourceTest from tests.utils import add_blocks_unlock_reward, add_new_transactions @@ -25,7 +24,7 @@ def test_get_data(self): ) data_success = response_success.json_value() self.assertTrue(data_success['success']) - self.assertEqual(data_success['accumulated_weight'], weight_to_work(genesis_tx.weight)) + self.assertEqual(data_success['accumulated_weight'], genesis_tx.weight) self.assertEqual(data_success['confirmation_level'], 0) # Adding blocks to have funds @@ -39,7 +38,7 @@ def test_get_data(self): {b'id': bytes(tx.hash.hex(), 'utf-8')} ) data_success2 = response_success2.json_value() - self.assertGreater(data_success2['accumulated_weight'], weight_to_work(tx.weight)) + self.assertGreater(data_success2['accumulated_weight'], tx.weight) self.assertEqual(data_success2['confirmation_level'], 1) # Test sending hash that does not exist From 92477434c6f46dd89bfcaff01639301643dfcc4e Mon Sep 17 00:00:00 2001 From: Jan Segre Date: Fri, 3 Jan 2025 17:15:22 +0100 Subject: [PATCH 3/4] chore(p2p): decrease p2p.max_enabled_sync's default value: 16 -> 8 --- hathor/conf/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hathor/conf/settings.py b/hathor/conf/settings.py index 9fd45bc3f..654ca398f 100644 --- a/hathor/conf/settings.py +++ b/hathor/conf/settings.py @@ -403,7 +403,7 @@ def GENESIS_TX2_TIMESTAMP(self) -> int: PARTIALLY_VALIDATED_ID: bytes = b'pending-validation' # Maximum number of sync running simultaneously. - MAX_ENABLED_SYNC: int = 16 + MAX_ENABLED_SYNC: int = 8 # Time to update the peers that are running sync. SYNC_UPDATE_INTERVAL: int = 10 * 60 # seconds From a53877893012825a97fcb97860b0ca84dc0df0b3 Mon Sep 17 00:00:00 2001 From: Jan Segre Date: Fri, 3 Jan 2025 17:38:07 +0100 Subject: [PATCH 4/4] chore(feature_activation): update start_height before release --- hathor/conf/testnet.py | 10 +++++----- hathor/conf/testnet.yml | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hathor/conf/testnet.py b/hathor/conf/testnet.py index f2d322489..dc6a42907 100644 --- a/hathor/conf/testnet.py +++ b/hathor/conf/testnet.py @@ -100,11 +100,11 @@ # NOP feature to test Feature Activation for Transactions Feature.NOP_FEATURE_1: Criteria( bit=0, - # N = 4_394_880 - # start_height expected to be reached around Sunday, 2024-12-01. - # Right now the best block is 4_377_375 on testnet (2024-11-25). - start_height=4_394_880, # N - timeout_height=4_475_520, # N + 4 * 20160 (4 weeks after the start) + # N = 4_495_680 + # Expected to be reached around Tuesday, 2025-01-06. + # Right now the best block is 4_489_259 on testnet (2025-01-03). + start_height=4_495_680, # N + timeout_height=4_576_320, # N + 4 * 20160 (4 weeks after the start) minimum_activation_height=0, lock_in_on_timeout=False, version='0.63.0', diff --git a/hathor/conf/testnet.yml b/hathor/conf/testnet.yml index f8dcf5290..7a4fb0452 100644 --- a/hathor/conf/testnet.yml +++ b/hathor/conf/testnet.yml @@ -81,11 +81,11 @@ FEATURE_ACTIVATION: # NOP feature to test Feature Activation for Transactions NOP_FEATURE_1: bit: 0 - # N = 4_394_880 - # start_height expected to be reached around Sunday, 2024-12-01. - # Right now the best block is 4_377_375 on testnet (2024-11-25). - start_height: 4_394_880 # N - timeout_height: 4_475_520 # N + 4 * 20160 (4 weeks after the start) + # N = 4_495_680 + # Expected to be reached around Tuesday, 2025-01-06. + # Right now the best block is 4_489_259 on testnet (2025-01-03). + start_height: 4_495_680 # N + timeout_height: 4_576_320 # N + 4 * 20160 (4 weeks after the start) minimum_activation_height: 0 lock_in_on_timeout: false version: 0.63.0