Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_persist.py
Show All 31 Lines | - Remove node0 mempool.dat and verify savemempool RPC recreates it | ||||
and verify that node1 can load it and has 5 transactions in its | and verify that node1 can load it and has 5 transactions in its | ||||
mempool. | mempool. | ||||
- Verify that savemempool throws when the RPC is called if | - Verify that savemempool throws when the RPC is called if | ||||
node1 can't write to disk. | node1 can't write to disk. | ||||
""" | """ | ||||
from decimal import Decimal | from decimal import Decimal | ||||
import os | import os | ||||
import time | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_greater_than_or_equal, | |||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
wait_until | wait_until, | ||||
) | ) | ||||
class MempoolPersistTest(BitcoinTestFramework): | class MempoolPersistTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 3 | self.num_nodes = 3 | ||||
self.extra_args = [[], ["-persistmempool=0"], []] | self.extra_args = [[], ["-persistmempool=0"], []] | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
chain_height = self.nodes[0].getblockcount() | |||||
assert_equal(chain_height, 200) | |||||
self.log.debug("Mine a single block to get out of IBD") | |||||
self.nodes[0].generate(1) | |||||
self.sync_all() | |||||
self.log.debug("Send 5 transactions from node2 (to its own address)") | self.log.debug("Send 5 transactions from node2 (to its own address)") | ||||
tx_creation_time_lower = int(time.time()) | |||||
for i in range(5): | for i in range(5): | ||||
last_txid = self.nodes[2].sendtoaddress( | last_txid = self.nodes[2].sendtoaddress( | ||||
self.nodes[2].getnewaddress(), Decimal("10")) | self.nodes[2].getnewaddress(), Decimal("10")) | ||||
node2_balance = self.nodes[2].getbalance() | node2_balance = self.nodes[2].getbalance() | ||||
self.sync_all() | self.sync_all() | ||||
tx_creation_time_higher = int(time.time()) | |||||
self.log.debug( | self.log.debug( | ||||
"Verify that node0 and node1 have 5 transactions in their mempools") | "Verify that node0 and node1 have 5 transactions in their mempools") | ||||
assert_equal(len(self.nodes[0].getrawmempool()), 5) | assert_equal(len(self.nodes[0].getrawmempool()), 5) | ||||
assert_equal(len(self.nodes[1].getrawmempool()), 5) | assert_equal(len(self.nodes[1].getrawmempool()), 5) | ||||
self.log.debug("Prioritize a transaction on node0") | self.log.debug("Prioritize a transaction on node0") | ||||
fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees'] | fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees'] | ||||
assert_equal(fees['base'], fees['modified']) | assert_equal(fees['base'], fees['modified']) | ||||
self.nodes[0].prioritisetransaction(txid=last_txid, fee_delta=1000) | self.nodes[0].prioritisetransaction(txid=last_txid, fee_delta=1000) | ||||
fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees'] | fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees'] | ||||
assert_equal(fees['base'] + Decimal('0.00001000'), fees['modified']) | assert_equal(fees['base'] + Decimal('0.00001000'), fees['modified']) | ||||
tx_creation_time = self.nodes[0].getmempoolentry(txid=last_txid)[ | |||||
'time'] | |||||
assert_greater_than_or_equal(tx_creation_time, tx_creation_time_lower) | |||||
assert_greater_than_or_equal(tx_creation_time_higher, tx_creation_time) | |||||
self.log.debug("Stop-start the nodes. Verify that node0 has the " | self.log.debug("Stop-start the nodes. Verify that node0 has the " | ||||
"transactions in its mempool and node1 does not. " | "transactions in its mempool and node1 does not. " | ||||
"Verify that node2 calculates its balance correctly " | "Verify that node2 calculates its balance correctly " | ||||
"after loading wallet transactions.") | "after loading wallet transactions.") | ||||
self.stop_nodes() | self.stop_nodes() | ||||
# Give this one a head-start, so we can be "extra-sure" that it didn't | # Give this one a head-start, so we can be "extra-sure" that it didn't | ||||
# load anything later | # load anything later | ||||
# Also don't store the mempool, to keep the datadir clean | # Also don't store the mempool, to keep the datadir clean | ||||
self.start_node(1, extra_args=["-persistmempool=0"]) | self.start_node(1, extra_args=["-persistmempool=0"]) | ||||
self.start_node(0) | self.start_node(0) | ||||
self.start_node(2) | self.start_node(2) | ||||
wait_until(lambda: self.nodes[0].getmempoolinfo()["loaded"], timeout=1) | wait_until(lambda: self.nodes[0].getmempoolinfo()["loaded"], timeout=1) | ||||
wait_until(lambda: self.nodes[2].getmempoolinfo()["loaded"], timeout=1) | wait_until(lambda: self.nodes[2].getmempoolinfo()["loaded"], timeout=1) | ||||
assert_equal(len(self.nodes[0].getrawmempool()), 5) | assert_equal(len(self.nodes[0].getrawmempool()), 5) | ||||
assert_equal(len(self.nodes[2].getrawmempool()), 5) | assert_equal(len(self.nodes[2].getrawmempool()), 5) | ||||
# The others have loaded their mempool. If node_1 loaded anything, we'd | # The others have loaded their mempool. If node_1 loaded anything, we'd | ||||
# probably notice by now: | # probably notice by now: | ||||
assert_equal(len(self.nodes[1].getrawmempool()), 0) | assert_equal(len(self.nodes[1].getrawmempool()), 0) | ||||
self.log.debug('Verify prioritization is loaded correctly') | self.log.debug('Verify prioritization is loaded correctly') | ||||
fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees'] | fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees'] | ||||
assert_equal(fees['base'] + Decimal('0.00001000'), fees['modified']) | assert_equal(fees['base'] + Decimal('0.00001000'), fees['modified']) | ||||
self.log.debug('Verify time is loaded correctly') | |||||
assert_equal( | |||||
tx_creation_time, | |||||
self.nodes[0].getmempoolentry( | |||||
txid=last_txid)['time']) | |||||
# Verify accounting of mempool transactions after restart is correct | # Verify accounting of mempool transactions after restart is correct | ||||
# Flush mempool to wallet | # Flush mempool to wallet | ||||
self.nodes[2].syncwithvalidationinterfacequeue() | self.nodes[2].syncwithvalidationinterfacequeue() | ||||
assert_equal(node2_balance, self.nodes[2].getbalance()) | assert_equal(node2_balance, self.nodes[2].getbalance()) | ||||
self.log.debug( | self.log.debug( | ||||
"Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.") | "Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.") | ||||
self.stop_nodes() | self.stop_nodes() | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |