Skip to content

Commit

Permalink
fix typo in PendingTxCache (#16417)
Browse files Browse the repository at this point in the history
fix typo in PendingTxCache when evicting the last MempoolItem of an assert-height level. add test coverage
  • Loading branch information
arvidn authored Sep 25, 2023
1 parent d293468 commit fb2a939
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chia/full_node/pending_tx_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def add(self, item: MempoolItem) -> None:
self._cache_cost -= removed_item.cost
to_evict[1].pop(first_in)
if to_evict[1] == {}:
self._by_height.pop()
self._by_height.popitem()

def drain(self, up_to_height: uint32) -> Dict[bytes32, MempoolItem]:
ret: Dict[bytes32, MempoolItem] = {}
Expand Down
14 changes: 14 additions & 0 deletions tests/core/mempool/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ def test_fifo_limit(self):
tx = c.drain(101)
assert tx == {items[-2].spend_bundle_name: items[-2], items[-1].spend_bundle_name: items[-1]}

def test_add_eviction(self):
c = PendingTxCache(160)
item = make_item(1, assert_height=100)
c.add(item)

for i in range(3):
item = make_item(i + 1, assert_height=50)
c.add(item)

txs = c.drain(161)
assert len(txs) == 2
for name, tx in txs.items():
assert tx.assert_height == 50

def test_item_limit(self):
c = PendingTxCache(1000000, 2)
# each item has cost 80
Expand Down

0 comments on commit fb2a939

Please sign in to comment.