mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #17108: test: fix "tx-size-small" errors after default address change
32d665c2657793c8b2cc7248d26d80a940acfe20 test: fix "tx-size-small" errors after default address change (Sebastian Falbesoner)
Pull request description:
Addresses #17043, affects RBF and BIP68 functional tests.
The "tx-size-small" policy rule rejects transactions with a non-witness size of
smaller than 82 bytes (see `src/validation.cpp:MemPoolAccept::PreChecks(...)`),
which corresponds to a transaction with 1 segwit input and 1 P2WPKH output.
Through the default address change, the created test transactions have segwit
inputs now and sending to short scriptPubKeys might violate this rule. By
bumping the dummy scriptPubKey size to 22 bytes (= the size of a P2WPKH
scriptPubKey), on all occurences the problem is solved.
The dummy scriptPubKey has the format:
```21 <21-byte-long string of 'a' or 1s>```
ACKs for top commit:
instagibbs:
reACK 32d665c265
just s/Bytes/bytes/
MarcoFalke:
ACK 32d665c2657793c8b2cc7248d26d80a940acfe20
Tree-SHA512: 80e0386ff3c3f462901ba5c1e5ef2cbf095d9c0a40c8c3cfeacd4a3ab676afe744aa95b9eed77b4b3eec88bed930b33aa718117ed0977f6374e858a2f3bd5c57
This commit is contained in:
parent
b71e6fd8b6
commit
5ab7f9074f
@ -6,9 +6,15 @@
|
||||
|
||||
from test_framework.blocktools import create_block, create_coinbase
|
||||
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, ToHex
|
||||
from test_framework.script import CScript
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, get_bip9_status, satoshi_round
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_greater_than,
|
||||
assert_raises_rpc_error,
|
||||
get_bip9_status,
|
||||
satoshi_round
|
||||
)
|
||||
from test_framework.script_util import DUMMY_P2SH_SCRIPT
|
||||
|
||||
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
|
||||
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)
|
||||
@ -76,7 +82,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
# input to mature.
|
||||
sequence_value = SEQUENCE_LOCKTIME_DISABLE_FLAG | 1
|
||||
tx1.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=sequence_value)]
|
||||
tx1.vout = [CTxOut(value, CScript([b'a']))]
|
||||
tx1.vout = [CTxOut(value, DUMMY_P2SH_SCRIPT)]
|
||||
|
||||
tx1_signed = self.nodes[0].signrawtransactionwithwallet(ToHex(tx1))["hex"]
|
||||
tx1_id = self.nodes[0].sendrawtransaction(tx1_signed)
|
||||
@ -88,7 +94,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx2.nVersion = 2
|
||||
sequence_value = sequence_value & 0x7fffffff
|
||||
tx2.vin = [CTxIn(COutPoint(tx1_id, 0), nSequence=sequence_value)]
|
||||
tx2.vout = [CTxOut(int(value - self.relayfee * COIN), CScript([b'a' * 35]))]
|
||||
tx2.vout = [CTxOut(int(value - self.relayfee * COIN), DUMMY_P2SH_SCRIPT)]
|
||||
tx2.rehash()
|
||||
|
||||
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2))
|
||||
@ -183,7 +189,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
value += utxos[j]["amount"]*COIN
|
||||
# Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output
|
||||
tx_size = len(ToHex(tx))//2 + 120*num_inputs + 50
|
||||
tx.vout.append(CTxOut(int(value-self.relayfee*tx_size*COIN/1000), CScript([b'a'])))
|
||||
tx.vout.append(CTxOut(int(value-self.relayfee*tx_size*COIN/1000), DUMMY_P2SH_SCRIPT))
|
||||
rawtx = self.nodes[0].signrawtransactionwithwallet(ToHex(tx))["hex"]
|
||||
|
||||
if (using_sequence_locks and not should_pass):
|
||||
@ -212,7 +218,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx2 = CTransaction()
|
||||
tx2.nVersion = 2
|
||||
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
|
||||
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))]
|
||||
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), DUMMY_P2SH_SCRIPT)]
|
||||
tx2_raw = self.nodes[0].signrawtransactionwithwallet(ToHex(tx2))["hex"]
|
||||
tx2 = FromHex(tx2, tx2_raw)
|
||||
tx2.rehash()
|
||||
@ -230,7 +236,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = 2
|
||||
tx.vin = [CTxIn(COutPoint(orig_tx.sha256, 0), nSequence=sequence_value)]
|
||||
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), CScript([b'a' * 35]))]
|
||||
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), DUMMY_P2SH_SCRIPT)]
|
||||
tx.rehash()
|
||||
|
||||
if (orig_tx.hash in node.getrawmempool()):
|
||||
@ -343,7 +349,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx2 = CTransaction()
|
||||
tx2.nVersion = 1
|
||||
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
|
||||
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))]
|
||||
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), DUMMY_P2SH_SCRIPT)]
|
||||
|
||||
# sign tx2
|
||||
tx2_raw = self.nodes[0].signrawtransactionwithwallet(ToHex(tx2))["hex"]
|
||||
@ -358,7 +364,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx3 = CTransaction()
|
||||
tx3.nVersion = 2
|
||||
tx3.vin = [CTxIn(COutPoint(tx2.sha256, 0), nSequence=sequence_value)]
|
||||
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), CScript([b'a' * 35]))]
|
||||
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), DUMMY_P2SH_SCRIPT)]
|
||||
tx3.rehash()
|
||||
|
||||
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3))
|
||||
|
25
test/functional/test_framework/script_util.py
Executable file
25
test/functional/test_framework/script_util.py
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2019 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Useful Script constants and utils."""
|
||||
from test_framework.script import CScript
|
||||
|
||||
# To prevent a "tx-size-small" policy rule error, a transaction has to have a
|
||||
# size of at least 83 bytes (MIN_STANDARD_TX_SIZE in
|
||||
# src/policy/policy.h). Considering a Tx with the smallest possible single
|
||||
# input (blank, empty scriptSig), and with an output omitting the scriptPubKey,
|
||||
# we get to a minimum size of 60 bytes:
|
||||
#
|
||||
# Tx Skeleton: 4 [Version] + 1 [InCount] + 1 [OutCount] + 4 [LockTime] = 10 bytes
|
||||
# Blank Input: 32 [PrevTxHash] + 4 [Index] + 1 [scriptSigLen] + 4 [SeqNo] = 41 bytes
|
||||
# Output: 8 [Amount] + 1 [scriptPubKeyLen] = 9 bytes
|
||||
#
|
||||
# Hence, the scriptPubKey of the single output has to have a size of at
|
||||
# least 23 bytes, which corresponds to the size of a P2SH scriptPubKey.
|
||||
# The following script constant consists of a single push of 22 bytes of 'a':
|
||||
# <PUSH_22> <22-bytes of 'a'>
|
||||
# resulting in a 23-byte size. It should be used whenever (small) fake
|
||||
# scriptPubKeys are needed, to guarantee that the minimum transaction size is
|
||||
# met.
|
||||
DUMMY_P2SH_SCRIPT = CScript([b'a' * 22])
|
Loading…
Reference in New Issue
Block a user