Skip to content

Commit

Permalink
safer place to check block
Browse files Browse the repository at this point in the history
  • Loading branch information
wjblanke committed Dec 9, 2024
1 parent ba84cec commit 7c9a888
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions chia/full_node/full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,17 +787,17 @@ async def short_sync_backtrack(
)

for block in reversed(blocks):
if self.blockchain.contains_block(block.header_hash):
self.log.info(f"short_sync_backtrack already has {block.header_hash.hex()}")
else:
# Wrap add_block with writer to ensure all writes and reads are on same connection.
# add_block should only be called under priority_mutex so this will not stall other
# writes to the DB.
self.log.info(f"PM LOCK ATTEMPT WJB task {asyncio.current_task().get_name()} short_sync_backtrack")
async with self.blockchain.priority_mutex.acquire(priority=BlockchainMutexPriority.high):
self.log.info(
f"PM LOCK ACQUIRE WJB task {asyncio.current_task().get_name()} short_sync_backtrack"
)
# Wrap add_block with writer to ensure all writes and reads are on same connection.
# add_block should only be called under priority_mutex so this will not stall other
# writes to the DB.
self.log.info(f"PM LOCK ATTEMPT WJB task {asyncio.current_task().get_name()} short_sync_backtrack")
async with self.blockchain.priority_mutex.acquire(priority=BlockchainMutexPriority.high):
self.log.info(
f"PM LOCK ACQUIRE WJB task {asyncio.current_task().get_name()} short_sync_backtrack"
)
if self.blockchain.contains_block(block.header_hash):
self.log.info(f"short_sync_backtrack main has {block.header_hash.hex()}")
else:
async with self.block_store.db_wrapper.writer() as conn:
self.log.info(
f"BEGIN WJB task {asyncio.current_task().get_name()} short_sync_backtrack add_block writer {conn}"
Expand All @@ -808,7 +808,7 @@ async def short_sync_backtrack(
self.log.info(
f"END WJB task {asyncio.current_task().get_name()} short_sync_backtrack add_block writer {conn}"
)
self.log.info(f"PM LOCK END WJB task {asyncio.current_task().get_name()} short_sync_backtrack")
self.log.info(f"PM LOCK END WJB task {asyncio.current_task().get_name()} short_sync_backtrack")

except (asyncio.CancelledError, Exception):
self.sync_store.decrement_backtrack_syncing(node_id=peer.peer_node_id)
Expand Down

0 comments on commit 7c9a888

Please sign in to comment.