Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-compactblocks.py
Show First 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Checks the node to forward it via compact block | # Checks the node to forward it via compact block | ||||
def received_block(): | def received_block(): | ||||
return (test_p2p.last_cmpctblock != None) | return (test_p2p.last_cmpctblock != None) | ||||
wait_until(received_block, timeout=30) | wait_until(received_block, timeout=30) | ||||
# Was it our block ? | # Was it our block ? | ||||
cmpctblk_header = test_p2p.last_cmpctblock.header_and_shortids.header | cmpctblk_header = test_p2p.last_cmpctblock.header_and_shortids.header | ||||
cmpctblk_header.calc_sha256() | cmpctblk_header.calc_sha256() | ||||
assert(cmpctblk_header.sha256 == b1.sha256) | assert cmpctblk_header.sha256 == b1.sha256 | ||||
# Send a large block with numerous transactions. | # Send a large block with numerous transactions. | ||||
test_p2p.clear_block_data() | test_p2p.clear_block_data() | ||||
b2 = block(2, spend=out[1], extra_txns=70000, | b2 = block(2, spend=out[1], extra_txns=70000, | ||||
block_size=self.excessive_block_size - 1000) | block_size=self.excessive_block_size - 1000) | ||||
default_p2p.send_blocks_and_test([self.tip], node) | default_p2p.send_blocks_and_test([self.tip], node) | ||||
# Checks the node forwards it via compact block | # Checks the node forwards it via compact block | ||||
wait_until(received_block, timeout=30) | wait_until(received_block, timeout=30) | ||||
# Was it our block ? | # Was it our block ? | ||||
cmpctblk_header = test_p2p.last_cmpctblock.header_and_shortids.header | cmpctblk_header = test_p2p.last_cmpctblock.header_and_shortids.header | ||||
cmpctblk_header.calc_sha256() | cmpctblk_header.calc_sha256() | ||||
assert(cmpctblk_header.sha256 == b2.sha256) | assert cmpctblk_header.sha256 == b2.sha256 | ||||
# In order to avoid having to resend a ton of transactions, we invalidate | # In order to avoid having to resend a ton of transactions, we invalidate | ||||
# b2, which will send all its transactions in the mempool. | # b2, which will send all its transactions in the mempool. | ||||
node.invalidateblock(node.getbestblockhash()) | node.invalidateblock(node.getbestblockhash()) | ||||
# Let's send a compact block and see if the node accepts it. | # Let's send a compact block and see if the node accepts it. | ||||
# Let's modify b2 and use it so that we can reuse the mempool. | # Let's modify b2 and use it so that we can reuse the mempool. | ||||
tx = b2.vtx[0] | tx = b2.vtx[0] | ||||
tx.vout.append(CTxOut(0, CScript([random.randint(0, 256), OP_RETURN]))) | tx.vout.append(CTxOut(0, CScript([random.randint(0, 256), OP_RETURN]))) | ||||
tx.rehash() | tx.rehash() | ||||
b2.vtx[0] = tx | b2.vtx[0] = tx | ||||
b2.hashMerkleRoot = b2.calc_merkle_root() | b2.hashMerkleRoot = b2.calc_merkle_root() | ||||
b2.solve() | b2.solve() | ||||
# Now we create the compact block and send it | # Now we create the compact block and send it | ||||
comp_block = HeaderAndShortIDs() | comp_block = HeaderAndShortIDs() | ||||
comp_block.initialize_from_block(b2) | comp_block.initialize_from_block(b2) | ||||
test_p2p.send_and_ping(msg_cmpctblock(comp_block.to_p2p())) | test_p2p.send_and_ping(msg_cmpctblock(comp_block.to_p2p())) | ||||
# Check that compact block is received properly | # Check that compact block is received properly | ||||
assert(int(node.getbestblockhash(), 16) == b2.sha256) | assert int(node.getbestblockhash(), 16) == b2.sha256 | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
FullBlockTest().main() | FullBlockTest().main() |