Skip to content

Commit f640b32

Browse files
committed
Merge bitcoin/bitcoin#30723: lint: Speed up and fix flake8 checks
fafdb7d lint: Speed up flake8 checks (MarcoFalke) faf17df lint: Document missing py_lint dependency (MarcoFalke) faebeb8 lint: Remove python whitespace and shadowing lint rules (MarcoFalke) 7777047 lint: Remove python lint rules that are SyntaxError (MarcoFalke) faaf3e5 test: [refactor] Fix F841 flake8 (MarcoFalke) 444421d test: [refactor] Fix E714 pycodestyle (MarcoFalke) Pull request description: The checks have many issues: * Some checks that could in theory hide bugs are not applied -> Fix them and apply them going forward * Some checks are redundant Python 2 checks, or of low value -> Remove them * The checks are slow -> Speed them up from ~10 seconds to about ~20 milliseconds ACKs for top commit: davidgumberg: review and tested reACK bitcoin/bitcoin@fafdb7d kevkevinpal: ACK [fafdb7d](bitcoin/bitcoin@fafdb7d) achow101: ACK fafdb7d Tree-SHA512: a0488b722cfaf7071bd6848cd3be002e0b6c38af80d8b5cbb08613c0b174ef63277289f960db8ac31adb09fe563a4973203b8fb10b83cbcfdc6f0ef39bd04410
2 parents 5373aa3 + fafdb7d commit f640b32

File tree

13 files changed

+80
-135
lines changed

13 files changed

+80
-135
lines changed

ci/lint/04_install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ fi
4848

4949
${CI_RETRY_EXE} pip3 install \
5050
codespell==2.2.6 \
51-
flake8==6.1.0 \
5251
lief==0.13.2 \
5352
mypy==1.4.1 \
5453
pyzmq==25.1.0 \

contrib/devtools/clang-format-diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def main():
164164
'Failed to run "%s" - %s"' % (" ".join(command), e.strerror)
165165
)
166166

167-
stdout, stderr = p.communicate()
167+
stdout, _stderr = p.communicate()
168168
if p.returncode != 0:
169169
sys.exit(p.returncode)
170170

test/functional/interface_usdt_coinselection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def run_test(self):
181181
# 5. aps_create_tx_internal (type 4)
182182
wallet.sendtoaddress(wallet.getnewaddress(), 10)
183183
events = self.get_tracepoints([1, 2, 3, 1, 4])
184-
success, use_aps, algo, waste, change_pos = self.determine_selection_from_usdt(events)
184+
success, use_aps, _algo, _waste, change_pos = self.determine_selection_from_usdt(events)
185185
assert_equal(success, True)
186186
assert_greater_than(change_pos, -1)
187187

@@ -190,7 +190,7 @@ def run_test(self):
190190
# 1. normal_create_tx_internal (type 2)
191191
assert_raises_rpc_error(-6, "Insufficient funds", wallet.sendtoaddress, wallet.getnewaddress(), 102 * 50)
192192
events = self.get_tracepoints([2])
193-
success, use_aps, algo, waste, change_pos = self.determine_selection_from_usdt(events)
193+
success, use_aps, _algo, _waste, change_pos = self.determine_selection_from_usdt(events)
194194
assert_equal(success, False)
195195

196196
self.log.info("Explicitly enabling APS results in 2 tracepoints")
@@ -200,7 +200,7 @@ def run_test(self):
200200
wallet.setwalletflag("avoid_reuse")
201201
wallet.sendtoaddress(address=wallet.getnewaddress(), amount=10, avoid_reuse=True)
202202
events = self.get_tracepoints([1, 2])
203-
success, use_aps, algo, waste, change_pos = self.determine_selection_from_usdt(events)
203+
success, use_aps, _algo, _waste, change_pos = self.determine_selection_from_usdt(events)
204204
assert_equal(success, True)
205205
assert_equal(use_aps, None)
206206

@@ -213,7 +213,7 @@ def run_test(self):
213213
# 5. aps_create_tx_internal (type 4)
214214
wallet.sendtoaddress(address=wallet.getnewaddress(), amount=wallet.getbalance(), subtractfeefromamount=True, avoid_reuse=False)
215215
events = self.get_tracepoints([1, 2, 3, 1, 4])
216-
success, use_aps, algo, waste, change_pos = self.determine_selection_from_usdt(events)
216+
success, use_aps, _algo, _waste, change_pos = self.determine_selection_from_usdt(events)
217217
assert_equal(success, True)
218218
assert_equal(change_pos, -1)
219219

@@ -223,7 +223,7 @@ def run_test(self):
223223
# 2. normal_create_tx_internal (type 2)
224224
wallet.sendtoaddress(address=wallet.getnewaddress(), amount=wallet.getbalance(), subtractfeefromamount=True)
225225
events = self.get_tracepoints([1, 2])
226-
success, use_aps, algo, waste, change_pos = self.determine_selection_from_usdt(events)
226+
success, use_aps, _algo, _waste, change_pos = self.determine_selection_from_usdt(events)
227227
assert_equal(success, True)
228228
assert_equal(change_pos, -1)
229229

test/functional/mempool_package_rbf.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_package_rbf_additional_fees(self):
189189
package_hex4, package_txns4 = self.create_simple_package(coin, parent_fee=DEFAULT_FEE, child_fee=DEFAULT_CHILD_FEE)
190190
node.submitpackage(package_hex4)
191191
self.assert_mempool_contents(expected=package_txns4)
192-
package_hex5, package_txns5 = self.create_simple_package(coin, parent_fee=DEFAULT_CHILD_FEE, child_fee=DEFAULT_CHILD_FEE)
192+
package_hex5, _package_txns5 = self.create_simple_package(coin, parent_fee=DEFAULT_CHILD_FEE, child_fee=DEFAULT_CHILD_FEE)
193193
pkg_results5 = node.submitpackage(package_hex5)
194194
assert 'package RBF failed: package feerate is less than or equal to parent feerate' in pkg_results5["package_msg"]
195195
self.assert_mempool_contents(expected=package_txns4)
@@ -336,16 +336,16 @@ def test_wrong_conflict_cluster_size_linear(self):
336336
self.assert_mempool_contents(expected=expected_txns)
337337

338338
# Now make conflicting packages for each coin
339-
package_hex1, package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
339+
package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
340340

341341
package_result = node.submitpackage(package_hex1)
342342
assert_equal(f"package RBF failed: {parent_result['tx'].rehash()} has 2 descendants, max 1 allowed", package_result["package_msg"])
343343

344-
package_hex2, package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
344+
package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
345345
package_result = node.submitpackage(package_hex2)
346346
assert_equal(f"package RBF failed: {child_result['tx'].rehash()} has both ancestor and descendant, exceeding cluster limit of 2", package_result["package_msg"])
347347

348-
package_hex3, package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
348+
package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
349349
package_result = node.submitpackage(package_hex3)
350350
assert_equal(f"package RBF failed: {grandchild_result['tx'].rehash()} has 2 ancestors, max 1 allowed", package_result["package_msg"])
351351

@@ -389,15 +389,15 @@ def test_wrong_conflict_cluster_size_parents_child(self):
389389
self.assert_mempool_contents(expected=expected_txns)
390390

391391
# Now make conflicting packages for each coin
392-
package_hex1, package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
392+
package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
393393
package_result = node.submitpackage(package_hex1)
394394
assert_equal(f"package RBF failed: {parent1_result['tx'].rehash()} is not the only parent of child {child_result['tx'].rehash()}", package_result["package_msg"])
395395

396-
package_hex2, package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
396+
package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
397397
package_result = node.submitpackage(package_hex2)
398398
assert_equal(f"package RBF failed: {parent2_result['tx'].rehash()} is not the only parent of child {child_result['tx'].rehash()}", package_result["package_msg"])
399399

400-
package_hex3, package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
400+
package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
401401
package_result = node.submitpackage(package_hex3)
402402
assert_equal(f"package RBF failed: {child_result['tx'].rehash()} has 2 ancestors, max 1 allowed", package_result["package_msg"])
403403

@@ -443,15 +443,15 @@ def test_wrong_conflict_cluster_size_parent_children(self):
443443
self.assert_mempool_contents(expected=expected_txns)
444444

445445
# Now make conflicting packages for each coin
446-
package_hex1, package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
446+
package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
447447
package_result = node.submitpackage(package_hex1)
448448
assert_equal(f"package RBF failed: {parent_result['tx'].rehash()} has 2 descendants, max 1 allowed", package_result["package_msg"])
449449

450-
package_hex2, package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
450+
package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
451451
package_result = node.submitpackage(package_hex2)
452452
assert_equal(f"package RBF failed: {child1_result['tx'].rehash()} is not the only child of parent {parent_result['tx'].rehash()}", package_result["package_msg"])
453453

454-
package_hex3, package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
454+
package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
455455
package_result = node.submitpackage(package_hex3)
456456
assert_equal(f"package RBF failed: {child2_result['tx'].rehash()} is not the only child of parent {parent_result['tx'].rehash()}", package_result["package_msg"])
457457

@@ -519,7 +519,7 @@ def test_insufficient_feerate(self):
519519

520520
# Package 2 feerate is below the feerate of directly conflicted parent, so it fails even though
521521
# total fees are higher than the original package
522-
package_hex2, package_txns2 = self.create_simple_package(coin, parent_fee=DEFAULT_CHILD_FEE - Decimal("0.00000001"), child_fee=DEFAULT_CHILD_FEE)
522+
package_hex2, _package_txns2 = self.create_simple_package(coin, parent_fee=DEFAULT_CHILD_FEE - Decimal("0.00000001"), child_fee=DEFAULT_CHILD_FEE)
523523
pkg_results2 = node.submitpackage(package_hex2)
524524
assert_equal(pkg_results2["package_msg"], 'package RBF failed: insufficient feerate: does not improve feerate diagram')
525525
self.assert_mempool_contents(expected=package_txns1)

test/functional/mempool_sigoplimit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def create_bare_multisig_tx(utxo_to_spend=None):
154154
return (tx_utxo, tx)
155155

156156
tx_parent_utxo, tx_parent = create_bare_multisig_tx()
157-
tx_child_utxo, tx_child = create_bare_multisig_tx(tx_parent_utxo)
157+
_tx_child_utxo, tx_child = create_bare_multisig_tx(tx_parent_utxo)
158158

159159
# Separately, the parent tx is ok
160160
parent_individual_testres = self.nodes[0].testmempoolaccept([tx_parent.serialize().hex()])[0]

test/functional/p2p_1p1c_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def create_packages(self):
107107

108108
# 3: 2-parent-1-child package. Both parents are above mempool min feerate. No package submission happens.
109109
# We require packages to be child-with-unconfirmed-parents and only allow 1-parent-1-child packages.
110-
package_hex_3, parent_31, parent_32, child_3 = self.create_package_2p1c(self.wallet)
110+
package_hex_3, parent_31, _parent_32, child_3 = self.create_package_2p1c(self.wallet)
111111

112112
# 4: parent + child package where the child spends 2 different outputs from the parent.
113113
package_hex_4, parent_4, child_4 = self.create_package_2outs(self.wallet)

test/functional/p2p_tx_download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ def test_expiry_fallback(self):
156156
# One of the peers is asked for the tx
157157
peer2.wait_until(lambda: sum(p.tx_getdata_count for p in [peer1, peer2]) == 1)
158158
with p2p_lock:
159-
peer_expiry, peer_fallback = (peer1, peer2) if peer1.tx_getdata_count == 1 else (peer2, peer1)
159+
_peer_expiry, peer_fallback = (peer1, peer2) if peer1.tx_getdata_count == 1 else (peer2, peer1)
160160
assert_equal(peer_fallback.tx_getdata_count, 0)
161-
self.nodes[0].setmocktime(int(time.time()) + GETDATA_TX_INTERVAL + 1) # Wait for request to peer_expiry to expire
161+
self.nodes[0].setmocktime(int(time.time()) + GETDATA_TX_INTERVAL + 1) # Wait for request to _peer_expiry to expire
162162
peer_fallback.wait_until(lambda: peer_fallback.tx_getdata_count >= 1, timeout=1)
163163
self.restart_node(0) # reset mocktime
164164

test/functional/rpc_createmultisig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def create_wallet(self, node, wallet_name):
4747
return node.get_wallet_rpc(wallet_name)
4848

4949
def run_test(self):
50-
node0, node1, node2 = self.nodes
50+
node0, node1, _node2 = self.nodes
5151
self.wallet = MiniWallet(test_node=node0)
5252

5353
if self.is_wallet_compiled():
@@ -122,7 +122,7 @@ def test_multisig_script_limit(self, wallet_multi):
122122
assert_raises_rpc_error(-4, "Unsupported multisig script size for legacy wallet. Upgrade to descriptors to overcome this limitation for p2sh-segwit or bech32 scripts", wallet_multi.addmultisigaddress, 16, pubkeys, '', 'bech32')
123123

124124
def do_multisig(self, nkeys, nsigs, output_type, wallet_multi):
125-
node0, node1, node2 = self.nodes
125+
node0, _node1, node2 = self.nodes
126126
pub_keys = self.pub[0: nkeys]
127127
priv_keys = self.priv[0: nkeys]
128128

test/functional/test_framework/blocktools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2015-2022 The Bitcoin Core developers
2+
# Copyright (c) 2015-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Utilities for manipulating blocks and transactions."""
@@ -74,7 +74,7 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl
7474
block.nVersion = version or tmpl.get('version') or VERSIONBITS_LAST_OLD_BLOCK_VERSION
7575
block.nTime = ntime or tmpl.get('curtime') or int(time.time() + 600)
7676
block.hashPrevBlock = hashprev or int(tmpl['previousblockhash'], 0x10)
77-
if tmpl and not tmpl.get('bits') is None:
77+
if tmpl and tmpl.get('bits') is not None:
7878
block.nBits = struct.unpack('>I', bytes.fromhex(tmpl['bits']))[0]
7979
else:
8080
block.nBits = 0x207fffff # difficulty retargeting is disabled in REGTEST chainparams

test/functional/wallet_upgradewallet.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def copy_split_hd():
231231
assert b'\x07hdchain' in new_kvs
232232
hd_chain = new_kvs[b'\x07hdchain']
233233
assert_equal(28, len(hd_chain))
234-
hd_chain_version, external_counter, seed_id = struct.unpack('<iI20s', hd_chain)
234+
hd_chain_version, _external_counter, seed_id = struct.unpack('<iI20s', hd_chain)
235235
assert_equal(1, hd_chain_version)
236236
seed_id = bytearray(seed_id)
237237
seed_id.reverse()
@@ -258,7 +258,7 @@ def copy_split_hd():
258258
new_kvs = dump_bdb_kv(node_master_wallet)
259259
hd_chain = new_kvs[b'\x07hdchain']
260260
assert_equal(32, len(hd_chain))
261-
hd_chain_version, external_counter, seed_id, internal_counter = struct.unpack('<iI20sI', hd_chain)
261+
hd_chain_version, _external_counter, seed_id, internal_counter = struct.unpack('<iI20sI', hd_chain)
262262
assert_equal(2, hd_chain_version)
263263
assert_equal(0, internal_counter)
264264
seed_id = bytearray(seed_id)
@@ -284,7 +284,7 @@ def copy_split_hd():
284284
new_kvs = dump_bdb_kv(node_master_wallet)
285285
hd_chain = new_kvs[b'\x07hdchain']
286286
assert_equal(32, len(hd_chain))
287-
hd_chain_version, external_counter, seed_id, internal_counter = struct.unpack('<iI20sI', hd_chain)
287+
hd_chain_version, _external_counter, seed_id, internal_counter = struct.unpack('<iI20sI', hd_chain)
288288
assert_equal(2, hd_chain_version)
289289
assert_equal(2, internal_counter)
290290
# The next addresses are HD and should be on different HD chains (the one remaining key in each pool should have been flushed)
@@ -301,8 +301,8 @@ def copy_split_hd():
301301
new_kvs = dump_bdb_kv(node_master_wallet)
302302
for k, old_v in old_kvs.items():
303303
if k.startswith(b'\x07keymeta'):
304-
new_ver, new_create_time, new_kp_str, new_seed_id, new_fpr, new_path_len, new_path, new_has_key_orig = deser_keymeta(BytesIO(new_kvs[k]))
305-
old_ver, old_create_time, old_kp_str, old_seed_id, old_fpr, old_path_len, old_path, old_has_key_orig = deser_keymeta(BytesIO(old_v))
304+
new_ver, new_create_time, new_kp_str, new_seed_id, _new_fpr, new_path_len, new_path, new_has_key_orig = deser_keymeta(BytesIO(new_kvs[k]))
305+
old_ver, old_create_time, old_kp_str, old_seed_id, _old_fpr, old_path_len, old_path, old_has_key_orig = deser_keymeta(BytesIO(old_v))
306306
assert_equal(10, old_ver)
307307
if old_kp_str == b"": # imported things that don't have keymeta (i.e. imported coinbase privkeys) won't be upgraded
308308
assert_equal(new_kvs[k], old_v)

0 commit comments

Comments
 (0)