Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@ class CRegTestParams : public CChainParams {
assert(genesis.hashMerkleRoot == uint256S("0xe0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7"));

vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
vSeeds.clear();
vSeeds.emplace_back("dummySeed.invalid.");

fDefaultConsistencyChecks = true;
fRequireStandard = true;
Expand Down
5 changes: 5 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,11 @@ bool AppInitParameterInteraction(const ArgsManager& args)

fAllowPrivateNet = args.GetBoolArg("-allowprivatenet", DEFAULT_ALLOWPRIVATENET);

// If -forcednsseed is set to true, ensure -dnsseed has not been set to false
if (args.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED) && !args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED)){
return InitError(_("Cannot set -forcednsseed to true when setting -dnsseed to false."));
}

// -bind and -whitebind can't be set when not listening
size_t nUserBind = args.GetArgs("-bind").size() + args.GetArgs("-whitebind").size();
if (nUserBind != 0 && !args.GetBoolArg("-listen", DEFAULT_LISTEN)) {
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ void CConnman::ThreadDNSAddressSeed()
{
READ_LOCK(m_nodes_mutex);
for (const CNode* pnode : m_nodes) {
if (pnode->fSuccessfullyConnected && !pnode->IsFullOutboundConn() && !pnode->m_masternode_probe_connection) ++nRelevant;
if (pnode->fSuccessfullyConnected && pnode->IsFullOutboundConn() && !pnode->m_masternode_probe_connection) ++nRelevant;
}
}
if (nRelevant >= 2) {
Expand Down
29 changes: 3 additions & 26 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
/** Number of file descriptors required for message capture **/
static const int NUM_FDS_MESSAGE_CAPTURE = 1;

static const bool DEFAULT_FORCEDNSSEED = false;
static const bool DEFAULT_DNSSEED = true;
static const bool DEFAULT_FIXEDSEEDS = true;
static constexpr bool DEFAULT_FORCEDNSSEED{false};
static constexpr bool DEFAULT_DNSSEED{true};
static constexpr bool DEFAULT_FIXEDSEEDS{true};
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;

Expand Down Expand Up @@ -1386,29 +1386,6 @@ friend class CNode;
ForEachNode(FullyConnectedOnly, fn);
}

template<typename Callable, typename CallableAfter>
void ForEachNodeThen(Callable&& pre, CallableAfter&& post) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
{
ForEachNodeThen(FullyConnectedOnly, pre, post);
}

template<typename Condition, typename Callable, typename CallableAfter>
void ForEachNodeThen(const Condition& cond, Callable&& pre, CallableAfter&& post) const EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
{
READ_LOCK(m_nodes_mutex);
for (auto&& node : m_nodes) {
if (cond(node))
pre(node);
}
post();
};

template<typename Callable, typename CallableAfter>
void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
{
ForEachNodeThen(FullyConnectedOnly, pre, post);
}

// Addrman functions
/**
* Return all or many randomly selected addresses, optionally by network.
Expand Down
4 changes: 2 additions & 2 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_

// create peer table context menu
peersTableContextMenu = new QMenu(this);
//: Context menu action to copy the address of a peer
//: Context menu action to copy the address of a peer.
peersTableContextMenu->addAction(tr("&Copy address"), [this] {
GUIUtil::copyEntryData(ui->peerWidget, PeerTableModel::Address, Qt::DisplayRole);
});
Expand Down Expand Up @@ -767,7 +767,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
banTableContextMenu = new QMenu(this);
/*: Context menu action to copy the IP/Netmask of a banned peer.
IP/Netmask is the combination of a peer's IP address and its Netmask.
For IP address see: https://en.wikipedia.org/wiki/IP_address */
For IP address, see: https://en.wikipedia.org/wiki/IP_address. */
banTableContextMenu->addAction(tr("&Copy IP/Netmask"), [this] {
GUIUtil::copyEntryData(ui->banlistWidget, BanTableModel::Address, Qt::DisplayRole);
});
Expand Down
2 changes: 1 addition & 1 deletion src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void SendCoinsDialog::setModel(WalletModel *_model)
updateSmartFeeLabel();

if (model->wallet().hasExternalSigner()) {
//: "device" usually means a hardware wallet
//: "device" usually means a hardware wallet.
ui->sendButton->setText(tr("Sign on device"));
if (gArgs.GetArg("-signer", "") != "") {
ui->sendButton->setEnabled(true);
Expand Down
7 changes: 5 additions & 2 deletions src/rpc/external_signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ static RPCHelpMan enumeratesigners()
{
{RPCResult::Type::ARR, "signers", /*optional=*/false, "",
{
{RPCResult::Type::STR_HEX, "masterkeyfingerprint", "Master key fingerprint"},
{RPCResult::Type::STR, "name", "Device name"},
{RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR_HEX, "fingerprint", "Master key fingerprint"},
{RPCResult::Type::STR, "name", "Device name"},
}},
},
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/test/fuzz/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,6 @@ FUZZ_TARGET(addrman, .init = initialize_addrman)
[&] {
(void)addr_man.SelectTriedCollision();
},
[&] {
(void)addr_man.Select(fuzzed_data_provider.ConsumeBool());
},
[&] {
(void)addr_man.GetAddr(
/*max_addresses=*/fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
/*max_pct=*/fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
/*network=*/std::nullopt);
},
[&] {
std::vector<CAddress> addresses;
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
Expand All @@ -288,9 +279,15 @@ FUZZ_TARGET(addrman, .init = initialize_addrman)
addr_man.SetServices(ConsumeService(fuzzed_data_provider), ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS));
});
}
(void)addr_man.Size();
const AddrMan& const_addr_man{addr_man};
(void)const_addr_man.GetAddr(
/* max_addresses */ fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
/* max_pct */ fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096),
/* network */ std::nullopt);
(void)const_addr_man.Select(fuzzed_data_provider.ConsumeBool());
(void)const_addr_man.Size();
CDataStream data_stream(SER_NETWORK, PROTOCOL_VERSION);
data_stream << addr_man;
data_stream << const_addr_man;
}

// Check that serialize followed by unserialize produces the same addrman.
Expand All @@ -309,4 +306,4 @@ FUZZ_TARGET(addrman_serdeser, .init = initialize_addrman)
data_stream << addr_man1;
data_stream >> addr_man2;
assert(addr_man1 == addr_man2);
}
}
3 changes: 0 additions & 3 deletions src/test/fuzz/connman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ FUZZ_TARGET(connman, .init = initialize_connman)
[&] {
connman.ForEachNode([](auto) {});
},
[&] {
connman.ForEachNodeThen([](auto) {}, []() {});
},
[&] {
(void)connman.ForNode(fuzzed_data_provider.ConsumeIntegral<NodeId>(), [&](auto) { return fuzzed_data_provider.ConsumeBool(); });
},
Expand Down
9 changes: 0 additions & 9 deletions src/test/fuzz/integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <pow.h>
#include <protocol.h>
#include <pubkey.h>
#include <rpc/util.h>
#include <script/sign.h>
#include <script/standard.h>
#include <serialize.h>
Expand Down Expand Up @@ -150,14 +149,6 @@ FUZZ_TARGET(integer, .init = initialize_integer)

const PKHash key_id{u160};
const ScriptHash script_id{u160};
// CTxDestination = CNoDestination ∪ PKHash ∪ ScriptHash
const std::vector<CTxDestination> destinations{key_id, script_id};
for (const CTxDestination& destination : destinations) {
(void)DescribeAddress(destination);
(void)EncodeDestination(destination);
(void)GetScriptForDestination(destination);
(void)IsValidDestination(destination);
}

{
CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION);
Expand Down
10 changes: 0 additions & 10 deletions src/test/fuzz/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include <chainparams.h>
#include <key_io.h>
#include <rpc/util.h>
#include <script/standard.h>
#include <test/fuzz/fuzz.h>

#include <cassert>
Expand Down Expand Up @@ -37,12 +35,4 @@ FUZZ_TARGET(key_io, .init = initialize_key_io)
if (ext_pub_key.pubkey.size() == CPubKey::COMPRESSED_SIZE) {
assert(ext_pub_key == DecodeExtPubKey(EncodeExtPubKey(ext_pub_key)));
}

const CTxDestination tx_destination = DecodeDestination(random_string);
(void)DescribeAddress(tx_destination);
(void)GetKeyForDestination(/*store=*/{}, tx_destination);
(void)GetScriptForDestination(tx_destination);
(void)IsValidDestination(tx_destination);

(void)IsValidDestinationString(random_string);
}
25 changes: 22 additions & 3 deletions src/test/fuzz/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include <core_io.h>
#include <core_memusage.h>
#include <key.h>
#include <key_io.h>
#include <policy/policy.h>
#include <pubkey.h>
#include <rpc/util.h>
#include <script/descriptor.h>
#include <script/interpreter.h>
#include <script/script.h>
Expand Down Expand Up @@ -126,9 +128,26 @@ FUZZ_TARGET(script, .init = initialize_script)
}

{
const CTxDestination tx_destination_1 = ConsumeTxDestination(fuzzed_data_provider);
const CTxDestination tx_destination_2 = ConsumeTxDestination(fuzzed_data_provider);
(void)(tx_destination_1 == tx_destination_2);
const CTxDestination tx_destination_1{
fuzzed_data_provider.ConsumeBool() ?
DecodeDestination(fuzzed_data_provider.ConsumeRandomLengthString()) :
ConsumeTxDestination(fuzzed_data_provider)};
const CTxDestination tx_destination_2{ConsumeTxDestination(fuzzed_data_provider)};
const std::string encoded_dest{EncodeDestination(tx_destination_1)};
const UniValue json_dest{DescribeAddress(tx_destination_1)};
Assert(tx_destination_1 == DecodeDestination(encoded_dest));
(void)GetKeyForDestination(/* store */ {}, tx_destination_1);
const CScript dest{GetScriptForDestination(tx_destination_1)};
const bool valid{IsValidDestination(tx_destination_1)};
Assert(dest.empty() != valid);

Assert(valid == IsValidDestinationString(encoded_dest));

(void)(tx_destination_1 < tx_destination_2);
if (tx_destination_1 == tx_destination_2) {
Assert(encoded_dest == EncodeDestination(tx_destination_2));
Assert(json_dest.write() == DescribeAddress(tx_destination_2).write());
Assert(dest == GetScriptForDestination(tx_destination_2));
}
}
}
19 changes: 19 additions & 0 deletions src/test/fuzz/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <net_processing.h>
#include <netaddress.h>
#include <netmessagemaker.h>
#include <pubkey.h>
#include <test/fuzz/util.h>
#include <test/util/script.h>
#include <util/overflow.h>
Expand Down Expand Up @@ -435,6 +436,24 @@ uint32_t ConsumeSequence(FuzzedDataProvider& fuzzed_data_provider) noexcept
fuzzed_data_provider.ConsumeIntegral<uint32_t>();
}

CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept
{
CTxDestination tx_destination;
const size_t call_size{CallOneOf(
fuzzed_data_provider,
[&] {
tx_destination = CNoDestination{};
},
[&] {
tx_destination = PKHash{ConsumeUInt160(fuzzed_data_provider)};
},
[&] {
tx_destination = ScriptHash{ConsumeUInt160(fuzzed_data_provider)};
})};
Assert(call_size == std::variant_size_v<CTxDestination>);
return tx_destination;
}

CKey ConsumePrivateKey(FuzzedDataProvider& fuzzed_data_provider, std::optional<bool> compressed) noexcept
{
auto key_data = fuzzed_data_provider.ConsumeBytes<uint8_t>(32);
Expand Down
20 changes: 3 additions & 17 deletions src/test/fuzz/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ class FuzzedSock : public Sock
}

template <typename... Callables>
void CallOneOf(FuzzedDataProvider& fuzzed_data_provider, Callables... callables)
size_t CallOneOf(FuzzedDataProvider& fuzzed_data_provider, Callables... callables)
{
constexpr size_t call_size{sizeof...(callables)};
static_assert(call_size >= 1);
const size_t call_index{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, call_size - 1)};

size_t i{0};
((i++ == call_index ? callables() : void()), ...);
return call_size;
}

template <typename Collection>
Expand Down Expand Up @@ -233,22 +234,7 @@ template <typename WeakEnumType, size_t size>

[[nodiscard]] CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider& fuzzed_data_provider, const CTransaction& tx) noexcept;

[[nodiscard]] inline CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept
{
CTxDestination tx_destination;
CallOneOf(
fuzzed_data_provider,
[&] {
tx_destination = CNoDestination{};
},
[&] {
tx_destination = PKHash{ConsumeUInt160(fuzzed_data_provider)};
},
[&] {
tx_destination = ScriptHash{ConsumeUInt160(fuzzed_data_provider)};
});
return tx_destination;
}
[[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;

[[nodiscard]] CKey ConsumePrivateKey(FuzzedDataProvider& fuzzed_data_provider, std::optional<bool> compressed = std::nullopt) noexcept;

Expand Down
31 changes: 19 additions & 12 deletions test/functional/feature_config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,19 @@ def test_seed_peers(self):
self.stop_node(0)

# No peers.dat exists and -dnsseed=1
# We expect the node will use DNS Seeds, but Regtest mode has 0 DNS seeds
# So after 60 seconds, the node should fallback to fixed seeds (this is a slow test)
# We expect the node will use DNS Seeds, but Regtest mode does not have
# any valid DNS seeds. So after 60 seconds, the node should fallback to
# fixed seeds
assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
start = int(time.time())
with self.nodes[0].assert_debug_log(expected_msgs=[
"Loaded 0 addresses from peers.dat",
"0 addresses found from DNS seeds",
"opencon thread start", # Ensure ThreadOpenConnections::start time is properly set
]):
with self.nodes[0].assert_debug_log(
expected_msgs=[
"Loaded 0 addresses from peers.dat",
"0 addresses found from DNS seeds",
"opencon thread start", # Ensure ThreadOpenConnections::start time is properly set
],
timeout=10,
):
self.start_node(0, extra_args=['-dnsseed=1', '-fixedseeds=1', f'-mocktime={start}'])
with self.nodes[0].assert_debug_log(expected_msgs=[
"Adding fixed seeds as 60 seconds have passed and addrman is empty",
Expand Down Expand Up @@ -226,11 +230,14 @@ def test_seed_peers(self):
# We expect the node will allow 60 seconds prior to using fixed seeds
assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
start = int(time.time())
with self.nodes[0].assert_debug_log(expected_msgs=[
"Loaded 0 addresses from peers.dat",
"DNS seeding disabled",
"opencon thread start", # Ensure ThreadOpenConnections::start time is properly set
]):
with self.nodes[0].assert_debug_log(
expected_msgs=[
"Loaded 0 addresses from peers.dat",
"DNS seeding disabled",
"opencon thread start", # Ensure ThreadOpenConnections::start time is properly set
],
timeout=10,
):
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1', '-addnode=fakenodeaddr', f'-mocktime={start}'])
with self.nodes[0].assert_debug_log(expected_msgs=[
"Adding fixed seeds as 60 seconds have passed and addrman is empty",
Expand Down
Loading
Loading