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.
|
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]}")
|
log.info(f"Received sync blocks {[b.height for b in request.blocks]}")
|
||||||
|
|
||||||
if not self.store.get_sync_mode():
|
if not self.store.get_sync_mode():
|
||||||
log.warning("Receiving sync blocks when we are not in sync mode.")
|
log.warning("Receiving sync blocks when we are not in sync mode.")
|
||||||
return
|
return
|
||||||
|
|
||||||
for block in request.blocks:
|
for block in request.blocks:
|
||||||
await self.store.add_potential_block(block)
|
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()
|
(self.store.get_potential_blocks_received(block.height)).set()
|
||||||
|
|
||||||
for _ in []: # Yields nothing
|
for _ in []: # Yields nothing
|
||||||
|
|
|
@ -130,6 +130,7 @@ class FullNodeStore:
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
await cursor_2.close()
|
await cursor_2.close()
|
||||||
|
await self.db.commit()
|
||||||
|
|
||||||
async def get_block(self, header_hash: bytes32) -> Optional[FullBlock]:
|
async def get_block(self, header_hash: bytes32) -> Optional[FullBlock]:
|
||||||
cursor = await self.db.execute(
|
cursor = await self.db.execute(
|
||||||
|
@ -180,6 +181,7 @@ class FullNodeStore:
|
||||||
(block.height, bytes(block)),
|
(block.height, bytes(block)),
|
||||||
)
|
)
|
||||||
await cursor.close()
|
await cursor.close()
|
||||||
|
await self.db.commit()
|
||||||
|
|
||||||
async def get_potential_block(self, height: uint32) -> Optional[FullBlock]:
|
async def get_potential_block(self, height: uint32) -> Optional[FullBlock]:
|
||||||
cursor = await self.db.execute(
|
cursor = await self.db.execute(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
from src.blockchain import Blockchain
|
from src.blockchain import Blockchain
|
||||||
|
@ -61,3 +62,5 @@ async def setup_two_nodes():
|
||||||
await server_2.await_closed()
|
await server_2.await_closed()
|
||||||
await store_1.close()
|
await store_1.close()
|
||||||
await store_2.close()
|
await store_2.close()
|
||||||
|
os.remove("blockchain_test")
|
||||||
|
os.remove("blockchain_test_2")
|
||||||
|
|
|
@ -146,6 +146,9 @@ class TestStore:
|
||||||
except Exception:
|
except Exception:
|
||||||
await db.close()
|
await db.close()
|
||||||
await db_2.close()
|
await db_2.close()
|
||||||
|
os.remove(db_filename)
|
||||||
|
os.remove(db_filename_2)
|
||||||
|
os.remove(db_filename_3)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# Different database should have different data
|
# Different database should have different data
|
||||||
|
@ -155,6 +158,9 @@ class TestStore:
|
||||||
await db.close()
|
await db.close()
|
||||||
await db_2.close()
|
await db_2.close()
|
||||||
await db_3.close()
|
await db_3.close()
|
||||||
|
os.remove(db_filename)
|
||||||
|
os.remove(db_filename_2)
|
||||||
|
os.remove(db_filename_3)
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_deadlock(self):
|
async def test_deadlock(self):
|
||||||
|
@ -187,3 +193,4 @@ class TestStore:
|
||||||
)
|
)
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
await db.close()
|
await db.close()
|
||||||
|
os.remove(db_filename)
|
||||||
|
|
Loading…
Reference in New Issue