Skip to content

Commit

Permalink
Log better, recalculate tried_count. (Chia-Network#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchirica authored Mar 30, 2021
1 parent 9fecd22 commit 801e735
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/server/address_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ def select_peer_(self, new_only: bool) -> Optional[ExtendedPeerInfo]:
cached_tried_matrix_positions = list(self.used_tried_matrix_positions)
while True:
if len(self.used_tried_matrix_positions) < math.sqrt(TRIED_BUCKET_COUNT * BUCKET_SIZE):
if len(self.used_tried_matrix_positions) == 0:
log.error(f"Empty tried table, but tried_count shows {self.tried_count}.")
return None
# The table is sparse, randomly pick from positions list.
index = randrange(len(cached_tried_matrix_positions))
tried_bucket, tried_bucket_pos = cached_tried_matrix_positions[index]
Expand All @@ -473,6 +476,9 @@ def select_peer_(self, new_only: bool) -> Optional[ExtendedPeerInfo]:
cached_new_matrix_positions = list(self.used_new_matrix_positions)
while True:
if len(self.used_new_matrix_positions) < math.sqrt(NEW_BUCKET_COUNT * BUCKET_SIZE):
if len(self.used_new_matrix_positions) == 0:
log.error(f"Empty new table, but new_count shows {self.new_count}.")
return None
index = randrange(len(cached_new_matrix_positions))
new_bucket, new_bucket_pos = cached_new_matrix_positions[index]
else:
Expand Down
12 changes: 7 additions & 5 deletions src/server/address_manager_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ async def deserialize(self) -> AddressManager:

address_manager.key = int(metadata["key"])
address_manager.new_count = int(metadata["new_count"])
address_manager.tried_count = int(metadata["tried_count"])
# address_manager.tried_count = int(metadata["tried_count"])
address_manager.tried_count = 0

new_table_nodes = [(node_id, info) for node_id, info in nodes if node_id < address_manager.new_count]
for n, info in new_table_nodes:
Expand All @@ -170,7 +171,7 @@ async def deserialize(self) -> AddressManager:
address_manager.random_pos.append(n)
address_manager.id_count = len(new_table_nodes)
tried_table_nodes = [(node_id, info) for node_id, info in nodes if node_id >= address_manager.new_count]
lost_count = 0
# lost_count = 0
for node_id, info in tried_table_nodes:
tried_bucket = info.get_tried_bucket(address_manager.key)
tried_bucket_pos = info.get_bucket_position(address_manager.key, False, tried_bucket)
Expand All @@ -183,10 +184,11 @@ async def deserialize(self) -> AddressManager:
address_manager.map_addr[info.peer_info.host] = id_count
address_manager.tried_matrix[tried_bucket][tried_bucket_pos] = id_count
address_manager.id_count += 1
else:
lost_count += 1
address_manager.tried_count += 1
# else:
# lost_count += 1

address_manager.tried_count -= lost_count
# address_manager.tried_count -= lost_count
for node_id, bucket in new_table_entries:
if node_id >= 0 and node_id < address_manager.new_count:
info = address_manager.map_info[node_id]
Expand Down

0 comments on commit 801e735

Please sign in to comment.