From ba9420b553bb07313c2feff11652d0e949bd8ae7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 2 Aug 2024 01:41:39 +0200 Subject: [PATCH] remove `block_height_list` from `BlockGenerator` (#18302) * remove block_height_list from BlockGenerator. This field is only used when farming blocks, and we don't use it in production right now. We only use it in the tests, BlockTools. It has been updated with a cleaner and more direct way of setting the block reference list in new blocks * test --- chia/_tests/blockchain/test_blockchain.py | 70 ++++--------------- .../core/full_node/stores/test_coin_store.py | 2 +- chia/_tests/core/mempool/test_mempool.py | 8 +-- chia/_tests/core/test_cost_calculation.py | 10 +-- chia/_tests/generator/test_generator_types.py | 6 -- chia/_tests/generator/test_rom.py | 3 +- chia/_tests/util/generator_tools_testing.py | 2 +- chia/_tests/util/run_block.py | 2 +- chia/consensus/block_creation.py | 9 +-- chia/consensus/blockchain.py | 4 +- chia/full_node/bundle_tools.py | 4 +- chia/full_node/generator.py | 37 ---------- chia/simulator/block_tools.py | 60 +++++++--------- chia/types/generator_types.py | 3 - tools/generate_chain.py | 2 +- 15 files changed, 55 insertions(+), 167 deletions(-) delete mode 100644 chia/full_node/generator.py diff --git a/chia/_tests/blockchain/test_blockchain.py b/chia/_tests/blockchain/test_blockchain.py index 11644adbd8bd..bf7dffb2cbeb 100644 --- a/chia/_tests/blockchain/test_blockchain.py +++ b/chia/_tests/blockchain/test_blockchain.py @@ -2533,56 +2533,12 @@ async def test_invalid_transactions_ref_list( block_list_input=blocks, guarantee_transaction_block=True, transaction_data=tx, - previous_generator=[blocks[-1].height], + block_refs=[blocks[-1].height], ) block = blocks[-1] - if consensus_mode >= ConsensusMode.HARD_FORK_2_0: - # once the hard for activates, we don't use this form of block - # compression anymore - assert len(block.transactions_generator_ref_list) == 0 - # the remaining tests assume a reflist - return - else: - assert len(block.transactions_generator_ref_list) > 0 - - block_2 = recursive_replace(block, "transactions_info.generator_refs_root", bytes([1] * 32)) - block_2 = recursive_replace( - block_2, "foliage_transaction_block.transactions_info_hash", block_2.transactions_info.get_hash() - ) - block_2 = recursive_replace( - block_2, "foliage.foliage_transaction_block_hash", block_2.foliage_transaction_block.get_hash() - ) - new_m = block_2.foliage.foliage_transaction_block_hash - assert new_m is not None - new_fsb_sig = bt.get_plot_signature(new_m, block.reward_chain_block.proof_of_space.plot_public_key) - block_2 = recursive_replace(block_2, "foliage.foliage_transaction_block_signature", new_fsb_sig) - - await _validate_and_add_block( - b, block_2, expected_error=Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT, skip_prevalidation=True - ) - - # Too many heights - block_2 = recursive_replace(block, "transactions_generator_ref_list", [block.height - 2, block.height - 1]) - # Fails preval - await _validate_and_add_block(b, block_2, expected_error=Err.FAILED_GETTING_GENERATOR_MULTIPROCESSING) - # Fails add_block - await _validate_and_add_block_multi_error( - b, - block_2, - [Err.GENERATOR_REF_HAS_NO_GENERATOR, Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT], - skip_prevalidation=True, - ) - - # Not tx block - for h in range(0, block.height - 1): - block_2 = recursive_replace(block, "transactions_generator_ref_list", [h]) - await _validate_and_add_block(b, block_2, expected_error=Err.FAILED_GETTING_GENERATOR_MULTIPROCESSING) - await _validate_and_add_block_multi_error( - b, - block_2, - [Err.GENERATOR_REF_HAS_NO_GENERATOR, Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT], - skip_prevalidation=True, - ) + # once the hard fork activated, we no longer use this form of block + # compression anymore + assert len(block.transactions_generator_ref_list) == 0 @pytest.mark.anyio async def test_cost_exceeds_max( @@ -2616,7 +2572,7 @@ async def test_cost_exceeds_max( ) assert blocks[-1].transactions_generator is not None - block_generator = BlockGenerator(blocks[-1].transactions_generator, [], []) + block_generator = BlockGenerator(blocks[-1].transactions_generator, []) npc_result = get_name_puzzle_conditions( block_generator, b.constants.MAX_BLOCK_COST_CLVM * 1000, @@ -2682,7 +2638,7 @@ async def test_invalid_cost_in_block( new_fsb_sig = bt.get_plot_signature(new_m, block.reward_chain_block.proof_of_space.plot_public_key) block_2 = recursive_replace(block_2, "foliage.foliage_transaction_block_signature", new_fsb_sig) assert block_2.transactions_generator is not None - block_generator = BlockGenerator(block_2.transactions_generator, [], []) + block_generator = BlockGenerator(block_2.transactions_generator, []) assert block.transactions_info is not None npc_result = get_name_puzzle_conditions( block_generator, @@ -2709,7 +2665,7 @@ async def test_invalid_cost_in_block( new_fsb_sig = bt.get_plot_signature(new_m, block.reward_chain_block.proof_of_space.plot_public_key) block_2 = recursive_replace(block_2, "foliage.foliage_transaction_block_signature", new_fsb_sig) assert block_2.transactions_generator is not None - block_generator = BlockGenerator(block_2.transactions_generator, [], []) + block_generator = BlockGenerator(block_2.transactions_generator, []) assert block.transactions_info is not None npc_result = get_name_puzzle_conditions( block_generator, @@ -2737,7 +2693,7 @@ async def test_invalid_cost_in_block( block_2 = recursive_replace(block_2, "foliage.foliage_transaction_block_signature", new_fsb_sig) assert block_2.transactions_generator is not None - block_generator = BlockGenerator(block_2.transactions_generator, [], []) + block_generator = BlockGenerator(block_2.transactions_generator, []) max_cost = ( min(b.constants.MAX_BLOCK_COST_CLVM * 1000, block.transactions_info.cost) if block.transactions_info is not None @@ -3619,7 +3575,7 @@ async def test_reorg_new_ref(empty_blockchain: Blockchain, bt: BlockTools) -> No spend_bundle2 = wallet_a.generate_signed_transaction(uint64(1_000), receiver_puzzlehash, all_coins.pop()) blocks_reorg_chain = bt.get_consecutive_blocks( - 4, blocks_reorg_chain, seed=b"2", previous_generator=[uint32(5), uint32(11)], transaction_data=spend_bundle2 + 4, blocks_reorg_chain, seed=b"2", block_refs=[uint32(5), uint32(11)], transaction_data=spend_bundle2 ) blocks_reorg_chain = bt.get_consecutive_blocks(4, blocks_reorg_chain, seed=b"2") @@ -3685,7 +3641,7 @@ async def test_reorg_stale_fork_height(empty_blockchain: Blockchain, bt: BlockTo # this block (height 10) refers back to the generator in block 5 spend_bundle2 = wallet_a.generate_signed_transaction(uint64(1_000), receiver_puzzlehash, all_coins.pop()) - blocks = bt.get_consecutive_blocks(4, blocks, previous_generator=[uint32(5)], transaction_data=spend_bundle2) + blocks = bt.get_consecutive_blocks(4, blocks, block_refs=[uint32(5)], transaction_data=spend_bundle2) for block in blocks[:5]: await _validate_and_add_block(b, block, expected_result=AddBlockResult.NEW_PEAK) @@ -3795,7 +3751,7 @@ async def test_reorg_flip_flop(empty_blockchain: Blockchain, bt: BlockTools) -> chain_a = bt.get_consecutive_blocks( 5, chain_a, - previous_generator=[uint32(10)], + block_refs=[uint32(10)], transaction_data=spend_bundle, guarantee_transaction_block=True, ) @@ -3835,9 +3791,7 @@ async def test_reorg_flip_flop(empty_blockchain: Blockchain, bt: BlockTools) -> ) spend_bundle = wallet_a.generate_signed_transaction(uint64(1_000), receiver_puzzlehash, all_coins.pop()) - chain_b = bt.get_consecutive_blocks( - 10, chain_b, seed=b"2", previous_generator=[uint32(15)], transaction_data=spend_bundle - ) + chain_b = bt.get_consecutive_blocks(10, chain_b, seed=b"2", block_refs=[uint32(15)], transaction_data=spend_bundle) assert len(chain_a) == len(chain_b) diff --git a/chia/_tests/core/full_node/stores/test_coin_store.py b/chia/_tests/core/full_node/stores/test_coin_store.py index 3e5849dc6f39..04afddd97688 100644 --- a/chia/_tests/core/full_node/stores/test_coin_store.py +++ b/chia/_tests/core/full_node/stores/test_coin_store.py @@ -99,7 +99,7 @@ async def test_basic_coin_store(db_version: int, softfork_height: uint32, bt: Bl should_be_included.add(pool_coin) if block.is_transaction_block(): if block.transactions_generator is not None: - block_gen: BlockGenerator = BlockGenerator(block.transactions_generator, [], []) + block_gen: BlockGenerator = BlockGenerator(block.transactions_generator, []) npc_result = get_name_puzzle_conditions( block_gen, bt.constants.MAX_BLOCK_COST_CLVM, diff --git a/chia/_tests/core/mempool/test_mempool.py b/chia/_tests/core/mempool/test_mempool.py index 000abfeb4496..59f0644ec827 100644 --- a/chia/_tests/core/mempool/test_mempool.py +++ b/chia/_tests/core/mempool/test_mempool.py @@ -2180,7 +2180,7 @@ def generator_condition_tester( prg = f"(q ((0x0101010101010101010101010101010101010101010101010101010101010101 {'(q ' if quote else ''} {conditions} {')' if quote else ''} {coin_amount} (() (q . ())))))" # noqa print(f"program: {prg}") program = SerializedProgram.from_bytes(binutils.assemble(prg).as_bin()) - generator = BlockGenerator(program, [], []) + generator = BlockGenerator(program, []) print(f"len: {len(bytes(program))}") npc_result: NPCResult = get_name_puzzle_conditions( generator, max_cost, mempool_mode=mempool_mode, height=height, constants=test_constants @@ -2437,7 +2437,7 @@ def test_create_coin_different_parent(self, softfork_height: uint32) -> None: f'(q ((0x0101010101010101010101010101010101010101010101010101010101010101 (q (51 "{puzzle_hash}" 10)) 123 (() (q . ())))(0x0101010101010101010101010101010101010101010101010101010101010102 (q (51 "{puzzle_hash}" 10)) 123 (() (q . ()))) ))' # noqa ).as_bin() ) - generator = BlockGenerator(program, [], []) + generator = BlockGenerator(program, []) npc_result: NPCResult = get_name_puzzle_conditions( generator, MAX_BLOCK_COST_CLVM, mempool_mode=False, height=softfork_height, constants=test_constants ) @@ -3184,6 +3184,4 @@ def test_get_puzzle_and_solution_for_coin_failure() -> None: with pytest.raises( ValueError, match=f"Failed to get puzzle and solution for coin {TEST_COIN}, error: \\('coin not found', '80'\\)" ): - get_puzzle_and_solution_for_coin( - BlockGenerator(SerializedProgram.to(None), [], []), TEST_COIN, 0, test_constants - ) + get_puzzle_and_solution_for_coin(BlockGenerator(SerializedProgram.to(None), []), TEST_COIN, 0, test_constants) diff --git a/chia/_tests/core/test_cost_calculation.py b/chia/_tests/core/test_cost_calculation.py index 7eb63aff75ae..1b7241619c72 100644 --- a/chia/_tests/core/test_cost_calculation.py +++ b/chia/_tests/core/test_cost_calculation.py @@ -148,7 +148,7 @@ async def test_mempool_mode(softfork_height: int, bt: BlockTools) -> None: f" (() (q . (({unknown_opcode} '00000000000000000000000000000000' 0x0cbba106e000))) ()))))" ).as_bin() ) - generator = BlockGenerator(program, [], []) + generator = BlockGenerator(program, []) npc_result: NPCResult = get_name_puzzle_conditions( generator, bt.constants.MAX_BLOCK_COST_CLVM, @@ -184,7 +184,7 @@ async def test_clvm_mempool_mode(softfork_height: int) -> None: # ("0xfe"). In mempool mode, this should fail, but in non-mempool # mode, the unknown operator should be treated as if it returns (). program = SerializedProgram.from_bytes(binutils.assemble(f"(i (0xfe (q . 0)) (q . ()) {disassembly})").as_bin()) - generator = BlockGenerator(program, [], []) + generator = BlockGenerator(program, []) npc_result: NPCResult = get_name_puzzle_conditions( generator, test_constants.MAX_BLOCK_COST_CLVM, @@ -210,7 +210,7 @@ async def test_tx_generator_speed(softfork_height: int, benchmark_runner: Benchm program = SerializedProgram.from_bytes(generator_bytes) with benchmark_runner.assert_runtime(seconds=1.25): - generator = BlockGenerator(program, [], []) + generator = BlockGenerator(program, []) npc_result = get_name_puzzle_conditions( generator, test_constants.MAX_BLOCK_COST_CLVM, @@ -238,7 +238,7 @@ async def test_clvm_max_cost(softfork_height: int) -> None: ) # ensure we fail if the program exceeds the cost - generator = BlockGenerator(program, [], []) + generator = BlockGenerator(program, []) npc_result = get_name_puzzle_conditions( generator, 10000000, mempool_mode=False, height=uint32(softfork_height), constants=test_constants ) @@ -306,7 +306,7 @@ async def test_get_puzzle_and_solution_for_coin_performance(benchmark_runner: Be # benchmark the function to pick out the puzzle and solution for a specific # coin - generator = BlockGenerator(LARGE_BLOCK.transactions_generator, [], []) + generator = BlockGenerator(LARGE_BLOCK.transactions_generator, []) with benchmark_runner.assert_runtime(seconds=8.5): for _ in range(3): for c in spent_coins: diff --git a/chia/_tests/generator/test_generator_types.py b/chia/_tests/generator/test_generator_types.py index 7fde83d0ca8b..04266b551038 100644 --- a/chia/_tests/generator/test_generator_types.py +++ b/chia/_tests/generator/test_generator_types.py @@ -3,7 +3,6 @@ from typing import Dict from unittest import TestCase -from chia.full_node.generator import create_block_generator from chia.types.blockchain_format.program import Program from chia.types.blockchain_format.serialized_program import SerializedProgram from chia.types.generator_types import GeneratorBlockCacheInterface @@ -37,11 +36,6 @@ def get_generator_for_block_height(self, index: uint32) -> SerializedProgram: class TestGeneratorTypes(TestCase): - def test_make_generator(self) -> None: - block_dict = BlockDict({uint32(1): gen1}) - gen = create_block_generator(gen2, [uint32(1)], block_dict) - print(gen) - def test_make_generator_args(self) -> None: gen_args = Program.to([[bytes(gen1)]]) diff --git a/chia/_tests/generator/test_rom.py b/chia/_tests/generator/test_rom.py index 232db48332b3..da5a204bf616 100644 --- a/chia/_tests/generator/test_rom.py +++ b/chia/_tests/generator/test_rom.py @@ -64,8 +64,7 @@ def to_sp(sexp: bytes) -> SerializedProgram: def block_generator() -> BlockGenerator: generator_list = [to_sp(FIRST_GENERATOR), to_sp(SECOND_GENERATOR)] - generator_heights = [uint32(0), uint32(1)] - return BlockGenerator(to_sp(COMPILED_GENERATOR_CODE), generator_list, generator_heights) + return BlockGenerator(to_sp(COMPILED_GENERATOR_CODE), generator_list) EXPECTED_ABBREVIATED_COST = 108379 diff --git a/chia/_tests/util/generator_tools_testing.py b/chia/_tests/util/generator_tools_testing.py index e4de434fad7b..f06596ed659f 100644 --- a/chia/_tests/util/generator_tools_testing.py +++ b/chia/_tests/util/generator_tools_testing.py @@ -30,7 +30,7 @@ def run_and_get_removals_and_additions( if block.transactions_generator is not None: npc_result = get_name_puzzle_conditions( - BlockGenerator(block.transactions_generator, [], []), + BlockGenerator(block.transactions_generator, []), max_cost, mempool_mode=mempool_mode, height=height, diff --git a/chia/_tests/util/run_block.py b/chia/_tests/util/run_block.py index be64c6322bb7..1c0e40ac9439 100644 --- a/chia/_tests/util/run_block.py +++ b/chia/_tests/util/run_block.py @@ -144,7 +144,7 @@ def run_generator_with_args( if not generator_program_hex: return [] generator_program = SerializedProgram.fromhex(generator_program_hex) - block_generator = BlockGenerator(generator_program, generator_args, []) + block_generator = BlockGenerator(generator_program, generator_args) return run_generator(block_generator, constants, min(constants.MAX_BLOCK_COST_CLVM, cost)) diff --git a/chia/consensus/block_creation.py b/chia/consensus/block_creation.py index 6d5e0cf41278..76b17b11a0e0 100644 --- a/chia/consensus/block_creation.py +++ b/chia/consensus/block_creation.py @@ -137,8 +137,6 @@ def create_foliage( assert prev_block is not None prev_block_hash = prev_block.header_hash - generator_block_heights_list: List[uint32] = [] - foliage_transaction_block_hash: Optional[bytes32] if is_transaction_block: @@ -146,7 +144,6 @@ def create_foliage( # Calculate the cost of transactions if block_generator is not None: - generator_block_heights_list = block_generator.block_height_list cost = compute_cost(block_generator, constants, height) spend_bundle_fees = compute_fees(additions, removals) @@ -229,10 +226,6 @@ def create_foliage( generator_hash = std_hash(block_generator.program) generator_refs_hash = bytes32([1] * 32) - if generator_block_heights_list not in (None, []): - generator_ref_list_bytes = b"".join([i.stream_to_bytes() for i in generator_block_heights_list]) - generator_refs_hash = std_hash(generator_ref_list_bytes) - filter_hash: bytes32 = std_hash(encoded) transactions_info: Optional[TransactionsInfo] = TransactionsInfo( @@ -423,7 +416,7 @@ def create_unfinished_block( foliage_transaction_block, transactions_info, block_generator.program if block_generator else None, - block_generator.block_height_list if block_generator else [], + [], # generator_refs ) diff --git a/chia/consensus/blockchain.py b/chia/consensus/blockchain.py index 90422086be07..2f544feda64b 100644 --- a/chia/consensus/blockchain.py +++ b/chia/consensus/blockchain.py @@ -1073,7 +1073,7 @@ async def get_block_generator( assert len(ref_list) == 0 return None if len(ref_list) == 0: - return BlockGenerator(block.transactions_generator, [], []) + return BlockGenerator(block.transactions_generator, []) result: List[SerializedProgram] = [] previous_br = await self.get_block_record_from_db(block.prev_header_hash) @@ -1120,4 +1120,4 @@ async def get_block_generator( [gen] = await self.block_store.get_generators_at([ref_height]) result.append(gen) assert len(result) == len(ref_list) - return BlockGenerator(block.transactions_generator, result, []) + return BlockGenerator(block.transactions_generator, result) diff --git a/chia/full_node/bundle_tools.py b/chia/full_node/bundle_tools.py index 34be26342002..b78679d7191e 100644 --- a/chia/full_node/bundle_tools.py +++ b/chia/full_node/bundle_tools.py @@ -10,10 +10,10 @@ def simple_solution_generator(bundle: SpendBundle) -> BlockGenerator: spends = [(cs.coin, bytes(cs.puzzle_reveal), bytes(cs.solution)) for cs in bundle.coin_spends] block_program = solution_generator(spends) - return BlockGenerator(SerializedProgram.from_bytes(block_program), [], []) + return BlockGenerator(SerializedProgram.from_bytes(block_program), []) def simple_solution_generator_backrefs(bundle: SpendBundle) -> BlockGenerator: spends = [(cs.coin, bytes(cs.puzzle_reveal), bytes(cs.solution)) for cs in bundle.coin_spends] block_program = solution_generator_backrefs(spends) - return BlockGenerator(SerializedProgram.from_bytes(block_program), [], []) + return BlockGenerator(SerializedProgram.from_bytes(block_program), []) diff --git a/chia/full_node/generator.py b/chia/full_node/generator.py deleted file mode 100644 index 73bc0db1545c..000000000000 --- a/chia/full_node/generator.py +++ /dev/null @@ -1,37 +0,0 @@ -from __future__ import annotations - -import logging -from typing import List, Optional - -from chia.types.blockchain_format.serialized_program import SerializedProgram -from chia.types.generator_types import BlockGenerator, GeneratorBlockCacheInterface -from chia.util.ints import uint32 -from chia.wallet.puzzles.load_clvm import load_clvm_maybe_recompile - -DECOMPRESS_BLOCK = load_clvm_maybe_recompile("block_program_zero.clsp", package_or_requirement="chia.full_node.puzzles") -DECOMPRESS_PUZZLE = load_clvm_maybe_recompile("decompress_puzzle.clsp", package_or_requirement="chia.full_node.puzzles") -# DECOMPRESS_CSE = load_clvm_maybe_recompile( -# "decompress_coin_spend_entry.clsp", -# package_or_requirement="chia.full_node.puzzles", -# ) - -DECOMPRESS_CSE_WITH_PREFIX = load_clvm_maybe_recompile( - "decompress_coin_spend_entry_with_prefix.clsp", package_or_requirement="chia.full_node.puzzles" -) -log = logging.getLogger(__name__) - - -def create_block_generator( - generator: SerializedProgram, block_heights_list: List[uint32], generator_block_cache: GeneratorBlockCacheInterface -) -> Optional[BlockGenerator]: - """`create_block_generator` will returns None if it fails to look up any referenced block""" - generator_list: List[SerializedProgram] = [] - generator_heights: List[uint32] = [] - for i in block_heights_list: - previous_generator = generator_block_cache.get_generator_for_block_height(i) - if previous_generator is None: - log.error(f"Failed to look up generator for block {i}. Ref List: {block_heights_list}") - return None - generator_list.append(previous_generator) - generator_heights.append(i) - return BlockGenerator(generator, generator_list, generator_heights) diff --git a/chia/simulator/block_tools.py b/chia/simulator/block_tools.py index 5846b1ab87fe..ac73fa7213f5 100644 --- a/chia/simulator/block_tools.py +++ b/chia/simulator/block_tools.py @@ -2,7 +2,6 @@ import asyncio import copy -import dataclasses import logging import os import random @@ -584,8 +583,7 @@ def get_consecutive_blocks( normalized_to_identity_cc_sp: bool = False, normalized_to_identity_cc_ip: bool = False, current_time: bool = False, - # TODO: rename this to block_refs - previous_generator: Optional[List[uint32]] = None, + block_refs: List[uint32] = [], genesis_timestamp: Optional[uint64] = None, force_plot_id: Optional[bytes32] = None, dummy_block_references: bool = False, @@ -768,7 +766,7 @@ def get_consecutive_blocks( removals = None if transaction_data_included: transaction_data = None - previous_generator = None + block_refs = [] if transaction_data is not None: additions = compute_additions_unchecked(transaction_data) removals = transaction_data.removals() @@ -796,11 +794,9 @@ def get_consecutive_blocks( if transaction_data is not None: if start_height >= constants.HARD_FORK_HEIGHT: block_generator = simple_solution_generator_backrefs(transaction_data) - previous_generator = None + block_refs = [] else: block_generator = simple_solution_generator(transaction_data) - if previous_generator is not None: - block_generator = BlockGenerator(block_generator.program, [], previous_generator) aggregate_signature = transaction_data.aggregated_signature else: @@ -810,20 +806,16 @@ def get_consecutive_blocks( if dummy_block_references: if block_generator is None: program = SerializedProgram.from_bytes(solution_generator([])) - block_generator = BlockGenerator(program, [], []) + block_generator = BlockGenerator(program, []) if len(tx_block_heights) > 4: - block_refs = [ - tx_block_heights[1], - tx_block_heights[len(tx_block_heights) // 2], - tx_block_heights[-2], - ] - else: - block_refs = [] - block_generator = dataclasses.replace( - block_generator, block_height_list=block_generator.block_height_list + block_refs - ) - + block_refs.extend( + [ + tx_block_heights[1], + tx_block_heights[len(tx_block_heights) // 2], + tx_block_heights[-2], + ] + ) ( full_block, block_record, @@ -857,10 +849,11 @@ def get_consecutive_blocks( seed, normalized_to_identity_cc_ip=normalized_to_identity_cc_ip, current_time=current_time, + block_refs=block_refs, ) if block_record.is_transaction_block: transaction_data_included = True - previous_generator = None + block_refs = [] keep_going_until_tx_block = False assert full_block.foliage_transaction_block is not None elif guarantee_transaction_block: @@ -1118,11 +1111,9 @@ def get_consecutive_blocks( if transaction_data is not None: if start_height >= constants.HARD_FORK_HEIGHT: block_generator = simple_solution_generator_backrefs(transaction_data) - previous_generator = None + block_refs = [] else: block_generator = simple_solution_generator(transaction_data) - if previous_generator is not None: - block_generator = BlockGenerator(block_generator.program, [], previous_generator) aggregate_signature = transaction_data.aggregated_signature else: block_generator = None @@ -1131,19 +1122,16 @@ def get_consecutive_blocks( if dummy_block_references: if block_generator is None: program = SerializedProgram.from_bytes(solution_generator([])) - block_generator = BlockGenerator(program, [], []) + block_generator = BlockGenerator(program, []) if len(tx_block_heights) > 4: - block_refs = [ - tx_block_heights[1], - tx_block_heights[len(tx_block_heights) // 2], - tx_block_heights[-2], - ] - else: - block_refs = [] - block_generator = dataclasses.replace( - block_generator, block_height_list=block_generator.block_height_list + block_refs - ) + block_refs.extend( + [ + tx_block_heights[1], + tx_block_heights[len(tx_block_heights) // 2], + tx_block_heights[-2], + ] + ) ( full_block, @@ -1180,11 +1168,12 @@ def get_consecutive_blocks( overflow_rc_challenge=overflow_rc_challenge, normalized_to_identity_cc_ip=normalized_to_identity_cc_ip, current_time=current_time, + block_refs=block_refs, ) if block_record.is_transaction_block: transaction_data_included = True - previous_generator = None + block_refs = [] keep_going_until_tx_block = False assert full_block.foliage_transaction_block is not None elif guarantee_transaction_block: @@ -1804,6 +1793,7 @@ def get_full_block_and_block_record( prev_block: BlockRecord, seed: bytes = b"", *, + block_refs: List[uint32] = [], overflow_cc_challenge: Optional[bytes32] = None, overflow_rc_challenge: Optional[bytes32] = None, normalized_to_identity_cc_ip: bool = False, diff --git a/chia/types/generator_types.py b/chia/types/generator_types.py index 465c11a3d835..c60683783d6f 100644 --- a/chia/types/generator_types.py +++ b/chia/types/generator_types.py @@ -20,6 +20,3 @@ def get_generator_for_block_height(self, height: uint32) -> SerializedProgram: class BlockGenerator(Streamable): program: SerializedProgram generator_refs: List[SerializedProgram] - - # the heights are only used when creating new blocks, never when validating - block_height_list: List[uint32] diff --git a/tools/generate_chain.py b/tools/generate_chain.py index 985158b9d39f..b1501c6f58c5 100644 --- a/tools/generate_chain.py +++ b/tools/generate_chain.py @@ -162,7 +162,7 @@ def main(length: int, fill_rate: int, profile: bool, block_refs: bool, output: O pool_reward_puzzle_hash=pool_puzzlehash, keep_going_until_tx_block=True, transaction_data=SpendBundle.aggregate(spend_bundles), - previous_generator=block_references, + block_refs=block_references, ) prev_tx_block = b prev_block = blocks[-2]