diff --git a/.github/workflows/cpp_full_node_workflow.yml b/.github/workflows/cpp_full_node_workflow.yml index d855aa3b..3158cbc9 100644 --- a/.github/workflows/cpp_full_node_workflow.yml +++ b/.github/workflows/cpp_full_node_workflow.yml @@ -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' @@ -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 diff --git a/cpp/cmake/CompilerSettings.cmake b/cpp/cmake/CompilerSettings.cmake index fc4ca98f..1d2efdc8 100644 --- a/cpp/cmake/CompilerSettings.cmake +++ b/cpp/cmake/CompilerSettings.cmake @@ -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. diff --git a/cpp/ppc-framework/protocol/GrpcConfig.h b/cpp/ppc-framework/protocol/GrpcConfig.h index 6b317fc8..06b3886f 100644 --- a/cpp/ppc-framework/protocol/GrpcConfig.h +++ b/cpp/ppc-framework/protocol/GrpcConfig.h @@ -26,27 +26,6 @@ namespace ppc::protocol { -class GrpcServerConfig -{ -public: - using Ptr = std::shared_ptr; - 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: @@ -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; } @@ -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() = 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) diff --git a/cpp/wedpr-helper/libhelper/CommandHelper.cpp b/cpp/wedpr-helper/libhelper/CommandHelper.cpp index 85a44441..b3b8939f 100644 --- a/cpp/wedpr-helper/libhelper/CommandHelper.cpp +++ b/cpp/wedpr-helper/libhelper/CommandHelper.cpp @@ -26,9 +26,9 @@ 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; @@ -36,7 +36,7 @@ void ppc::printVersion() 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")( @@ -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")) @@ -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"); diff --git a/cpp/wedpr-helper/libhelper/CommandHelper.h b/cpp/wedpr-helper/libhelper/CommandHelper.h index ab15d51f..73e44286 100644 --- a/cpp/wedpr-helper/libhelper/CommandHelper.h +++ b/cpp/wedpr-helper/libhelper/CommandHelper.h @@ -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 \ No newline at end of file diff --git a/cpp/wedpr-main/air-node/main.cpp b/cpp/wedpr-main/air-node/main.cpp index b7cfd67f..ae54afee 100644 --- a/cpp/wedpr-main/air-node/main.cpp +++ b/cpp/wedpr-main/air-node/main.cpp @@ -22,6 +22,11 @@ int main(int argc, const char* argv[]) { - auto initializer = std::make_shared(); - startProgram(argc, argv, "ppc-psi", initializer); + std::string binaryName = "ppc-psi"; + auto initializer = std::make_shared(); + auto ret = startProgram(argc, argv, binaryName, initializer); + initializer.reset(); + std::cout << "[" << bcos::getCurrentDateTime() << "] "; + std::cout << "The " << binaryName << " program exit normally." << std::endl; + return ret; } \ No newline at end of file diff --git a/cpp/wedpr-main/cem-node/main.cpp b/cpp/wedpr-main/cem-node/main.cpp index cfd4a724..a34f1093 100644 --- a/cpp/wedpr-main/cem-node/main.cpp +++ b/cpp/wedpr-main/cem-node/main.cpp @@ -53,19 +53,19 @@ int main(int argc, const char* argv[]) auto initializer = std::make_shared(); 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()) diff --git a/cpp/wedpr-main/common/NodeStarter.h b/cpp/wedpr-main/common/NodeStarter.h index 71b7b69b..fd08bd41 100644 --- a/cpp/wedpr-main/common/NodeStarter.h +++ b/cpp/wedpr-main/common/NodeStarter.h @@ -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)); @@ -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 @@ -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 \ No newline at end of file diff --git a/cpp/wedpr-main/gateway/main.cpp b/cpp/wedpr-main/gateway/main.cpp index 3f309bbd..c8795457 100644 --- a/cpp/wedpr-main/gateway/main.cpp +++ b/cpp/wedpr-main/gateway/main.cpp @@ -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(); - 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; } \ No newline at end of file diff --git a/cpp/wedpr-main/mpc-node/CMakeLists.txt b/cpp/wedpr-main/mpc-node/CMakeLists.txt index fd3942db..2ca48eba 100644 --- a/cpp/wedpr-main/mpc-node/CMakeLists.txt +++ b/cpp/wedpr-main/mpc-node/CMakeLists.txt @@ -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) diff --git a/cpp/wedpr-main/mpc-node/main.cpp b/cpp/wedpr-main/mpc-node/main.cpp index dae16bf5..1df02246 100644 --- a/cpp/wedpr-main/mpc-node/main.cpp +++ b/cpp/wedpr-main/mpc-node/main.cpp @@ -53,19 +53,19 @@ int main(int argc, const char* argv[]) auto initializer = std::make_shared(); 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()) diff --git a/cpp/wedpr-main/pro-node/main.cpp b/cpp/wedpr-main/pro-node/main.cpp index a122784b..2e075403 100644 --- a/cpp/wedpr-main/pro-node/main.cpp +++ b/cpp/wedpr-main/pro-node/main.cpp @@ -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(); - 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; } \ No newline at end of file diff --git a/cpp/wedpr-protocol/grpc/server/GrpcServer.cpp b/cpp/wedpr-protocol/grpc/server/GrpcServer.cpp index 350d622e..4a589205 100644 --- a/cpp/wedpr-protocol/grpc/server/GrpcServer.cpp +++ b/cpp/wedpr-protocol/grpc/server/GrpcServer.cpp @@ -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) { diff --git a/cpp/wedpr-transport/ppc-http/demo/http_demo.cpp b/cpp/wedpr-transport/ppc-http/demo/http_demo.cpp index 08ad495d..072c0e7e 100644 --- a/cpp/wedpr-transport/ppc-http/demo/http_demo.cpp +++ b/cpp/wedpr-transport/ppc-http/demo/http_demo.cpp @@ -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(); // not specify the certPath in air-mode ppcConfig->loadGatewayConfig(param.configFilePath); @@ -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; diff --git a/cpp/wedpr-transport/ppc-rpc/demo/rpc_demo.cpp b/cpp/wedpr-transport/ppc-rpc/demo/rpc_demo.cpp index 252e3ba4..9fdaf747 100644 --- a/cpp/wedpr-transport/ppc-rpc/demo/rpc_demo.cpp +++ b/cpp/wedpr-transport/ppc-rpc/demo/rpc_demo.cpp @@ -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(); // not specify the certPath in air-mode ppcConfig->loadRpcConfig(param.configFilePath); @@ -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;