56
56
internal_hash ,
57
57
key_hash ,
58
58
leaf_hash ,
59
- row_to_node ,
60
59
unspecified ,
61
60
)
62
61
from chia .util .batches import to_batches
@@ -711,22 +710,6 @@ async def get_terminal_nodes_by_hashes(
711
710
712
711
return terminal_nodes
713
712
714
- async def get_first_generation (self , node_hash : bytes32 , store_id : bytes32 ) -> Optional [int ]:
715
- async with self .db_wrapper .reader () as reader :
716
- cursor = await reader .execute (
717
- "SELECT generation FROM nodes WHERE hash = ? AND store_id = ?" ,
718
- (
719
- node_hash ,
720
- store_id ,
721
- ),
722
- )
723
-
724
- row = await cursor .fetchone ()
725
- if row is None :
726
- return None
727
-
728
- return int (row [0 ])
729
-
730
713
async def get_existing_hashes (self , node_hashes : list [bytes32 ], store_id : bytes32 ) -> set [bytes32 ]:
731
714
result : set [bytes32 ] = set ()
732
715
batch_size = min (500 , SQLITE_MAX_VARIABLE_NUMBER - 10 )
@@ -976,25 +959,6 @@ async def get_roots_between(self, store_id: bytes32, generation_begin: int, gene
976
959
977
960
return roots
978
961
979
- async def get_last_tree_root_by_hash (
980
- self , store_id : bytes32 , hash : Optional [bytes32 ], max_generation : Optional [int ] = None
981
- ) -> Optional [Root ]:
982
- async with self .db_wrapper .reader () as reader :
983
- max_generation_str = "AND generation < :max_generation " if max_generation is not None else ""
984
- node_hash_str = "AND node_hash == :node_hash " if hash is not None else "AND node_hash is NULL "
985
- cursor = await reader .execute (
986
- "SELECT * FROM root WHERE tree_id == :tree_id "
987
- f"{ max_generation_str } "
988
- f"{ node_hash_str } "
989
- "ORDER BY generation DESC LIMIT 1" ,
990
- {"tree_id" : store_id , "node_hash" : hash , "max_generation" : max_generation },
991
- )
992
- row = await cursor .fetchone ()
993
-
994
- if row is None :
995
- return None
996
- return Root .from_row (row = row )
997
-
998
962
async def get_ancestors (
999
963
self ,
1000
964
node_hash : bytes32 ,
@@ -1026,35 +990,6 @@ async def get_ancestors(
1026
990
)
1027
991
return result
1028
992
1029
- async def get_internal_nodes (self , store_id : bytes32 , root_hash : Optional [bytes32 ] = None ) -> list [InternalNode ]:
1030
- async with self .db_wrapper .reader () as reader :
1031
- if root_hash is None :
1032
- root = await self .get_tree_root (store_id = store_id )
1033
- root_hash = root .node_hash
1034
- cursor = await reader .execute (
1035
- """
1036
- WITH RECURSIVE
1037
- tree_from_root_hash(hash, node_type, left, right, key, value) AS (
1038
- SELECT node.* FROM node WHERE node.hash == :root_hash
1039
- UNION ALL
1040
- SELECT node.* FROM node, tree_from_root_hash WHERE node.hash == tree_from_root_hash.left
1041
- OR node.hash == tree_from_root_hash.right
1042
- )
1043
- SELECT * FROM tree_from_root_hash
1044
- WHERE node_type == :node_type
1045
- """ ,
1046
- {"root_hash" : root_hash , "node_type" : NodeType .INTERNAL },
1047
- )
1048
-
1049
- internal_nodes : list [InternalNode ] = []
1050
- async for row in cursor :
1051
- node = row_to_node (row = row )
1052
- if not isinstance (node , InternalNode ):
1053
- raise Exception (f"Unexpected internal node found: { node .hash .hex ()} " )
1054
- internal_nodes .append (node )
1055
-
1056
- return internal_nodes
1057
-
1058
993
def get_terminal_node_from_table_blobs (
1059
994
self ,
1060
995
kid : KeyId ,
@@ -1234,19 +1169,6 @@ async def get_kv_diff_paginated(
1234
1169
kv_diff ,
1235
1170
)
1236
1171
1237
- async def get_node_type (self , node_hash : bytes32 ) -> NodeType :
1238
- async with self .db_wrapper .reader () as reader :
1239
- cursor = await reader .execute (
1240
- "SELECT node_type FROM node WHERE hash == :hash LIMIT 1" ,
1241
- {"hash" : node_hash },
1242
- )
1243
- raw_node_type = await cursor .fetchone ()
1244
-
1245
- if raw_node_type is None :
1246
- raise Exception (f"No node found for specified hash: { node_hash .hex ()} " )
1247
-
1248
- return NodeType (raw_node_type ["node_type" ])
1249
-
1250
1172
async def autoinsert (
1251
1173
self ,
1252
1174
key : bytes ,
@@ -1265,14 +1187,6 @@ async def autoinsert(
1265
1187
root = root ,
1266
1188
)
1267
1189
1268
- async def get_keys_values_dict (
1269
- self ,
1270
- store_id : bytes32 ,
1271
- root_hash : Union [bytes32 , Unspecified ] = unspecified ,
1272
- ) -> dict [bytes , bytes ]:
1273
- pairs = await self .get_keys_values (store_id = store_id , root_hash = root_hash )
1274
- return {node .key : node .value for node in pairs }
1275
-
1276
1190
async def get_keys (
1277
1191
self ,
1278
1192
store_id : bytes32 ,
@@ -1490,59 +1404,6 @@ async def insert_batch(
1490
1404
new_root = await self .insert_root_from_merkle_blob (merkle_blob , store_id , status , old_root )
1491
1405
return new_root .node_hash
1492
1406
1493
- async def _get_one_ancestor (
1494
- self ,
1495
- node_hash : bytes32 ,
1496
- store_id : bytes32 ,
1497
- generation : Optional [int ] = None ,
1498
- ) -> Optional [InternalNode ]:
1499
- async with self .db_wrapper .reader () as reader :
1500
- if generation is None :
1501
- generation = await self .get_tree_generation (store_id = store_id )
1502
- cursor = await reader .execute (
1503
- """
1504
- SELECT * from node INNER JOIN (
1505
- SELECT ancestors.ancestor AS hash, MAX(ancestors.generation) AS generation
1506
- FROM ancestors
1507
- WHERE ancestors.hash == :hash
1508
- AND ancestors.tree_id == :tree_id
1509
- AND ancestors.generation <= :generation
1510
- GROUP BY hash
1511
- ) asc on asc.hash == node.hash
1512
- """ ,
1513
- {"hash" : node_hash , "tree_id" : store_id , "generation" : generation },
1514
- )
1515
- row = await cursor .fetchone ()
1516
- if row is None :
1517
- return None
1518
- return InternalNode .from_row (row = row )
1519
-
1520
- async def _get_one_ancestor_multiple_hashes (
1521
- self ,
1522
- node_hashes : list [bytes32 ],
1523
- store_id : bytes32 ,
1524
- generation : Optional [int ] = None ,
1525
- ) -> list [InternalNode ]:
1526
- async with self .db_wrapper .reader () as reader :
1527
- node_hashes_place_holders = "," .join ("?" for _ in node_hashes )
1528
- if generation is None :
1529
- generation = await self .get_tree_generation (store_id = store_id )
1530
- cursor = await reader .execute (
1531
- f"""
1532
- SELECT * from node INNER JOIN (
1533
- SELECT ancestors.ancestor AS hash, MAX(ancestors.generation) AS generation
1534
- FROM ancestors
1535
- WHERE ancestors.hash IN ({ node_hashes_place_holders } )
1536
- AND ancestors.tree_id == ?
1537
- AND ancestors.generation <= ?
1538
- GROUP BY hash
1539
- ) asc on asc.hash == node.hash
1540
- """ ,
1541
- [* node_hashes , store_id , generation ],
1542
- )
1543
- rows = await cursor .fetchall ()
1544
- return [InternalNode .from_row (row = row ) for row in rows ]
1545
-
1546
1407
async def get_node_by_key (
1547
1408
self ,
1548
1409
key : bytes ,
@@ -1568,17 +1429,6 @@ async def get_node_by_key(
1568
1429
kid = KeyId (kvid )
1569
1430
return await self .get_terminal_node_from_kid (merkle_blob , kid , store_id )
1570
1431
1571
- async def get_node (self , node_hash : bytes32 ) -> Node :
1572
- async with self .db_wrapper .reader () as reader :
1573
- cursor = await reader .execute ("SELECT * FROM node WHERE hash == :hash LIMIT 1" , {"hash" : node_hash })
1574
- row = await cursor .fetchone ()
1575
-
1576
- if row is None :
1577
- raise Exception (f"Node not found for requested hash: { node_hash .hex ()} " )
1578
-
1579
- node = row_to_node (row = row )
1580
- return node
1581
-
1582
1432
async def get_tree_as_nodes (self , store_id : bytes32 ) -> Node :
1583
1433
async with self .db_wrapper .reader ():
1584
1434
root = await self .get_tree_root (store_id = store_id )
0 commit comments