Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-fullblocktest.py
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0, extra_sigops=0): | ||||
# We need to have something to spend to fill the block. | # We need to have something to spend to fill the block. | ||||
assert_equal(block_size, 0) | assert_equal(block_size, 0) | ||||
block = create_block(base_block_hash, coinbase, block_time) | block = create_block(base_block_hash, coinbase, block_time) | ||||
else: | else: | ||||
# all but one satoshi to fees | # all but one satoshi to fees | ||||
coinbase.vout[0].nValue += spend.tx.vout[spend.n].nValue - 1 | coinbase.vout[0].nValue += spend.tx.vout[spend.n].nValue - 1 | ||||
coinbase.rehash() | coinbase.rehash() | ||||
block = create_block(base_block_hash, coinbase, block_time) | block = create_block(base_block_hash, coinbase, block_time) | ||||
# spend 1 satoshi | |||||
tx = CTransaction() | |||||
tx.vin.append(CTxIn(COutPoint(spend.tx.sha256, spend.n))) | |||||
# Make sure we have plenty engough to spend going forward. | # Make sure we have plenty engough to spend going forward. | ||||
spendable_outputs = deque([]) | spendable_outputs = deque([spend]) | ||||
def add_spendable_outputs(tx): | def get_base_transaction(): | ||||
for i in range(8): | # Create the new transaction | ||||
tx = CTransaction() | |||||
# Spend from one of the spendable outputs | |||||
spend = spendable_outputs.popleft() | |||||
tx.vin.append(CTxIn(COutPoint(spend.tx.sha256, spend.n))) | |||||
# Add spendable outputs | |||||
for i in range(4): | |||||
tx.vout.append(CTxOut(0, CScript([OP_TRUE]))) | tx.vout.append(CTxOut(0, CScript([OP_TRUE]))) | ||||
spendable_outputs.append(PreviousSpendableOutput(tx, i)) | spendable_outputs.append(PreviousSpendableOutput(tx, i)) | ||||
add_spendable_outputs(tx) | return tx | ||||
tx = get_base_transaction() | |||||
# Make it the same format as transaction added for padding and save the size. | # Make it the same format as transaction added for padding and save the size. | ||||
# It's missing the padding output, so we add a constant to account for it. | # It's missing the padding output, so we add a constant to account for it. | ||||
tx.rehash() | tx.rehash() | ||||
base_tx_size = len(tx.serialize()) + 18 | base_tx_size = len(tx.serialize()) + 18 | ||||
# If a specific script is required, add it. | # If a specific script is required, add it. | ||||
if script != None: | if script != None: | ||||
Show All 12 Lines | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0, extra_sigops=0): | ||||
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. | ||||
current_block_size -= len(ser_compact_size(len(block.vtx))) | current_block_size -= len(ser_compact_size(len(block.vtx))) | ||||
current_block_size += len(ser_compact_size(len(block.vtx) + 1)) | current_block_size += len(ser_compact_size(len(block.vtx) + 1)) | ||||
# Create the new transaction | # Create the new transaction | ||||
tx = CTransaction() | tx = get_base_transaction() | ||||
# Spend from one of the spendable outputs | |||||
spend = spendable_outputs.popleft() | |||||
tx.vin.append(CTxIn(COutPoint(spend.tx.sha256, spend.n))) | |||||
# Add spendable outputs | |||||
add_spendable_outputs(tx) | |||||
# Add padding to fill the block. | # Add padding to fill the block. | ||||
script_length = block_size - current_block_size - base_tx_size | script_length = block_size - current_block_size - base_tx_size | ||||
if script_length > 510000: | if script_length > 510000: | ||||
if script_length < 1000000: | |||||
# Make sure we don't find ourselves in a position where we | |||||
# need to generate a transaction smaller than what we expected. | |||||
script_length = script_length // 2 | |||||
else: | |||||
script_length = 500000 | script_length = 500000 | ||||
tx_sigops = min(extra_sigops, script_length, | tx_sigops = min(extra_sigops, script_length, | ||||
MAX_TX_SIGOPS_COUNT) | MAX_TX_SIGOPS_COUNT) | ||||
extra_sigops -= tx_sigops | extra_sigops -= tx_sigops | ||||
script_pad_len = script_length - tx_sigops | script_pad_len = script_length - tx_sigops | ||||
script_output = CScript( | script_output = CScript( | ||||
[b'\x00' * script_pad_len] + [OP_CHECKSIG] * tx_sigops) | [b'\x00' * script_pad_len] + [OP_CHECKSIG] * tx_sigops) | ||||
tx.vout.append(CTxOut(0, script_output)) | tx.vout.append(CTxOut(0, script_output)) | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |