From 17dea1b708d9b8c87f1bbd8427ea6d4d05ede5bb Mon Sep 17 00:00:00 2001 From: dustinface <35775977+xdustinface@users.noreply.github.com> Date: Wed, 1 Sep 2021 18:21:29 +0200 Subject: [PATCH] plotting|util|tests: Fix and test re-trying of plots which failed to load (#8279) * Revert "plotting: Fix failed_to_open_filenames re-try interval" This reverts 8a8abc41a8c37a920d84ee90c34ece4d6d0254c5 which is part of #7848. Seems like i confused myself there. * plotting|util: Introduce `retry_invalid_seconds` in plot refresh params * plotting: Cleanup `failed_to_open_filenames` * tests: Test re-try of plots which failed to load --- chia/plotting/manager.py | 8 ++++-- chia/plotting/util.py | 1 + chia/util/initial-config.yaml | 1 + tests/core/test_farmer_harvester_rpc.py | 36 +++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/chia/plotting/manager.py b/chia/plotting/manager.py index 70dbe16f9709..6422de2b424d 100644 --- a/chia/plotting/manager.py +++ b/chia/plotting/manager.py @@ -162,9 +162,10 @@ class PlotManager: if file_path.exists(): if ( file_path in self.failed_to_open_filenames - and (time.time() - self.failed_to_open_filenames[file_path]) > 1200 + and (time.time() - self.failed_to_open_filenames[file_path]) + < self.refresh_parameter.retry_invalid_seconds ): - # Try once every 20 minutes to open the file + # Try once every `refresh_parameter.retry_invalid_seconds` seconds to open the file return new_provers if file_path in self.plots: try: @@ -268,6 +269,9 @@ class PlotManager: result.loaded_plots += 1 result.loaded_size += stat_info.st_size + if file_path in self.failed_to_open_filenames: + del self.failed_to_open_filenames[file_path] + except Exception as e: tb = traceback.format_exc() log.error(f"Failed to open file {file_path}. {e} {tb}") diff --git a/chia/plotting/util.py b/chia/plotting/util.py index 75d67a6e6d52..879a278b5c51 100644 --- a/chia/plotting/util.py +++ b/chia/plotting/util.py @@ -16,6 +16,7 @@ log = logging.getLogger(__name__) @dataclass class PlotsRefreshParameter: interval_seconds: int = 120 + retry_invalid_seconds: int = 1200 batch_size: int = 30 batch_sleep_milliseconds: int = 10 diff --git a/chia/util/initial-config.yaml b/chia/util/initial-config.yaml index d8a152a913be..468b60d53748 100644 --- a/chia/util/initial-config.yaml +++ b/chia/util/initial-config.yaml @@ -127,6 +127,7 @@ harvester: num_threads: 30 plots_refresh_parameter: interval_seconds: 120 # The interval in seconds to refresh the plot file manager + retry_invalid_seconds: 1200 # How long to wait before re-trying plots which failed to load batch_size: 30 # How many plot files the harvester processes before it waits batch_sleep_milliseconds batch_sleep_milliseconds: 10 # Milliseconds the harvester sleeps between batch processing diff --git a/tests/core/test_farmer_harvester_rpc.py b/tests/core/test_farmer_harvester_rpc.py index d0bb4d58bbde..cd28f1af8352 100644 --- a/tests/core/test_farmer_harvester_rpc.py +++ b/tests/core/test_farmer_harvester_rpc.py @@ -1,6 +1,8 @@ # flake8: noqa: E501 import logging +from pathlib import Path from secrets import token_bytes +from shutil import copy, move import pytest from blspy import AugSchemeMPL @@ -198,6 +200,7 @@ class TestRpc: await time_out_assert(5, harvester.plot_manager.needs_refresh, value=False) result = await client_2.get_plots() assert len(result["plots"]) == expect_total_plots + assert len(harvester.plot_manager.failed_to_open_filenames) == 0 # Add plot_dir with two new plots await test_case( @@ -291,6 +294,39 @@ class TestRpc: expect_total_plots=0, ) + # Test re-trying if processing a plot failed + # First save the plot + retry_test_plot = Path(plot_dir_sub / filename_2).resolve() + retry_test_plot_save = Path(plot_dir_sub / "save").resolve() + copy(retry_test_plot, retry_test_plot_save) + # Invalidate the plot + with open(plot_dir_sub / filename_2, "r+b") as file: + file.write(bytes(100)) + # Add it and validate it fails to load + await harvester.add_plot_directory(str(plot_dir_sub)) + expected_result.loaded_plots = 0 + expected_result.removed_plots = 0 + expected_result.processed_files = 1 + expected_result.remaining_files = 0 + harvester.plot_manager.start_refreshing() + await time_out_assert(5, harvester.plot_manager.needs_refresh, value=False) + assert retry_test_plot in harvester.plot_manager.failed_to_open_filenames + # Make sure the file stays in `failed_to_open_filenames` and doesn't get loaded or processed in the next + # update round + expected_result.loaded_plots = 0 + expected_result.processed_files = 0 + harvester.plot_manager.trigger_refresh() + await time_out_assert(5, harvester.plot_manager.needs_refresh, value=False) + assert retry_test_plot in harvester.plot_manager.failed_to_open_filenames + # Now decrease the re-try timeout, restore the valid plot file and make sure it properly loads now + harvester.plot_manager.refresh_parameter.retry_invalid_seconds = 0 + move(retry_test_plot_save, retry_test_plot) + expected_result.loaded_plots = 1 + expected_result.processed_files = 1 + harvester.plot_manager.trigger_refresh() + await time_out_assert(5, harvester.plot_manager.needs_refresh, value=False) + assert retry_test_plot not in harvester.plot_manager.failed_to_open_filenames + targets_1 = await client.get_reward_targets(False) assert "have_pool_sk" not in targets_1 assert "have_farmer_sk" not in targets_1