mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
merge bitcoin#20332: Mock IBD in net_processing fuzzers
This commit is contained in:
parent
d9f01c3c9f
commit
1ecd587183
@ -17,6 +17,7 @@ TEST_UTIL_H = \
|
||||
test/util/str.h \
|
||||
test/util/transaction_utils.h \
|
||||
test/util/wallet.h \
|
||||
test/util/validation.h \
|
||||
test/util/xoroshiro128plusplus.h
|
||||
|
||||
libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
|
||||
@ -30,6 +31,7 @@ libtest_util_a_SOURCES = \
|
||||
test/util/setup_common.cpp \
|
||||
test/util/str.cpp \
|
||||
test/util/transaction_utils.cpp \
|
||||
test/util/validation.cpp \
|
||||
test/util/wallet.cpp \
|
||||
$(TEST_UTIL_H)
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <test/util/mining.h>
|
||||
#include <test/util/net.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/validation.h>
|
||||
#include <validationinterface.h>
|
||||
#include <version.h>
|
||||
|
||||
@ -74,10 +75,14 @@ void fuzz_target(FuzzBufferType buffer, const std::string& LIMIT_TO_MESSAGE_TYPE
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
|
||||
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
|
||||
chainstate.ResetIbd();
|
||||
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
||||
if (!LIMIT_TO_MESSAGE_TYPE.empty() && random_message_type != LIMIT_TO_MESSAGE_TYPE) {
|
||||
return;
|
||||
}
|
||||
const bool jump_out_of_ibd{fuzzed_data_provider.ConsumeBool()};
|
||||
if (jump_out_of_ibd) chainstate.JumpOutOfIbd();
|
||||
CNode& p2p_node = *ConsumeNodeAsUniquePtr(fuzzed_data_provider).release();
|
||||
|
||||
const bool successfully_connected{fuzzed_data_provider.ConsumeBool()};
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <test/util/mining.h>
|
||||
#include <test/util/net.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/validation.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
|
||||
@ -34,7 +35,10 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
|
||||
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
|
||||
chainstate.ResetIbd();
|
||||
std::vector<CNode*> peers;
|
||||
bool jump_out_of_ibd{false};
|
||||
|
||||
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
|
||||
for (int i = 0; i < num_peers_to_add; ++i) {
|
||||
@ -51,6 +55,8 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
|
||||
}
|
||||
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
if (!jump_out_of_ibd) jump_out_of_ibd = fuzzed_data_provider.ConsumeBool();
|
||||
if (jump_out_of_ibd && chainstate.IsInitialBlockDownload()) chainstate.JumpOutOfIbd();
|
||||
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
||||
|
||||
CSerializedNetMsg net_msg;
|
||||
|
22
src/test/util/validation.cpp
Normal file
22
src/test/util/validation.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/util/validation.h>
|
||||
|
||||
#include <util/check.h>
|
||||
#include <util/time.h>
|
||||
#include <validation.h>
|
||||
|
||||
void TestChainState::ResetIbd()
|
||||
{
|
||||
m_cached_finished_ibd = false;
|
||||
assert(IsInitialBlockDownload());
|
||||
}
|
||||
|
||||
void TestChainState::JumpOutOfIbd()
|
||||
{
|
||||
Assert(IsInitialBlockDownload());
|
||||
m_cached_finished_ibd = true;
|
||||
Assert(!IsInitialBlockDownload());
|
||||
}
|
17
src/test/util/validation.h
Normal file
17
src/test/util/validation.h
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_TEST_UTIL_VALIDATION_H
|
||||
#define BITCOIN_TEST_UTIL_VALIDATION_H
|
||||
|
||||
#include <validation.h>
|
||||
|
||||
struct TestChainState : public CChainState {
|
||||
/** Reset the ibd cache to its initial state */
|
||||
void ResetIbd();
|
||||
/** Toggle IsInitialBlockDownload from true to false */
|
||||
void JumpOutOfIbd();
|
||||
};
|
||||
|
||||
#endif // BITCOIN_TEST_UTIL_VALIDATION_H
|
@ -625,8 +625,7 @@ enum class CoinsCacheSizeState
|
||||
*/
|
||||
class CChainState
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Every received block is assigned a unique and increasing identifier, so we
|
||||
* know which one to give priority in case of a fork.
|
||||
|
Loading…
Reference in New Issue
Block a user