Merge 19242 via uaappend

This commit is contained in:
Luke Dashjr 2025-03-05 03:27:08 +00:00
commit 4d64e9e4a9
2 changed files with 12 additions and 0 deletions

View File

@ -640,6 +640,7 @@ void SetupServerArgs(ArgsManager& argsman)
Ticks<std::chrono::seconds>(DEFAULT_MAX_TIP_AGE)),
ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-printpriority", strprintf("Log transaction fee rate in " + CURRENCY_UNIT + "/kvB when mining blocks (default: %u)", DEFAULT_PRINT_MODIFIED_FEE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-uaappend=<cmt>", "Append literal to the user agent string (should only be used for software embedding)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
SetupChainParamsBaseOptions(argsman);
@ -1371,6 +1372,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
uacomments.push_back(cmt);
}
strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments);
for (auto append : gArgs.GetArgs("-uaappend")) {
if (append.back() != '/') append += '/';
strSubVersion += append;
}
if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
return InitError(strprintf(_("Total length of network version string (%i) exceeds maximum length (%i). Reduce the number or size of uacomments."),
strSubVersion.size(), MAX_SUBVERSION_LENGTH));

View File

@ -35,6 +35,13 @@ class UacommentTest(BitcoinTestFramework):
expected = r"Error: User Agent comment \(" + re.escape(unsafe_char) + r"\) contains unsafe characters."
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX)
self.log.info("test -uaappend")
self.restart_node(0, ["-uaappend=foo:0"])
assert_equal(self.nodes[0].getnetworkinfo()["subversion"][-7:], '/foo:0/')
self.restart_node(0, ["-uaappend=foo:9/"])
assert_equal(self.nodes[0].getnetworkinfo()["subversion"][-7:], '/foo:9/')
if __name__ == '__main__':
UacommentTest(__file__).main()