Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-transaction-ordering.py
Show First 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
block(5100 + i) | block(5100 + i) | ||||
test.blocks_and_transactions.append([self.tip, True]) | test.blocks_and_transactions.append([self.tip, True]) | ||||
yield test | yield test | ||||
# Check that the MTP is just before the configured fork point. | # Check that the MTP is just before the configured fork point. | ||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | ||||
MAGNETIC_ANOMALY_START_TIME - 1) | MAGNETIC_ANOMALY_START_TIME - 1) | ||||
# Before we activate the Nov 15, 2018 HF, transaction order is respected. | |||||
def ordered_block(block_number, spend): | |||||
b = block(block_number, spend=spend, tx_count=16) | |||||
b.vtx = [b.vtx[0]] + sorted(b.vtx[1:], key=lambda tx: tx.get_id()) | |||||
update_block(block_number) | |||||
return b | |||||
ordered_block(4444, out[16]) | |||||
yield rejected(RejectResult(16, b'bad-txns-inputs-missingorspent')) | |||||
# Rewind bad block. | |||||
tip(5104) | |||||
# Activate the Nov 15, 2018 HF | # Activate the Nov 15, 2018 HF | ||||
block(5556, out[16], tx_count=16) | block(5556, out[16], tx_count=16) | ||||
yield accepted() | yield accepted() | ||||
# Now MTP is exactly the fork time. Transactions are expected to be ordered now. | # Now MTP is exactly the fork time. Transactions are expected to be ordered now. | ||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | ||||
MAGNETIC_ANOMALY_START_TIME) | MAGNETIC_ANOMALY_START_TIME) | ||||
# Block with regular ordering are now rejected. | # Block with regular ordering are now rejected. | ||||
block(5557, out[17], tx_count=16) | block(5557, out[17], tx_count=16) | ||||
yield rejected(RejectResult(16, b'tx-ordering')) | yield rejected(RejectResult(16, b'tx-ordering')) | ||||
# Rewind bad block. | # Rewind bad block. | ||||
tip(5556) | tip(5556) | ||||
# After we activate the Nov 15, 2018 HF, transaction order is enforced. | |||||
def ordered_block(block_number, spend): | |||||
b = block(block_number, spend=spend, tx_count=16) | |||||
b.vtx = [b.vtx[0]] + sorted(b.vtx[1:], key=lambda tx: tx.get_id()) | |||||
update_block(block_number) | |||||
return b | |||||
# Now that the fork activated, we need to order transaction per txid. | # Now that the fork activated, we need to order transaction per txid. | ||||
ordered_block(4445, out[17]) | ordered_block(4445, out[17]) | ||||
yield accepted() | yield accepted() | ||||
# Invalidate the best block and make sure we are back at the fork point. | # Invalidate the best block and make sure we are back at the fork point. | ||||
ctorblockhash = node.getbestblockhash() | ctorblockhash = node.getbestblockhash() | ||||
node.invalidateblock(ctorblockhash) | node.invalidateblock(ctorblockhash) | ||||
forkblockhash = node.getbestblockhash() | forkblockhash = node.getbestblockhash() | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |