3434 DedupCoinSpend ,
3535 IdenticalSpendDedup ,
3636 SkipDedup ,
37- run_for_cost ,
3837)
3938from chia .full_node .mempool import MAX_SKIPPED_ITEMS , PRIORITY_TX_THRESHOLD
4039from chia .full_node .mempool_manager import (
@@ -535,7 +534,7 @@ def spend_bundle_from_conditions(
535534
536535async def add_spendbundle (
537536 mempool_manager : MempoolManager , sb : SpendBundle , sb_name : bytes32
538- ) -> tuple [Optional [ uint64 ] , MempoolInclusionStatus , Optional [Err ]]:
537+ ) -> tuple [uint64 , MempoolInclusionStatus , Optional [Err ]]:
539538 sbc = await mempool_manager .pre_validate_spendbundle (sb , sb_name )
540539 ret = await mempool_manager .add_spend_bundle (sb , sbc , sb_name , TEST_HEIGHT )
541540 invariant_check_mempool (mempool_manager .mempool )
@@ -547,7 +546,7 @@ async def generate_and_add_spendbundle(
547546 conditions : list [list [Any ]],
548547 coin : Coin = TEST_COIN ,
549548 aggsig : G2Element = G2Element (),
550- ) -> tuple [SpendBundle , bytes32 , tuple [Optional [ uint64 ] , MempoolInclusionStatus , Optional [Err ]]]:
549+ ) -> tuple [SpendBundle , bytes32 , tuple [uint64 , MempoolInclusionStatus , Optional [Err ]]]:
551550 sb = spend_bundle_from_conditions (conditions , coin , aggsig )
552551 sb_name = sb .name ()
553552 result = await add_spendbundle (mempool_manager , sb , sb_name )
@@ -579,6 +578,7 @@ def make_bundle_spends_map_and_fee(
579578 eligible_for_dedup = bool (spend_conds .flags & ELIGIBLE_FOR_DEDUP ),
580579 eligible_for_fast_forward = bool (spend_conds .flags & ELIGIBLE_FOR_FF ),
581580 additions = additions ,
581+ cost = uint64 (spend_conds .condition_cost + spend_conds .execution_cost ),
582582 latest_singleton_lineage = UnspentLineageInfo (coin_id , coin_spend .coin .parent_coin_info , bytes32 ([0 ] * 32 ))
583583 if bool (spend_conds .flags & ELIGIBLE_FOR_FF )
584584 else None ,
@@ -703,7 +703,7 @@ async def get_coin_records(_: Collection[bytes32]) -> list[CoinRecord]:
703703 mempool_manager = await instantiate_mempool_manager (get_coin_records )
704704 conditions = [[ConditionOpcode .CREATE_COIN , IDENTITY_PUZZLE_HASH , 1 ]]
705705 _ , _ , result = await generate_and_add_spendbundle (mempool_manager , conditions )
706- assert result == (None , MempoolInclusionStatus .FAILED , Err .UNKNOWN_UNSPENT )
706+ assert result == (0 , MempoolInclusionStatus .FAILED , Err .UNKNOWN_UNSPENT )
707707
708708
709709@pytest .mark .anyio
@@ -885,6 +885,7 @@ def mk_bcs(coin_spend: CoinSpend, flags: int = 0) -> BundleCoinSpend:
885885 eligible_for_dedup = bool (flags & ELIGIBLE_FOR_DEDUP ),
886886 eligible_for_fast_forward = bool (flags & ELIGIBLE_FOR_FF ),
887887 additions = [],
888+ cost = uint64 (0 ),
888889 )
889890
890891
@@ -1578,21 +1579,6 @@ async def test_replacing_one_with_an_eligible_coin() -> None:
15781579 assert_sb_in_pool (mempool_manager , sb123e4 )
15791580
15801581
1581- @pytest .mark .parametrize ("amount" , [0 , 1 ])
1582- def test_run_for_cost (amount : int ) -> None :
1583- conditions = [[ConditionOpcode .CREATE_COIN , IDENTITY_PUZZLE_HASH , amount ]]
1584- solution = SerializedProgram .to (conditions )
1585- cost = run_for_cost (IDENTITY_PUZZLE , solution , additions_count = 1 , max_cost = uint64 (10000000 ))
1586- assert cost == uint64 (1800044 )
1587-
1588-
1589- def test_run_for_cost_max_cost () -> None :
1590- conditions = [[ConditionOpcode .CREATE_COIN , IDENTITY_PUZZLE_HASH , 1 ]]
1591- solution = SerializedProgram .to (conditions )
1592- with pytest .raises (ValueError , match = "cost exceeded" ):
1593- run_for_cost (IDENTITY_PUZZLE , solution , additions_count = 1 , max_cost = uint64 (43 ))
1594-
1595-
15961582def test_dedup_info_nothing_to_do () -> None :
15971583 # No eligible coins, nothing to deduplicate, item gets considered normally
15981584
@@ -1636,7 +1622,9 @@ def test_dedup_info_eligible_1st_time() -> None:
16361622 Coin (TEST_COIN_ID , IDENTITY_PUZZLE_HASH , uint64 (1 )),
16371623 Coin (TEST_COIN_ID , IDENTITY_PUZZLE_HASH , uint64 (TEST_COIN_AMOUNT - 1 )),
16381624 }
1639- assert dedup_coin_spends == IdenticalSpendDedup ({TEST_COIN_ID : DedupCoinSpend (solution = solution , cost = None )})
1625+ assert dedup_coin_spends == IdenticalSpendDedup (
1626+ {TEST_COIN_ID : DedupCoinSpend (solution = solution , cost = uint64 (3600044 ))}
1627+ )
16401628
16411629
16421630def test_dedup_info_eligible_but_different_solution () -> None :
@@ -1646,7 +1634,7 @@ def test_dedup_info_eligible_but_different_solution() -> None:
16461634 [ConditionOpcode .CREATE_COIN , IDENTITY_PUZZLE_HASH , TEST_COIN_AMOUNT ],
16471635 ]
16481636 initial_solution = SerializedProgram .to (initial_conditions )
1649- dedup_coin_spends = IdenticalSpendDedup ({TEST_COIN_ID : DedupCoinSpend (solution = initial_solution , cost = None )})
1637+ dedup_coin_spends = IdenticalSpendDedup ({TEST_COIN_ID : DedupCoinSpend (solution = initial_solution , cost = uint64 ( 10 ) )})
16501638 conditions = [[ConditionOpcode .CREATE_COIN , IDENTITY_PUZZLE_HASH , TEST_COIN_AMOUNT ]]
16511639 sb = spend_bundle_from_conditions (conditions , TEST_COIN )
16521640 mempool_item = mempool_item_from_spendbundle (sb )
@@ -1663,7 +1651,9 @@ def test_dedup_info_eligible_2nd_time_and_another_1st_time() -> None:
16631651 [ConditionOpcode .CREATE_COIN , IDENTITY_PUZZLE_HASH , TEST_COIN_AMOUNT - 1 ],
16641652 ]
16651653 initial_solution = SerializedProgram .to (initial_conditions )
1666- dedup_coin_spends = IdenticalSpendDedup ({TEST_COIN_ID : DedupCoinSpend (solution = initial_solution , cost = None )})
1654+ dedup_coin_spends = IdenticalSpendDedup (
1655+ {TEST_COIN_ID : DedupCoinSpend (solution = initial_solution , cost = uint64 (1337 ))}
1656+ )
16671657 sb1 = spend_bundle_from_conditions (initial_conditions , TEST_COIN )
16681658 second_conditions = [[ConditionOpcode .CREATE_COIN , IDENTITY_PUZZLE_HASH , TEST_COIN_AMOUNT2 ]]
16691659 second_solution = SerializedProgram .to (second_conditions )
@@ -1676,15 +1666,14 @@ def test_dedup_info_eligible_2nd_time_and_another_1st_time() -> None:
16761666 )
16771667 # Only the eligible one that we encountered more than once gets deduplicated
16781668 assert unique_coin_spends == sb2 .coin_spends
1679- saved_cost = uint64 (3600044 )
1680- assert cost_saving == saved_cost
1669+ assert cost_saving == uint64 (1337 )
16811670 assert unique_additions == [Coin (TEST_COIN_ID2 , IDENTITY_PUZZLE_HASH , TEST_COIN_AMOUNT2 )]
16821671 # The coin we encountered a second time has its cost and additions properly updated
16831672 # The coin we encountered for the first time gets cost None and an empty set of additions
16841673 expected_dedup_coin_spends = IdenticalSpendDedup (
16851674 {
1686- TEST_COIN_ID : DedupCoinSpend (solution = initial_solution , cost = saved_cost ),
1687- TEST_COIN_ID2 : DedupCoinSpend (solution = second_solution , cost = None ),
1675+ TEST_COIN_ID : DedupCoinSpend (solution = initial_solution , cost = uint64 ( 1337 ) ),
1676+ TEST_COIN_ID2 : DedupCoinSpend (solution = second_solution , cost = uint64 ( 1800044 ) ),
16881677 }
16891678 )
16901679 assert dedup_coin_spends == expected_dedup_coin_spends
@@ -1703,7 +1692,7 @@ def test_dedup_info_eligible_3rd_time_another_2nd_time_and_one_non_eligible() ->
17031692 dedup_coin_spends = IdenticalSpendDedup (
17041693 {
17051694 TEST_COIN_ID : DedupCoinSpend (solution = initial_solution , cost = saved_cost ),
1706- TEST_COIN_ID2 : DedupCoinSpend (solution = second_solution , cost = None ),
1695+ TEST_COIN_ID2 : DedupCoinSpend (solution = second_solution , cost = uint64 ( 1337 ) ),
17071696 }
17081697 )
17091698 sb1 = spend_bundle_from_conditions (initial_conditions , TEST_COIN )
@@ -1723,7 +1712,7 @@ def test_dedup_info_eligible_3rd_time_another_2nd_time_and_one_non_eligible() ->
17231712 bundle_coin_spends = mempool_item .bundle_coin_spends , max_cost = mempool_item .conds .cost
17241713 )
17251714 assert unique_coin_spends == sb3 .coin_spends
1726- saved_cost2 = uint64 (1800044 )
1715+ saved_cost2 = uint64 (1337 )
17271716 assert cost_saving == saved_cost + saved_cost2
17281717 assert unique_additions == [Coin (TEST_COIN_ID3 , IDENTITY_PUZZLE_HASH , TEST_COIN_AMOUNT3 )]
17291718 expected_dedup_coin_spends = IdenticalSpendDedup (
@@ -1805,12 +1794,14 @@ async def test_bundle_coin_spends() -> None:
18051794 eligible_for_dedup = False ,
18061795 eligible_for_fast_forward = False ,
18071796 additions = [Coin (coins [i ].name (), IDENTITY_PUZZLE_HASH , coins [i ].amount )],
1797+ cost = uint64 (3000044 ),
18081798 )
18091799 assert mi123e .bundle_coin_spends [coins [3 ].name ()] == BundleCoinSpend (
18101800 coin_spend = eligible_sb .coin_spends [0 ],
18111801 eligible_for_dedup = True ,
18121802 eligible_for_fast_forward = False ,
18131803 additions = [Coin (coins [3 ].name (), IDENTITY_PUZZLE_HASH , coins [3 ].amount )],
1804+ cost = uint64 (1800044 ),
18141805 )
18151806
18161807
@@ -2162,7 +2153,7 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> list[CoinRecord]:
21622153 result = await add_spendbundle (mempool_manager , bundle , bundle_name )
21632154 print (result )
21642155 if expected is not None :
2165- assert result == (None , MempoolInclusionStatus .FAILED , expected )
2156+ assert result == (0 , MempoolInclusionStatus .FAILED , expected )
21662157 else :
21672158 assert result [0 ] is not None
21682159 assert result [1 ] != MempoolInclusionStatus .FAILED
@@ -2453,7 +2444,7 @@ async def test_new_peak_ff_eviction(
24532444
24542445 bundle_add_info = await mempool_manager .add_spend_bundle (
24552446 bundle ,
2456- make_test_conds (spend_ids = [(singleton_spend .coin , ELIGIBLE_FOR_FF ), (TEST_COIN , 0 )], cost = 1000000 ),
2447+ make_test_conds (spend_ids = [(singleton_spend .coin , ELIGIBLE_FOR_FF ), (TEST_COIN , 0 )], cost = uint64 ( 1000000 ) ),
24572448 bundle .name (),
24582449 first_added_height = uint32 (1 ),
24592450 )
@@ -2541,7 +2532,7 @@ async def test_multiple_ff(use_optimization: bool) -> None:
25412532 (singleton_spend2 .coin , ELIGIBLE_FOR_FF ),
25422533 (TEST_COIN , 0 ),
25432534 ],
2544- cost = 1000000 ,
2535+ cost = uint64 ( 1000000 ) ,
25452536 ),
25462537 bundle .name (),
25472538 first_added_height = uint32 (1 ),
0 commit comments