Skip to content

Commit eca97fa

Browse files
authored
CHIA-3746 Simplify can_replace (#20086)
Simplify can_replace.
1 parent 2d15a04 commit eca97fa

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

chia/_tests/core/mempool/test_mempool_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,7 @@ def make_test_coins() -> list[Coin]:
11221122
],
11231123
)
11241124
def test_can_replace(existing_items: list[MempoolItem], new_item: MempoolItem, expected: bool) -> None:
1125-
removals = {c.name() for c in new_item.spend_bundle.removals()}
1126-
assert can_replace(existing_items, removals, new_item) == expected
1125+
assert can_replace(existing_items, new_item) == expected
11271126

11281127

11291128
@pytest.mark.anyio

chia/full_node/mempool_manager.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ async def validate_spend_bundle(
760760

761761
if fail_reason is Err.MEMPOOL_CONFLICT:
762762
log.debug(f"Replace attempted. number of MempoolItems: {len(conflicts)}")
763-
if not can_replace(conflicts, removal_names, potential):
763+
if not can_replace(conflicts, potential):
764764
return Err.MEMPOOL_CONFLICT, potential, []
765765

766766
duration = time.monotonic() - start_time
@@ -1020,17 +1020,12 @@ def optional_max(a: Optional[T], b: Optional[T]) -> Optional[T]:
10201020
return max((v for v in [a, b] if v is not None), default=None)
10211021

10221022

1023-
def can_replace(
1024-
conflicting_items: list[MempoolItem],
1025-
removal_names: set[bytes32],
1026-
new_item: MempoolItem,
1027-
) -> bool:
1023+
def can_replace(conflicting_items: list[MempoolItem], new_item: MempoolItem) -> bool:
10281024
"""
10291025
This function implements the mempool replacement rules. Given a Mempool item
10301026
we're attempting to insert into the mempool (new_item) and the set of existing
10311027
mempool items that conflict with it, this function answers the question whether
1032-
the existing items can be replaced by the new one. The removals parameter are
1033-
the coin IDs the new mempool item is spending.
1028+
the existing items can be replaced by the new one.
10341029
"""
10351030

10361031
conflicting_fees = 0
@@ -1055,7 +1050,7 @@ def can_replace(
10551050
# fee than AB therefore kicking out A altogether. The better way to solve this would be to keep a cache
10561051
# of booted transactions like A, and retry them after they get removed from mempool due to a conflict.
10571052
for coin_id, bcs in item.bundle_coin_spends.items():
1058-
if coin_id not in removal_names:
1053+
if coin_id not in new_item.bundle_coin_spends:
10591054
log.debug("Rejecting conflicting tx as it does not spend conflicting coin %s", coin_id)
10601055
return False
10611056
if bcs.supports_fast_forward:

0 commit comments

Comments
 (0)