Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-compactblocks.py
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.test = TestManager(self, self.options.tmpdir) | self.test = TestManager(self, self.options.tmpdir) | ||||
self.test.add_all_connections(self.nodes) | self.test.add_all_connections(self.nodes) | ||||
# Start up network handling in another thread | # Start up network handling in another thread | ||||
NetworkThread().start() | NetworkThread().start() | ||||
# Set the blocksize to 2MB as initial condition | # Set the blocksize to 2MB as initial condition | ||||
self.nodes[0].setexcessiveblock(self.excessive_block_size) | self.nodes[0].setexcessiveblock(self.excessive_block_size) | ||||
self.test.run() | self.test.run() | ||||
def add_transactions_to_block(self, block, tx_list): | |||||
[tx.rehash() for tx in tx_list] | |||||
block.vtx.extend(tx_list) | |||||
# this is a little handier to use than the version in blocktools.py | # this is a little handier to use than the version in blocktools.py | ||||
def create_tx(self, spend_tx, n, value, script=CScript([OP_TRUE])): | def create_tx(self, spend_tx, n, value, script=CScript([OP_TRUE])): | ||||
tx = create_transaction(spend_tx, n, b"", value, script) | tx = create_transaction(spend_tx, n, b"", value, script) | ||||
return tx | return tx | ||||
def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0, extra_txns=0): | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0, extra_txns=0): | ||||
assert number not in self.blocks | assert number not in self.blocks | ||||
if self.tip == None: | if self.tip == None: | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0, extra_txns=0): | ||||
if script != None: | if script != None: | ||||
tx.vout.append(CTxOut(1, script)) | tx.vout.append(CTxOut(1, script)) | ||||
# Put some random data into the first transaction of the chain to randomize ids. | # Put some random data into the first transaction of the chain to randomize ids. | ||||
tx.vout.append( | tx.vout.append( | ||||
CTxOut(0, CScript([random.randint(0, 256), OP_RETURN]))) | CTxOut(0, CScript([random.randint(0, 256), OP_RETURN]))) | ||||
# Add the transaction to the block | # Add the transaction to the block | ||||
self.add_transactions_to_block(block, [tx]) | block.vtx.append(tx) | ||||
# Add transaction until we reach the expected transaction count | # Add transaction until we reach the expected transaction count | ||||
for _ in range(extra_txns): | block.vtx.extend([get_base_transaction() | ||||
self.add_transactions_to_block(block, [get_base_transaction()]) | for _ in range(extra_txns)]) | ||||
# If we have a block size requirement, just fill | # If we have a block size requirement, just fill | ||||
# the block until we get there | # the block until we get there | ||||
current_block_size = len(block.serialize()) | current_block_size = len(block.serialize()) | ||||
while current_block_size < block_size: | while current_block_size < block_size: | ||||
# We will add a new transaction. That means the size of | # We will add a new transaction. That means the size of | ||||
# the field enumerating how many transaction go in the block | # the field enumerating how many transaction go in the block | ||||
# may change. | # may change. | ||||
Show All 12 Lines | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0, extra_txns=0): | ||||
script_length = script_length // 2 | script_length = script_length // 2 | ||||
else: | else: | ||||
script_length = 500000 | script_length = 500000 | ||||
script_output = CScript([b'\x00' * script_length]) | script_output = CScript([b'\x00' * script_length]) | ||||
tx.vout.append(CTxOut(0, script_output)) | tx.vout.append(CTxOut(0, script_output)) | ||||
# Add the tx to the list of transactions to be included | # Add the tx to the list of transactions to be included | ||||
# in the block. | # in the block. | ||||
self.add_transactions_to_block(block, [tx]) | block.vtx.append(tx) | ||||
current_block_size += len(tx.serialize()) | current_block_size += len(tx.serialize()) | ||||
# Now that we added a bunch of transaction, we need to recompute | # Now that we added a bunch of transaction, we need to recompute | ||||
# the merkle root. | # the merkle root. | ||||
make_conform_to_ctor(block) | make_conform_to_ctor(block) | ||||
block.hashMerkleRoot = block.calc_merkle_root() | block.hashMerkleRoot = block.calc_merkle_root() | ||||
# Check that the block size is what's expected | # Check that the block size is what's expected | ||||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |