27
27
from chia .consensus .block_body_validation import ForkInfo , validate_block_body
28
28
from chia .consensus .block_header_validation import validate_unfinished_header_block
29
29
from chia .consensus .block_height_map import BlockHeightMap
30
+ from chia .consensus .block_store_protocol import BlockStoreProtocol
30
31
from chia .consensus .coin_store_protocol import CoinStoreProtocol
31
32
from chia .consensus .cost_calculator import NPCResult
32
33
from chia .consensus .difficulty_adjustment import get_next_sub_slot_iters_and_difficulty
35
36
from chia .consensus .generator_tools import get_block_header
36
37
from chia .consensus .get_block_generator import get_block_generator
37
38
from chia .consensus .multiprocess_validation import PreValidationResult
38
- from chia .full_node .block_store import BlockStore
39
39
from chia .types .blockchain_format .coin import Coin
40
40
from chia .types .blockchain_format .vdf import VDFInfo
41
41
from chia .types .coin_record import CoinRecord
@@ -104,7 +104,7 @@ class Blockchain:
104
104
# Unspent Store
105
105
coin_store : CoinStoreProtocol
106
106
# Store
107
- block_store : BlockStore
107
+ block_store : BlockStoreProtocol
108
108
# Used to verify blocks in parallel
109
109
pool : Executor
110
110
# Set holding seen compact proofs, in order to avoid duplicates.
@@ -122,7 +122,7 @@ class Blockchain:
122
122
@staticmethod
123
123
async def create (
124
124
coin_store : CoinStoreProtocol ,
125
- block_store : BlockStore ,
125
+ block_store : BlockStoreProtocol ,
126
126
height_map : BlockHeightMap ,
127
127
consensus_constants : ConsensusConstants ,
128
128
reserved_cores : int ,
@@ -421,7 +421,7 @@ async def add_block(
421
421
422
422
try :
423
423
# Always add the block to the database
424
- async with self .block_store .db_wrapper . writer ():
424
+ async with self .block_store .transaction ():
425
425
# Perform the DB operations to update the state, and rollback if something goes wrong
426
426
await self .block_store .add_full_block (header_hash , block , block_record )
427
427
records , state_change_summary = await self ._reconsider_peak (block_record , genesis , fork_info )
@@ -883,7 +883,7 @@ async def get_header_blocks_in_range(
883
883
884
884
blocks : list [FullBlock ] = []
885
885
for hash in hashes .copy ():
886
- block = self .block_store .block_cache . get (hash )
886
+ block = self .block_store .get_block_from_cache (hash )
887
887
if block is not None :
888
888
blocks .append (block )
889
889
hashes .remove (hash )
@@ -926,27 +926,18 @@ async def get_header_block_by_height(
926
926
return None
927
927
return header_dict [header_hash ]
928
928
929
- async def get_block_records_at (self , heights : list [uint32 ], batch_size : int = 900 ) -> list [BlockRecord ]:
929
+ async def get_block_records_at (self , heights : list [uint32 ]) -> list [BlockRecord ]:
930
930
"""
931
931
gets block records by height (only blocks that are part of the chain)
932
932
"""
933
- records : list [BlockRecord ] = []
934
933
hashes : list [bytes32 ] = []
935
- assert batch_size < self .block_store .db_wrapper .host_parameter_limit
936
934
for height in heights :
937
935
header_hash : Optional [bytes32 ] = self .height_to_hash (height )
938
936
if header_hash is None :
939
937
raise ValueError (f"Do not have block at height { height } " )
940
938
hashes .append (header_hash )
941
- if len (hashes ) > batch_size :
942
- res = await self .block_store .get_block_records_by_hash (hashes )
943
- records .extend (res )
944
- hashes = []
945
-
946
- if len (hashes ) > 0 :
947
- res = await self .block_store .get_block_records_by_hash (hashes )
948
- records .extend (res )
949
- return records
939
+
940
+ return await self .block_store .get_block_records_by_hash (hashes )
950
941
951
942
def try_block_record (self , header_hash : bytes32 ) -> Optional [BlockRecord ]:
952
943
if header_hash in self .__block_records :
0 commit comments