From 595cd62fe394ac3f6c47e87473315861f8e8ba31 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Tue, 3 Nov 2026 09:18:21 +0100 Subject: [PATCH] client: a start-up banner names the community release At start the console and the log show the CREDITS logo with "community" under it, the release from VERSION, the protocol, the build commit, the storage (pruned or full, database), snapshot serving and, for a full node, the backfill. [params] banner=off keeps the text lines only, for log collectors. The start used to log nothing about the version. Co-Authored-By: Claude Opus 5.5 --- client/config/CMakeLists.txt | 2 ++ client/config/banner.cpp | 50 +++++++++++++++++++++++++++++++++++ client/config/banner.hpp | 29 ++++++++++++++++++++ client/config/config.cpp | 5 ++++ client/config/config.hpp | 6 +++++ client/src/peer.cpp | 16 +++++++++++ docs/CHANGES.md | 4 ++- docs/differences.md | 6 +++++ tests/csnode/CMakeLists.txt | 1 + tests/csnode/banner_tests.cpp | 43 ++++++++++++++++++++++++++++++ 10 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 client/config/banner.cpp create mode 100644 client/config/banner.hpp create mode 100644 tests/csnode/banner_tests.cpp diff --git a/client/config/CMakeLists.txt b/client/config/CMakeLists.txt index 159265f14..7dbf451e1 100644 --- a/client/config/CMakeLists.txt +++ b/client/config/CMakeLists.txt @@ -10,6 +10,8 @@ add_library(${PROJECT_NAME} "observer.cpp" "config.hpp" "config.cpp" + "banner.hpp" + "banner.cpp" ) target_link_libraries (${PROJECT_NAME} csnode lib) diff --git a/client/config/banner.cpp b/client/config/banner.cpp new file mode 100644 index 000000000..3b8eaa932 --- /dev/null +++ b/client/config/banner.cpp @@ -0,0 +1,50 @@ +#include "banner.hpp" + +#include + +namespace cs { + +std::vector startupBanner(const BannerInfo& info, bool art) { + std::vector lines; + if (art) { + lines = { + " ____ ____ _____ ____ ___ _____ ____", + " / ___| _ \\| ____| _ \\_ _|_ _/ ___|", + " | | | |_) | _| | | | | | | | \\___ \\", + " | |___| _ <| |___| |_| | | | | ___) |", + " \\____|_| \\_\\_____|____/___| |_| |____/", + " c o m m u n i t y", + "", + }; + } + std::string build = info.build.substr(0, 8); + lines.push_back(" node " + info.version + " (protocol " + std::to_string(info.protocol) + + (build.empty() ? "" : ", build " + build) + ")"); + std::string storage = " storage: " + std::string(info.pruned ? "pruned" : "full") + ", " + info.backend + + " snapshots: serve " + (info.serve ? "on" : "off"); + if (!info.pruned) { + storage += " backfill: " + std::string(info.backfill ? "on" : "off"); + } + lines.push_back(storage); + lines.push_back(" https://github.com/CreditsCommunity/node"); + return lines; +} + +std::string packageVersion(int protocol, int minor) { + std::string version; + std::ifstream file("VERSION"); + if (!file || !std::getline(file, version) || version.empty() || version.size() > 64) { + return "4.2." + std::to_string(protocol) + "." + std::to_string(minor); + } + while (!version.empty() && (version.back() == '\r' || version.back() == ' ')) { + version.pop_back(); + } + for (auto& c : version) { + if (c < 0x20 || c >= 0x7f) { + c = '_'; + } + } + return version; +} + +} // namespace cs diff --git a/client/config/banner.hpp b/client/config/banner.hpp new file mode 100644 index 000000000..01f057cf0 --- /dev/null +++ b/client/config/banner.hpp @@ -0,0 +1,29 @@ +#ifndef CLIENT_CONFIG_BANNER_HPP +#define CLIENT_CONFIG_BANNER_HPP + +#include +#include + +namespace cs { + +// what the start-up banner shows, so that a log says at once which node wrote it +struct BannerInfo { + std::string version; // 4.2.532-community.N, from the VERSION file of the package + int protocol = 0; // NODE_VERSION, the version the network checks + std::string build; // the commit the binary was built from + bool pruned = false; + std::string backend; // berkeleydb, lmdb or rocksdb + bool serve = false; // [snapshot] serve + bool backfill = false; // [storage] backfill, for a full node +}; + +// the lines to log at start-up: the logo and "community" when art is set ([params] banner), +// then the version and the settings; plain lines only without art +std::vector startupBanner(const BannerInfo& info, bool art); + +// the version of the package: the first line of ./VERSION, else 4.2.. +std::string packageVersion(int protocol, int minor); + +} // namespace cs + +#endif // CLIENT_CONFIG_BANNER_HPP diff --git a/client/config/config.cpp b/client/config/config.cpp index 8c3e7a5ee..743bb73c9 100644 --- a/client/config/config.cpp +++ b/client/config/config.cpp @@ -59,6 +59,7 @@ const std::string PARAM_NAME_ROUND_ELAPSE_TIME = "round_elapse_time"; const std::string PARAM_NAME_STORE_BLOCK_ELAPSE_TIME = "store_block_elapse_time"; const std::string PARAM_NAME_ALWAYS_EXECUTE_CONTRACTS = "always_execute_contracts"; const std::string PARAM_NAME_SYNC_CONTRACT_EXECUTION = "sync_contract_execution"; +const std::string PARAM_NAME_BANNER = "banner"; const std::string PARAM_NAME_MIN_COMPATIBLE_VERSION = "min_compatible_version"; const std::string PARAM_NAME_COMPATIBLE_VERSION = "compatible_version"; const std::string PARAM_NAME_TRAVERSE_NAT = "traverse_nat"; @@ -904,6 +905,10 @@ Config Config::readFromFile(const std::string& fileName) { if (params.count(PARAM_NAME_SYNC_CONTRACT_EXECUTION) > 0) { result.syncContractExecution_ = params.get(PARAM_NAME_SYNC_CONTRACT_EXECUTION); } + if (params.count(PARAM_NAME_BANNER) > 0) { + const std::string banner = params.get(PARAM_NAME_BANNER); + result.startupBanner_ = !(banner == "off" || banner == "false" || banner == "0" || banner == "no"); + } if (params.count(PARAM_NAME_ALWAYS_EXECUTE_CONTRACTS) > 0) { result.alwaysExecuteContracts_ = params.get(PARAM_NAME_ALWAYS_EXECUTE_CONTRACTS); } diff --git a/client/config/config.hpp b/client/config/config.hpp index 422f38c62..e39fd0b3b 100644 --- a/client/config/config.hpp +++ b/client/config/config.hpp @@ -309,6 +309,11 @@ class Config { return alwaysExecuteContracts_; } + // [params] banner: the logo at start-up (off: the version and settings lines only) + bool startupBanner() const { + return startupBanner_; + } + bool newBlockchainTop() const { return newBlockchainTop_; } @@ -461,6 +466,7 @@ class Config { bool showBalanceChange_ = false; bool alwaysExecuteContracts_ = false; + bool startupBanner_ = true; bool syncContractExecution_ = true; bool recreateIndex_ = false; bool newBlockchainTop_ = false; diff --git a/client/src/peer.cpp b/client/src/peer.cpp index 8d581ac10..33ae2e656 100644 --- a/client/src/peer.cpp +++ b/client/src/peer.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #ifdef WIN32 #include @@ -108,6 +110,20 @@ bool Peer::onInit(const char*) { #endif logger::initialize(config_.getLoggerSettings()); + { + // which node wrote this log: the community release, its build and the main settings + cs::BannerInfo info; + info.version = cs::packageVersion(Config::getNodeVersion(), Config::getMinorNodeVersion()); + info.protocol = Config::getNodeVersion(); + info.build = client::Version::GIT_SHA1; + info.pruned = config_.getStorageSettings().pruneKeepBlocks > 0; + info.backend = config_.getStorageSettings().dbBackend; + info.serve = config_.getSnapshotSettings().serve; + info.backfill = config_.getStorageSettings().backfill; + for (const auto& line : cs::startupBanner(info, config_.startupBanner())) { + cslog() << line; + } + } observer_ = std::make_unique(config_, vm_); cs::ConfigHolder::instance().setConfig(config_); cs::Connector::connect( diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 316b5a38f..138fe5b47 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -40,7 +40,9 @@ lines under the new release. ## Not released yet -Nothing yet. +| PR | Change | +|---|---| +| #157 | client: at start the console and the log show a banner, the CREDITS logo with "community" under it, the release from `VERSION`, the protocol, the build commit, the storage, snapshot serving and the backfill; `[params] banner=off` keeps the text lines only (the start used to log nothing about the version) | ## community.16 — 2026-11-03 diff --git a/docs/differences.md b/docs/differences.md index 049889f3a..370b5c67b 100644 --- a/docs/differences.md +++ b/docs/differences.md @@ -107,6 +107,12 @@ rebuilt from the chain when the checkpoint holds none. See [tokens.md](tokens.md ## Start-up behaviour +- **A banner names the release.** At start the console and the log show the CREDITS logo with + "community" under it, then the release (`4.2.532-community.N` from the `VERSION` file), the + protocol, the build commit, the storage (pruned or full, database), whether snapshots are served, + and for a full node whether it backfills. `[params] banner=off` keeps the text lines only, for + log collectors. + - **Database check.** Before opening the block database, the node looks at `db/`. It writes the backend's name in `db/.backend`, and holds `db/.lock` so that two node processes cannot use the same folder. It stops with exit code 3, changing nothing, in these cases: diff --git a/tests/csnode/CMakeLists.txt b/tests/csnode/CMakeLists.txt index f5ef12da2..d8c64ad40 100644 --- a/tests/csnode/CMakeLists.txt +++ b/tests/csnode/CMakeLists.txt @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) file(GLOB SRCS *.cpp) list(APPEND SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../../client/config/config.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/../../client/config/banner.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../../client/src/dbcheck.cpp" ) diff --git a/tests/csnode/banner_tests.cpp b/tests/csnode/banner_tests.cpp new file mode 100644 index 000000000..1d49f2f2a --- /dev/null +++ b/tests/csnode/banner_tests.cpp @@ -0,0 +1,43 @@ +#include + +#include + +#include + +namespace { +cs::BannerInfo info(bool pruned) { + cs::BannerInfo i; + i.version = "4.2.532-community.16"; + i.protocol = 532; + i.build = "7de684740d7585fbc167cfdd44819a496ee26912"; + i.pruned = pruned; + i.backend = "lmdb"; + i.serve = true; + i.backfill = true; + return i; +} +} // namespace + +TEST(StartupBanner, LogoThenVersionAndSettings) { + const auto lines = cs::startupBanner(info(false), true); + ASSERT_EQ(lines.size(), 10u); + EXPECT_EQ(lines[0], " ____ ____ _____ ____ ___ _____ ____"); + EXPECT_EQ(lines[5], " c o m m u n i t y"); + EXPECT_EQ(lines[7], " node 4.2.532-community.16 (protocol 532, build 7de68474)"); + EXPECT_EQ(lines[8], " storage: full, lmdb snapshots: serve on backfill: on"); + EXPECT_EQ(lines[9], " https://github.com/CreditsCommunity/node"); +} + +// banner=off: the same lines without the logo; a pruned node shows no backfill +TEST(StartupBanner, PlainLinesForAPrunedNode) { + const auto lines = cs::startupBanner(info(true), false); + ASSERT_EQ(lines.size(), 3u); + EXPECT_EQ(lines[0], " node 4.2.532-community.16 (protocol 532, build 7de68474)"); + EXPECT_EQ(lines[1], " storage: pruned, lmdb snapshots: serve on"); +} + +TEST(StartupBanner, NoBuildWhenUnknown) { + auto i = info(true); + i.build.clear(); + EXPECT_EQ(cs::startupBanner(i, false)[0], " node 4.2.532-community.16 (protocol 532)"); +}