Skip to content

Commit eafd0c4

Browse files
committed
Don't use double underscore.
1 parent 9f4f99b commit eafd0c4

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

chia/consensus/blockchain.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ class Blockchain:
9393
# peak of the blockchain
9494
_peak_height: Optional[uint32]
9595
# 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]
9797
# 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]]
9999
# maps block height (of the current heaviest chain) to block hash and sub
100100
# epoch summaries
101101
consensus_store: ConsensusStoreProtocol
@@ -159,17 +159,15 @@ def _initialize_caches(self) -> None:
159159
"""
160160
Initialize the blockchain cache data structures.
161161
"""
162-
self.__block_records = {}
163-
self.__heights_in_cache = {}
162+
self._block_records = {}
163+
self._heights_in_cache = {}
164164

165165
async def _load_recent_blocks_from_store(self) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]:
166166
"""
167167
Load recent blocks from the consensus store.
168168
Returns block records and peak hash.
169169
"""
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)
173171

174172
def _populate_cache_with_blocks(self, block_records: dict[bytes32, BlockRecord]) -> None:
175173
"""
@@ -814,7 +812,7 @@ def contains_block(self, header_hash: bytes32, height: uint32) -> bool:
814812
return True
815813

816814
def block_record(self, header_hash: bytes32) -> BlockRecord:
817-
return self.__block_records[header_hash]
815+
return self._block_records[header_hash]
818816

819817
def height_to_block_record(self, height: uint32) -> BlockRecord:
820818
# Precondition: height is in the blockchain
@@ -867,16 +865,16 @@ def clean_block_record(self, height: int) -> None:
867865
height = self._peak_height - self.constants.BLOCKS_CACHE_SIZE
868866
if height < 0:
869867
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)
871869
while blocks_to_remove is not None and height >= 0:
872870
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
875873

876874
if height == 0:
877875
break
878876
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)
880878

881879
def clean_block_records(self) -> None:
882880
"""
@@ -885,7 +883,7 @@ def clean_block_records(self) -> None:
885883
These blocks are necessary for calculating future difficulty adjustments.
886884
"""
887885

888-
if len(self.__block_records) < self.constants.BLOCKS_CACHE_SIZE:
886+
if len(self._block_records) < self.constants.BLOCKS_CACHE_SIZE:
889887
return None
890888

891889
assert self._peak_height is not None
@@ -964,12 +962,12 @@ async def get_block_records_at(self, heights: list[uint32]) -> list[BlockRecord]
964962
return await self.consensus_store.get_block_records_by_hash(hashes)
965963

966964
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:
968966
return self.block_record(header_hash)
969967
return None
970968

971969
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)
973971
if ret is not None:
974972
return ret
975973
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]:
981979
"""
982980
ret = []
983981
for h in header_hashes:
984-
b = self.__block_records.get(h)
982+
b = self._block_records.get(h)
985983
if b is not None:
986984
ret.append(b.prev_hash)
987985
else:
988986
ret.append(await self.consensus_store.get_prev_hash(h))
989987
return ret
990988

991989
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
993991
if ret:
994992
return True
995993

996994
return (await self.consensus_store.get_block_record(header_hash)) is not None
997995

998996
def remove_block_record(self, header_hash: bytes32) -> None:
999997
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)
10021000

10031001
def add_block_record(self, block_record: BlockRecord) -> None:
10041002
"""
10051003
Adds a block record to the cache.
10061004
"""
10071005

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)
10121010

10131011
async def persist_sub_epoch_challenge_segments(
10141012
self, ses_block_hash: bytes32, segments: list[SubEpochChallengeSegment]

0 commit comments

Comments
 (0)