Skip to content

Commit

Permalink
scripted-diff: Remove redundant sync_all and sync_blocks
Browse files Browse the repository at this point in the history
The sync calls are redundant after a call to generate, because generate
already syncs itself.

-BEGIN VERIFY SCRIPT-
perl -0777 -pi -e 's/(generate[^\n]*\)[^\n]*)(\n|\s)+self.sync_(all|blocks)\([^\)]*\)\n/\1\n/g' $(git grep -l generate ./test)
-END VERIFY SCRIPT-
  • Loading branch information
MarcoFalke committed Nov 10, 2021
1 parent fad1399 commit fa974f1
Show file tree
Hide file tree
Showing 47 changed files with 0 additions and 160 deletions.
4 changes: 0 additions & 4 deletions test/functional/feature_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ def setup_nodes(self):
def run_test(self):
self.generatetoaddress(self.nodes[0], COINBASE_MATURITY + 1, self.nodes[0].getnewaddress())

self.sync_blocks()

# Sanity check the test framework:
res = self.nodes[self.num_nodes - 1].getblockchaininfo()
assert_equal(res['blocks'], COINBASE_MATURITY + 1)
Expand All @@ -93,15 +91,13 @@ def run_test(self):
self.nodes[0].sendtoaddress(address, 10)
self.sync_mempools()
self.generate(self.nodes[0], 1)
self.sync_blocks()
# Create a conflicting transaction using RBF
return_address = self.nodes[0].getnewaddress()
tx1_id = self.nodes[1].sendtoaddress(return_address, 1)
tx2_id = self.nodes[1].bumpfee(tx1_id)["txid"]
# Confirm the transaction
self.sync_mempools()
self.generate(self.nodes[0], 1)
self.sync_blocks()
# Create another conflicting transaction using RBF
tx3_id = self.nodes[1].sendtoaddress(return_address, 1)
tx4_id = self.nodes[1].bumpfee(tx3_id)["txid"]
Expand Down
2 changes: 0 additions & 2 deletions test/functional/feature_blockfilterindex_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def run_test(self):
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
# Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection
self.generate(self.nodes[0], 250)
self.sync_all()
self.generate(self.nodes[0], 250)
self.sync_all()
self.sync_index(height=700)

self.log.info("prune some blocks")
Expand Down
4 changes: 0 additions & 4 deletions test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def _test_coin_stats_index(self):
node.sendtoaddress(address=address, amount=10, subtractfeefromamount=True)
self.generate(node, 1)

self.sync_blocks(timeout=120)

self.log.info("Test that gettxoutsetinfo() output is consistent with or without coinstatsindex option")
res0 = node.gettxoutsetinfo('none')

Expand Down Expand Up @@ -170,7 +168,6 @@ def _test_coin_stats_index(self):

# Include both txs in a block
self.generate(self.nodes[0], 1)
self.sync_all()

for hash_option in index_hash_options:
# Check all amounts were registered correctly
Expand Down Expand Up @@ -271,7 +268,6 @@ def _test_reorg_index(self):
# Add another block, so we don't depend on reconsiderblock remembering which
# blocks were touched by invalidateblock
self.generate(index_node, 1)
self.sync_all()

# Ensure that removing and re-adding blocks yields consistent results
block = index_node.getblockhash(99)
Expand Down
5 changes: 0 additions & 5 deletions test/functional/feature_fee_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ def transact_and_mine(self, numblocks, mining_node):
self.fees_per_kb.append(float(fee) / tx_kbytes)
self.sync_mempools(wait=.1)
mined = mining_node.getblock(self.generate(mining_node, 1)[0], True)["tx"]
self.sync_blocks(wait=.1)
# update which txouts are confirmed
newmem = []
for utx in self.memutxo:
Expand Down Expand Up @@ -278,8 +277,6 @@ def sanity_check_estimates_range(self):
# Finish by mining a normal-sized block:
while len(self.nodes[1].getrawmempool()) > 0:
self.generate(self.nodes[1], 1)

self.sync_blocks(self.nodes[0:3], wait=.1)
self.log.info("Final estimates after emptying mempools")
check_estimates(self.nodes[1], self.fees_per_kb)

Expand Down Expand Up @@ -322,7 +319,6 @@ def sanity_check_rbf_estimates(self, utxos):
for txid in txids_to_replace:
miner.prioritisetransaction(txid=txid, fee_delta=-COIN)
self.generate(miner, 1)
self.sync_blocks(wait=.1, nodes=[node, miner])
# RBF the low-fee transactions
while True:
try:
Expand All @@ -334,7 +330,6 @@ def sanity_check_rbf_estimates(self, utxos):
# Mine the last replacement txs
self.sync_mempools(wait=.1, nodes=[node, miner])
self.generate(miner, 1)
self.sync_blocks(wait=.1, nodes=[node, miner])

# Only 10% of the transactions were really confirmed with a low feerate,
# the rest needed to be RBF'd. We must return the 90% conf rate feerate.
Expand Down
1 change: 0 additions & 1 deletion test/functional/feature_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def run_test(self):
self.log.info("test -walletnotify with conflicting transactions")
self.nodes[0].rescanblockchain()
self.generatetoaddress(self.nodes[0], 100, ADDRESS_BCRT1_UNSPENDABLE)
self.sync_blocks()

# Generate transaction on node 0, sync mempools, and check for
# notification on node 1.
Expand Down
5 changes: 0 additions & 5 deletions test/functional/feature_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,13 @@ def run_test(self):
p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999")))

self.generate(self.nodes[0], 1) # block 163
self.sync_blocks()

# Make sure all nodes recognize the transactions as theirs
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60 * 50 + 20 * Decimal("49.999") + 50)
assert_equal(self.nodes[1].getbalance(), 20 * Decimal("49.999"))
assert_equal(self.nodes[2].getbalance(), 20 * Decimal("49.999"))

self.generate(self.nodes[0], 260) # block 423
self.sync_blocks()

self.log.info("Verify witness txs are skipped for mining before the fork")
self.skip_mine(self.nodes[2], wit_ids[NODE_2][P2WPKH][0], True) # block 424
Expand All @@ -216,7 +214,6 @@ def run_test(self):
self.log.info("Verify previous witness txs skipped for mining can now be mined")
assert_equal(len(self.nodes[2].getrawmempool()), 4)
blockhash = self.generate(self.nodes[2], 1)[0] # block 432 (first block with new rules; 432 = 144 * 3)
self.sync_blocks()
assert_equal(len(self.nodes[2].getrawmempool()), 0)
segwit_tx_list = self.nodes[2].getblock(blockhash)["tx"]
assert_equal(len(segwit_tx_list), 5)
Expand Down Expand Up @@ -630,7 +627,6 @@ def mine_and_test_listunspent(self, script_list, ismine):
signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex']
txid = self.nodes[0].sendrawtransaction(hexstring=signresults, maxfeerate=0)
txs_mined[txid] = self.generate(self.nodes[0], 1)[0]
self.sync_blocks()
watchcount = 0
spendcount = 0
for i in self.nodes[0].listunspent():
Expand Down Expand Up @@ -680,7 +676,6 @@ def create_and_mine_tx_from_txids(self, txids, success=True):
signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex']
self.nodes[0].sendrawtransaction(hexstring=signresults, maxfeerate=0)
self.generate(self.nodes[0], 1)
self.sync_blocks()


if __name__ == '__main__':
Expand Down
7 changes: 0 additions & 7 deletions test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def run_test(self):
not_related_address = "2MxqoHEdNQTyYeX1mHcbrrpzgojbosTpCvJ"

self.generate(self.nodes[0], 1)
self.sync_all()
self.generatetoaddress(self.nodes[1], 100, not_related_address)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 50)

Expand All @@ -108,7 +106,6 @@ def run_test(self):
self.log.info("Query an unspent TXO using the /getutxos URI")

self.generatetoaddress(self.nodes[1], 1, not_related_address)
self.sync_all()
bb_hash = self.nodes[0].getbestblockhash()

assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))
Expand Down Expand Up @@ -183,7 +180,6 @@ def run_test(self):
assert_equal(len(json_obj['utxos']), 0)

self.generate(self.nodes[0], 1)
self.sync_all()

json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}")
assert_equal(len(json_obj['utxos']), 1)
Expand All @@ -204,7 +200,6 @@ def run_test(self):
self.test_rest_request(f"/getutxos/checkmempool/{long_uri}", http_method='POST', status=200)

self.generate(self.nodes[0], 1) # generate block to not affect upcoming tests
self.sync_all()

self.log.info("Test the /block, /blockhashbyheight and /headers URIs")
bb_hash = self.nodes[0].getbestblockhash()
Expand Down Expand Up @@ -275,7 +270,6 @@ def run_test(self):

# See if we can get 5 headers in one response
self.generate(self.nodes[1], 5)
self.sync_all()
json_obj = self.test_rest_request(f"/headers/5/{bb_hash}")
assert_equal(len(json_obj), 5) # now we should have 5 header objects

Expand Down Expand Up @@ -310,7 +304,6 @@ def run_test(self):

# Now mine the transactions
newblockhash = self.generate(self.nodes[1], 1)
self.sync_all()

# Check if the 3 tx show up in the new block
json_obj = self.test_rest_request(f"/block/{newblockhash[0]}")
Expand Down
4 changes: 0 additions & 4 deletions test/functional/interface_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ def test_basic(self):
self.log.info(f"Generate {num_blocks} blocks (and {num_blocks} coinbase txes)")
genhashes = self.generatetoaddress(self.nodes[0], num_blocks, ADDRESS_BCRT1_UNSPENDABLE)

self.sync_all()

for x in range(num_blocks):
# Should receive the coinbase txid.
txid = hashtx.receive()
Expand Down Expand Up @@ -353,7 +351,6 @@ def test_sequence(self):
# removed from the mempool by the block mining it.
mempool_size = len(self.nodes[0].getrawmempool())
c_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0]
self.sync_all()
# Make sure the number of mined transactions matches the number of txs out of mempool
mempool_size_delta = mempool_size - len(self.nodes[0].getrawmempool())
assert_equal(len(self.nodes[0].getblock(c_block)["tx"])-1, mempool_size_delta)
Expand Down Expand Up @@ -393,7 +390,6 @@ def test_sequence(self):
# Other things may happen but aren't wallet-deterministic so we don't test for them currently
self.nodes[0].reconsiderblock(best_hash)
self.generatetoaddress(self.nodes[1], 1, ADDRESS_BCRT1_UNSPENDABLE)
self.sync_all()

self.log.info("Evict mempool transaction by block conflict")
orig_txid = self.nodes[0].sendtoaddress(address=self.nodes[0].getnewaddress(), amount=1.0, replaceable=True)
Expand Down
3 changes: 0 additions & 3 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def run_test(self):
# Check that prioritising a tx before it's added to the mempool works
# First clear the mempool by mining a block.
self.generate(self.nodes[0], 1)
self.sync_blocks()
assert_equal(len(self.nodes[0].getrawmempool()), 0)
# Prioritise a transaction that has been mined, then add it back to the
# mempool by using invalidateblock.
Expand Down Expand Up @@ -283,7 +282,6 @@ def run_test(self):
# Test reorg handling
# First, the basics:
self.generate(self.nodes[0], 1)
self.sync_blocks()
self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash())
self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash())

Expand Down Expand Up @@ -330,7 +328,6 @@ def run_test(self):

# Mine these in a block
self.generate(self.nodes[0], 1)
self.sync_all()

# Now generate tx8, with a big fee
inputs = [ {'txid' : tx1_id, 'vout': 0}, {'txid' : txid, 'vout': 0} ]
Expand Down
1 change: 0 additions & 1 deletion test/functional/mining_getblocktemplate_longpoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def run_test(self):

# Add enough mature utxos to the wallets, so that all txs spend confirmed coins
self.generate(self.nodes[0], COINBASE_MATURITY)
self.sync_blocks()

self.log.info("Test that introducing a new transaction into the mempool will terminate the longpoll")
thr = LongpollThread(self.nodes[0])
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_blockfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def run_test(self):

# Nodes 0 & 1 share the same first 999 blocks in the chain.
self.generate(self.nodes[0], 999)
self.sync_blocks(timeout=600)

# Stale blocks by disconnecting nodes 0 & 1, mining, then reconnecting
self.disconnect_nodes(0, 1)
Expand Down
2 changes: 0 additions & 2 deletions test/functional/p2p_compactblocks_hb.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def relay_block_through(self, peer):
"""Relay a new block through peer peer, and return HB status between 1 and [2,3,4,5]."""
self.connect_nodes(peer, 0)
self.generate(self.nodes[0], 1)
self.sync_blocks()
self.disconnect_nodes(peer, 0)
status_to = [self.peer_info(1, i)['bip152_hb_to'] for i in range(2, 6)]
status_from = [self.peer_info(i, 1)['bip152_hb_from'] for i in range(2, 6)]
Expand All @@ -45,7 +44,6 @@ def run_test(self):
for i in range(1, 6):
self.connect_nodes(i, 0)
self.generate(self.nodes[0], 2)
self.sync_blocks()
for i in range(1, 6):
self.disconnect_nodes(i, 0)

Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_ibd_txrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def run_test(self):

# Come out of IBD by generating a block
self.generate(self.nodes[0], 1)
self.sync_all()

self.log.info("Check that nodes reset minfilter after coming out of IBD")
for node in self.nodes:
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def run_test(self):

def check_tx_relay(self):
block_op_true = self.nodes[0].getblock(self.generatetoaddress(self.nodes[0], 100, ADDRESS_BCRT1_P2WSH_OP_TRUE)[0])
self.sync_all()

self.log.debug("Create a connection from a forcerelay peer that rebroadcasts raw txs")
# A test framework p2p connection is needed to send the raw transaction directly. If a full node was used, it could only
Expand Down
7 changes: 0 additions & 7 deletions test/functional/p2p_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ def test_standardness_v0(self):
# Mine it on test_node to create the confirmed output.
test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_tx, with_witness=True, accepted=True)
self.generate(self.nodes[0], 1)
self.sync_blocks()

# Now test standardness of v0 P2WSH outputs.
# Start by creating a transaction with two outputs.
Expand Down Expand Up @@ -651,7 +650,6 @@ def test_standardness_v0(self):
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True)

self.generate(self.nodes[0], 1)
self.sync_blocks()
self.utxo.pop(0)
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
assert_equal(len(self.nodes[1].getrawmempool()), 0)
Expand Down Expand Up @@ -1354,7 +1352,6 @@ def test_segwit_versions(self):
temp_utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue))

self.generate(self.nodes[0], 1) # Mine all the transactions
self.sync_blocks()
assert len(self.nodes[0].getrawmempool()) == 0

# Finally, verify that version 0 -> version 2 transactions
Expand Down Expand Up @@ -1425,7 +1422,6 @@ def test_premature_coinbase_witness_spend(self):

# Now test a premature spend.
self.generate(self.nodes[0], 98)
self.sync_blocks()
block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx])
test_witness_block(self.nodes[0], self.test_node, block2, accepted=False, reason='bad-txns-premature-spend-of-coinbase')
Expand Down Expand Up @@ -1744,7 +1740,6 @@ def test_non_standard_witness_blinding(self):
tx.rehash()
test_transaction_acceptance(self.nodes[0], self.test_node, tx, False, True)
self.generate(self.nodes[0], 1)
self.sync_blocks()

# We'll add an unnecessary witness to this transaction that would cause
# it to be non-standard, to test that violating policy with a witness
Expand Down Expand Up @@ -1773,7 +1768,6 @@ def test_non_standard_witness_blinding(self):
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, False, True)

self.generate(self.nodes[0], 1)
self.sync_blocks()

# Update our utxo list; we spent the first entry.
self.utxo.pop(0)
Expand Down Expand Up @@ -1808,7 +1802,6 @@ def test_non_standard_witness(self):
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)

self.generate(self.nodes[0], 1)
self.sync_blocks()

# Creating transactions for tests
p2wsh_txs = []
Expand Down
2 changes: 0 additions & 2 deletions test/functional/p2p_sendheaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ def mine_reorg(self, length):

# make sure all invalidated blocks are node0's
self.generatetoaddress(self.nodes[0], length, self.nodes[0].get_deterministic_priv_key().address)
self.sync_blocks(self.nodes, wait=0.1)
for x in self.nodes[0].p2ps:
x.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16))
x.clear_block_announcements()
Expand All @@ -226,7 +225,6 @@ def mine_reorg(self, length):
hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1))
self.nodes[1].invalidateblock(hash_to_invalidate)
all_hashes = self.generatetoaddress(self.nodes[1], length + 1, self.nodes[1].get_deterministic_priv_key().address) # Must be longer than the orig chain
self.sync_blocks(self.nodes, wait=0.1)
return [int(x, 16) for x in all_hashes]

def run_test(self):
Expand Down
2 changes: 0 additions & 2 deletions test/functional/rpc_createmultisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def run_test(self):

self.log.info('Generating blocks ...')
self.generate(node0, 149)
self.sync_all()

self.moved = 0
for self.nkeys in [3, 5]:
Expand Down Expand Up @@ -117,7 +116,6 @@ def check_addmultisigaddress_errors(self):
def checkbalances(self):
node0, node1, node2 = self.nodes
self.generate(node0, COINBASE_MATURITY)
self.sync_all()

bal0 = node0.getbalance()
bal1 = node1.getbalance()
Expand Down
Loading

0 comments on commit fa974f1

Please sign in to comment.