Skip to content

Commit fd84364

Browse files
committed
after the hard fork, disallow block references
1 parent 8c50242 commit fd84364

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

chia/consensus/block_body_validation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,14 @@ async def validate_block_body(
341341
# the generator ref list for this block (or 'one' bytes [0x01] if no generator)
342342
# 8b. The generator ref list length must be less than or equal to MAX_GENERATOR_REF_LIST_SIZE entries
343343
# 8c. The generator ref list must not point to a height >= this block's height
344-
if block.transactions_generator_ref_list in (None, []):
344+
if block.transactions_generator_ref_list == []:
345345
if block.transactions_info.generator_refs_root != bytes([1] * 32):
346346
return Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT
347347
else:
348+
# With hard fork 2 we ban transactions_generator_ref_list.
349+
if prev_transaction_block_height >= constants.HARD_FORK2_HEIGHT:
350+
return Err.TOO_MANY_GENERATOR_REFS
351+
348352
# If we have a generator reference list, we must have a generator
349353
if block.transactions_generator is None:
350354
return Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT

chia/consensus/blockchain.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from chia.consensus.find_fork_point import lookup_fork_chain
3434
from chia.consensus.full_block_to_block_record import block_to_block_record
3535
from chia.consensus.generator_tools import get_block_header
36+
from chia.consensus.get_block_challenge import prev_tx_block
3637
from chia.consensus.get_block_generator import get_block_generator
3738
from chia.consensus.multiprocess_validation import PreValidationResult
3839
from chia.full_node.block_store import BlockStore
@@ -698,12 +699,16 @@ async def validate_unfinished_block_header(
698699
if len(block.transactions_generator_ref_list) > self.constants.MAX_GENERATOR_REF_LIST_SIZE:
699700
return None, Err.TOO_MANY_GENERATOR_REFS
700701

701-
if (
702-
self.try_block_record(block.prev_header_hash) is None
703-
and block.prev_header_hash != self.constants.GENESIS_CHALLENGE
704-
):
702+
prev_b = self.try_block_record(block.prev_header_hash)
703+
if prev_b is None and block.prev_header_hash != self.constants.GENESIS_CHALLENGE:
705704
return None, Err.INVALID_PREV_BLOCK_HASH
706705

706+
prev_tx_height = prev_tx_block(self, prev_b)
707+
708+
# With hard fork 2 we ban transactions_generator_ref_list.
709+
if prev_tx_height >= self.constants.HARD_FORK2_HEIGHT and block.transactions_generator_ref_list != []:
710+
return None, Err.TOO_MANY_GENERATOR_REFS
711+
707712
if block.transactions_info is not None:
708713
if block.transactions_generator is not None:
709714
if std_hash(bytes(block.transactions_generator)) != block.transactions_info.generator_root:

chia/simulator/block_tools.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ def setup_new_gen(
385385
transaction_data: Optional[SpendBundle],
386386
block_refs: list[uint32],
387387
) -> Optional[NewBlockGenerator]:
388+
if prev_tx_height >= self.constants.HARD_FORK2_HEIGHT:
389+
assert block_refs == [], "block references are not allowed after hard fork 2"
390+
dummy_block_references = False
391+
388392
# we don't know if the new block will be a transaction
389393
# block or not, so even though we prepare a block
390394
# generator, we can't update our state (like,

0 commit comments

Comments
 (0)