Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix grpc bind error caused program crash && add exception handler for java wrapper #85

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
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 .github/workflows/cpp_toolkit_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
with:
toolchain: nightly-2022-07-28
override: true
- name: Prepare python
if: runner.os == 'Windows'
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Prepare vcpkg
if: runner.os != 'Windows'
uses: friendlyanon/setup-vcpkg@v1
Expand All @@ -65,7 +70,7 @@ jobs:
- name: Build for windows
if: runner.os == 'Windows'
run: |
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DBUILD_PYTHON=OFF -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DBUILD_PYTHON=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
- name: Build for linux
if: runner.os == 'Linux'
run: |
Expand Down
43 changes: 32 additions & 11 deletions cpp/cmake/CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "/usr/bin/time")
# set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "/usr/bin/time")
# Use ISO C++17 standard language.
set(CMAKE_CXX_FLAGS "-pthread -fPIC -fexceptions")
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Enables all the warnings about constructions that some users consider questionable,
# and that are easy to avoid. Also enable some extra warning flags that are not
Expand Down Expand Up @@ -75,11 +74,16 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA

option(USE_LD_GOLD "Use GNU gold linker" ON)
if (USE_LD_GOLD)
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if ("${LD_VERSION}" MATCHES "GNU gold")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
endif ()
if("${LINKER}" MATCHES "gold")
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if("${LD_VERSION}" MATCHES "GNU gold")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
endif()
elseif("${LINKER}" MATCHES "mold")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=mold")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=mold")
endif()
endif ()

# Additional GCC-specific compiler settings.
Expand All @@ -91,15 +95,32 @@ 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}")
set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_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.
# Use it if we have the option to do so.
# See https://lwn.net/Articles/584225/
if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
add_compile_options(-fstack-protector-strong)
add_compile_options(-fstack-protector)
add_compile_options(-fstack-protector-strong)
add_compile_options(-fstack-protector)

add_compile_options(-fPIC)
add_compile_options(-Wno-error=nonnull)
add_compile_options(-foptimize-sibling-calls)
add_compile_options(-Wno-stringop-overflow)
add_compile_options(-Wno-restrict)
add_compile_options(-Wno-error=format-truncation)

if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
add_compile_options(-Wno-stringop-overread)
add_compile_options(-Wno-maybe-uninitialized)
add_compile_options(-Wno-array-bounds)
add_compile_options(-Wno-aggressive-loop-optimizations)
endif()
# Additional Clang-specific compiler settings.
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
Expand Down
4 changes: 2 additions & 2 deletions cpp/cmake/ProjectTCMalloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ ExternalProject_Add(gperftools
)

ExternalProject_Get_Property(gperftools SOURCE_DIR)
add_library(TCMalloc INTERFACE IMPORTED)
add_library(TCMalloc STATIC IMPORTED GLOBAL)

set(TCMALLOC_INCLUDE_DIR ${SOURCE_DIR}/include/)
set(TCMALLOC_LIBRARY ${SOURCE_DIR}/.libs/${TCMALLOC_LIB_NAME})
file(MAKE_DIRECTORY ${TCMALLOC_INCLUDE_DIR}) # Must exist.

set_property(TARGET TCMalloc PROPERTY INTERFACE_LINK_LIBRARIES ${TCMALLOC_LIBRARY})
set_property(TARGET TCMalloc PROPERTY IMPORTED_LOCATION ${TCMALLOC_LIBRARY})
set_property(TARGET TCMalloc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${TCMALLOC_INCLUDE_DIR})

add_dependencies(TCMalloc gperftools)
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 @@ -102,14 +93,53 @@ class GrpcConfig
bool m_enableHealthCheck = true;
std::string m_loadBalancePolicy = "round_robin";
bool m_enableDnslookup = false;
// Note: grpc use int to set the maxMsgSize
uint64_t const c_maxMsgSize = INT_MAX;

// 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
38 changes: 5 additions & 33 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 All @@ -81,31 +81,3 @@ CommandLineParam ppc::initCommandLine(int argc, const char* argv[])
}
return ppc::CommandLineParam{configPath};
}

void ppc::initAppCommandLine(int argc, 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");
boost::program_options::variables_map vm;
try
{
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, main_options), vm);
}
catch (...)
{
printVersion();
}
/// help information
if (vm.count("help") || vm.count("h"))
{
std::cout << main_options << std::endl;
exit(0);
}
/// version information
if (vm.count("version") || vm.count("v"))
{
printVersion();
exit(0);
}
}
5 changes: 2 additions & 3 deletions cpp/wedpr-helper/libhelper/CommandHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct CommandLineParam
{
std::string configFilePath;
};
void printVersion();
CommandLineParam initCommandLine(int argc, const char* argv[]);
void initAppCommandLine(int argc, char* argv[]);
void printVersion(std::string const& binaryName);
CommandLineParam initCommandLine(std::string const& binaryName, int argc, const char* argv[]);
} // namespace ppc
4 changes: 0 additions & 4 deletions cpp/wedpr-initializer/Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ void Initializer::init(ppc::gateway::IGateway::Ptr const& gateway)
INIT_LOG(INFO) << LOG_DESC("create bs mode ecdh psi success");

initMsgHandlers();

// add parallelism control for tbb
tbb::global_control gc(
tbb::global_control::max_allowed_parallelism, m_config->threadPoolSize());
}

// init the msg-handlers
Expand Down
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
Loading
Loading