@@ -93,9 +93,9 @@ class Blockchain:
93
93
# peak of the blockchain
94
94
_peak_height : Optional [uint32 ]
95
95
# All blocks in peak path are guaranteed to be included, can include orphan blocks
96
- __block_records : dict [bytes32 , BlockRecord ]
96
+ _block_records : dict [bytes32 , BlockRecord ]
97
97
# all hashes of blocks in block_record by height, used for garbage collection
98
- __heights_in_cache : dict [uint32 , set [bytes32 ]]
98
+ _heights_in_cache : dict [uint32 , set [bytes32 ]]
99
99
# maps block height (of the current heaviest chain) to block hash and sub
100
100
# epoch summaries
101
101
consensus_store : ConsensusStoreProtocol
@@ -159,17 +159,15 @@ def _initialize_caches(self) -> None:
159
159
"""
160
160
Initialize the blockchain cache data structures.
161
161
"""
162
- self .__block_records = {}
163
- self .__heights_in_cache = {}
162
+ self ._block_records = {}
163
+ self ._heights_in_cache = {}
164
164
165
165
async def _load_recent_blocks_from_store (self ) -> tuple [dict [bytes32 , BlockRecord ], Optional [bytes32 ]]:
166
166
"""
167
167
Load recent blocks from the consensus store.
168
168
Returns block records and peak hash.
169
169
"""
170
- return await self .consensus_store .get_block_records_close_to_peak (
171
- self .constants .BLOCKS_CACHE_SIZE
172
- )
170
+ return await self .consensus_store .get_block_records_close_to_peak (self .constants .BLOCKS_CACHE_SIZE )
173
171
174
172
def _populate_cache_with_blocks (self , block_records : dict [bytes32 , BlockRecord ]) -> None :
175
173
"""
@@ -814,7 +812,7 @@ def contains_block(self, header_hash: bytes32, height: uint32) -> bool:
814
812
return True
815
813
816
814
def block_record (self , header_hash : bytes32 ) -> BlockRecord :
817
- return self .__block_records [header_hash ]
815
+ return self ._block_records [header_hash ]
818
816
819
817
def height_to_block_record (self , height : uint32 ) -> BlockRecord :
820
818
# Precondition: height is in the blockchain
@@ -867,16 +865,16 @@ def clean_block_record(self, height: int) -> None:
867
865
height = self ._peak_height - self .constants .BLOCKS_CACHE_SIZE
868
866
if height < 0 :
869
867
return None
870
- blocks_to_remove = self .__heights_in_cache .get (uint32 (height ), None )
868
+ blocks_to_remove = self ._heights_in_cache .get (uint32 (height ), None )
871
869
while blocks_to_remove is not None and height >= 0 :
872
870
for header_hash in blocks_to_remove :
873
- del self .__block_records [header_hash ] # remove from blocks
874
- del self .__heights_in_cache [uint32 (height )] # remove height from heights in cache
871
+ del self ._block_records [header_hash ] # remove from blocks
872
+ del self ._heights_in_cache [uint32 (height )] # remove height from heights in cache
875
873
876
874
if height == 0 :
877
875
break
878
876
height -= 1
879
- blocks_to_remove = self .__heights_in_cache .get (uint32 (height ), None )
877
+ blocks_to_remove = self ._heights_in_cache .get (uint32 (height ), None )
880
878
881
879
def clean_block_records (self ) -> None :
882
880
"""
@@ -885,7 +883,7 @@ def clean_block_records(self) -> None:
885
883
These blocks are necessary for calculating future difficulty adjustments.
886
884
"""
887
885
888
- if len (self .__block_records ) < self .constants .BLOCKS_CACHE_SIZE :
886
+ if len (self ._block_records ) < self .constants .BLOCKS_CACHE_SIZE :
889
887
return None
890
888
891
889
assert self ._peak_height is not None
@@ -964,12 +962,12 @@ async def get_block_records_at(self, heights: list[uint32]) -> list[BlockRecord]
964
962
return await self .consensus_store .get_block_records_by_hash (hashes )
965
963
966
964
def try_block_record (self , header_hash : bytes32 ) -> Optional [BlockRecord ]:
967
- if header_hash in self .__block_records :
965
+ if header_hash in self ._block_records :
968
966
return self .block_record (header_hash )
969
967
return None
970
968
971
969
async def get_block_record_from_db (self , header_hash : bytes32 ) -> Optional [BlockRecord ]:
972
- ret = self .__block_records .get (header_hash )
970
+ ret = self ._block_records .get (header_hash )
973
971
if ret is not None :
974
972
return ret
975
973
return await self .consensus_store .get_block_record (header_hash )
@@ -981,34 +979,34 @@ async def prev_block_hash(self, header_hashes: list[bytes32]) -> list[bytes32]:
981
979
"""
982
980
ret = []
983
981
for h in header_hashes :
984
- b = self .__block_records .get (h )
982
+ b = self ._block_records .get (h )
985
983
if b is not None :
986
984
ret .append (b .prev_hash )
987
985
else :
988
986
ret .append (await self .consensus_store .get_prev_hash (h ))
989
987
return ret
990
988
991
989
async def contains_block_from_db (self , header_hash : bytes32 ) -> bool :
992
- ret = header_hash in self .__block_records
990
+ ret = header_hash in self ._block_records
993
991
if ret :
994
992
return True
995
993
996
994
return (await self .consensus_store .get_block_record (header_hash )) is not None
997
995
998
996
def remove_block_record (self , header_hash : bytes32 ) -> None :
999
997
sbr = self .block_record (header_hash )
1000
- del self .__block_records [header_hash ]
1001
- self .__heights_in_cache [sbr .height ].remove (header_hash )
998
+ del self ._block_records [header_hash ]
999
+ self ._heights_in_cache [sbr .height ].remove (header_hash )
1002
1000
1003
1001
def add_block_record (self , block_record : BlockRecord ) -> None :
1004
1002
"""
1005
1003
Adds a block record to the cache.
1006
1004
"""
1007
1005
1008
- self .__block_records [block_record .header_hash ] = block_record
1009
- if block_record .height not in self .__heights_in_cache .keys ():
1010
- self .__heights_in_cache [block_record .height ] = set ()
1011
- self .__heights_in_cache [block_record .height ].add (block_record .header_hash )
1006
+ self ._block_records [block_record .header_hash ] = block_record
1007
+ if block_record .height not in self ._heights_in_cache .keys ():
1008
+ self ._heights_in_cache [block_record .height ] = set ()
1009
+ self ._heights_in_cache [block_record .height ].add (block_record .header_hash )
1012
1010
1013
1011
async def persist_sub_epoch_challenge_segments (
1014
1012
self , ses_block_hash : bytes32 , segments : list [SubEpochChallengeSegment ]
0 commit comments