Skip to content

Commit 138f35c

Browse files
committed
Simplify can_replace.
1 parent 3652e60 commit 138f35c

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
@@ -1119,8 +1119,7 @@ def make_test_coins() -> list[Coin]:
11191119
],
11201120
)
11211121
def test_can_replace(existing_items: list[MempoolItem], new_item: MempoolItem, expected: bool) -> None:
1122-
removals = {c.name() for c in new_item.spend_bundle.removals()}
1123-
assert can_replace(existing_items, removals, new_item) == expected
1122+
assert can_replace(existing_items, new_item) == expected
11241123

11251124

11261125
@pytest.mark.anyio

chia/full_node/mempool_manager.py

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

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

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

10261026

1027-
def can_replace(
1028-
conflicting_items: list[MempoolItem],
1029-
removal_names: set[bytes32],
1030-
new_item: MempoolItem,
1031-
) -> bool:
1027+
def can_replace(conflicting_items: list[MempoolItem], new_item: MempoolItem) -> bool:
10321028
"""
10331029
This function implements the mempool replacement rules. Given a Mempool item
10341030
we're attempting to insert into the mempool (new_item) and the set of existing
10351031
mempool items that conflict with it, this function answers the question whether
1036-
the existing items can be replaced by the new one. The removals parameter are
1037-
the coin IDs the new mempool item is spending.
1032+
the existing items can be replaced by the new one.
10381033
"""
10391034

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

0 commit comments

Comments
 (0)