mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-19 23:21:46 +03:00
tidy the DataLayer._update_confirmation_status()
usage pattern (#16094)
tidy the `DataLayer._update_confiration_status() usage pattern
This commit is contained in:
parent
ccd715119e
commit
39cf13288e
@ -182,9 +182,9 @@ class DataLayer:
|
||||
tree_id: bytes32,
|
||||
changelist: List[Dict[str, Any]],
|
||||
) -> bytes32:
|
||||
await self._update_confirmation_status(tree_id=tree_id)
|
||||
|
||||
async with self.data_store.transaction():
|
||||
# Make sure we update based on the latest confirmed root.
|
||||
await self._update_confirmation_status(tree_id=tree_id)
|
||||
pending_root: Optional[Root] = await self.data_store.get_pending_root(tree_id=tree_id)
|
||||
if pending_root is not None:
|
||||
raise Exception("Already have a pending root waiting for confirmation.")
|
||||
@ -211,8 +211,8 @@ class DataLayer:
|
||||
tree_id: bytes32,
|
||||
fee: uint64,
|
||||
) -> TransactionRecord:
|
||||
# Make sure we update based on the latest confirmed root.
|
||||
await self._update_confirmation_status(tree_id=tree_id)
|
||||
|
||||
pending_root: Optional[Root] = await self.data_store.get_pending_root(tree_id=tree_id)
|
||||
if pending_root is None:
|
||||
raise Exception("Latest root is already confirmed.")
|
||||
@ -232,14 +232,16 @@ class DataLayer:
|
||||
key: bytes,
|
||||
root_hash: Optional[bytes32] = None,
|
||||
) -> bytes32:
|
||||
await self._update_confirmation_status(tree_id=store_id)
|
||||
|
||||
async with self.data_store.transaction():
|
||||
await self._update_confirmation_status(tree_id=store_id)
|
||||
node = await self.data_store.get_node_by_key(tree_id=store_id, key=key, root_hash=root_hash)
|
||||
return node.hash
|
||||
|
||||
async def get_value(self, store_id: bytes32, key: bytes, root_hash: Optional[bytes32] = None) -> Optional[bytes]:
|
||||
await self._update_confirmation_status(tree_id=store_id)
|
||||
|
||||
async with self.data_store.transaction():
|
||||
await self._update_confirmation_status(tree_id=store_id)
|
||||
res = await self.data_store.get_node_by_key(tree_id=store_id, key=key, root_hash=root_hash)
|
||||
if res is None:
|
||||
self.log.error("Failed to fetch key")
|
||||
@ -248,6 +250,7 @@ class DataLayer:
|
||||
|
||||
async def get_keys_values(self, store_id: bytes32, root_hash: Optional[bytes32]) -> List[TerminalNode]:
|
||||
await self._update_confirmation_status(tree_id=store_id)
|
||||
|
||||
res = await self.data_store.get_keys_values(store_id, root_hash)
|
||||
if res is None:
|
||||
self.log.error("Failed to fetch keys values")
|
||||
@ -255,6 +258,7 @@ class DataLayer:
|
||||
|
||||
async def get_keys(self, store_id: bytes32, root_hash: Optional[bytes32]) -> List[bytes]:
|
||||
await self._update_confirmation_status(tree_id=store_id)
|
||||
|
||||
res = await self.data_store.get_keys(store_id, root_hash)
|
||||
return res
|
||||
|
||||
@ -642,11 +646,12 @@ class DataLayer:
|
||||
return changelist
|
||||
|
||||
async def process_offered_stores(self, offer_stores: Tuple[OfferStore, ...]) -> Dict[bytes32, StoreProofs]:
|
||||
for offer_store in offer_stores:
|
||||
await self._update_confirmation_status(tree_id=offer_store.store_id)
|
||||
|
||||
async with self.data_store.transaction():
|
||||
our_store_proofs: Dict[bytes32, StoreProofs] = {}
|
||||
for offer_store in offer_stores:
|
||||
await self._update_confirmation_status(tree_id=offer_store.store_id)
|
||||
|
||||
changelist = await self.build_offer_changelist(
|
||||
store_id=offer_store.store_id,
|
||||
inclusions=offer_store.inclusions,
|
||||
|
Loading…
Reference in New Issue
Block a user