Skip to content
Merged
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
2 changes: 2 additions & 0 deletions client/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions client/config/banner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "banner.hpp"

#include <fstream>

namespace cs {

std::vector<std::string> startupBanner(const BannerInfo& info, bool art) {
std::vector<std::string> 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
29 changes: 29 additions & 0 deletions client/config/banner.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef CLIENT_CONFIG_BANNER_HPP
#define CLIENT_CONFIG_BANNER_HPP

#include <string>
#include <vector>

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<std::string> startupBanner(const BannerInfo& info, bool art);

// the version of the package: the first line of ./VERSION, else 4.2.<protocol>.<minor>
std::string packageVersion(int protocol, int minor);

} // namespace cs

#endif // CLIENT_CONFIG_BANNER_HPP
5 changes: 5 additions & 0 deletions client/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -904,6 +905,10 @@ Config Config::readFromFile(const std::string& fileName) {
if (params.count(PARAM_NAME_SYNC_CONTRACT_EXECUTION) > 0) {
result.syncContractExecution_ = params.get<bool>(PARAM_NAME_SYNC_CONTRACT_EXECUTION);
}
if (params.count(PARAM_NAME_BANNER) > 0) {
const std::string banner = params.get<std::string>(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<bool>(PARAM_NAME_ALWAYS_EXECUTE_CONTRACTS);
}
Expand Down
6 changes: 6 additions & 0 deletions client/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}
Expand Down Expand Up @@ -461,6 +466,7 @@ class Config {

bool showBalanceChange_ = false;
bool alwaysExecuteContracts_ = false;
bool startupBanner_ = true;
bool syncContractExecution_ = true;
bool recreateIndex_ = false;
bool newBlockchainTop_ = false;
Expand Down
16 changes: 16 additions & 0 deletions client/src/peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <net/transport.hpp>
#include <csnode/configholder.hpp>
#include <cmdlineargs.hpp>
#include <banner.hpp>
#include <version.hpp>

#ifdef WIN32
#include <csignal>
Expand Down Expand Up @@ -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::Observer>(config_, vm_);
cs::ConfigHolder::instance().setConfig(config_);
cs::Connector::connect(
Expand Down
4 changes: 3 additions & 1 deletion docs/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions docs/differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/csnode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
43 changes: 43 additions & 0 deletions tests/csnode/banner_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <gtest/gtest.h>

#include <string>

#include <banner.hpp>

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)");
}
Loading