Skip to content

Commit

Permalink
optimize version print
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Nov 12, 2024
1 parent 229e31c commit 5575327
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cpp_full_node_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ jobs:
export GCC='gcc-10'
export CXX='g++-10'
sudo bash -x cpp/tools/install_depends.sh -o ubuntu
mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
mkdir -p cpp/build && cd cpp/build && cmake -DBUILD_STATIC=ON -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
make -j3
- name: Build for macOS
if: runner.os == 'macOS'
run: |
bash -x cpp/tools/install_depends.sh -o macos
mkdir -p cpp/build && cd cpp/build && cmake -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
mkdir -p cpp/build && cd cpp/build && cmake -DBUILD_STATIC=ON -DTESTS=ON -DCOVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake ../
make -j3
- uses: actions/upload-artifact@v4
if: runner.os == 'macOS'
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
rm -rf python
mkdir -p cpp/build
cd cpp/build
cmake3 -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
cmake3 -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
- name: FreeDiskSpace
run: |
df -lh
Expand Down
7 changes: 6 additions & 1 deletion cpp/cmake/CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
if (NOT (GCC_VERSION VERSION_GREATER ${GCC_MIN_VERSION} OR GCC_VERSION VERSION_EQUAL ${GCC_MIN_VERSION}))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ ${GCC_MIN_VERSION} or greater. Current is ${GCC_VERSION}")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}")
if(BUILD_STATIC)
# solve multiple definition of `__lll_lock_wait_private'
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE} -ftree-parallelize-loops=2 -flto")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}")
endif()
set(CMAKE_C_FLAGS "-std=c99 -fexceptions ${CMAKE_C_FLAGS} ${MARCH_TYPE}")

# Strong stack protection was only added in GCC 4.9.
Expand Down
76 changes: 53 additions & 23 deletions cpp/ppc-framework/protocol/GrpcConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@

namespace ppc::protocol
{
class GrpcServerConfig
{
public:
using Ptr = std::shared_ptr<GrpcServerConfig>;
GrpcServerConfig() = default;
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck)
: m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
{}
std::string listenEndPoint() const { return m_endPoint.listenEndPoint(); }

void setEndPoint(EndPoint endPoint) { m_endPoint = endPoint; }
void setEnableHealthCheck(bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }

EndPoint const& endPoint() const { return m_endPoint; }
EndPoint& mutableEndPoint() { return m_endPoint; }
bool enableHealthCheck() const { return m_enableHealthCheck; }

protected:
ppc::protocol::EndPoint m_endPoint;
bool m_enableHealthCheck = true;
};
class GrpcConfig
{
public:
Expand All @@ -71,10 +50,22 @@ class GrpcConfig

void setMaxSendMessageSize(uint64_t maxSendMessageSize)
{
if (maxSendMessageSize > c_maxMsgSize)
{
BOOST_THROW_EXCEPTION(
WeDPRException() << bcos::errinfo_comment(
"The MaxSendMessageSize limit is " + std::to_string(c_maxMsgSize)));
}
m_maxSendMessageSize = maxSendMessageSize;
}
void setMaxReceivedMessageSize(uint64_t maxReceivedMessageSize)
{
if (maxReceivedMessageSize > c_maxMsgSize)
{
BOOST_THROW_EXCEPTION(
WeDPRException() << bcos::errinfo_comment(
"The MaxReceivedMessageSize limit is " + std::to_string(c_maxMsgSize)));
}
m_maxReceivedMessageSize = maxReceivedMessageSize;
}

Expand Down Expand Up @@ -103,13 +94,52 @@ class GrpcConfig
std::string m_loadBalancePolicy = "round_robin";
bool m_enableDnslookup = false;

uint64_t const c_maxMsgSize = 1024 * 1024 * 1024;

// the max send message size in bytes
uint64_t m_maxSendMessageSize = 1024 * 1024 * 1024;
uint64_t m_maxSendMessageSize = c_maxMsgSize;
// the max received message size in bytes
uint64_t m_maxReceivedMessageSize = 1024 * 1024 * 1024;
uint64_t m_maxReceivedMessageSize = c_maxMsgSize;
int m_compressAlgorithm = 0;
};

class GrpcServerConfig : public GrpcConfig
{
public:
using Ptr = std::shared_ptr<GrpcServerConfig>;
GrpcServerConfig() = default;
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck)
: m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
{}
~GrpcServerConfig() override = default;

std::string listenEndPoint() const { return m_endPoint.listenEndPoint(); }

void setEndPoint(EndPoint endPoint) { m_endPoint = endPoint; }
void setEnableHealthCheck(bool enableHealthCheck) { m_enableHealthCheck = enableHealthCheck; }

EndPoint const& endPoint() const { return m_endPoint; }
EndPoint& mutableEndPoint() { return m_endPoint; }
bool enableHealthCheck() const { return m_enableHealthCheck; }

uint64_t maxMsgSize() const { return m_maxMsgSize; }
void setMaxMsgSize(uint64_t maxMsgSize)
{
if (maxMsgSize > c_maxMsgSize)
{
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
"The maxMsgSize limit is " + std::to_string(c_maxMsgSize)));
}
m_maxMsgSize = maxMsgSize;
}

protected:
ppc::protocol::EndPoint m_endPoint;
bool m_enableHealthCheck = true;
uint64_t m_maxMsgSize = c_maxMsgSize;
};


inline std::string printGrpcConfig(ppc::protocol::GrpcConfig::Ptr const& grpcConfig)
{
if (!grpcConfig)
Expand Down
10 changes: 5 additions & 5 deletions cpp/wedpr-helper/libhelper/CommandHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@

using namespace ppc;

void ppc::printVersion()
void ppc::printVersion(std::string const& binaryName)
{
std::cout << "PPCS-Core Version : " << PPC_PROJECT_VERSION << std::endl;
std::cout << binaryName << " Version : " << PPC_PROJECT_VERSION << std::endl;
std::cout << "Build Time : " << PPC_BUILD_TIME << std::endl;
std::cout << "Build Type : " << PPC_BUILD_PLATFORM << "/" << PPC_BUILD_TYPE
<< std::endl;
std::cout << "Git Branch : " << PPC_BUILD_BRANCH << std::endl;
std::cout << "Git Commit : " << PPC_COMMIT_HASH << std::endl;
}

CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
CommandLineParam ppc::initCommandLine(std::string const& binaryName, int argc, const char* argv[])
{
boost::program_options::options_description main_options("Usage of PPC");
main_options.add_options()("help,h", "print help information")("version,v", "version of PPC")(
Expand All @@ -49,7 +49,7 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
}
catch (...)
{
printVersion();
printVersion(binaryName);
}
/// help information
if (vm.count("help") || vm.count("h"))
Expand All @@ -60,7 +60,7 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
/// version information
if (vm.count("version") || vm.count("v"))
{
printVersion();
printVersion(binaryName);
exit(0);
}
std::string configPath("./config.ini");
Expand Down
4 changes: 2 additions & 2 deletions cpp/wedpr-helper/libhelper/CommandHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ struct CommandLineParam
{
std::string configFilePath;
};
void printVersion();
CommandLineParam initCommandLine(int argc, const char* argv[]);
void printVersion(std::string const& binaryName);
CommandLineParam initCommandLine(std::string const& binaryName, int argc, const char* argv[]);
} // namespace ppc
9 changes: 7 additions & 2 deletions cpp/wedpr-main/air-node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

int main(int argc, const char* argv[])
{
auto initializer = std::make_shared<ppc::node::AirNodeInitializer>();
startProgram(argc, argv, "ppc-psi", initializer);
std::string binaryName = "ppc-psi";
auto initializer = std::make_shared<ppc::node::AirNodeInitializer>();
auto ret = startProgram(argc, argv, binaryName, initializer);
initializer.reset();
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "The " << binaryName << " program exit normally." << std::endl;
return ret;
}
6 changes: 3 additions & 3 deletions cpp/wedpr-main/cem-node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ int main(int argc, const char* argv[])
auto initializer = std::make_shared<ppc::cem::CEMInitializer>();
try
{
auto param = initCommandLine(argc, argv);
auto param = initCommandLine("wedpr-cem", argc, argv);
initializer->init(param.configFilePath);
initializer->start();
}
catch (std::exception const& e)
{
printVersion();
printVersion("wedpr-cem");
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "start ppc-cem failed, error:" << boost::diagnostic_information(e)
<< std::endl;
return -1;
}
printVersion();
printVersion("wedpr-cem");
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "The ppc-cem is running..." << std::endl;
while (!exitHandler.shouldExit())
Expand Down
14 changes: 6 additions & 8 deletions cpp/wedpr-main/common/NodeStarter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int startProgram(
/// set LC_ALL
setDefaultOrCLocale();
std::set_terminate([]() {
std::cerr << "terminate handler called, print stacks" << std::endl;
std::cout << "terminate handler called, print stacks" << std::endl;
void* trace_elems[20];
int trace_elem_count(backtrace(trace_elems, 20));
char** stack_syms(backtrace_symbols(trace_elems, trace_elem_count));
Expand All @@ -43,7 +43,7 @@ int startProgram(
std::cout << stack_syms[i] << "\n";
}
free(stack_syms);
std::cerr << "terminate handler called, print stack end" << std::endl;
std::cout << "terminate handler called, print stack end" << std::endl;
abort();
});
// get datetime and output welcome info
Expand All @@ -55,27 +55,25 @@ int startProgram(
// Note: the initializer must exist in the life time of the whole program
try
{
auto param = ppc::initCommandLine(argc, argv);
auto param = ppc::initCommandLine(binaryName, argc, argv);
starter->init(param.configFilePath);
starter->start();
}
catch (std::exception const& e)
{
printVersion();
printVersion(binaryName);
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "start " + binaryName + " failed, error:" << boost::diagnostic_information(e)
<< std::endl;
return -1;
}
printVersion();
printVersion(binaryName);
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "The " + binaryName + " is running..." << std::endl;
while (!exitHandler.shouldExit())
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
starter.reset();
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "The " + binaryName + " program exit normally." << std::endl;
return 0;
}
} // namespace ppc::node
7 changes: 6 additions & 1 deletion cpp/wedpr-main/gateway/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
using namespace ppc::node;
int main(int argc, const char* argv[])
{
std::string binaryName = "ppc-gateway-service";
auto initializer = std::make_shared<ppc::gateway::GatewayInitializer>();
startProgram(argc, argv, "ppc-gateway-service", initializer);
auto ret = startProgram(argc, argv, binaryName, initializer);
initializer.reset();
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "The " << binaryName << " program exit normally." << std::endl;
return ret;
}
2 changes: 1 addition & 1 deletion cpp/wedpr-main/mpc-node/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aux_source_directory(. SRC_LIST)

add_executable(${MPC_BINARY_NAME} ${SRC_LIST})
target_link_libraries(${MPC_BINARY_NAME} PUBLIC ${MPC_TARGET} ${RPC_TARGET} ${HELPER_TARGET} ${WEDPR_TRANSPORT_SDK_TARGET} TBB::tbb)
target_link_libraries(${MPC_BINARY_NAME} PUBLIC ${WEDPR_TRANSPORT_SDK_TARGET} ${MPC_TARGET} ${RPC_TARGET} ${HELPER_TARGET} TBB::tbb)
6 changes: 3 additions & 3 deletions cpp/wedpr-main/mpc-node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ int main(int argc, const char* argv[])
auto initializer = std::make_shared<ppc::mpc::MPCInitializer>();
try
{
auto param = initCommandLine(argc, argv);
auto param = initCommandLine("wedpr-mpc", argc, argv);
initializer->init(param.configFilePath);
initializer->start();
}
catch (std::exception const& e)
{
printVersion();
printVersion("wedpr-mpc");
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "start ppc-mpc failed, error:" << boost::diagnostic_information(e)
<< std::endl;
return -1;
}
printVersion();
printVersion("wedpr-mpc");
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "The ppc-mpc is running..." << std::endl;
while (!exitHandler.shouldExit())
Expand Down
7 changes: 6 additions & 1 deletion cpp/wedpr-main/pro-node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
using namespace ppc::node;
int main(int argc, const char* argv[])
{
std::string binaryName = "ppc-pro-node";
auto initializer = std::make_shared<ppc::node::ProNodeInitializer>();
startProgram(argc, argv, "ppc-pro-node", initializer);
auto ret = startProgram(argc, argv, binaryName, initializer);
initializer.reset();
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "The " << binaryName << " program exit normally." << std::endl;
return ret;
}
3 changes: 3 additions & 0 deletions cpp/wedpr-protocol/grpc/server/GrpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void GrpcServer::start()
builder.AddChannelArgument(GRPC_ARG_ALLOW_REUSEPORT, 0);
// without authentication
builder.AddListeningPort(m_config->listenEndPoint(), grpc::InsecureServerCredentials());
builder.SetMaxMessageSize(m_config->maxMsgSize());
builder.SetMaxSendMessageSize(m_config->maxSendMessageSize());
builder.SetMaxReceiveMessageSize(m_config->maxReceivedMessageSize());
// register the service
for (auto const& service : m_bindingServices)
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/wedpr-transport/ppc-http/demo/http_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char const* argv[])

try
{
auto param = initCommandLine(argc, argv);
auto param = initCommandLine("http_demo", argc, argv);
auto ppcConfig = std::make_shared<PPCConfig>();
// not specify the certPath in air-mode
ppcConfig->loadGatewayConfig(param.configFilePath);
Expand All @@ -67,7 +67,7 @@ int main(int argc, char const* argv[])
}
catch (std::exception const& e)
{
ppc::printVersion();
ppc::printVersion("http-demo");
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "start http-demo failed, error:" << boost::diagnostic_information(e)
<< std::endl;
Expand Down
4 changes: 2 additions & 2 deletions cpp/wedpr-transport/ppc-rpc/demo/rpc_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, const char* argv[])
signal(SIGINT, &ExitHandler::exitHandler);
try
{
auto param = initCommandLine(argc, argv);
auto param = initCommandLine("rpc_demo", argc, argv);
auto ppcConfig = std::make_shared<PPCConfig>();
// not specify the certPath in air-mode
ppcConfig->loadRpcConfig(param.configFilePath);
Expand All @@ -63,7 +63,7 @@ int main(int argc, const char* argv[])
}
catch (std::exception const& e)
{
ppc::printVersion();
ppc::printVersion("rpc_demo");
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "start rpc-demo failed, error:" << boost::diagnostic_information(e)
<< std::endl;
Expand Down

0 comments on commit 5575327

Please sign in to comment.