diff --git a/chia/_tests/conftest.py b/chia/_tests/conftest.py index 63f262b9fc6d..0afe804dc097 100644 --- a/chia/_tests/conftest.py +++ b/chia/_tests/conftest.py @@ -200,7 +200,8 @@ class ConsensusMode(ComparableEnum): @pytest.fixture( scope="session", - params=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0, ConsensusMode.HARD_FORK_3_0], + # TODO: todo_v2_plots add HARD_FORK_3_0 mode as well as after phase-out + params=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0], ) def consensus_mode(request): return request.param diff --git a/chia/_tests/core/server/test_rate_limits.py b/chia/_tests/core/server/test_rate_limits.py index c915b2ca05dd..b90d2afdd36d 100644 --- a/chia/_tests/core/server/test_rate_limits.py +++ b/chia/_tests/core/server/test_rate_limits.py @@ -24,7 +24,6 @@ rl_v2 = [Capability.BASE, Capability.BLOCK_HEADERS, Capability.RATE_LIMITS_V2] rl_v1 = [Capability.BASE] node_with_params_b = node_with_params -test_different_versions_results: list[int] = [] @dataclass @@ -418,11 +417,14 @@ async def test_different_versions( # The following code checks whether all of the runs resulted in the same number of items in "rate_limits_tx", # which would mean the same rate limits are always used. This should not happen, since two nodes with V2 # will use V2. - total_tx_msg_count = len(get_rate_limits_to_use(a_con.local_capabilities, a_con.peer_capabilities)) + rate_limits = get_rate_limits_to_use(a_con.local_capabilities, a_con.peer_capabilities)[0] + limit = rate_limits[ProtocolMessageTypes.request_header_blocks] + assert isinstance(limit, RLSettings) - test_different_versions_results.append(total_tx_msg_count) - if len(test_different_versions_results) >= 4: - assert len(set(test_different_versions_results)) >= 2 + if Capability.RATE_LIMITS_V2 in a_con.local_capabilities and Capability.RATE_LIMITS_V2 in a_con.peer_capabilities: + assert limit.frequency == 5000 + else: + assert limit.frequency == 500 @pytest.mark.anyio diff --git a/chia/consensus/block_body_validation.py b/chia/consensus/block_body_validation.py index c113184cf9c6..6506e3b051e4 100644 --- a/chia/consensus/block_body_validation.py +++ b/chia/consensus/block_body_validation.py @@ -341,10 +341,14 @@ async def validate_block_body( # the generator ref list for this block (or 'one' bytes [0x01] if no generator) # 8b. The generator ref list length must be less than or equal to MAX_GENERATOR_REF_LIST_SIZE entries # 8c. The generator ref list must not point to a height >= this block's height - if block.transactions_generator_ref_list in (None, []): + if block.transactions_generator_ref_list == []: if block.transactions_info.generator_refs_root != bytes([1] * 32): return Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT else: + # With hard fork 2 we ban transactions_generator_ref_list. + if prev_transaction_block_height >= constants.HARD_FORK2_HEIGHT: + return Err.TOO_MANY_GENERATOR_REFS + # If we have a generator reference list, we must have a generator if block.transactions_generator is None: return Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT diff --git a/chia/consensus/blockchain.py b/chia/consensus/blockchain.py index 00d9df5d1a4c..34e3252e4ec8 100644 --- a/chia/consensus/blockchain.py +++ b/chia/consensus/blockchain.py @@ -33,6 +33,7 @@ from chia.consensus.find_fork_point import lookup_fork_chain from chia.consensus.full_block_to_block_record import block_to_block_record from chia.consensus.generator_tools import get_block_header +from chia.consensus.get_block_challenge import prev_tx_block from chia.consensus.get_block_generator import get_block_generator from chia.consensus.multiprocess_validation import PreValidationResult from chia.full_node.block_store import BlockStore @@ -698,12 +699,16 @@ async def validate_unfinished_block_header( if len(block.transactions_generator_ref_list) > self.constants.MAX_GENERATOR_REF_LIST_SIZE: return None, Err.TOO_MANY_GENERATOR_REFS - if ( - self.try_block_record(block.prev_header_hash) is None - and block.prev_header_hash != self.constants.GENESIS_CHALLENGE - ): + prev_b = self.try_block_record(block.prev_header_hash) + if prev_b is None and block.prev_header_hash != self.constants.GENESIS_CHALLENGE: return None, Err.INVALID_PREV_BLOCK_HASH + prev_tx_height = prev_tx_block(self, prev_b) + + # With hard fork 2 we ban transactions_generator_ref_list. + if prev_tx_height >= self.constants.HARD_FORK2_HEIGHT and block.transactions_generator_ref_list != []: + return None, Err.TOO_MANY_GENERATOR_REFS + if block.transactions_info is not None: if block.transactions_generator is not None: if std_hash(bytes(block.transactions_generator)) != block.transactions_info.generator_root: diff --git a/chia/simulator/block_tools.py b/chia/simulator/block_tools.py index 828ed0061b3f..04330f0a274c 100644 --- a/chia/simulator/block_tools.py +++ b/chia/simulator/block_tools.py @@ -385,6 +385,10 @@ def setup_new_gen( transaction_data: Optional[SpendBundle], block_refs: list[uint32], ) -> Optional[NewBlockGenerator]: + if prev_tx_height >= self.constants.HARD_FORK2_HEIGHT: + assert block_refs == [], "block references are not allowed after hard fork 2" + dummy_block_references = False + # we don't know if the new block will be a transaction # block or not, so even though we prepare a block # generator, we can't update our state (like,