Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed remaining Functional tests for 8.22 #106

Merged
merged 10 commits into from
Mar 12, 2023
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ if test x$need_bundled_univalue = xyes; then
AC_CONFIG_SUBDIRS([src/univalue])
fi

ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-schnorrsig --enable-experimental"
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-schnorrsig --enable-experimental --disable-openssl-tests"
AC_CONFIG_SUBDIRS([src/secp256k1])

AC_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), check_ratio);

assert(!node.stempool);
node.stempool = std::make_unique<CTxMemPool>(nullptr, 0);
node.stempool = std::make_unique<CTxMemPool>(nullptr, 0, true);

assert(!node.chainman);
node.chainman = std::make_unique<ChainstateManager>();
Expand Down
10 changes: 7 additions & 3 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee,
assert(int(nSigOpCostWithAncestors) >= 0);
}

CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator, int check_ratio)
: m_check_ratio(check_ratio), minerPolicyEstimator(estimator)
CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator, int check_ratio, bool isStempool)
: m_check_ratio(check_ratio), minerPolicyEstimator(estimator), m_is_stempool(isStempool)
{
_clear(); //lock free clear
}
Expand Down Expand Up @@ -419,7 +419,11 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
// for any reason except being included in a block. Clients interested
// in transactions included in blocks can subscribe to the BlockConnected
// notification.
GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);

if (!this->isStempool()) {
// Do not notify subscribers about stempool removals
GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);
}
}

const uint256 hash = it->GetTx().GetHash();
Expand Down
7 changes: 6 additions & 1 deletion src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ class CTxMemPool
void trackPackageRemoved(const CFeeRate& rate) EXCLUSIVE_LOCKS_REQUIRED(cs);

bool m_is_loaded GUARDED_BY(cs){false};
const bool m_is_stempool;

public:

Expand Down Expand Up @@ -598,7 +599,7 @@ class CTxMemPool
* @param[in] estimator is used to estimate appropriate transaction fees.
* @param[in] check_ratio is the ratio used to determine how often sanity checks will run.
*/
explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr, int check_ratio = 0);
explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr, int check_ratio = 0, bool isStempool = false);

/**
* If sanity-checking is turned on, check makes sure the pool is
Expand Down Expand Up @@ -791,6 +792,10 @@ class CTxMemPool
return m_sequence_number;
}

bool isStempool() const {
return this->m_is_stempool;
}

private:
/** UpdateForDescendants is used by UpdateTransactionsFromBlock to update
* the descendants for a single transaction that has been added to the
Expand Down
5 changes: 4 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,10 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef

if (!Finalize(args, ws)) return MempoolAcceptResult::Failure(ws.m_state);

GetMainSignals().TransactionAddedToMempool(ptx, m_pool.GetAndIncrementSequence());
if (!this->m_pool.isStempool()) {
// Do not notify subscribers about stempool additions
GetMainSignals().TransactionAddedToMempool(ptx, m_pool.GetAndIncrementSequence());
}

return MempoolAcceptResult::Success(std::move(ws.m_replaced_transactions), ws.m_base_fees);
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool VerifyWallets(interfaces::Chain& chain)
fs::path wallet_dir = gArgs.GetArg("-walletdir", "");
boost::system::error_code error;
// The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error).remove_trailing_separator();
if (error || !fs::exists(wallet_dir)) {
chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist"), wallet_dir.string()));
return false;
Expand Down
56 changes: 22 additions & 34 deletions test/functional/interface_zmq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# Copyright (c) 2015-2021 The DigiByte Core developers
# Copyright (c) 2015-2020 The Bitcoin Core developers
# Copyright (c) 2015-2023 The DigiByte Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the ZMQ notification interface."""
Expand All @@ -18,12 +19,12 @@
from test_framework.messages import (
CTransaction,
hash256,
tx_from_hex,
)
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)
from test_framework.netutil import test_ipv6_local
from io import BytesIO
from time import sleep

Expand Down Expand Up @@ -81,6 +82,7 @@ class ZMQTestSetupBlock:
the generated block's hash, it's (coinbase) transaction id, the raw block or
raw transaction data.
"""

def __init__(self, test_framework, node):
self.block_hash = test_framework.generate(node, 1, sync_fun=test_framework.no_op)[0]
coinbase = node.getblock(self.block_hash, 2)['tx'][0]
Expand Down Expand Up @@ -118,23 +120,20 @@ def run_test(self):
self.test_mempool_sync()
self.test_reorg()
self.test_multiple_interfaces()
self.test_ipv6()
finally:
# Destroy the ZMQ context.
self.log.debug("Destroying ZMQ context")
self.ctx.destroy(linger=None)

# Restart node with the specified zmq notifications enabled, subscribe to
# all of them and return the corresponding ZMQSubscriber objects.
def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True, ipv6=False):
def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True):
subscribers = []
for topic, address in services:
socket = self.ctx.socket(zmq.SUB)
if ipv6:
socket.setsockopt(zmq.IPV6, 1)
subscribers.append(ZMQSubscriber(socket, topic.encode()))

self.restart_node(0, [f"-zmqpub{topic}={address}" for topic, address in services] +
self.restart_node(0, ["-zmqpub%s=%s" % (topic, address) for topic, address in services] +
self.extra_args[0])

for i, sub in enumerate(subscribers):
Expand Down Expand Up @@ -186,9 +185,11 @@ def test_basic(self):
rawtx = subs[3]

num_blocks = 5
self.log.info(f"Generate {num_blocks} blocks (and {num_blocks} coinbase txes)")
self.log.info("Generate %(n)d blocks (and %(n)d coinbase txes)" % {"n": num_blocks})
genhashes = self.generatetoaddress(self.nodes[0], num_blocks, ADDRESS_BCRT1_UNSPENDABLE)

self.sync_all()

for x in range(num_blocks):
# Should receive the coinbase txid.
txid = hashtx.receive()
Expand Down Expand Up @@ -349,7 +350,8 @@ def test_sequence(self):
# though the mempool sequence number does go up by the number of transactions
# removed from the mempool by the block mining it.
mempool_size = len(self.nodes[0].getrawmempool())
c_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)[0]
c_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)[0]

# Make sure the number of mined transactions matches the number of txs out of mempool
mempool_size_delta = mempool_size - len(self.nodes[0].getrawmempool())
assert_equal(len(self.nodes[0].getblock(c_block)["tx"])-1, mempool_size_delta)
Expand Down Expand Up @@ -401,8 +403,12 @@ def test_sequence(self):
raw_tx = self.nodes[0].getrawtransaction(orig_txid)
bump_info = self.nodes[0].bumpfee(orig_txid)
# Mine the pre-bump tx
txs_to_add = [raw_tx] + [self.nodes[0].getrawtransaction(txid) for txid in more_tx]
block = create_block(int(self.nodes[0].getbestblockhash(), 16), create_coinbase(self.nodes[0].getblockcount()+1), txlist=txs_to_add)
block = create_block(int(self.nodes[0].getbestblockhash(), 16), create_coinbase(self.nodes[0].getblockcount()+1))
tx = tx_from_hex(raw_tx)
block.vtx.append(tx)
for txid in more_tx:
tx = tx_from_hex(self.nodes[0].getrawtransaction(txid))
block.vtx.append(tx)
add_witness_commitment(block)
block.solve()
assert_equal(self.nodes[0].submitblock(block.serialize().hex()), None)
Expand Down Expand Up @@ -436,7 +442,6 @@ def test_sequence(self):
assert_equal((orig_txid_2, "A", mempool_seq), seq.receive_sequence())
mempool_seq += 1
self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)
self.sync_all() # want to make sure we didn't break "consensus" for other tests

def test_mempool_sync(self):
"""
Expand Down Expand Up @@ -464,7 +469,7 @@ def test_mempool_sync(self):
# 1) Consume backlog until we get a mempool sequence number
(hash_str, label, zmq_mem_seq) = seq.receive_sequence()
while zmq_mem_seq is None:
(hash_str, label, zmq_mem_seq) = seq.receive_sequence()
(hash_str, label, zmq_mem_seq) = seq.receive_sequence()

assert label == "A" or label == "R"
assert hash_str is not None
Expand Down Expand Up @@ -498,7 +503,7 @@ def test_mempool_sync(self):
if mempool_sequence is not None:
zmq_mem_seq = mempool_sequence
if zmq_mem_seq > get_raw_seq:
raise Exception(f"We somehow jumped mempool sequence numbers! zmq_mem_seq: {zmq_mem_seq} > get_raw_seq: {get_raw_seq}")
raise Exception("We somehow jumped mempool sequence numbers! zmq_mem_seq: {} > get_raw_seq: {}".format(zmq_mem_seq, get_raw_seq))

# 4) Moving forward, we apply the delta to our local view
# remaining txs(5) + 1 rbf(A+R) + 1 block connect + 1 final tx
Expand All @@ -514,7 +519,7 @@ def test_mempool_sync(self):
assert mempool_sequence > expected_sequence
r_gap += mempool_sequence - expected_sequence
else:
raise Exception(f"WARNING: txhash has unexpected mempool sequence value: {mempool_sequence} vs expected {expected_sequence}")
raise Exception("WARNING: txhash has unexpected mempool sequence value: {} vs expected {}".format(mempool_sequence, expected_sequence))
if label == "A":
assert hash_str not in mempool_view
mempool_view.add(hash_str)
Expand Down Expand Up @@ -556,28 +561,11 @@ def test_multiple_interfaces(self):
], sync_blocks=False)

# Generate 1 block in nodes[0] and receive all notifications
self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)
self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)

# Should receive the same block hash on both subscribers
assert_equal(self.nodes[0].getbestblockhash(), subscribers[0].receive().hex())
assert_equal(self.nodes[0].getbestblockhash(), subscribers[1].receive().hex())

def test_ipv6(self):
if not test_ipv6_local():
self.log.info("Skipping IPv6 test, because IPv6 is not supported.")
return
self.log.info("Testing IPv6")
# Set up subscriber using IPv6 loopback address
subscribers = self.setup_zmq_test([
("hashblock", "tcp://[::1]:28332")
], ipv6=True)

# Generate 1 block in nodes[0]
self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE)

# Should receive the same block hash
assert_equal(self.nodes[0].getbestblockhash(), subscribers[0].receive().hex())


if __name__ == '__main__':
ZMQTest().main()
ZMQTest().main()
2 changes: 1 addition & 1 deletion test/functional/p2p_addr_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AddrTest(DigiByteTestFramework):

def set_test_params(self):
self.num_nodes = 1
self.extra_args = [["-whitelist=addr@127.0.0.1"]]
self.extra_args = [["-whitelist=addr@127.0.0.1", "-easypow"]]

def run_test(self):
self.oversized_addr_test()
Expand Down
37 changes: 0 additions & 37 deletions test/functional/rpc_zmq.py

This file was deleted.

Loading