diff --git a/chia/_tests/blockchain/test_blockchain.py b/chia/_tests/blockchain/test_blockchain.py index 89b015cc524f..98ecd040c3bc 100644 --- a/chia/_tests/blockchain/test_blockchain.py +++ b/chia/_tests/blockchain/test_blockchain.py @@ -170,7 +170,7 @@ async def test_long_chain(self, empty_blockchain: Blockchain, default_1000_block block_bad = recursive_replace( block, "finished_sub_slots", [new_finished_ss] + block.finished_sub_slots[1:] ) - header_block_bad = get_block_header(block_bad, [], []) + header_block_bad = get_block_header(block_bad) # TODO: Inspect these block values as they are currently None expected_difficulty = block.finished_sub_slots[0].challenge_chain.new_difficulty or uint64(0) expected_sub_slot_iters = block.finished_sub_slots[0].challenge_chain.new_sub_slot_iters or uint64(0) @@ -195,7 +195,7 @@ async def test_long_chain(self, empty_blockchain: Blockchain, default_1000_block block, "finished_sub_slots", [new_finished_ss_2] + block.finished_sub_slots[1:] ) - header_block_bad_2 = get_block_header(block_bad_2, [], []) + header_block_bad_2 = get_block_header(block_bad_2) # TODO: Inspect these block values as they are currently None expected_difficulty = block.finished_sub_slots[0].challenge_chain.new_difficulty or uint64(0) expected_sub_slot_iters = block.finished_sub_slots[0].challenge_chain.new_sub_slot_iters or uint64(0) @@ -225,7 +225,7 @@ async def test_long_chain(self, empty_blockchain: Blockchain, default_1000_block log.warning(f"Number of slots: {len(block.finished_sub_slots)}") block_bad_3 = recursive_replace(block, "finished_sub_slots", [new_finished_ss_3]) - header_block_bad_3 = get_block_header(block_bad_3, [], []) + header_block_bad_3 = get_block_header(block_bad_3) # TODO: Inspect these block values as they are currently None expected_difficulty = block.finished_sub_slots[0].challenge_chain.new_difficulty or uint64(0) expected_sub_slot_iters = block.finished_sub_slots[0].challenge_chain.new_sub_slot_iters or uint64(0) @@ -254,7 +254,7 @@ async def test_long_chain(self, empty_blockchain: Blockchain, default_1000_block ) block_bad_4 = recursive_replace(block, "finished_sub_slots", [new_finished_ss_4]) - header_block_bad_4 = get_block_header(block_bad_4, [], []) + header_block_bad_4 = get_block_header(block_bad_4) # TODO: Inspect these block values as they are currently None expected_difficulty = block.finished_sub_slots[0].challenge_chain.new_difficulty or uint64(0) expected_sub_slot_iters = block.finished_sub_slots[0].challenge_chain.new_sub_slot_iters or uint64(0) @@ -510,7 +510,7 @@ async def test_invalid_sub_slot_challenge_hash_genesis(self, empty_blockchain: B blocks[0], "finished_sub_slots", [new_finished_ss] + blocks[0].finished_sub_slots[1:] ) - header_block_bad = get_block_header(block_0_bad, [], []) + header_block_bad = get_block_header(block_0_bad) expected_vs = ValidationState( empty_blockchain.constants.SUB_SLOT_ITERS_STARTING, empty_blockchain.constants.DIFFICULTY_STARTING, None ) @@ -539,7 +539,7 @@ async def test_invalid_sub_slot_challenge_hash_non_genesis( ) await _validate_and_add_block(empty_blockchain, blocks[0]) - header_block_bad = get_block_header(block_1_bad, [], []) + header_block_bad = get_block_header(block_1_bad) # TODO: Inspect these block values as they are currently None expected_difficulty = blocks[1].finished_sub_slots[0].challenge_chain.new_difficulty or uint64(0) expected_sub_slot_iters = blocks[1].finished_sub_slots[0].challenge_chain.new_sub_slot_iters or uint64(0) @@ -566,7 +566,7 @@ async def test_invalid_sub_slot_challenge_hash_empty_ss(self, empty_blockchain: ) await _validate_and_add_block(empty_blockchain, blocks[0]) - header_block_bad = get_block_header(block_1_bad, [], []) + header_block_bad = get_block_header(block_1_bad) # TODO: Inspect these block values as they are currently None expected_difficulty = blocks[1].finished_sub_slots[0].challenge_chain.new_difficulty or uint64(0) expected_sub_slot_iters = blocks[1].finished_sub_slots[0].challenge_chain.new_sub_slot_iters or uint64(0) @@ -721,7 +721,7 @@ async def test_invalid_icc_into_cc(self, empty_blockchain: Blockchain, bt: Block block, "finished_sub_slots", block.finished_sub_slots[:-1] + [new_finished_ss] ) - header_block_bad = get_block_header(block_bad, [], []) + header_block_bad = get_block_header(block_bad) # TODO: Inspect these block values as they are currently None expected_difficulty = block.finished_sub_slots[0].challenge_chain.new_difficulty or uint64(0) expected_sub_slot_iters = block.finished_sub_slots[0].challenge_chain.new_sub_slot_iters or uint64(0) @@ -792,7 +792,7 @@ async def test_empty_slot_no_ses(self, empty_blockchain: Blockchain, bt: BlockTo blocks[-1], "finished_sub_slots", blocks[-1].finished_sub_slots[:-1] + [new_finished_ss] ) - header_block_bad = get_block_header(block_bad, [], []) + header_block_bad = get_block_header(block_bad) expected_vs = ValidationState( empty_blockchain.constants.SUB_SLOT_ITERS_STARTING, empty_blockchain.constants.DIFFICULTY_STARTING, None ) diff --git a/chia/_tests/util/test_full_block_utils.py b/chia/_tests/util/test_full_block_utils.py index 320d28ddf100..2af426dd3e7c 100644 --- a/chia/_tests/util/test_full_block_utils.py +++ b/chia/_tests/util/test_full_block_utils.py @@ -274,6 +274,6 @@ async def test_parser(): @pytest.mark.skip("This test is expensive and has already convinced us the parser works") async def test_header_block(): for block in get_full_blocks(): - hb: HeaderBlock = get_block_header(block, [], []) + hb: HeaderBlock = get_block_header(block) hb_bytes = header_block_from_block(memoryview(bytes(block))) assert HeaderBlock.from_bytes(hb_bytes) == hb diff --git a/chia/_tests/wallet/test_wallet_blockchain.py b/chia/_tests/wallet/test_wallet_blockchain.py index 03b76a81c9a9..48dd868c97d7 100644 --- a/chia/_tests/wallet/test_wallet_blockchain.py +++ b/chia/_tests/wallet/test_wallet_blockchain.py @@ -75,7 +75,7 @@ async def test_wallet_blockchain( header_blocks: list[HeaderBlock] = [] for block in default_1000_blocks: - header_block = get_block_header(block, [], []) + header_block = get_block_header(block) header_blocks.append(header_block) res, err = await chain.add_block(header_blocks[50]) diff --git a/chia/_tests/weight_proof/test_weight_proof.py b/chia/_tests/weight_proof/test_weight_proof.py index e17232e3180d..3913fc695ab9 100644 --- a/chia/_tests/weight_proof/test_weight_proof.py +++ b/chia/_tests/weight_proof/test_weight_proof.py @@ -74,7 +74,7 @@ async def load_blocks_dont_validate( ) sub_blocks[block.header_hash] = sub_block height_to_hash[block.height] = block.header_hash - header_cache[block.header_hash] = get_block_header(block, [], []) + header_cache[block.header_hash] = get_block_header(block) if sub_block.sub_epoch_summary_included is not None: sub_epoch_summaries[block.height] = sub_block.sub_epoch_summary_included prev_block = block diff --git a/chia/consensus/blockchain.py b/chia/consensus/blockchain.py index 71e5d49c58a9..761e1c00c086 100644 --- a/chia/consensus/blockchain.py +++ b/chia/consensus/blockchain.py @@ -897,11 +897,11 @@ async def get_header_blocks_in_range( if self.height_to_hash(block.height) != block.header_hash: raise ValueError(f"Block at {block.header_hash} is no longer in the blockchain (it's in a fork)") if tx_filter is False: - header = get_block_header(block, [], []) + header = get_block_header(block) elif block.transactions_generator is None: # There is no point in getting additions and removals for # blocks that do not have transactions. - header = get_block_header(block, [], []) + header = get_block_header(block) else: added_coins_records, removed_coins_records = await asyncio.gather( self.coin_store.get_coins_added_at_height(block.height), @@ -909,7 +909,7 @@ async def get_header_blocks_in_range( ) tx_additions = [cr.coin for cr in added_coins_records if not cr.coinbase] removed = [cr.coin.name() for cr in removed_coins_records] - header = get_block_header(block, tx_additions, removed) + header = get_block_header(block, (tx_additions, removed)) header_blocks[header.header_hash] = header return header_blocks diff --git a/chia/consensus/multiprocess_validation.py b/chia/consensus/multiprocess_validation.py index df330d6ee42b..aecf162b8346 100644 --- a/chia/consensus/multiprocess_validation.py +++ b/chia/consensus/multiprocess_validation.py @@ -121,7 +121,7 @@ def _pre_validate_block( removals, tx_additions = tx_removals_and_additions(conds) assert conds is None or conds.validated_signature is True - header_block = get_block_header(block, tx_additions, removals) + header_block = get_block_header(block, (tx_additions, removals)) required_iters, error = validate_finished_header_block( constants, blockchain, diff --git a/chia/full_node/full_node_api.py b/chia/full_node/full_node_api.py index da2ce74db22d..604a1da51ef1 100644 --- a/chia/full_node/full_node_api.py +++ b/chia/full_node/full_node_api.py @@ -1237,7 +1237,7 @@ async def request_block_header(self, request: wallet_protocol.RequestBlockHeader tx_additions = [add[0] for add in additions] tx_removals = [rem.name() for rem in removals] - header_block = get_block_header(block, tx_additions, tx_removals) + header_block = get_block_header(block, (tx_additions, tx_removals)) msg = make_msg( ProtocolMessageTypes.respond_block_header, wallet_protocol.RespondBlockHeader(header_block), @@ -1529,7 +1529,7 @@ async def request_header_blocks(self, request: wallet_protocol.RequestHeaderBloc ) added_coins = [record.coin for record in added_coins_records if not record.coinbase] removal_names = [record.coin.name() for record in removed_coins_records] - header_block = get_block_header(block, added_coins, removal_names) + header_block = get_block_header(block, (added_coins, removal_names)) header_blocks.append(header_block) msg = make_msg( diff --git a/chia/util/generator_tools.py b/chia/util/generator_tools.py index 8ee76f2b84d9..b2c6ec739d28 100644 --- a/chia/util/generator_tools.py +++ b/chia/util/generator_tools.py @@ -14,11 +14,18 @@ def get_block_header( - block: FullBlock, tx_addition_coins: Collection[Coin], removals_names: Collection[bytes32] + block: FullBlock, additions_and_removals: Optional[tuple[Collection[Coin], Collection[bytes32]]] = None ) -> HeaderBlock: - # Create filter + """ + Returns a HeaderBlock from a FullBlock. + If `additions_and_removals` is not None, account for them, as well as + reward coins, in the creation of the transactions filter, otherwise create + an empty one. + """ + # Create an empty filter to begin with byte_array_tx: list[bytearray] = [] - if block.is_transaction_block(): + if additions_and_removals is not None and block.is_transaction_block(): + tx_addition_coins, removals_names = additions_and_removals for coin in tx_addition_coins: byte_array_tx.append(bytearray(coin.puzzle_hash)) for coin in block.get_included_reward_coins():