diff --git a/src/full_node.py b/src/full_node.py index 8bcb72ce..cb168c1b 100644 --- a/src/full_node.py +++ b/src/full_node.py @@ -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 diff --git a/src/store.py b/src/store.py index 3489bbcf..1eb345bc 100644 --- a/src/store.py +++ b/src/store.py @@ -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( diff --git a/tests/setup_nodes.py b/tests/setup_nodes.py index bfa5a35d..e95cf625 100644 --- a/tests/setup_nodes.py +++ b/tests/setup_nodes.py @@ -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") diff --git a/tests/test_store.py b/tests/test_store.py index 746ccae1..ec445e44 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -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)