@@ -47,14 +47,18 @@ def run_test(self):
47
47
value = sent_value
48
48
chain .append (txid )
49
49
50
- # Check mempool has MAX_ANCESTORS transactions in it, and descendant
50
+ # Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
51
51
# count and fees should look correct
52
52
mempool = self .nodes [0 ].getrawmempool (True )
53
53
assert_equal (len (mempool ), MAX_ANCESTORS )
54
54
descendant_count = 1
55
55
descendant_fees = 0
56
56
descendant_size = 0
57
57
58
+ ancestor_size = sum ([mempool [tx ]['size' ] for tx in mempool ])
59
+ ancestor_count = MAX_ANCESTORS
60
+ ancestor_fees = sum ([mempool [tx ]['fee' ] for tx in mempool ])
61
+
58
62
descendants = []
59
63
ancestors = list (chain )
60
64
for x in reversed (chain ):
@@ -71,14 +75,43 @@ def run_test(self):
71
75
assert_equal (mempool [x ]['descendantsize' ], descendant_size )
72
76
descendant_count += 1
73
77
78
+ # Check that ancestor calculations are correct
79
+ assert_equal (mempool [x ]['ancestorcount' ], ancestor_count )
80
+ assert_equal (mempool [x ]['ancestorfees' ], ancestor_fees * COIN )
81
+ assert_equal (mempool [x ]['ancestorsize' ], ancestor_size )
82
+ ancestor_size -= mempool [x ]['size' ]
83
+ ancestor_fees -= mempool [x ]['fee' ]
84
+ ancestor_count -= 1
85
+
86
+ # Check that parent/child list is correct
87
+ assert_equal (mempool [x ]['spentby' ], descendants [- 1 :])
88
+ assert_equal (mempool [x ]['depends' ], ancestors [- 2 :- 1 ])
89
+
74
90
# Check that getmempooldescendants is correct
75
91
assert_equal (sorted (descendants ), sorted (self .nodes [0 ].getmempooldescendants (x )))
92
+
93
+ # Check getmempooldescendants verbose output is correct
94
+ for descendant , dinfo in self .nodes [0 ].getmempooldescendants (x , True ).items ():
95
+ assert_equal (dinfo ['depends' ], [chain [chain .index (descendant )- 1 ]])
96
+ if dinfo ['descendantcount' ] > 1 :
97
+ assert_equal (dinfo ['spentby' ], [chain [chain .index (descendant )+ 1 ]])
98
+ else :
99
+ assert_equal (dinfo ['spentby' ], [])
76
100
descendants .append (x )
77
101
78
102
# Check that getmempoolancestors is correct
79
103
ancestors .remove (x )
80
104
assert_equal (sorted (ancestors ), sorted (self .nodes [0 ].getmempoolancestors (x )))
81
105
106
+ # Check that getmempoolancestors verbose output is correct
107
+ for ancestor , ainfo in self .nodes [0 ].getmempoolancestors (x , True ).items ():
108
+ assert_equal (ainfo ['spentby' ], [chain [chain .index (ancestor )+ 1 ]])
109
+ if ainfo ['ancestorcount' ] > 1 :
110
+ assert_equal (ainfo ['depends' ], [chain [chain .index (ancestor )- 1 ]])
111
+ else :
112
+ assert_equal (ainfo ['depends' ], [])
113
+
114
+
82
115
# Check that getmempoolancestors/getmempooldescendants correctly handle verbose=true
83
116
v_ancestors = self .nodes [0 ].getmempoolancestors (chain [- 1 ], True )
84
117
assert_equal (len (v_ancestors ), len (chain )- 1 )
@@ -100,7 +133,7 @@ def run_test(self):
100
133
for x in chain :
101
134
ancestor_fees += mempool [x ]['fee' ]
102
135
assert_equal (mempool [x ]['ancestorfees' ], ancestor_fees * COIN + 1000 )
103
-
136
+
104
137
# Undo the prioritisetransaction for later tests
105
138
self .nodes [0 ].prioritisetransaction (txid = chain [0 ], fee_delta = - 1000 )
106
139
@@ -149,6 +182,7 @@ def run_test(self):
149
182
vout = utxo [1 ]['vout' ]
150
183
151
184
transaction_package = []
185
+ tx_children = []
152
186
# First create one parent tx with 10 children
153
187
(txid , sent_value ) = self .chain_transaction (self .nodes [0 ], txid , vout , value , fee , 10 )
154
188
parent_transaction = txid
@@ -159,11 +193,17 @@ def run_test(self):
159
193
for i in range (MAX_DESCENDANTS - 1 ):
160
194
utxo = transaction_package .pop (0 )
161
195
(txid , sent_value ) = self .chain_transaction (self .nodes [0 ], utxo ['txid' ], utxo ['vout' ], utxo ['amount' ], fee , 10 )
196
+ if utxo ['txid' ] is parent_transaction :
197
+ tx_children .append (txid )
162
198
for j in range (10 ):
163
199
transaction_package .append ({'txid' : txid , 'vout' : j , 'amount' : sent_value })
164
200
165
201
mempool = self .nodes [0 ].getrawmempool (True )
166
202
assert_equal (mempool [parent_transaction ]['descendantcount' ], MAX_DESCENDANTS )
203
+ assert_equal (sorted (mempool [parent_transaction ]['spentby' ]), sorted (tx_children ))
204
+
205
+ for child in tx_children :
206
+ assert_equal (mempool [child ]['depends' ], [parent_transaction ])
167
207
168
208
# Sending one more chained transaction will fail
169
209
utxo = transaction_package .pop (0 )
@@ -232,7 +272,7 @@ def run_test(self):
232
272
signedtx = self .nodes [0 ].signrawtransactionwithwallet (rawtx )
233
273
txid = self .nodes [0 ].sendrawtransaction (signedtx ['hex' ])
234
274
sync_mempools (self .nodes )
235
-
275
+
236
276
# Now try to disconnect the tip on each node...
237
277
self .nodes [1 ].invalidateblock (self .nodes [1 ].getbestblockhash ())
238
278
self .nodes [0 ].invalidateblock (self .nodes [0 ].getbestblockhash ())
0 commit comments