chia-blockchain/chia/plotting/check_plots.py

216 lines
9.5 KiB
Python
Raw Normal View History

from __future__ import annotations
2020-07-03 08:14:16 +03:00
import logging
from collections import Counter
from pathlib import Path
2022-04-22 03:00:00 +03:00
from time import sleep, time
from typing import List, Optional
from blspy import G1Element
from chiapos import Verifier
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
from chia.plotting.manager import PlotManager
from chia.plotting.util import (
2022-04-22 03:00:00 +03:00
PlotRefreshEvents,
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
PlotRefreshResult,
PlotsRefreshParameter,
find_duplicate_plot_IDs,
2022-04-22 03:00:00 +03:00
get_plot_filenames,
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
parse_plot_info,
)
from chia.util.bech32m import encode_puzzle_hash
from chia.util.config import load_config
from chia.util.hash import std_hash
from chia.util.ints import uint32
from chia.util.keychain import Keychain
from chia.wallet.derive_keys import master_sk_to_farmer_sk, master_sk_to_local_sk
2021-03-03 06:49:19 +03:00
2020-07-03 08:14:16 +03:00
log = logging.getLogger(__name__)
def plot_refresh_callback(event: PlotRefreshEvents, refresh_result: PlotRefreshResult) -> None:
log.info(f"event: {event.name}, loaded {len(refresh_result.loaded)} plots, {refresh_result.remaining} remaining")
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
def check_plots(
root_path: Path,
num: Optional[int],
challenge_start: Optional[int],
grep_string: str,
list_duplicates: bool,
debug_show_memo: bool,
) -> None:
2020-07-03 08:14:16 +03:00
config = load_config(root_path, "config.yaml")
address_prefix = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"]
plot_refresh_parameter: PlotsRefreshParameter = PlotsRefreshParameter(batch_sleep_milliseconds=uint32(0))
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
plot_manager: PlotManager = PlotManager(
root_path,
match_str=grep_string,
open_no_key_filenames=True,
refresh_parameter=plot_refresh_parameter,
refresh_callback=plot_refresh_callback,
)
if num is not None:
if num == 0:
log.warning("Not opening plot files")
else:
if num < 5:
log.warning(f"{num} challenges is too low, setting it to the minimum of 5")
num = 5
if num < 30:
log.warning("Use 30 challenges (our default) for balance of speed and accurate results")
2020-07-03 08:14:16 +03:00
else:
2021-01-20 22:44:56 +03:00
num = 30
if challenge_start is not None:
num_start = challenge_start
num_end = num_start + num
else:
num_start = 0
num_end = num
challenges = num_end - num_start
if list_duplicates:
log.warning("Checking for duplicate Plot IDs")
log.info("Plot filenames expected to end with -[64 char plot ID].plot")
if list_duplicates:
all_filenames: List[Path] = []
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
for paths in get_plot_filenames(root_path).values():
all_filenames += paths
find_duplicate_plot_IDs(all_filenames)
if num == 0:
return None
2020-07-03 08:14:16 +03:00
parallel_read: bool = config["harvester"].get("parallel_read", True)
2020-07-03 08:14:16 +03:00
v = Verifier()
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
log.info(f"Loading plots in config.yaml using plot_manager loading code (parallel read: {parallel_read})\n")
Keyring passphrase protection (#7249) * Moved keyring handling into a KeyringWrapper class * Update click to 8.0.x for prompt_required support * Renamed KeyringWrapper to _KeyringWrapper * Expose password management options on Linux * CLI support for setting/removing a password * Global option for specifying the master password * Cache the password instead of setting on the context * Password bootstrapping during chia init * Tidying up _KeyringWraper's interface * Initial pass migrating the legacy keyring contents * Encryption/decryption of keyring.yaml contents * FileKeyring backend encrypts with ChaCha20Poly1305 * Tightened up keyring migration and initialization * Fixed issues identified by linters * Remove root_path from Keychain * Prevent double-migration if setting master passwd * KeyringWrapper tests are mostly complete * FileKeyring will now honor the service param * Tests for get/set/delete password * Formatting/commenting updates * Writer lock support with tests - WIP * keyring.yaml is now watched for modifications * Reader/Writer lock for get/delete password * Fixed linter issues * Reader lock tests * Formatting update * Hook up CHIA_ROOT support for KeychainWrapper * Quick fix to address test failures * Fixed failures when existing legacy keyring exists * Fixed test failures caused by reusing the same temp dir * keyring.yaml now lives in ~/.chia_keys by default. Can be overridden with CHIA_KEYS_ROOT or --keys-root-path * Fixed migration failure when setting a password (not using the default) * KeyringWrapper now uses supports_keyring_password to determine if a FileKeyring should be used. Patched tests to work regardless of whether supports_keyring_password return False * The daemon now takes a --have-gui option that will prevent calling check_keys() during startup. If the keyring is locked, we want the GUI to prompt for the password. * Added is_keyring_locked RPC call * Added 'unlock_keyring' RPC command * Added KeychainProxy and KeychainServer to handle RPC messages related to keyring operations. WalletNode no longer directly accesses the Keychain class. * Turn on macOS support for testing keyring passwords * Fixed get_key_for_fingerprint to use the ocal keychain if the platform doesn't need to remotely access the daemon's keychain. Fixed key reconstruction when sent over RPC. * Farmer now accesses the keychain over RPC * Fixes for linter issues and some restructuring to support tests that use setup_nodes.py * Couple of fixes to unblock the GUI from launching when a keyring password is set * Added a keychain RPC call for add_private_key() * Added remaining keychain proxy RPC calls for delete_key_by_fingerprint and delete_all_keys * Check for None when inspecting request arguments * Run check_keys after unlocking the keyring when the daemon is launched via GUI * Added check_keys RPC method. Fixed deserialization of key entropy in get_all_private_keys. This was preventing the GUI from being able to show key details. * Added get_first_private_key to keychain_server/proxy. create_plots now uses the keychain proxy when launched from the daemon. * Added a comment about KeychainProxy in chia plots check * Workaround import conflict when importing from 'tests.*' due to fasteners name conflict * Simulator now uses KeychainProxy if launched by the daemon. KeychainServer/Proxy now takes keychain user/testing params for testing scenarios. * Added "set_keyring_passphrase" RPC message * Reworking KeychainProxy usage to handle local keychain tests and RPC keychain tests. * Replace my prior usage of asyncio.run() with asyncio.get_event_loop().run_until_complete() * Silencing file_keyring logging for the moment. * Updated tests to use test keychains and appropriate BlockTools construction BlockTools should now be created with create_block_tools(_async) to handle async scenarios. Updated block_tools to be async compatible Updated fasteners to fix installation of top-level 'tests' in site-packages * Added 'remove_keyring_passphrase' RPC message to the daemon Minor tweak to TempKeyring to default to some test params * Fixed linter issues * Remove flake8 ignore statement now that the fasteners module has been updated * Some initial renaming changes: password -> passphrase * Fixed wallet RPC issue where get_key_for_fingerprint wasn't awaited-upon. Fixed legacy keyring initialization (for migration scenarios) * Fixed improperly merged file * Fixed linter issues. More renaming. * Updated spots that were still using an incorrect keychain call * Renamed use_password_cache, obtain_current_password * Renamed supports_keyring_password * Renamed has_master_password * Renamed has_cached_password, get_cached_master_password * Linter fixes * Renamed master_password_is_valid * Renamed set_cached_master_password * Renamed set_master_password * Renamed remove_master_password * Renamed has_cached_master_password * Renaming in file_keyring and keyring_wrapper Updated default keyring payload used for tests * Renamed get_password Other renaming updates * Renamed set_password Other renaming updates * Renamed remaining password occurrences (where appropriate) * password -> passphrase * Added tests for setting an emoji and Japanese master passphrase * Attempt to notify the daemon when a keyring passphrase is set/updated/removed * Missed one password -> passphrase replacement. * Fixed some file synchronization issues found when running tests on macOS * Adjusted timeout values for test_writer_lock_reacquisition_failure for macOS. * Removed logging statements previously added for debugging * Prompt for keyring passphrase up-front when launching a service. Changed --have-gui flag to --wait-for-unlock * Updated set_keyring_passphrase RPC message to fix optional current_passphrase param when the keyring is using the default passphrase. * Minor test cleanup to deduplicate some code. * Fixed regression when setting a new master passphrase * Minor refactoring and docs/commenting updates * Renaming password -> passphrase went too far. Keyring backends use password terminology for compatibility with third party backends. * Disabling macOS support (previously added for testing only) * Disabling passphrase support in preparation for sending out the PR * Fixed improper merge (vscode didn't save changes during rebase) * Update chia/cmds/init_funcs.py Co-authored-by: Adam Kelly <338792+aqk@users.noreply.github.com> * skip_check_keys -> should_check_keys * Shuffling some imports around to break cycles reported by LGTM * Handle unlocking the daemon if it's already launched and waiting for unlock. * Replaced uses_keychain_proxy decorator in farmer.py. Fixed async usage of get_reward_targets. Linter/reformatting fixes * Replaced uses_keychain_proxy decorator with a clearer method. * Cleanup the temp keyring dir using shutil.rmtree() * Restored self._root_path (had been changed to self.root_path) * Minor cleanup * ensure_keychain_proxy() now throws if connect_to_keychain_and_validate() fails * Plot key resolution now yields a PlotKeys object which can be passed into create_plots. De-indented test_invalid_icc_sub_slot_vdf to keep git blame tidy. * Added 'keyring_status' daemon RPC message to support the GUI * Minor changes relating to PR feedback * Addressed more PR feedback (mostly type annotations) * Commented-out macOS file keyring usage. This can be re-enabled for testing purposes. * Addressed test failures that require multiple keyrings in the same process. Each TempKeyring will now set a custom KeyringWrapper instance. * Fixed logic for communicating user_passphrase_is_set in the keyring_status RPC response. * Updated type annotations and method signature for set_passphrase to expect a string instead of bytes. * Fixed Wallet RPC tests * Fixed full_node_store tests. BlockTools should be created using the create_block_tools(_async) function(s) * Fixed test failures in test_pool_rpc * Fixed test_daemon. After BlockTools.setup_plots is run, the config file needs to be re-read to refresh stale plot_directories. * Suppressing LGTM false positives regarding passphrase leakage in CLI error output. Seems that LGTM sees MIN_PASSPHRASE_LEN as sensitive data. * Second attempt at suppressing LGTM false positives * Third attempt at addressing LGTM false positives * Removed test_keyring_wrapper param from Keychain ctor. Test setup now sets the keyring_wrapper property directly. * Reformatting * More targeted update of the test config to refresh just the "plot_directories" value * More LGTM suppressions Co-authored-by: Adam Kelly <338792+aqk@users.noreply.github.com> Co-authored-by: wjblanke <wjb98672@gmail.com>
2021-08-04 22:46:55 +03:00
# Prompts interactively if the keyring is protected by a master passphrase. To use the daemon
# for keychain access, KeychainProxy/connect_to_keychain should be used instead of Keychain.
2020-07-03 08:14:16 +03:00
kc: Keychain = Keychain()
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
plot_manager.set_public_keys(
[master_sk_to_farmer_sk(sk).get_g1() for sk, _ in kc.get_all_private_keys()],
[G1Element.from_bytes(bytes.fromhex(pk)) for pk in config["farmer"]["pool_public_keys"]],
2020-07-03 08:14:16 +03:00
)
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
plot_manager.start_refreshing()
while plot_manager.needs_refresh():
sleep(1)
plot_manager.stop_refreshing()
if plot_manager.plot_count() > 0:
2020-07-03 08:14:16 +03:00
log.info("")
log.info("")
log.info(f"Starting to test each plot with {num} challenges each\n")
total_good_plots: Counter[str] = Counter()
2020-07-03 08:14:16 +03:00
total_size = 0
bad_plots_list: List[Path] = []
2020-07-03 08:14:16 +03:00
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
with plot_manager:
for plot_path, plot_info in plot_manager.plots.items():
pr = plot_info.prover
log.info(f"Testing plot {plot_path} k={pr.get_size()}")
if plot_info.pool_public_key is not None:
log.info(f"\t{'Pool public key:':<23} {plot_info.pool_public_key}")
if plot_info.pool_contract_puzzle_hash is not None:
pca: str = encode_puzzle_hash(plot_info.pool_contract_puzzle_hash, address_prefix)
log.info(f"\t{'Pool contract address:':<23} {pca}")
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
# Look up local_sk from plot to save locked memory
(
pool_public_key_or_puzzle_hash,
farmer_public_key,
local_master_sk,
) = parse_plot_info(pr.get_memo())
local_sk = master_sk_to_local_sk(local_master_sk)
log.info(f"\t{'Farmer public key:' :<23} {farmer_public_key}")
log.info(f"\t{'Local sk:' :<23} {local_sk}")
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
total_proofs = 0
caught_exception: bool = False
for i in range(num_start, num_end):
challenge = std_hash(i.to_bytes(32, "big"))
# Some plot errors cause get_qualities_for_challenge to throw a RuntimeError
try:
quality_start_time = int(round(time() * 1000))
for index, quality_str in enumerate(pr.get_qualities_for_challenge(challenge)):
quality_spent_time = int(round(time() * 1000)) - quality_start_time
if quality_spent_time > 5000:
log.warning(
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
f"\tLooking up qualities took: {quality_spent_time} ms. This should be below 5 seconds "
f"to minimize risk of losing rewards."
)
else:
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
log.info(f"\tLooking up qualities took: {quality_spent_time} ms.")
# Other plot errors cause get_full_proof or validate_proof to throw an AssertionError
try:
proof_start_time = int(round(time() * 1000))
proof = pr.get_full_proof(challenge, index, parallel_read)
proof_spent_time = int(round(time() * 1000)) - proof_start_time
if proof_spent_time > 15000:
log.warning(
f"\tFinding proof took: {proof_spent_time} ms. This should be below 15 seconds "
f"to minimize risk of losing rewards."
)
else:
log.info(f"\tFinding proof took: {proof_spent_time} ms")
total_proofs += 1
ver_quality_str = v.validate_proof(pr.get_id(), pr.get_size(), challenge, proof)
assert quality_str == ver_quality_str
except AssertionError as e:
log.error(f"{type(e)}: {e} error in proving/verifying for plot {plot_path}")
caught_exception = True
quality_start_time = int(round(time() * 1000))
except KeyboardInterrupt:
log.warning("Interrupted, closing")
return None
except SystemExit:
log.warning("System is shutting down.")
return None
except Exception as e:
log.error(f"{type(e)}: {e} error in getting challenge qualities for plot {plot_path}")
caught_exception = True
if caught_exception is True:
break
if total_proofs > 0 and caught_exception is False:
log.info(f"\tProofs {total_proofs} / {challenges}, {round(total_proofs/float(challenges), 4)}")
total_good_plots[pr.get_size()] += 1
total_size += plot_path.stat().st_size
else:
log.error(f"\tProofs {total_proofs} / {challenges}, {round(total_proofs/float(challenges), 4)}")
bad_plots_list.append(plot_path)
2020-07-03 08:14:16 +03:00
log.info("")
log.info("")
log.info("Summary")
total_plots: int = sum(list(total_good_plots.values()))
log.info(f"Found {total_plots} valid plots, total size {total_size / (1024 * 1024 * 1024 * 1024):.5f} TiB")
2023-02-23 19:42:44 +03:00
for k, count in sorted(dict(total_good_plots).items()):
2020-07-03 08:14:16 +03:00
log.info(f"{count} plots of size {k}")
grand_total_bad = len(bad_plots_list) + len(plot_manager.failed_to_open_filenames)
2020-07-03 08:14:16 +03:00
if grand_total_bad > 0:
log.warning(f"{grand_total_bad} invalid plots found:")
if len(bad_plots_list) > 0:
log.warning(f" {len(bad_plots_list)} bad plots:")
for bad_plot_path in bad_plots_list:
log.warning(f"{bad_plot_path}")
if len(plot_manager.failed_to_open_filenames) > 0:
log.warning(f" {len(plot_manager.failed_to_open_filenames)} unopenable plots:")
for unopenable_plot_path in plot_manager.failed_to_open_filenames.keys():
log.warning(f"{unopenable_plot_path}")
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
if len(plot_manager.no_key_filenames) > 0:
2020-07-03 08:14:16 +03:00
log.warning(
chia|tests: Introduce `PlotManager` + some plot loading improvements and fixes (#7848) * harvester|plotting|tests: Introduce `PlotManager` class This moves all plots related and plot-directory related stuff from the harvester into the class `PlotManager`, adjusts all related code accordingly and adds some extra wrappers there. * harvester|plotting|tests: Return how many new plots were loaded * plotting: Fix `failed_to_open_filenames` re-try interval With `< 1200` it just tries it on the next refresh. * plotting: Fix and improve duplicates handling * harvester|plotting: Thread locks for `PlotManager.plots` * chia|tests: Load plots in batches * chia|tests: Move plot refreshing into a separate thread * plotting: Properly handle removed plots And fix tests accordingly. It seems like this fix https://github.com/Chia-Network/chia-blockchain/pull/3350 wasn't really a fix, rather adjusting to allow for a bug? * plotting|harvester|tests: Introduce `PlotRefreshResult` * tests: Expand `test_farmer_harvester_rpc.py` * chia|tests: Move some stuff from `plot_tools.py` into new file `util.py` * refactor: Rename `plot_tools.py` to `manager.py` * chia|tests: Use pure dataclass for `PlotsRefreshParameter` With `uint16` as type saving to config doesn't work, this is a preparation for the next commit. * harvester: Adjust deprecation message, use `info` instead of `warning` * plotting: Fix typo * refactor: Rename `filename` to `file_path` Fits better and does avoid shadowing with filename from outer scope. * chia|tests: Move some methods from `plotting.manager` to `plotting.util` * plotting: Make `refresh_callback` mandatory
2021-08-09 20:25:15 +03:00
f"There are {len(plot_manager.no_key_filenames)} plots with a farmer or pool public key that "
2020-07-03 08:14:16 +03:00
f"is not on this machine. The farmer private key must be in the keychain in order to "
f"farm them, use 'chia keys' to transfer keys. The pool public keys must be in the config.yaml"
)
if debug_show_memo:
plot_memo_str: str = "Plot Memos:\n"
with plot_manager:
for path, plot in plot_manager.plots.items():
plot_memo_str += f"{path}: {plot.prover.get_memo().hex()}\n"
log.info(plot_memo_str)