mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-09-26 17:20:25 -04:00
CHIA-2776 Simplify DB checks in invariant_check_mempool (#19526)
Simplify DB checks in invariant_check_mempool.
This commit is contained in:
+14
-16
@@ -477,24 +477,22 @@ def create_logger(file: TextIO = sys.stdout) -> logging.Logger:
|
||||
|
||||
|
||||
def invariant_check_mempool(mempool: Mempool) -> None:
|
||||
with mempool._db_conn as conn:
|
||||
cursor = conn.execute("SELECT COALESCE(SUM(cost), 0), COALESCE(SUM(fee), 0) FROM tx")
|
||||
val = cursor.fetchone()
|
||||
assert (mempool._total_cost, mempool._total_fee) == val
|
||||
cursor = mempool._db_conn.execute("SELECT COALESCE(SUM(cost), 0), COALESCE(SUM(fee), 0) FROM tx")
|
||||
val = cursor.fetchone()
|
||||
assert (mempool._total_cost, mempool._total_fee) == val
|
||||
|
||||
with mempool._db_conn as conn:
|
||||
cursor = conn.execute("SELECT coin_id, tx FROM spends")
|
||||
for coin_id, item_id in cursor.fetchall():
|
||||
item = mempool._items.get(item_id)
|
||||
assert item is not None
|
||||
# item is expected to contain a spend of coin_id, but it might be a
|
||||
# fast-forward spend, in which case the dictionary won't help us,
|
||||
# but we'll have to do a linear search
|
||||
if coin_id in item.bundle_coin_spends:
|
||||
assert item.bundle_coin_spends[coin_id].coin_spend.coin.name() == coin_id
|
||||
continue
|
||||
cursor = mempool._db_conn.execute("SELECT coin_id, tx FROM spends")
|
||||
for coin_id, item_id in cursor.fetchall():
|
||||
item = mempool._items.get(item_id)
|
||||
assert item is not None
|
||||
# item is expected to contain a spend of coin_id, but it might be a
|
||||
# fast-forward spend, in which case the dictionary won't help us,
|
||||
# but we'll have to do a linear search
|
||||
if coin_id in item.bundle_coin_spends:
|
||||
assert item.bundle_coin_spends[coin_id].coin_spend.coin.name() == coin_id
|
||||
continue
|
||||
|
||||
assert any(i.latest_singleton_coin == coin_id for i in item.bundle_coin_spends.values())
|
||||
assert any(i.latest_singleton_coin == coin_id for i in item.bundle_coin_spends.values())
|
||||
|
||||
|
||||
async def wallet_height_at_least(wallet_node: WalletNode, h: uint32) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user