Skip to content

Commit

Permalink
Merge pull request #1196 from HathorNetwork/master
Browse files Browse the repository at this point in the history
Release-candidate v0.63.0-rc.3
  • Loading branch information
jansegre authored Jan 9, 2025
2 parents 262e4ef + ae6a85c commit 00fa77f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 41 deletions.
9 changes: 3 additions & 6 deletions extras/github/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions extras/github/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion hathor/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions hathor/conf/testnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions hathor/conf/testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions hathor/transaction/base_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)

Expand Down
29 changes: 20 additions & 9 deletions hathor/transaction/resources/transaction_confirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions tests/resources/transaction/test_transaction_confirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 00fa77f

Please sign in to comment.