2021-01-25 12:23:45 +01:00
|
|
|
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
2020-04-04 07:30:51 +08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <consensus/consensus.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <net_processing.h>
|
|
|
|
#include <protocol.h>
|
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <test/fuzz/util.h>
|
|
|
|
#include <test/util/mining.h>
|
|
|
|
#include <test/util/net.h>
|
|
|
|
#include <test/util/setup_common.h>
|
2020-11-06 15:03:51 +01:00
|
|
|
#include <test/util/validation.h>
|
2021-01-31 00:55:54 +10:00
|
|
|
#include <txorphanage.h>
|
2020-04-04 07:30:51 +08:00
|
|
|
#include <validation.h>
|
|
|
|
#include <validationinterface.h>
|
|
|
|
|
2021-01-15 15:31:50 -05:00
|
|
|
namespace {
|
2020-04-08 19:48:38 -04:00
|
|
|
const TestingSetup* g_setup;
|
2021-01-15 15:31:50 -05:00
|
|
|
} // namespace
|
2020-04-04 07:30:51 +08:00
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
void initialize_process_messages()
|
2020-04-04 07:30:51 +08:00
|
|
|
{
|
2021-01-25 12:23:45 +01:00
|
|
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
2021-01-15 15:31:50 -05:00
|
|
|
g_setup = testing_setup.get();
|
2020-04-04 07:30:51 +08:00
|
|
|
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
|
|
|
|
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
|
|
|
|
}
|
|
|
|
SyncWithValidationInterfaceQueue();
|
|
|
|
}
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
|
2020-04-04 07:30:51 +08:00
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
|
|
|
|
2021-03-23 11:04:18 +01:00
|
|
|
ConnmanTestMsg& connman = *static_cast<ConnmanTestMsg*>(g_setup->m_node.connman.get());
|
|
|
|
TestChainState& chainstate = *static_cast<TestChainState*>(&g_setup->m_node.chainman->ActiveChainstate());
|
2021-01-10 16:41:52 +01:00
|
|
|
SetMockTime(1610000000); // any time to successfully reset ibd
|
2020-11-06 15:03:51 +01:00
|
|
|
chainstate.ResetIbd();
|
2020-04-04 07:30:51 +08:00
|
|
|
|
2021-01-10 16:41:52 +01:00
|
|
|
std::vector<CNode*> peers;
|
2020-04-04 07:30:51 +08:00
|
|
|
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
|
|
|
|
for (int i = 0; i < num_peers_to_add; ++i) {
|
2020-12-28 21:53:19 +01:00
|
|
|
peers.push_back(ConsumeNodeAsUniquePtr(fuzzed_data_provider, i).release());
|
2020-04-04 07:30:51 +08:00
|
|
|
CNode& p2p_node = *peers.back();
|
|
|
|
|
2021-01-10 17:00:43 +01:00
|
|
|
const bool successfully_connected{fuzzed_data_provider.ConsumeBool()};
|
2021-01-23 19:39:30 +01:00
|
|
|
p2p_node.fSuccessfullyConnected = successfully_connected;
|
2020-04-04 07:30:51 +08:00
|
|
|
p2p_node.fPauseSend = false;
|
2020-08-29 10:31:11 +01:00
|
|
|
g_setup->m_node.peerman->InitializeNode(&p2p_node);
|
2021-01-23 19:39:30 +01:00
|
|
|
FillNode(fuzzed_data_provider, p2p_node, /* init_version */ successfully_connected);
|
2020-04-04 07:30:51 +08:00
|
|
|
|
|
|
|
connman.AddTestNode(p2p_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fuzzed_data_provider.ConsumeBool()) {
|
|
|
|
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
|
|
|
|
2021-01-10 16:41:52 +01:00
|
|
|
const auto mock_time = ConsumeTime(fuzzed_data_provider);
|
|
|
|
SetMockTime(mock_time);
|
|
|
|
|
2020-04-04 07:30:51 +08:00
|
|
|
CSerializedNetMsg net_msg;
|
2020-05-10 19:48:11 +02:00
|
|
|
net_msg.m_type = random_message_type;
|
2020-04-04 07:30:51 +08:00
|
|
|
net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
|
|
|
|
|
|
|
CNode& random_node = *peers.at(fuzzed_data_provider.ConsumeIntegralInRange<int>(0, peers.size() - 1));
|
|
|
|
|
|
|
|
(void)connman.ReceiveMsgFrom(random_node, net_msg);
|
|
|
|
random_node.fPauseSend = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
connman.ProcessMessagesOnce(random_node);
|
|
|
|
} catch (const std::ios_base::failure&) {
|
|
|
|
}
|
2020-11-12 18:06:00 +01:00
|
|
|
{
|
|
|
|
LOCK(random_node.cs_sendProcessing);
|
|
|
|
g_setup->m_node.peerman->SendMessages(&random_node);
|
|
|
|
}
|
2020-04-04 07:30:51 +08:00
|
|
|
}
|
|
|
|
SyncWithValidationInterfaceQueue();
|
2020-05-04 20:16:22 -04:00
|
|
|
LOCK2(::cs_main, g_cs_orphans); // See init.cpp for rationale for implicit locking order requirement
|
|
|
|
g_setup->m_node.connman->StopNodes();
|
2020-04-04 07:30:51 +08:00
|
|
|
}
|