@@ -155,57 +155,27 @@ def shut_down(self) -> None:
155
155
self ._shut_down = True
156
156
self .pool .shutdown (wait = True )
157
157
158
- def _initialize_caches (self ) -> None :
158
+ async def _load_chain_from_store (self ) -> None :
159
159
"""
160
- Initialize the blockchain cache data structures .
160
+ Initializes the state of the Blockchain class from the database .
161
161
"""
162
162
self ._block_records = {}
163
163
self ._heights_in_cache = {}
164
-
165
- async def _load_recent_blocks_from_store (self ) -> tuple [dict [bytes32 , BlockRecord ], Optional [bytes32 ]]:
166
- """
167
- Load recent blocks from the consensus store.
168
- Returns block records and peak hash.
169
- """
170
- return await self .consensus_store .get_block_records_close_to_peak (self .constants .BLOCKS_CACHE_SIZE )
171
-
172
- def _populate_cache_with_blocks (self , block_records : dict [bytes32 , BlockRecord ]) -> None :
173
- """
174
- Add the loaded block records to the cache.
175
- """
164
+ block_records , peak = await self .consensus_store .get_block_records_close_to_peak (
165
+ self .constants .BLOCKS_CACHE_SIZE
166
+ )
176
167
for block in block_records .values ():
177
168
self .add_block_record (block )
178
169
179
- def _set_peak_height_from_blocks (self , block_records : dict [bytes32 , BlockRecord ], peak : Optional [bytes32 ]) -> None :
180
- """
181
- Set the peak height based on loaded blocks.
182
- Handles the case where no blocks are loaded (empty blockchain).
183
- """
184
170
if len (block_records ) == 0 :
185
171
assert peak is None
186
172
self ._peak_height = None
187
173
return
188
174
189
175
assert peak is not None
190
176
self ._peak_height = self .block_record (peak ).height
191
-
192
- def _validate_blockchain_state (self ) -> None :
193
- """
194
- Validate the loaded blockchain state for consistency.
195
- """
196
- if self ._peak_height is not None :
197
- assert self .consensus_store .contains_height (self ._peak_height )
198
- assert not self .consensus_store .contains_height (uint32 (self ._peak_height + 1 ))
199
-
200
- async def _load_chain_from_store (self ) -> None :
201
- """
202
- Initializes the state of the Blockchain class from the database.
203
- """
204
- self ._initialize_caches ()
205
- block_records , peak = await self ._load_recent_blocks_from_store ()
206
- self ._populate_cache_with_blocks (block_records )
207
- self ._set_peak_height_from_blocks (block_records , peak )
208
- self ._validate_blockchain_state ()
177
+ assert self .consensus_store .contains_height (self ._peak_height )
178
+ assert not self .consensus_store .contains_height (uint32 (self ._peak_height + 1 ))
209
179
210
180
def get_peak (self ) -> Optional [BlockRecord ]:
211
181
"""
0 commit comments