Update locks

(cherry picked from commit 2c0c973b09f83a97ac107c1b4c5dbdb99a95ca15)
This commit is contained in:
Mariano Sorgente 2020-03-28 01:10:01 +09:00
parent f96ae11094
commit 51ce66d7b2
No known key found for this signature in database
GPG Key ID: 0F866338C369278C
6 changed files with 15 additions and 23 deletions

View File

@ -114,10 +114,11 @@ class FullNodeStore:
await self.db.close()
async def _clear_database(self):
await self.db.execute("DELETE FROM blocks")
await self.db.execute("DELETE FROM potential_blocks")
await self.db.execute("DELETE FROM headers")
await self.db.commit()
async with self.lock:
await self.db.execute("DELETE FROM blocks")
await self.db.execute("DELETE FROM potential_blocks")
await self.db.execute("DELETE FROM headers")
await self.db.commit()
async def add_block(self, block: FullBlock) -> None:
assert block.proof_of_time is not None

View File

@ -1046,16 +1046,18 @@ class WalletStateManager:
self.tx_pending_changed()
async def close_all_stores(self):
await self.wallet_store.close()
await self.tx_store.close()
await self.puzzle_store.close()
await self.user_store.close()
async with self.lock:
await self.wallet_store.close()
await self.tx_store.close()
await self.puzzle_store.close()
await self.user_store.close()
async def clear_all_stores(self):
await self.wallet_store._clear_database()
await self.tx_store._clear_database()
await self.puzzle_store._clear_database()
await self.user_store._clear_database()
async with self.lock:
await self.wallet_store._clear_database()
await self.tx_store._clear_database()
await self.puzzle_store._clear_database()
await self.user_store._clear_database()
def unlink_db(self):
Path(self.db_path).unlink()

View File

@ -17,7 +17,6 @@ class WalletStore:
db_connection: aiosqlite.Connection
# Whether or not we are syncing
lock: asyncio.Lock
coin_record_cache: Dict[str, WalletCoinRecord]
cache_size: uint32
@ -74,8 +73,6 @@ class WalletStore:
)
await self.db_connection.commit()
# Lock
self.lock = asyncio.Lock() # external
self.coin_record_cache = dict()
return self

View File

@ -15,7 +15,6 @@ class WalletTransactionStore:
"""
db_connection: aiosqlite.Connection
lock: asyncio.Lock
cache_size: uint32
tx_record_cache: Dict[bytes32, TransactionRecord]
@ -77,8 +76,6 @@ class WalletTransactionStore:
)
await self.db_connection.commit()
# Lock
self.lock = asyncio.Lock() # external
self.tx_record_cache = dict()
return self

View File

@ -14,7 +14,6 @@ class WalletUserStore:
"""
db_connection: aiosqlite.Connection
lock: asyncio.Lock
cache_size: uint32
@classmethod
@ -46,8 +45,6 @@ class WalletUserStore:
)
await self.db_connection.commit()
# Lock
self.lock = asyncio.Lock() # external
await self.init_wallet()
return self

View File

@ -336,9 +336,7 @@ class WebSocketServer:
"state": state,
}
if self.websocket is not None:
# try:
await self.websocket.send(format_response("state_changed", data))
# except Conne
def state_changed_callback(self, state: str):
if self.websocket is None: