Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Jan 12, 2024
1 parent 530b63d commit 5107413
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions hathor/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ def GENESIS_TX2_TIMESTAMP(self) -> int:
# Time in seconds to request the best blockchain from peers.
BEST_BLOCKCHAIN_INTERVAL: int = 5 # seconds

# Merged mining settings. The old value is going to be replaced by the new value through Feature Activation.
OLD_MAX_MERKLE_PATH_LENGTH: int = 12
NEW_MAX_MERKLE_PATH_LENGTH: int = 15

@classmethod
def from_yaml(cls, *, filepath: str) -> 'HathorSettings':
"""Takes a filepath to a yaml file and returns a validated HathorSettings instance."""
Expand Down
6 changes: 4 additions & 2 deletions hathor/merged_mining/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from hathor.merged_mining.bitcoin_rpc import IBitcoinRPC
from hathor.merged_mining.util import Periodic
from hathor.transaction import BitcoinAuxPow, MergeMinedBlock as HathorBlock
from hathor.transaction.aux_pow import NEW_MAX_MERKLE_PATH_LENGTH
from hathor.transaction.exceptions import ScriptError, TxValidationError
from hathor.util import MaxSizeOrderedDict, Random, ichunks

Expand Down Expand Up @@ -625,7 +624,10 @@ def handle_submit(self, params: list[Any], msgid: Optional[str]) -> None:

try:
aux_pow = job.build_aux_pow(work)
aux_pow.verify(block_base_hash, NEW_MAX_MERKLE_PATH_LENGTH)
# This constant usually comes from full node settings, but it's hardcoded here as this runs as a
# standalone CLI tool.
old_max_merkle_path_length = 12
aux_pow.verify(block_base_hash, old_max_merkle_path_length)
except TxValidationError as e:
self.log.warn('invalid work', job_id=work.job_id, error=e)
self.send_error(INVALID_SOLUTION, data={'message': 'Job has invalid work.'})
Expand Down
4 changes: 0 additions & 4 deletions hathor/transaction/aux_pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
logger = get_logger()


OLD_MAX_MERKLE_PATH_LENGTH: int = 12
NEW_MAX_MERKLE_PATH_LENGTH: int = 15


class BitcoinAuxPow(NamedTuple):
header_head: bytes # 36 bytes
coinbase_head: bytes # variable length (at least 47 bytes)
Expand Down
6 changes: 4 additions & 2 deletions hathor/verification/merge_mined_block_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from hathor.feature_activation.feature import Feature
from hathor.feature_activation.feature_service import FeatureService
from hathor.transaction import MergeMinedBlock
from hathor.transaction.aux_pow import NEW_MAX_MERKLE_PATH_LENGTH, OLD_MAX_MERKLE_PATH_LENGTH


class MergeMinedBlockVerifier:
Expand All @@ -35,6 +34,9 @@ def verify_aux_pow(self, block: MergeMinedBlock) -> None:
block=block,
feature=Feature.INCREASE_MAX_MERKLE_PATH_LENGTH
)
max_merkle_path_length = NEW_MAX_MERKLE_PATH_LENGTH if is_feature_active else OLD_MAX_MERKLE_PATH_LENGTH
max_merkle_path_length = (
self._settings.NEW_MAX_MERKLE_PATH_LENGTH if is_feature_active
else self._settings.OLD_MAX_MERKLE_PATH_LENGTH
)

block.aux_pow.verify(block.get_base_hash(), max_merkle_path_length)
5 changes: 2 additions & 3 deletions tests/tx/test_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from hathor.feature_activation.feature_service import FeatureService
from hathor.simulator.utils import add_new_blocks
from hathor.transaction import MAX_OUTPUT_VALUE, Block, Transaction, TxInput, TxOutput
from hathor.transaction.aux_pow import NEW_MAX_MERKLE_PATH_LENGTH, OLD_MAX_MERKLE_PATH_LENGTH
from hathor.transaction.exceptions import (
BlockWithInputs,
ConflictingInputs,
Expand Down Expand Up @@ -354,7 +353,7 @@ def is_feature_active_true(self: FeatureService, *, block: Block, feature: Featu
b'\x00' * 32,
b'\x00' * 42 + MAGIC_NUMBER,
b'\x00' * 18,
[b'\x00' * 32] * (OLD_MAX_MERKLE_PATH_LENGTH + 1), # 1 too long
[b'\x00' * 32] * (self._settings.OLD_MAX_MERKLE_PATH_LENGTH + 1), # 1 too long
b'\x00' * 12,
)
)
Expand All @@ -377,7 +376,7 @@ def is_feature_active_true(self: FeatureService, *, block: Block, feature: Featu
b'\x00' * 32,
b'\x00' * 42 + MAGIC_NUMBER,
b'\x00' * 18,
[b'\x00' * 32] * (NEW_MAX_MERKLE_PATH_LENGTH + 1), # 1 too long
[b'\x00' * 32] * (self._settings.NEW_MAX_MERKLE_PATH_LENGTH + 1), # 1 too long
b'\x00' * 12,
)
)
Expand Down

0 comments on commit 5107413

Please sign in to comment.