Skip to content

Commit 6a773ba

Browse files
authored
Addendum to use per-puzzle cost to estimate DEDUP savings (#19816)
Addendum to use per-puzzle cost to estimate DEDUP savings.
1 parent cbaed7a commit 6a773ba

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

chia/_tests/core/mempool/test_mempool.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,8 @@ def make_coin(idx: int) -> Coin:
31283128
return Coin(IDENTITY_PUZZLE_HASH, IDENTITY_PUZZLE_HASH, uint64(2_000_000_000 + idx * 2))
31293129

31303130

3131-
def test_dedup_by_fee() -> None:
3131+
@pytest.mark.parametrize("old", [True, False])
3132+
def test_dedup_by_fee(old: bool) -> None:
31323133
"""
31333134
We pick the solution to use for dedup based on the spendbundle with the highest
31343135
fee per cost, not based on which one would give the overall best fee per cost
@@ -3155,12 +3156,12 @@ def add_spend_bundles(spend_bundles: list[SpendBundle]) -> None:
31553156
sb_low_rate = make_test_spendbundle(COIN_A2, fee=10)
31563157
add_spend_bundles([sb_A, sb_low_rate])
31573158

3159+
create_block = mempool.create_block_generator if old else mempool.create_block_generator2
31583160
# validate that dedup happens at all for sb_A
3159-
result = mempool.create_bundle_from_mempool_items(test_constants, uint32(0))
3161+
result = create_block(test_constants, uint32(0), 5.0)
31603162
assert result is not None
3161-
agg, _ = result
31623163
# Make sure both items would be processed
3163-
assert [c.coin for c in agg.coin_spends] == [DEDUP_COIN, COIN_A1, COIN_A2]
3164+
assert result.removals == [DEDUP_COIN, COIN_A1, COIN_A2]
31643165

31653166
# Now we add a bunch of alternative spends for coin 0, with lower fees
31663167
# Even though the total fee would be higher if we deduped on this solution,
@@ -3170,26 +3171,24 @@ def add_spend_bundles(spend_bundles: list[SpendBundle]) -> None:
31703171
sb_high_rate = make_test_spendbundle(make_coin(i), fee=10)
31713172
add_spend_bundles([sb_B, sb_high_rate])
31723173

3173-
result = mempool.create_bundle_from_mempool_items(test_constants, uint32(0))
3174+
result = create_block(test_constants, uint32(0), 5.0)
31743175
assert result is not None
3175-
agg, _ = result
31763176
# We ran with solution A and missed bigger savings on solution B
31773177
# we've added 599 spend bundles now. 2 with solution A and 598 with solution B
31783178
assert mempool.size() == 599
3179-
assert [c.coin for c in agg.coin_spends] == [DEDUP_COIN, COIN_A1, COIN_A2]
3179+
assert result.removals == [DEDUP_COIN, COIN_A1, COIN_A2]
31803180

31813181
# Now, if we add a high fee per-cost-for sb_B, it should be picked
31823182
sb_high_rate = make_test_spendbundle(make_coin(600), fee=1_000_000_000)
31833183
add_spend_bundles([sb_B, sb_high_rate])
31843184

3185-
result = mempool.create_bundle_from_mempool_items(test_constants, uint32(0))
3185+
result = create_block(test_constants, uint32(0), 5.0)
31863186
assert result is not None
3187-
agg, _ = result
31883187
# The 3 items got skipped here
31893188
# We ran with solution B
31903189
# we've added 600 spend bundles now. 2 with solution A and 599 with solution B
31913190
assert mempool.size() == 600
3192-
spends_in_block = {c.coin for c in agg.coin_spends}
3191+
spends_in_block = set(result.removals)
31933192
assert DEDUP_COIN in spends_in_block
31943193
assert COIN_A1 not in spends_in_block
31953194
assert COIN_A2 not in spends_in_block

0 commit comments

Comments
 (0)