Skip to content

Commit

Permalink
[test] wait for inital broadcast to complete before comparing mempool…
Browse files Browse the repository at this point in the history
… entries

- mempool entry 'unbroadcast' field changes when initial broadcast is complete,
so anytime you want to compare mempool entries, wait for initial broadcast to complete
('unbroadcast' = False) otherwise it may change in between calls
- mempool_packages.py needs to do this especially because it compares entries as a whole
and compares getrawmempool with getmempoolentry
  • Loading branch information
glozow committed May 13, 2020
1 parent 19bc947 commit b7fc327
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from decimal import Decimal

from test_framework.messages import COIN
from test_framework.mininode import P2PTxInvStore, mininode_lock
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
Expand Down Expand Up @@ -58,6 +59,7 @@ def chain_transaction(self, node, parent_txid, vout, value, fee, num_outputs):

def run_test(self):
# Mine some blocks and have them mature.
self.nodes[0].add_p2p_connection(P2PTxInvStore()) # keep track of invs
self.nodes[0].generate(101)
utxo = self.nodes[0].listunspent(10)
txid = utxo[0]['txid']
Expand All @@ -72,6 +74,11 @@ def run_test(self):
value = sent_value
chain.append(txid)

# Wait until mempool transactions have passed initial broadcast (sent inv and received getdata)
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if status changes in between
wait_until(lambda: len(self.nodes[0].p2p.get_invs()) == len(chain), lock=mininode_lock)
self.nodes[0].p2p.sync_with_ping()

# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
# count and fees should look correct
mempool = self.nodes[0].getrawmempool(True)
Expand Down Expand Up @@ -139,8 +146,6 @@ def run_test(self):
else:
assert_equal(ainfo['depends'], [])



# Check that getmempoolancestors/getmempooldescendants correctly handle verbose=true
v_ancestors = self.nodes[0].getmempoolancestors(chain[-1], True)
assert_equal(len(v_ancestors), len(chain)-1)
Expand Down

0 comments on commit b7fc327

Please sign in to comment.