12
12
CTxInWitness ,
13
13
CTxOut ,
14
14
WITNESS_SCALE_FACTOR ,
15
+ tx_from_hex ,
15
16
)
16
17
from test_framework .script import (
17
18
CScript ,
29
30
from test_framework .test_framework import BitcoinTestFramework
30
31
from test_framework .util import (
31
32
assert_equal ,
33
+ assert_greater_than ,
32
34
assert_greater_than_or_equal ,
33
35
)
34
36
from test_framework .wallet import MiniWallet
@@ -106,6 +108,31 @@ def test_sigops_limit(self, bytes_per_sigop, num_sigops):
106
108
assert_equal (res ['allowed' ], True )
107
109
assert_equal (res ['vsize' ], sigop_equivalent_vsize )
108
110
111
+ # check that the ancestor and descendant size calculations in the mempool
112
+ # also use the same max(sigop_equivalent_vsize, serialized_vsize) logic
113
+ # (to keep it simple, we only test the case here where the sigop vsize
114
+ # is much larger than the serialized vsize, i.e. we create a small child
115
+ # tx by getting rid of the large padding output)
116
+ tx .vout [0 ].scriptPubKey = CScript ([OP_RETURN , b'test123' ])
117
+ assert_greater_than (sigop_equivalent_vsize , tx .get_vsize ())
118
+ self .nodes [0 ].sendrawtransaction (hexstring = tx .serialize ().hex (), maxburnamount = '1.0' )
119
+
120
+ # fetch parent tx, which doesn't contain any sigops
121
+ parent_txid = tx .vin [0 ].prevout .hash .to_bytes (32 , 'big' ).hex ()
122
+ parent_tx = tx_from_hex (self .nodes [0 ].getrawtransaction (txid = parent_txid ))
123
+
124
+ entry_child = self .nodes [0 ].getmempoolentry (tx .rehash ())
125
+ assert_equal (entry_child ['descendantcount' ], 1 )
126
+ assert_equal (entry_child ['descendantsize' ], sigop_equivalent_vsize )
127
+ assert_equal (entry_child ['ancestorcount' ], 2 )
128
+ assert_equal (entry_child ['ancestorsize' ], sigop_equivalent_vsize + parent_tx .get_vsize ())
129
+
130
+ entry_parent = self .nodes [0 ].getmempoolentry (parent_tx .rehash ())
131
+ assert_equal (entry_parent ['ancestorcount' ], 1 )
132
+ assert_equal (entry_parent ['ancestorsize' ], parent_tx .get_vsize ())
133
+ assert_equal (entry_parent ['descendantcount' ], 2 )
134
+ assert_equal (entry_parent ['descendantsize' ], parent_tx .get_vsize () + sigop_equivalent_vsize )
135
+
109
136
def run_test (self ):
110
137
self .wallet = MiniWallet (self .nodes [0 ])
111
138
@@ -120,6 +147,8 @@ def run_test(self):
120
147
for num_sigops in (69 , 101 , 142 , 183 , 222 ):
121
148
self .test_sigops_limit (bytes_per_sigop , num_sigops )
122
149
150
+ self .generate (self .wallet , 1 )
151
+
123
152
124
153
if __name__ == '__main__' :
125
154
BytesPerSigOpTest ().main ()
0 commit comments