Skip to content

Commit

Permalink
TEMPORARY debug logging patch for CI failures
Browse files Browse the repository at this point in the history
also slight mod to fill_mempool() to make more room
  • Loading branch information
LarryRuane committed May 21, 2024
1 parent ac6e14b commit 9bc440d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
10 changes: 8 additions & 2 deletions test/functional/mempool_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,22 @@ def test_mid_package_eviction(self):
# UTXOs to be spent by the ultimate child transaction
parent_utxos = []

self.log.info(f"LMR mempoolinfo {current_info}")
evicted_weight = 8000
# Mempool transaction which is evicted due to being at the "bottom" of the mempool when the
# mempool overflows and evicts by descendant score. It's important that the eviction doesn't
# happen in the middle of package evaluation, as it can invalidate the coins cache.
mempool_evicted_tx = self.wallet.send_self_transfer(
from_node=node,
mempool_evicted_tx = self.wallet.create_self_transfer(
fee=(mempoolmin_feerate / 1000) * (evicted_weight // 4) + Decimal('0.000001'),
target_weight=evicted_weight,
confirmed_only=True
)
self.log.info(f"LMR tx fee: {(mempoolmin_feerate / 1000) * (evicted_weight // 4) + Decimal('0.000001')}")
self.log.info(f"LMR tx weight: {mempool_evicted_tx['tx'].get_weight()}")
self.log.info(f"LMR tx vsize: {mempool_evicted_tx['tx'].get_vsize()}")
self.wallet.sendrawtransaction(from_node=node, tx_hex=mempool_evicted_tx['hex'])
current_info = node.getmempoolinfo()
self.log.info(f"LMR mempoolinfo {current_info}")
# Already in mempool when package is submitted.
assert mempool_evicted_tx["txid"] in node.getrawmempool()

Expand Down
4 changes: 2 additions & 2 deletions test/functional/mining_prioritisetransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ def run_test(self):
# Create 3 batches of transactions at 3 different fee rate levels
range_size = utxo_count // 3
for i in range(3):
txids.append([])
start_range = i * range_size
end_range = start_range + range_size
txids[i] = create_lots_of_big_transactions(
tx_list = create_lots_of_big_transactions(
self.wallet,
self.nodes[0],
(i+1) * base_fee,
end_range - start_range,
self.txouts,
utxos[start_range:end_range])
txids.append([tx.hash for tx in tx_list])

# Make sure that the size of each group of transactions exceeds
# MAX_BLOCK_WEIGHT // 4 -- otherwise the test needs to be revised to
Expand Down
28 changes: 20 additions & 8 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,26 @@ def fill_mempool(test_framework, node, miniwallet):
for batch_of_txid in range(num_of_batches):
fee = (batch_of_txid + 1) * base_fee
utxos = confirmed_utxos[:tx_batch_size]
create_lots_of_big_transactions(miniwallet, node, fee, tx_batch_size, txouts, utxos)
tx = create_lots_of_big_transactions(miniwallet, node, fee, tx_batch_size, txouts, utxos)
del confirmed_utxos[:tx_batch_size]

test_framework.log.debug("The tx should be evicted by now")
test_framework.log.debug(f"The tx should be evicted by now")
# The number of transactions created should be greater than the ones present in the mempool
assert_greater_than(tx_batch_size * num_of_batches, len(node.getrawmempool()))
# Initial tx created should not be present in the mempool anymore as it had a lower fee rate
assert tx_to_be_evicted_id not in node.getrawmempool()

# Replace the last (largest-fee) tx with a slightly smaller one (in physical size)
# to make some room in the mempool.
test_framework.log.debug("Replace one tx with a slightly smaller one")
tx = tx[0]
# increase the fee slightly
tx.vout[0].nValue -= 60_000
assert len(tx.vout) == 2
txos = gen_return_txouts(67437-10_000)
tx.vout[1] = txos[0]
node.sendrawtransaction(tx.serialize().hex())

test_framework.log.debug("Check that mempoolminfee is larger than minrelaytxfee")
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
Expand All @@ -563,29 +574,30 @@ def fill_mempool(test_framework, node, miniwallet):
# Create large OP_RETURN txouts that can be appended to a transaction
# to make it large (helper for constructing large transactions). The
# total serialized size of the txouts is about 66k vbytes.
def gen_return_txouts():
def gen_return_txouts(op_return_len=67437):
from .messages import CTxOut
from .script import CScript, OP_RETURN
txouts = [CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'\x01'*67437]))]
assert_equal(sum([len(txout.serialize()) for txout in txouts]), 67456)
txouts = [CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'\x01'*op_return_len]))]
return txouts


# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
# transaction to make it large. See gen_return_txouts() above.
def create_lots_of_big_transactions(mini_wallet, node, fee, tx_batch_size, txouts, utxos=None):
txids = []
txs = []
use_internal_utxos = utxos is None
for _ in range(tx_batch_size):
tx = mini_wallet.create_self_transfer(
utxo_to_spend=None if use_internal_utxos else utxos.pop(),
fee=fee,
)["tx"]
tx.vout.extend(txouts)
tx.rehash()
res = node.testmempoolaccept([tx.serialize().hex()])[0]
assert_equal(res['fees']['base'], fee)
txids.append(node.sendrawtransaction(tx.serialize().hex()))
return txids
txs.append(tx)
node.sendrawtransaction(tx.serialize().hex())
return txs


def mine_large_block(test_framework, mini_wallet, node):
Expand Down

0 comments on commit 9bc440d

Please sign in to comment.