Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions chia/_tests/core/mempool/test_mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,7 @@ def make_test_coins() -> list[Coin]:
],
)
def test_can_replace(existing_items: list[MempoolItem], new_item: MempoolItem, expected: bool) -> None:
removals = {c.name() for c in new_item.spend_bundle.removals()}
assert can_replace(existing_items, removals, new_item) == expected
assert can_replace(existing_items, new_item) == expected


@pytest.mark.anyio
Expand Down
13 changes: 4 additions & 9 deletions chia/full_node/mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ async def validate_spend_bundle(

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

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


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

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