Make sure to commit after adding blocks
This commit is contained in:
parent
ea74bd1124
commit
aa0aa6d8c9
|
@ -680,12 +680,17 @@ class FullNode:
|
|||
We have received the blocks that we needed for syncing. Add them to processing queue.
|
||||
"""
|
||||
log.info(f"Received sync blocks {[b.height for b in request.blocks]}")
|
||||
|
||||
if not self.store.get_sync_mode():
|
||||
log.warning("Receiving sync blocks when we are not in sync mode.")
|
||||
return
|
||||
|
||||
for block in request.blocks:
|
||||
await self.store.add_potential_block(block)
|
||||
if (
|
||||
not self.store.get_sync_mode()
|
||||
): # We might have left sync mode after the previous await
|
||||
return
|
||||
(self.store.get_potential_blocks_received(block.height)).set()
|
||||
|
||||
for _ in []: # Yields nothing
|
||||
|
|
|
@ -130,6 +130,7 @@ class FullNodeStore:
|
|||
),
|
||||
)
|
||||
await cursor_2.close()
|
||||
await self.db.commit()
|
||||
|
||||
async def get_block(self, header_hash: bytes32) -> Optional[FullBlock]:
|
||||
cursor = await self.db.execute(
|
||||
|
@ -180,6 +181,7 @@ class FullNodeStore:
|
|||
(block.height, bytes(block)),
|
||||
)
|
||||
await cursor.close()
|
||||
await self.db.commit()
|
||||
|
||||
async def get_potential_block(self, height: uint32) -> Optional[FullBlock]:
|
||||
cursor = await self.db.execute(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
from typing import Any, Dict
|
||||
|
||||
from src.blockchain import Blockchain
|
||||
|
@ -61,3 +62,5 @@ async def setup_two_nodes():
|
|||
await server_2.await_closed()
|
||||
await store_1.close()
|
||||
await store_2.close()
|
||||
os.remove("blockchain_test")
|
||||
os.remove("blockchain_test_2")
|
||||
|
|
|
@ -146,6 +146,9 @@ class TestStore:
|
|||
except Exception:
|
||||
await db.close()
|
||||
await db_2.close()
|
||||
os.remove(db_filename)
|
||||
os.remove(db_filename_2)
|
||||
os.remove(db_filename_3)
|
||||
raise
|
||||
|
||||
# Different database should have different data
|
||||
|
@ -155,6 +158,9 @@ class TestStore:
|
|||
await db.close()
|
||||
await db_2.close()
|
||||
await db_3.close()
|
||||
os.remove(db_filename)
|
||||
os.remove(db_filename_2)
|
||||
os.remove(db_filename_3)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_deadlock(self):
|
||||
|
@ -187,3 +193,4 @@ class TestStore:
|
|||
)
|
||||
await asyncio.gather(*tasks)
|
||||
await db.close()
|
||||
os.remove(db_filename)
|
||||
|
|
Loading…
Reference in New Issue