Skip to content

Commit

Permalink
Adjust ban times for DL dat files (#17021)
Browse files Browse the repository at this point in the history
  • Loading branch information
emlowe authored Dec 8, 2023
1 parent ca9a601 commit cfab3a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion chia/data_layer/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,8 @@ async def received_correct_file(self, tree_id: bytes32, server_info: ServerInfo)
await self.update_server_info(tree_id, new_server_info)

async def server_misses_file(self, tree_id: bytes32, server_info: ServerInfo, timestamp: int) -> None:
BAN_TIME_BY_MISSING_COUNT = [5 * 60] * 3 + [15 * 60] * 3 + [60 * 60] * 2 + [240 * 60]
# Max banned time is 1 hour.
BAN_TIME_BY_MISSING_COUNT = [5 * 60] * 3 + [15 * 60] * 3 + [30 * 60] * 2 + [60 * 60]
index = min(server_info.num_consecutive_failures, len(BAN_TIME_BY_MISSING_COUNT) - 1)
new_server_info = replace(
server_info,
Expand Down
6 changes: 5 additions & 1 deletion chia/data_layer/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ async def insert_from_delta_file(
except Exception:
target_filename = client_foldername.joinpath(filename)
os.remove(target_filename)
await data_store.received_incorrect_file(tree_id, server_info, timestamp)
# await data_store.received_incorrect_file(tree_id, server_info, timestamp)
# incorrect file bans for 7 days which in practical usage
# is too long given this file might be incorrect for various reasons
# therefore, use the misses file logic instead
await data_store.server_misses_file(tree_id, server_info, timestamp)
await data_store.rollback_to_generation(tree_id, existing_generation - 1)
raise

Expand Down
2 changes: 1 addition & 1 deletion tests/core/data_layer/test_data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ async def test_server_selection(data_store: DataStore, tree_id: bytes32) -> None
assert servers_info[0].url == "http://127.0.0.1/8000"
await data_store.received_correct_file(tree_id=tree_id, server_info=servers_info[0])

ban_times = [5 * 60] * 3 + [15 * 60] * 3 + [60 * 60] * 2 + [240 * 60] * 10
ban_times = [5 * 60] * 3 + [15 * 60] * 3 + [30 * 60] * 2 + [60 * 60] * 10
for ban_time in ban_times:
servers_info = await data_store.get_available_servers_for_store(tree_id=tree_id, timestamp=current_timestamp)
assert len(servers_info) == 1
Expand Down

0 comments on commit cfab3a4

Please sign in to comment.