Skip to content
Closed
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
10 changes: 6 additions & 4 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ void ReadFromStream(AddrMan& addr, CDataStream& ssPeers)
std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, const ArgsManager& args, std::unique_ptr<AddrMan>& addrman)
{
auto check_addrman = std::clamp<int32_t>(args.GetIntArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
bool deterministic = HasTestOption(args, "addrman"); // use a deterministic addrman only for tests

addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/deterministic, /*consistency_check_ratio=*/check_addrman);

const auto start{SteadyClock::now()};
const auto path_addr{gArgs.GetDataDirNet() / "peers.dat"};
Expand All @@ -194,7 +196,7 @@ std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, con
LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman->Size(), Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
} catch (const DbNotFoundError&) {
// Addrman can be in an inconsistent state after failure, reset it
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/deterministic, /*consistency_check_ratio=*/check_addrman);
LogPrintf("Creating peers.dat because the file was not found (%s)\n", fs::quoted(fs::PathToString(path_addr)));
DumpPeerAddresses(args, *addrman);
} catch (const DbInconsistentError& e) {
Expand All @@ -203,7 +205,7 @@ std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, con
// with frequent corruption, we are restoring old behaviour that does the same, silently.
//
// TODO: Evaluate cause and fix, revert this change at some point.
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/deterministic, /*consistency_check_ratio=*/check_addrman);
LogPrintf("Creating peers.dat because of invalid or corrupt file (%s)\n", e.what());
DumpPeerAddresses(args, *addrman);
} catch (const InvalidAddrManVersionError&) {
Expand All @@ -212,7 +214,7 @@ std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, con
return strprintf(_("Failed to rename invalid peers.dat file. Please move or delete it and try again."));
}
// Addrman can be in an inconsistent state after failure, reset it
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/deterministic, /*consistency_check_ratio=*/check_addrman);
LogPrintf("Creating new peers.dat because the file version was not compatible (%s). Original backed up to peers.dat.bak\n", fs::quoted(fs::PathToString(path_addr)));
DumpPeerAddresses(args, *addrman);
} catch (const std::exception& e) {
Expand Down
31 changes: 31 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-stopatheight", strprintf("Stop running after reaching the given height in the main chain (default: %u)", DEFAULT_STOPATHEIGHT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-watchquorums=<n>", strprintf("Watch and validate quorum communication (default: %u)", llmq::DEFAULT_WATCH_QUORUMS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-test=<option>", "Pass a test-only option. Options include : " + Join(TEST_OPTIONS_DOC, ", ") + ".", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-disablegovernance", strprintf("Disable governance validation (0-1, default: %u)", 0), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-maxsigcachesize=<n>", strprintf("Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_SIZE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
Expand Down Expand Up @@ -1352,12 +1353,42 @@ bool AppInitParameterInteraction(const ArgsManager& args)
if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM);

<<<<<<< HEAD
nMaxTipAge = args.GetIntArg("-maxtipage", DEFAULT_MAX_TIP_AGE);

if (args.GetBoolArg("-reindex-chainstate", false)) {
// indexes that must be deactivated to prevent index corruption, see #24630
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
return InitError(_("-reindex-chainstate option is not compatible with -coinstatsindex. Please temporarily disable coinstatsindex while using -reindex-chainstate, or replace -reindex-chainstate with -reindex to fully rebuild all indexes."));
=======
if (args.IsArgSet("-test")) {
if (chainparams.GetChainType() != ChainType::REGTEST) {
return InitError(Untranslated("-test=<option> should only be used in functional tests"));
}
const std::vector<std::string> options = args.GetArgs("-test");
for (const std::string& option : options) {
auto it = std::find_if(TEST_OPTIONS_DOC.begin(), TEST_OPTIONS_DOC.end(), [&option](const std::string& doc_option) {
size_t pos = doc_option.find(" (");
return (pos != std::string::npos) && (doc_option.substr(0, pos) == option);
});
if (it == TEST_OPTIONS_DOC.end()) {
InitWarning(strprintf(_("Unrecognised option \"%s\" provided in -test=<option>."), option));
}
}
}

// Also report errors from parsing before daemonization
{
kernel::Notifications notifications{};
ChainstateManager::Options chainman_opts_dummy{
.chainparams = chainparams,
.datadir = args.GetDataDirNet(),
.notifications = notifications,
};
auto chainman_result{ApplyArgsManOptions(args, chainman_opts_dummy)};
if (!chainman_result) {
return InitError(util::ErrorString(chainman_result));
>>>>>>> a945f09fa6 (Merge bitcoin/bitcoin#29007: test: create deterministic addrman in the functional tests)
}
if (g_enabled_filter_types.count(BlockFilterType::BASIC_FILTER)) {
return InitError(_("-reindex-chainstate option is not compatible with -blockfilterindex. Please temporarily disable blockfilterindex while using -reindex-chainstate, or replace -reindex-chainstate with -reindex to fully rebuild all indexes."));
Expand Down
3 changes: 1 addition & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ std::optional<CService> GetLocalAddrForPeer(CNode& node)
addrLocal.SetIP(node.GetAddrLocal());
}
}
if (addrLocal.IsRoutable())
{
if (addrLocal.IsRoutable()) {
LogPrint(BCLog::NET, "Advertising address %s to peer=%d\n", addrLocal.ToStringAddrPort(), node.GetId());
return addrLocal;
}
Expand Down
12 changes: 12 additions & 0 deletions src/util/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,18 @@ void PrintExceptionContinue(const std::exception_ptr pex, const char* pszExcepti
tfm::format(std::cerr, "\n\n************************\n%s\n", message);
}

const std::vector<std::string> TEST_OPTIONS_DOC{
"addrman (use deterministic addrman)",
};

bool HasTestOption(const ArgsManager& args, const std::string& test_option)
{
const auto options = args.GetArgs("-test");
return std::any_of(options.begin(), options.end(), [test_option](const auto& option) {
return option == test_option;
});
}

fs::path GetDefaultDataDir()
{
// Windows: C:\Users\Username\AppData\Roaming\DashCore
Expand Down
5 changes: 5 additions & 0 deletions src/util/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ bool HelpRequested(const ArgsManager& args);
/** Add help options to the args manager */
void SetupHelpOptions(ArgsManager& args);

extern const std::vector<std::string> TEST_OPTIONS_DOC;

/** Checks if a particular test option is present in -test command-line arg options */
bool HasTestOption(const ArgsManager& args, const std::string& test_option);

/**
* Format a string to be used as group of options in help messages
*
Expand Down
7 changes: 1 addition & 6 deletions test/functional/feature_addrman.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,7 @@ def run_test(self):
self.start_node(0)

self.log.info("Check that missing addrman is recreated")
self.stop_node(0)
os.remove(peers_dat)
with self.nodes[0].assert_debug_log([
f'Creating peers.dat because the file was not found ("{peers_dat}")',
]):
self.start_node(0)
self.restart_node(0, clear_addrman=True)
assert_equal(self.nodes[0].getnodeaddresses(), [])


Expand Down
18 changes: 13 additions & 5 deletions test/functional/feature_asmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def set_test_params(self):
self.extra_args = [["-checkaddrman=1"]] # Do addrman checks on all operations.

def fill_addrman(self, node_id):
"""Add 1 tried address to the addrman, followed by 1 new address."""
for addr, tried in [[0, True], [1, False]]:
"""Add 2 tried addresses to the addrman, followed by 2 new addresses."""
for addr, tried in [[0, True], [1, True], [2, False], [3, False]]:
self.nodes[node_id].addpeeraddress(address=f"101.{addr}.0.0", tried=tried, port=8333)

def test_without_asmap_arg(self):
Expand Down Expand Up @@ -84,12 +84,12 @@ def test_asmap_interaction_with_addrman_containing_entries(self):
self.log.info("Test dashd -asmap restart with addrman containing new and tried entries")
self.stop_node(0)
shutil.copyfile(self.asmap_raw, self.default_asmap)
self.start_node(0, ["-asmap", "-checkaddrman=1"])
self.start_node(0, ["-asmap", "-checkaddrman=1", "-test=addrman"])
self.fill_addrman(node_id=0)
self.restart_node(0, ["-asmap", "-checkaddrman=1"])
self.restart_node(0, ["-asmap", "-checkaddrman=1", "-test=addrman"])
with self.node.assert_debug_log(
expected_msgs=[
"CheckAddrman: new 1, tried 1, total 2 started",
"CheckAddrman: new 2, tried 2, total 4 started",
"CheckAddrman: completed",
]
):
Expand All @@ -111,6 +111,14 @@ def test_empty_asmap(self):
self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg)
os.remove(self.default_asmap)

def test_asmap_health_check(self):
self.log.info('Test dashd -asmap logs ASMap Health Check with basic stats')
shutil.copyfile(self.asmap_raw, self.default_asmap)
msg = "ASMap Health Check: 4 clearnet peers are mapped to 3 ASNs with 0 peers being unmapped"
with self.node.assert_debug_log(expected_msgs=[msg]):
self.start_node(0, extra_args=['-asmap'])
os.remove(self.default_asmap)

def run_test(self):
self.node = self.nodes[0]
self.datadir = os.path.join(self.node.datadir, self.chain)
Expand Down
Loading
Loading