Skip to content

Commit 3e199c1

Browse files
authored
CHIA-2963 Avoid recomputing coin record names in rollback_to_block when we have access to them (#19649)
Avoid recomputing coin record names in rollback_to_block when we have access to them.
1 parent 39fd1b6 commit 3e199c1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

chia/full_node/coin_store.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,28 +531,30 @@ async def rollback_to_block(self, block_index: int) -> list[CoinRecord]:
531531
async with self.db_wrapper.writer_maybe_transaction() as conn:
532532
async with conn.execute(
533533
"SELECT confirmed_index, spent_index, coinbase, puzzle_hash, "
534-
"coin_parent, amount, timestamp FROM coin_record WHERE confirmed_index>?",
534+
"coin_parent, amount, timestamp, coin_name FROM coin_record WHERE confirmed_index>?",
535535
(block_index,),
536536
) as cursor:
537537
for row in await cursor.fetchall():
538538
coin = self.row_to_coin(row)
539539
record = CoinRecord(coin, uint32(0), row[1], row[2], uint64(0))
540-
coin_changes[record.name] = record
540+
coin_name = bytes32(row[7])
541+
coin_changes[coin_name] = record
541542

542543
# Delete reverted blocks from storage
543544
await conn.execute("DELETE FROM coin_record WHERE confirmed_index>?", (block_index,))
544545

545546
# Add coins that are confirmed in the reverted blocks to the list of changed coins.
546547
async with conn.execute(
547548
"SELECT confirmed_index, spent_index, coinbase, puzzle_hash, "
548-
"coin_parent, amount, timestamp FROM coin_record WHERE spent_index>?",
549+
"coin_parent, amount, timestamp, coin_name FROM coin_record WHERE spent_index>?",
549550
(block_index,),
550551
) as cursor:
551552
for row in await cursor.fetchall():
552553
coin = self.row_to_coin(row)
553554
record = CoinRecord(coin, row[0], uint32(0), row[2], row[6])
554-
if record.name not in coin_changes:
555-
coin_changes[record.name] = record
555+
coin_name = bytes32(row[7])
556+
if coin_name not in coin_changes:
557+
coin_changes[coin_name] = record
556558

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

0 commit comments

Comments
 (0)