Skip to content

Commit 242ef4f

Browse files
authored
CHIA-3031 Leverage execute_fetchall in CoinStore's rollback_to_block (#19682)
Leverage execute_fetchall in CoinStore's rollback_to_block.
1 parent f1885d6 commit 242ef4f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

chia/full_node/coin_store.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -529,32 +529,32 @@ async def rollback_to_block(self, block_index: int) -> list[CoinRecord]:
529529
coin_changes: dict[bytes32, CoinRecord] = {}
530530
# Add coins that are confirmed in the reverted blocks to the list of updated coins.
531531
async with self.db_wrapper.writer_maybe_transaction() as conn:
532-
async with conn.execute(
532+
rows = await conn.execute_fetchall(
533533
"SELECT confirmed_index, spent_index, coinbase, puzzle_hash, "
534534
"coin_parent, amount, timestamp, coin_name FROM coin_record WHERE confirmed_index>?",
535535
(block_index,),
536-
) as cursor:
537-
for row in await cursor.fetchall():
538-
coin = self.row_to_coin(row)
539-
record = CoinRecord(coin, uint32(0), row[1], row[2], uint64(0))
540-
coin_name = bytes32(row[7])
541-
coin_changes[coin_name] = record
536+
)
537+
for row in rows:
538+
coin = self.row_to_coin(row)
539+
record = CoinRecord(coin, uint32(0), row[1], row[2], uint64(0))
540+
coin_name = bytes32(row[7])
541+
coin_changes[coin_name] = record
542542

543543
# Delete reverted blocks from storage
544544
await conn.execute("DELETE FROM coin_record WHERE confirmed_index>?", (block_index,))
545545

546546
# Add coins that are confirmed in the reverted blocks to the list of changed coins.
547-
async with conn.execute(
547+
rows = await conn.execute_fetchall(
548548
"SELECT confirmed_index, spent_index, coinbase, puzzle_hash, "
549549
"coin_parent, amount, timestamp, coin_name FROM coin_record WHERE spent_index>?",
550550
(block_index,),
551-
) as cursor:
552-
for row in await cursor.fetchall():
553-
coin = self.row_to_coin(row)
554-
record = CoinRecord(coin, row[0], uint32(0), row[2], row[6])
555-
coin_name = bytes32(row[7])
556-
if coin_name not in coin_changes:
557-
coin_changes[coin_name] = record
551+
)
552+
for row in rows:
553+
coin = self.row_to_coin(row)
554+
record = CoinRecord(coin, row[0], uint32(0), row[2], row[6])
555+
coin_name = bytes32(row[7])
556+
if coin_name not in coin_changes:
557+
coin_changes[coin_name] = record
558558

559559
await conn.execute("UPDATE coin_record SET spent_index=0 WHERE spent_index>?", (block_index,))
560560
return list(coin_changes.values())

0 commit comments

Comments
 (0)