Skip to content

Commit 1360614

Browse files
committed
fix(feature-activation): add signal bits to minimally valid block
1 parent 0e18dd4 commit 1360614

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

hathor/mining/block_template.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ class BlockTemplate(NamedTuple):
3636
score: float # metadata
3737
signal_bits: int # signal bits for blocks generated from this template
3838

39-
def generate_minimaly_valid_block(self) -> BaseTransaction:
39+
def generate_minimally_valid_block(self) -> BaseTransaction:
4040
""" Generates a block, without any extra information that is valid for this template. No random choices."""
4141
from hathor.transaction import TxOutput, TxVersion
4242
return TxVersion(min(self.versions)).get_cls()(
4343
timestamp=self.timestamp_min,
4444
parents=self.parents[:] + sorted(self.parents_any)[:(3 - len(self.parents))],
4545
outputs=[TxOutput(self.reward, b'')],
4646
weight=self.weight,
47+
signal_bits=self.signal_bits,
4748
)
4849

4950
def generate_mining_block(self, rng: Random, merge_mined: bool = False, address: Optional[bytes] = None,
@@ -83,7 +84,7 @@ def get_random_parents(self, rng: Random) -> tuple[bytes, bytes, bytes]:
8384

8485
def to_dict(self) -> dict:
8586
return {
86-
'data': self.generate_minimaly_valid_block().get_struct_without_nonce().hex(),
87+
'data': self.generate_minimally_valid_block().get_struct_without_nonce().hex(),
8788
'versions': sorted(self.versions),
8889
'reward': self.reward,
8990
'weight': self.weight,

tests/tx/test_mining.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Any
2+
13
from hathor.conf import HathorSettings
24
from hathor.mining import BlockTemplate
3-
from hathor.transaction import sum_weights
5+
from hathor.transaction import Block, sum_weights
46
from hathor.transaction.storage import TransactionMemoryStorage
57
from tests import unittest
68
from tests.utils import add_new_blocks
@@ -75,6 +77,39 @@ def test_regular_block_template(self) -> None:
7577

7678
self.assertConsensusValid(manager)
7779

80+
def test_minimally_valid_block(self) -> None:
81+
template = BlockTemplate(
82+
versions={0},
83+
reward=6400,
84+
weight=60,
85+
timestamp_now=12345,
86+
timestamp_min=12344,
87+
timestamp_max=12346,
88+
parents=[b'\x01', b'\x02', b'\x03'],
89+
parents_any=[],
90+
height=999,
91+
score=100,
92+
signal_bits=0b0101,
93+
)
94+
block = template.generate_minimally_valid_block()
95+
json = block.to_json()
96+
expected: dict[str, Any] = dict(
97+
data='',
98+
hash=None,
99+
inputs=[],
100+
nonce=0,
101+
outputs=[dict(script='', token_data=0, value=6400)],
102+
parents=['01', '02', '03'],
103+
signal_bits=0b0101,
104+
timestamp=12344,
105+
tokens=[],
106+
version=0,
107+
weight=60
108+
)
109+
110+
self.assertTrue(isinstance(block, Block))
111+
self.assertEqual(json, expected)
112+
78113

79114
class SyncV1MiningTest(unittest.SyncV1Params, BaseMiningTest):
80115
__test__ = True

0 commit comments

Comments
 (0)