diff --git a/chia/_tests/core/full_node/stores/test_block_store.py b/chia/_tests/core/full_node/stores/test_block_store.py index 0bf2ba048f5a..5cb22d158f7d 100644 --- a/chia/_tests/core/full_node/stores/test_block_store.py +++ b/chia/_tests/core/full_node/stores/test_block_store.py @@ -418,8 +418,8 @@ def generator(i: int) -> SerializedProgram: store = await BlockStore.create(db_wrapper, use_cache=use_cache) new_blocks = [] - for i, block in enumerate(blocks): - block = block.replace(transactions_generator=generator(i)) + for i, original_block in enumerate(blocks): + block = original_block.replace(transactions_generator=generator(i)) block_record = header_block_to_sub_block_record( DEFAULT_CONSTANTS, uint64(0), block, uint64(0), False, uint8(0), uint32(max(0, block.height - 1)), None ) diff --git a/chia/_tests/core/mempool/test_mempool_fee_estimator.py b/chia/_tests/core/mempool/test_mempool_fee_estimator.py index b18f7c109294..91f0f12b9de6 100644 --- a/chia/_tests/core/mempool/test_mempool_fee_estimator.py +++ b/chia/_tests/core/mempool/test_mempool_fee_estimator.py @@ -23,7 +23,6 @@ async def test_basics() -> None: cost = uint64(5000000) for i in range(300, 700): - i = uint32(i) items = [] for _ in range(2, 100): fee = uint64(10000000) @@ -50,7 +49,7 @@ async def test_basics() -> None: ) items.append(mempool_item2) - fee_tracker.process_block(i, items) + fee_tracker.process_block(uint32(i), items) short, med, long = fee_tracker.estimate_fees() @@ -72,7 +71,6 @@ async def test_fee_increase() -> None: estimator = SmartFeeEstimator(fee_tracker, uint64(test_constants.MAX_BLOCK_COST_CLVM)) random = Random(x=1) for i in range(300, 700): - i = uint32(i) items = [] for _ in range(20): fee = uint64(0) @@ -85,7 +83,7 @@ async def test_fee_increase() -> None: ) items.append(mempool_item) - fee_tracker.process_block(i, items) + fee_tracker.process_block(uint32(i), items) short, med, long = fee_tracker.estimate_fees() mempool_info = mempool_manager.mempool.fee_estimator.get_mempool_info() diff --git a/chia/_tests/core/util/test_keychain.py b/chia/_tests/core/util/test_keychain.py index c0ba58e99886..b252667c5f21 100644 --- a/chia/_tests/core/util/test_keychain.py +++ b/chia/_tests/core/util/test_keychain.py @@ -220,9 +220,9 @@ def test_bip39_test_vectors_short(self): test_vectors_path = importlib_resources.files(chia._tests.util.__name__).joinpath("bip39_test_vectors.json") all_vectors = json.loads(test_vectors_path.read_text(encoding="utf-8")) - for idx, [entropy_hex, full_mnemonic, seed, short_mnemonic] in enumerate(all_vectors["english"]): + for idx, [entropy_hex, full_mnemonic, seed_hex, short_mnemonic] in enumerate(all_vectors["english"]): entropy_bytes = bytes.fromhex(entropy_hex) - seed = bytes.fromhex(seed) + seed = bytes.fromhex(seed_hex) assert mnemonic_from_short_words(short_mnemonic) == full_mnemonic assert bytes_from_mnemonic(short_mnemonic) == entropy_bytes diff --git a/chia/_tests/fee_estimation/test_fee_estimation_unit_tests.py b/chia/_tests/fee_estimation/test_fee_estimation_unit_tests.py index 27830d0b791f..cd91c3def305 100644 --- a/chia/_tests/fee_estimation/test_fee_estimation_unit_tests.py +++ b/chia/_tests/fee_estimation/test_fee_estimation_unit_tests.py @@ -68,8 +68,7 @@ def test_steady_fee_pressure() -> None: estimates_during = [] start_from = 250 for height in range(start, end): - height = uint32(height) - items = make_block(height, 1, cost, fee, num_blocks_wait_in_mempool) + items = make_block(uint32(height), 1, cost, fee, num_blocks_wait_in_mempool) estimator.new_block(FeeBlockInfo(uint32(height), items)) if height >= start_from: estimation = estimator.estimate_fee_rate(time_offset_seconds=time_offset_seconds * (height - start_from)) diff --git a/chia/_tests/wallet/test_signer_protocol.py b/chia/_tests/wallet/test_signer_protocol.py index 29668eec8d48..c1d7a0dc590e 100644 --- a/chia/_tests/wallet/test_signer_protocol.py +++ b/chia/_tests/wallet/test_signer_protocol.py @@ -848,8 +848,8 @@ def run(self) -> None: with open("some file", "wb") as file: file.write(byte_serialize_clvm_streamable(coin, translation_layer=FOO_COIN_TRANSLATION)) - with open("some file2", "wb") as file: - file.write(byte_serialize_clvm_streamable(coin, translation_layer=FOO_COIN_TRANSLATION)) + with open("some file2", "wb") as file2: + file2.write(byte_serialize_clvm_streamable(coin, translation_layer=FOO_COIN_TRANSLATION)) result = runner.invoke( cmd, ["temp_cmd", "--signer-protocol-input", "some file", "--signer-protocol-input", "some file2"] diff --git a/chia/cmds/plotnft_funcs.py b/chia/cmds/plotnft_funcs.py index 09204896bed1..6cc003c88748 100644 --- a/chia/cmds/plotnft_funcs.py +++ b/chia/cmds/plotnft_funcs.py @@ -445,8 +445,10 @@ async def change_payout_instructions(launcher_id: bytes32, address: CliAddress, for pool_config in old_configs: if pool_config.launcher_id == launcher_id: id_found = True - pool_config = replace(pool_config, payout_instructions=puzzle_hash.hex()) - new_pool_configs.append(pool_config) + new_pool_config = replace(pool_config, payout_instructions=puzzle_hash.hex()) + else: + new_pool_config = pool_config + new_pool_configs.append(new_pool_config) if id_found: print(f"Launcher Id: {launcher_id.hex()} Found, Updating Config.") await update_pool_config(root_path, new_pool_configs) diff --git a/chia/cmds/wallet_funcs.py b/chia/cmds/wallet_funcs.py index bae70e4518d8..b46c31bdb7ac 100644 --- a/chia/cmds/wallet_funcs.py +++ b/chia/cmds/wallet_funcs.py @@ -265,7 +265,9 @@ async def get_transactions( if len(coin_records["coin_records"]) > 0: coin_record = coin_records["coin_records"][0] else: - j -= 1 + # Ignoring this because it seems useful to the loop + # But we should probably consider a better loop + j -= 1 # noqa: PLW2901 skipped += 1 continue print_transaction( diff --git a/chia/data_layer/data_layer_wallet.py b/chia/data_layer/data_layer_wallet.py index 771d2719458e..39d7de2f5eb6 100644 --- a/chia/data_layer/data_layer_wallet.py +++ b/chia/data_layer/data_layer_wallet.py @@ -1137,9 +1137,11 @@ async def finish_graftroot_solutions(offer: Offer, solver: Solver) -> Offer: ] ) ) - new_spend: CoinSpend = spend.replace(solution=new_solution.to_serialized()) - spend = new_spend - new_spends.append(spend) + new_spends.append(spend.replace(solution=new_solution.to_serialized())) + else: + new_spends.append(spend) + else: + new_spends.append(spend) return Offer({}, WalletSpendBundle(new_spends, offer.aggregated_signature()), offer.driver_dict) diff --git a/chia/data_layer/data_store.py b/chia/data_layer/data_store.py index 67be682079dc..c2357aa52e5e 100644 --- a/chia/data_layer/data_store.py +++ b/chia/data_layer/data_store.py @@ -1876,8 +1876,12 @@ async def get_tree_as_nodes(self, store_id: bytes32) -> Node: hash_to_node: dict[bytes32, Node] = {} for node in reversed(nodes): if isinstance(node, InternalNode): - node = replace(node, left=hash_to_node[node.left_hash], right=hash_to_node[node.right_hash]) - hash_to_node[node.hash] = node + node_entry: Node = replace( + node, left=hash_to_node[node.left_hash], right=hash_to_node[node.right_hash] + ) + else: + node_entry = node + hash_to_node[node_entry.hash] = node_entry root_node = hash_to_node[root_node.hash] diff --git a/chia/full_node/weight_proof.py b/chia/full_node/weight_proof.py index 98954878121f..6bc1a0527626 100644 --- a/chia/full_node/weight_proof.py +++ b/chia/full_node/weight_proof.py @@ -1532,10 +1532,10 @@ def _get_last_ses_hash( ) -> tuple[Optional[bytes32], uint32]: for idx, block in enumerate(reversed(recent_reward_chain)): if (block.reward_chain_block.height % constants.SUB_EPOCH_BLOCKS) == 0: - idx = len(recent_reward_chain) - 1 - idx # reverse + reversed_idx = len(recent_reward_chain) - 1 - idx # reverse # find first block after sub slot end - while idx < len(recent_reward_chain): - curr = recent_reward_chain[idx] + while reversed_idx < len(recent_reward_chain): + curr = recent_reward_chain[reversed_idx] if len(curr.finished_sub_slots) > 0: for slot in curr.finished_sub_slots: if slot.challenge_chain.subepoch_summary_hash is not None: @@ -1543,7 +1543,7 @@ def _get_last_ses_hash( slot.challenge_chain.subepoch_summary_hash, curr.reward_chain_block.height, ) - idx += 1 + reversed_idx += 1 return None, uint32(0) diff --git a/chia/seeder/crawl_store.py b/chia/seeder/crawl_store.py index d3e566e27158..be565efcea81 100644 --- a/chia/seeder/crawl_store.py +++ b/chia/seeder/crawl_store.py @@ -341,9 +341,6 @@ def load_host_to_version(self) -> tuple[dict[str, str], dict[str, uint64]]: handshake = {} for host, record in self.host_to_records.items(): - if host not in self.host_to_records: - continue - record = self.host_to_records[host] if record.version == "undefined": continue if record.handshake_time < time.time() - 5 * 24 * 3600: diff --git a/chia/wallet/cat_wallet/cat_outer_puzzle.py b/chia/wallet/cat_wallet/cat_outer_puzzle.py index 1b20cd2d829f..f5a83d9f8581 100644 --- a/chia/wallet/cat_wallet/cat_outer_puzzle.py +++ b/chia/wallet/cat_wallet/cat_outer_puzzle.py @@ -105,8 +105,11 @@ def solve(self, constructor: PuzzleInfo, solver: Solver, inner_puzzle: Program, parent_coin: Coin = parent_spend.coin also = constructor.also() if also is not None: - solution = self._solve(also, solver, puzzle, solution) - puzzle = self._construct(also, puzzle) + constructed_solution = self._solve(also, solver, puzzle, solution) + constructed_puzzle = self._construct(also, puzzle) + else: + constructed_solution = solution + constructed_puzzle = puzzle args = match_cat_puzzle(uncurry_puzzle(parent_spend.puzzle_reveal)) assert args is not None _, _, parent_inner_puzzle = args @@ -114,8 +117,8 @@ def solve(self, constructor: PuzzleInfo, solver: Solver, inner_puzzle: Program, SpendableCAT( coin, tail_hash, - puzzle, - solution, + constructed_puzzle, + constructed_solution, lineage_proof=LineageProof( parent_coin.parent_coin_info, parent_inner_puzzle.get_tree_hash(), uint64(parent_coin.amount) ), diff --git a/chia/wallet/util/merkle_utils.py b/chia/wallet/util/merkle_utils.py index 9a8df4adc711..d15569479d7c 100644 --- a/chia/wallet/util/merkle_utils.py +++ b/chia/wallet/util/merkle_utils.py @@ -39,9 +39,9 @@ def build_merkle_tree_from_binary_tree(tuples: TupleTree) -> tuple[bytes32, dict proof.append(right_root) new_proofs[name] = (path, proof) for name, (path, proof) in right_proofs.items(): - path |= 1 << len(proof) + appended_path = path | (1 << len(proof)) proof.append(left_root) - new_proofs[name] = (path, proof) + new_proofs[name] = (appended_path, proof) return new_root, new_proofs diff --git a/chia/wallet/wallet_state_manager.py b/chia/wallet/wallet_state_manager.py index a71f6e0473f7..a000260bbac9 100644 --- a/chia/wallet/wallet_state_manager.py +++ b/chia/wallet/wallet_state_manager.py @@ -1945,8 +1945,8 @@ async def _add_coin_states( # No more singleton (maybe destroyed?) break - coin_name = new_singleton_coin.name() - existing = await self.coin_store.get_coin_record(coin_name) + new_singleton_name = new_singleton_coin.name() + existing = await self.coin_store.get_coin_record(new_singleton_name) if existing is None: await self.coin_added( new_singleton_coin, @@ -1955,7 +1955,7 @@ async def _add_coin_states( uint32(record.wallet_id), record.wallet_type, peer, - coin_name, + new_singleton_name, coin_data, ) await self.coin_store.set_spent( @@ -1963,7 +1963,7 @@ async def _add_coin_states( ) await self.add_interested_coin_ids([new_singleton_coin.name()]) new_coin_state: list[CoinState] = await self.wallet_node.get_coin_state( - [coin_name], peer=peer, fork_height=fork_height + [new_singleton_name], peer=peer, fork_height=fork_height ) assert len(new_coin_state) == 1 curr_coin_state = new_coin_state[0] @@ -2039,8 +2039,8 @@ async def _add_coin_states( launcher_spend_additions = compute_additions(launcher_spend) assert len(launcher_spend_additions) == 1 coin_added = launcher_spend_additions[0] - coin_name = coin_added.name() - existing = await self.coin_store.get_coin_record(coin_name) + coin_added_name = coin_added.name() + existing = await self.coin_store.get_coin_record(coin_added_name) if existing is None: await self.coin_added( coin_added, @@ -2049,10 +2049,10 @@ async def _add_coin_states( pool_wallet.id(), pool_wallet.type(), peer, - coin_name, + coin_added_name, coin_data, ) - await self.add_interested_coin_ids([coin_name]) + await self.add_interested_coin_ids([coin_added_name]) else: raise RuntimeError("All cases already handled") # Logic error, all cases handled diff --git a/ruff.toml b/ruff.toml index a62e25000cb1..fb2dfaa479dd 100644 --- a/ruff.toml +++ b/ruff.toml @@ -65,7 +65,6 @@ ignore = [ # Pylint warning "PLW1641", # eq-without-hash # Should probably fix these - "PLW2901", # redefined-loop-name "PLW1514", # unspecified-encoding "PLW0603", # global-statement diff --git a/tools/cpu_utilization.py b/tools/cpu_utilization.py index 41333f014c68..b1487d0a75f4 100644 --- a/tools/cpu_utilization.py +++ b/tools/cpu_utilization.py @@ -83,7 +83,8 @@ def main(pid: int, output: str, threads: bool) -> None: out.write(f" {(c[row].system_time - c[row - 1].system_time) * 100 / time_delta:6.2f}% ") else: out.write(" 0.00% 0.00% ") - row += 1 + # Ignoring this because it seems like I could delete it but there's no test so I'm unsure + row += 1 # noqa: PLW2901 out.write("\n") with open("plot-cpu.gnuplot", "w+") as out: