From 244e108442b774759aacabc7e1c5c3b2258eea6d Mon Sep 17 00:00:00 2001 From: wjblanke Date: Wed, 26 Jul 2023 19:00:55 -0700 Subject: [PATCH] remove chip13 (#15871) * remove chip13 * flake8 * flake8 * flake8 * isort * Remove chip-13 test --------- Co-authored-by: Earle Lowe --- chia/consensus/block_body_validation.py | 35 -------------- chia/consensus/block_header_validation.py | 31 +----------- chia/simulator/block_tools.py | 9 ---- tests/blockchain/test_blockchain.py | 59 ----------------------- 4 files changed, 1 insertion(+), 133 deletions(-) diff --git a/chia/consensus/block_body_validation.py b/chia/consensus/block_body_validation.py index 001254a38dc0..3d1e96fc281f 100644 --- a/chia/consensus/block_body_validation.py +++ b/chia/consensus/block_body_validation.py @@ -19,7 +19,6 @@ from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions, mempool_check_time_locks from chia.types.block_protocol import BlockInfo from chia.types.blockchain_format.coin import Coin -from chia.types.blockchain_format.proof_of_space import calculate_prefix_bits, get_plot_id, passes_plot_filter from chia.types.blockchain_format.sized_bytes import bytes32, bytes48 from chia.types.coin_record import CoinRecord from chia.types.full_block import FullBlock @@ -62,40 +61,6 @@ async def validate_block_body( prev_transaction_block_height: uint32 = uint32(0) prev_transaction_block_timestamp: uint64 = uint64(0) - # We repeat the ProofOfSpace check from block header validation here, because we want to fetch blocks - # from the database too (BlockStore). In `BlockHeaderValidation` we don't have access to the database, - # just the cache. This check makes sure we retrieve blocks from the database and perform the check with them, - # in case they were missing from the cache. - if height >= constants.SOFT_FORK3_HEIGHT: - curr_optional_block_record: Optional[BlockRecord] = await blocks.get_block_record_from_db( - block.prev_header_hash - ) - plot_id = get_plot_id(block.reward_chain_block.proof_of_space) - if block.reward_chain_block.challenge_chain_sp_vdf is None: - # Edge case of first sp (start of slot), where sp_iters == 0 - curr_sp: bytes32 = block.reward_chain_block.pos_ss_cc_challenge_hash - else: - curr_sp = block.reward_chain_block.challenge_chain_sp_vdf.output.get_hash() - sp_count = 1 - - while curr_optional_block_record is not None and sp_count < constants.UNIQUE_PLOTS_WINDOW: - prefix_bits = calculate_prefix_bits(constants, curr_optional_block_record.height) - - if curr_optional_block_record.cc_sp_hash != curr_sp: - if passes_plot_filter( - prefix_bits, - plot_id, - curr_optional_block_record.pos_ss_cc_challenge_hash, - curr_optional_block_record.cc_sp_hash, - ): - log.error(f"Chip-13 Block Failed at height: {height}") - return Err.INVALID_POSPACE, None - - sp_count += 1 - curr_sp = curr_optional_block_record.cc_sp_hash - if sp_count < constants.UNIQUE_PLOTS_WINDOW: - curr_optional_block_record = await blocks.get_block_record_from_db(curr_optional_block_record.prev_hash) - # 1. For non transaction-blocs: foliage block, transaction filter, transactions info, and generator must # be empty. If it is a block but not a transaction block, there is no body to validate. Check that all fields are # None diff --git a/chia/consensus/block_header_validation.py b/chia/consensus/block_header_validation.py index 178b5294bd08..9e207dc1251a 100644 --- a/chia/consensus/block_header_validation.py +++ b/chia/consensus/block_header_validation.py @@ -23,12 +23,7 @@ ) from chia.consensus.vdf_info_computation import get_signage_point_vdf_info from chia.types.blockchain_format.classgroup import ClassgroupElement -from chia.types.blockchain_format.proof_of_space import ( - calculate_prefix_bits, - get_plot_id, - passes_plot_filter, - verify_and_get_quality_string, -) +from chia.types.blockchain_format.proof_of_space import verify_and_get_quality_string from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.blockchain_format.slots import ChallengeChainSubSlot, RewardChainSubSlot, SubSlotProofs from chia.types.blockchain_format.vdf import VDFInfo, VDFProof @@ -496,30 +491,6 @@ def validate_unfinished_header_block( if q_str is None: return None, ValidationError(Err.INVALID_POSPACE) - # 5c. Check plot id is not present within last `NUM_DISTINCT_CONSECUTIVE_PLOT_IDS` blocks. - if height >= constants.SOFT_FORK3_HEIGHT: - curr_optional_block_record: Optional[BlockRecord] = prev_b - plot_id = get_plot_id(header_block.reward_chain_block.proof_of_space) - curr_sp = cc_sp_hash - sp_count = 1 - - while curr_optional_block_record is not None and sp_count < constants.UNIQUE_PLOTS_WINDOW: - prefix_bits = calculate_prefix_bits(constants, curr_optional_block_record.height) - - if curr_optional_block_record.cc_sp_hash != curr_sp: - if passes_plot_filter( - prefix_bits, - plot_id, - curr_optional_block_record.pos_ss_cc_challenge_hash, - curr_optional_block_record.cc_sp_hash, - ): - return None, ValidationError(Err.INVALID_POSPACE, f"Chip-13 Block Failed: {height}") - - sp_count += 1 - curr_sp = curr_optional_block_record.cc_sp_hash - if sp_count < constants.UNIQUE_PLOTS_WINDOW: - curr_optional_block_record = blocks.try_block_record(curr_optional_block_record.prev_hash) - # 6. check signage point index # no need to check negative values as this is uint 8 if header_block.reward_chain_block.signage_point_index >= constants.NUM_SPS_SUB_SLOT: diff --git a/chia/simulator/block_tools.py b/chia/simulator/block_tools.py index b42b7bb1bc5d..a246f47dde59 100644 --- a/chia/simulator/block_tools.py +++ b/chia/simulator/block_tools.py @@ -80,7 +80,6 @@ calculate_prefix_bits, generate_plot_public_key, generate_taproot_sk, - get_plot_id, passes_plot_filter, verify_and_get_quality_string, ) @@ -728,10 +727,6 @@ def get_consecutive_blocks( if required_iters <= latest_block.required_iters: continue assert latest_block.header_hash in blocks - plot_id = get_plot_id(proof_of_space) - if latest_block.height + 1 >= constants.SOFT_FORK3_HEIGHT: - if self.plot_id_passed_previous_filters(plot_id, cc_sp_output_hash, block_list): - continue additions = None removals = None if transaction_data_included: @@ -1030,10 +1025,6 @@ def get_consecutive_blocks( if blocks_added_this_sub_slot == constants.MAX_SUB_SLOT_BLOCKS: break assert last_timestamp is not None - plot_id = get_plot_id(proof_of_space) - if latest_block.height + 1 >= constants.SOFT_FORK3_HEIGHT: - if self.plot_id_passed_previous_filters(plot_id, cc_sp_output_hash, block_list): - continue if proof_of_space.pool_contract_puzzle_hash is not None: if pool_reward_puzzle_hash is not None: # The caller wants to be paid to a specific address, but this PoSpace is tied to an diff --git a/tests/blockchain/test_blockchain.py b/tests/blockchain/test_blockchain.py index 84f261f8593a..55ae6925b432 100644 --- a/tests/blockchain/test_blockchain.py +++ b/tests/blockchain/test_blockchain.py @@ -52,7 +52,6 @@ from tests.blockchain.blockchain_test_utils import ( _validate_and_add_block, _validate_and_add_block_multi_error, - _validate_and_add_block_multi_error_or_pass, _validate_and_add_block_multi_result, _validate_and_add_block_no_error, ) @@ -3609,61 +3608,3 @@ async def test_reorg_flip_flop(empty_blockchain, bt): for block in chain_b[40:]: await _validate_and_add_block(b, block) - - -@pytest.mark.parametrize("unique_plots_window", [1, 2]) -@pytest.mark.parametrize("bt_respects_soft_fork3", [True, False]) -@pytest.mark.parametrize("soft_fork3_height", [0, 10, 10000]) -@pytest.mark.asyncio -async def test_soft_fork3_activation( - consensus_mode, blockchain_constants, bt_respects_soft_fork3, soft_fork3_height, db_version, unique_plots_window -): - # We don't run Mode.SOFT_FORK3, since this is already parametrized by this test. - # Additionally, Mode.HARD_FORK_2_0 mode is incopatible with this test, since plot filter size would be zero, - # blocks won't ever be produced (we'll pass every consecutive plot filter, hence no block would pass CHIP-13). - if consensus_mode != Mode.PLAIN: - pytest.skip("Skipped test") - with TempKeyring() as keychain: - bt = await create_block_tools_async( - constants=blockchain_constants.replace( - SOFT_FORK3_HEIGHT=(0 if bt_respects_soft_fork3 else 10000), - UNIQUE_PLOTS_WINDOW=unique_plots_window, - ), - keychain=keychain, - ) - blockchain_constants = bt.constants.replace(SOFT_FORK3_HEIGHT=soft_fork3_height) - b, db_wrapper, db_path = await create_blockchain(blockchain_constants, db_version) - blocks = bt.get_consecutive_blocks(25) - for height, block in enumerate(blocks): - await _validate_and_add_block_multi_error_or_pass(b, block, [Err.INVALID_POSPACE]) - peak = b.get_peak() - assert peak is not None - if peak.height != height: - break - - peak = b.get_peak() - assert peak is not None - - # We expect to add all blocks here (25 blocks), either because `unique_plots_window`=1 means we're not - # checking any extra plot filter, or `unique_plots_window`=True means `BlockTools` produced blocks - # that respect CHIP-13. - if bt_respects_soft_fork3 or unique_plots_window == 1: - assert peak.height == 24 - else: - # Here we have `bt_respects_soft_fork3`=False, which means the produced blocks by `BlockTools` will not - # respect the CHIP-13 condition. We expect not adding blocks at some point after the soft fork 3 - # activation height (`soft_fork3_height`). - if soft_fork3_height == 0: - # We're not adding all blocks, since at some point `BlockTools` will break the CHIP-13 condition with - # very high likelyhood. - assert peak.height < 24 - elif soft_fork3_height == 10: - # We're not adding all blocks, but we've added all of them until the soft fork 3 activated (height 10) - assert peak.height < 24 and peak.height >= 9 - else: - # Soft fork 3 will activate in the future (height 100), so we're adding all blocks. - assert peak.height == 24 - - await db_wrapper.close() - b.shut_down() - db_path.unlink()