From 3e35acccf57242b8721b40cb429e8ce5b63e273e Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Wed, 4 Sep 2024 17:05:42 +0100 Subject: [PATCH] Adapt to fixing get_conditions_from_spendbundle's return value to include the cost of the whole spend. --- chia/_tests/core/full_node/test_full_node.py | 4 ++-- .../core/mempool/test_mempool_manager.py | 18 +++++++++++------- chia/clvm/spend_sim.py | 1 + chia/full_node/mempool_manager.py | 4 +--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/chia/_tests/core/full_node/test_full_node.py b/chia/_tests/core/full_node/test_full_node.py index 8a23b19565a7..2f4cafbf1e0f 100644 --- a/chia/_tests/core/full_node/test_full_node.py +++ b/chia/_tests/core/full_node/test_full_node.py @@ -935,8 +935,8 @@ async def test_new_transaction_and_mempool(self, wallet_nodes, self_hostname, se # these numbers reflect the capacity of the mempool. In these # tests MEMPOOL_BLOCK_BUFFER is 1. The other factors are COST_PER_BYTE # and MAX_BLOCK_COST_CLVM - assert included_tx == 27 - assert not_included_tx == 6 + assert included_tx == 23 + assert not_included_tx == 10 assert seen_bigger_transaction_has_high_fee # Mempool is full diff --git a/chia/_tests/core/mempool/test_mempool_manager.py b/chia/_tests/core/mempool/test_mempool_manager.py index 894a433a0aae..e5505d9db568 100644 --- a/chia/_tests/core/mempool/test_mempool_manager.py +++ b/chia/_tests/core/mempool/test_mempool_manager.py @@ -510,7 +510,7 @@ async def test_duplicate_output() -> None: async def test_block_cost_exceeds_max() -> None: mempool_manager = await instantiate_mempool_manager(zero_calls_get_coin_records) conditions = [] - for i in range(3800): + for i in range(2400): conditions.append([ConditionOpcode.CREATE_COIN, IDENTITY_PUZZLE_HASH, i]) sb = spend_bundle_from_conditions(conditions) with pytest.raises(ValidationError, match="BLOCK_COST_EXCEEDS_MAX"): @@ -581,7 +581,7 @@ async def test_same_sb_twice_with_eligible_coin() -> None: sb = SpendBundle.aggregate([sb1, sb2]) sb_name = sb.name() result = await add_spendbundle(mempool_manager, sb, sb_name) - expected_cost = uint64(6_600_088) + expected_cost = uint64(10_236_088) assert result == (expected_cost, MempoolInclusionStatus.SUCCESS, None) assert mempool_manager.get_spendbundle(sb_name) == sb result = await add_spendbundle(mempool_manager, sb, sb_name) @@ -614,7 +614,7 @@ async def test_sb_twice_with_eligible_coin_and_different_spends_order() -> None: assert mempool_manager.get_spendbundle(sb_name) is None assert mempool_manager.get_spendbundle(reordered_sb_name) is None result = await add_spendbundle(mempool_manager, sb, sb_name) - expected_cost = uint64(7_800_132) + expected_cost = uint64(13_056_132) assert result == (expected_cost, MempoolInclusionStatus.SUCCESS, None) assert mempool_manager.get_spendbundle(sb_name) == sb assert mempool_manager.get_spendbundle(reordered_sb_name) is None @@ -1053,7 +1053,7 @@ async def make_and_send_big_cost_sb(coin: Coin) -> None: g1 = sk.get_g1() sig = AugSchemeMPL.sign(sk, IDENTITY_PUZZLE_HASH, g1) aggsig = G2Element() - for _ in range(318): + for _ in range(169): conditions.append([ConditionOpcode.AGG_SIG_UNSAFE, g1, IDENTITY_PUZZLE_HASH]) aggsig += sig conditions.append([ConditionOpcode.CREATE_COIN, IDENTITY_PUZZLE_HASH, coin.amount - 10_000_000]) @@ -1942,7 +1942,9 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]: assert e.code == expected -TEST_FILL_RATE_ITEM_COST = 144_744_040 +TEST_FILL_RATE_ITEM_COST = 144_720_020 +QUOTE_BYTE_COST = 2 * DEFAULT_CONSTANTS.COST_PER_BYTE +QUOTE_EXECUTION_COST = 20 @pytest.mark.anyio @@ -1956,10 +1958,12 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]: # because of the spend bundle aggregation that creates the block # bundle, in addition to a small block compression effect that we # can't completely avoid. - (TEST_FILL_RATE_ITEM_COST * 2, 2, TEST_FILL_RATE_ITEM_COST * 2 - 156_020), + (TEST_FILL_RATE_ITEM_COST * 2, 2, TEST_FILL_RATE_ITEM_COST * 2 - 107_980), # Here we set the block cost limit to twice the test items' cost - 1, # so we expect only one of the two test items to get included in the block. - (TEST_FILL_RATE_ITEM_COST * 2 - 1, 1, TEST_FILL_RATE_ITEM_COST), + # NOTE: The cost difference here is because get_conditions_from_spendbundle + # does not include the overhead to make a block (quote byte cost + quote runtime cost). + (TEST_FILL_RATE_ITEM_COST * 2 - 1, 1, TEST_FILL_RATE_ITEM_COST + QUOTE_BYTE_COST + QUOTE_EXECUTION_COST), ], ) async def test_fill_rate_block_validation( diff --git a/chia/clvm/spend_sim.py b/chia/clvm/spend_sim.py index ea06a14d8dc6..92457ee0fa58 100644 --- a/chia/clvm/spend_sim.py +++ b/chia/clvm/spend_sim.py @@ -268,6 +268,7 @@ async def farm_block( get_unspent_lineage_info_for_puzzle_hash=self.coin_store.get_unspent_lineage_info_for_puzzle_hash, item_inclusion_filter=item_inclusion_filter, ) + if result is not None: bundle, additions = result generator_bundle = bundle diff --git a/chia/full_node/mempool_manager.py b/chia/full_node/mempool_manager.py index afc48de758aa..e7c1813327de 100644 --- a/chia/full_node/mempool_manager.py +++ b/chia/full_node/mempool_manager.py @@ -302,9 +302,7 @@ async def pre_validate_spendbundle( if ret.error is not None: raise ValidationError(Err(ret.error), "pre_validate_spendbundle failed") assert ret.conds is not None - # TODO: this cost padding is temporary, until we update the mempool's - # block creation logic to take the block overhead into account - return ret.conds.replace(cost=ret.conds.cost + 10000000) + return ret.conds.replace(cost=ret.conds.cost) async def add_spend_bundle( self,