From 150136870d838d9ae4843f97790f7295d0c1bb88 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 18 Jan 2024 09:42:58 +0300 Subject: [PATCH] #577 - add additional cmake flag for disabling sidechain plugin --- .gitlab-ci.yml | 42 +++++++++++++++++++ CMakeLists.txt | 10 +++-- README.md | 28 +++++++++++++ libraries/app/CMakeLists.txt | 10 +++-- libraries/app/api.cpp | 6 +++ libraries/app/include/graphene/app/api.hpp | 11 ++++- libraries/plugins/CMakeLists.txt | 4 +- libraries/plugins/delayed_node/CMakeLists.txt | 9 +++- .../peerplays_sidechain/CMakeLists.txt | 5 ++- .../wallet/include/graphene/wallet/wallet.hpp | 6 ++- libraries/wallet/wallet.cpp | 18 ++++++++ programs/witness_node/CMakeLists.txt | 9 +++- programs/witness_node/main.cpp | 4 ++ tests/CMakeLists.txt | 8 ++-- 14 files changed, 154 insertions(+), 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca0c83a6..b6067704 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,6 +32,27 @@ build-mainnet: tags: - builder +build-mainnet-without-sidechain-plugin: + stage: build + script: + - rm -rf .git/modules/docs .git/modules/libraries/fc ./docs ./libraries/fc + - git submodule sync + - git submodule update --init --recursive + - rm -rf build + - mkdir build + - cd build + - cmake -DCMAKE_BUILD_TYPE=Release -DDISABLE_PEERPLAYS_SIDECHAIN_PLUGIN=1 .. + - make -j$(nproc) + artifacts: + untracked: true + paths: + - build/libraries/ + - build/programs/ + - build/tests/ + when: manual + tags: + - builder + test-mainnet: stage: test dependencies: @@ -83,6 +104,27 @@ build-testnet: tags: - builder +build-testnet-without-sidechain-plugin: + stage: build + script: + - rm -rf .git/modules/docs .git/modules/libraries/fc ./docs ./libraries/fc + - git submodule sync + - git submodule update --init --recursive + - rm -rf build + - mkdir build + - cd build + - cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_PEERPLAYS_TESTNET=1 -DDISABLE_PEERPLAYS_SIDECHAIN_PLUGIN=1 .. + - make -j$(nproc) + artifacts: + untracked: true + paths: + - build/libraries/ + - build/programs/ + - build/tests/ + when: manual + tags: + - builder + deploy-testnet: stage: deploy dependencies: diff --git a/CMakeLists.txt b/CMakeLists.txt index 695881be..4bc9dae3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,9 +38,6 @@ function(get_linux_lsb_release_information) endfunction() if(CMAKE_SYSTEM_NAME MATCHES "Linux") - find_package(cppzmq) - target_link_libraries(cppzmq) - get_linux_lsb_release_information() message(STATUS "Linux ${LSB_RELEASE_ID_SHORT} ${LSB_RELEASE_VERSION_SHORT} ${LSB_RELEASE_CODENAME_SHORT}") string(REGEX MATCHALL "([0-9]+)" arg_list ${LSB_RELEASE_VERSION_SHORT}) @@ -83,6 +80,11 @@ endmacro() set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") +if(NOT DEFINED DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN) + add_definitions(-DBUILD_PEERPLAYS_SIDECHAIN_PLUGIN=1) + message ("\n====================\nBuilding with Sidechain Plugin\n====================\n") +endif () + if (BUILD_PEERPLAYS_TESTNET) set(GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR}/genesis-testnet.json" CACHE PATH "location of the genesis.json to embed in the executable" ) #add_compile_definitions(BUILD_PEERPLAYS_TESTNET=1) @@ -285,3 +287,5 @@ unset(GRAPHENE_EGENESIS_JSON) unset(GRAPHENE_EGENESIS_JSON CACHE) unset(BUILD_PEERPLAYS_TESTNET) unset(BUILD_PEERPLAYS_TESTNET CACHE) +unset(DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN) +unset(DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN CACHE) diff --git a/README.md b/README.md index 3d8b1b12..3e3fca7d 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,34 @@ make -j$(nproc) sudo make install # this can install the executable files under /usr/local ``` +## Building without support for sidechain plugin + +Building Peerplays +``` +git clone https://gitlab.com/PBSA/peerplays.git +cd peerplays +git submodule update --init --recursive + +# If you want to build Mainnet node +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DDISABLE_PEERPLAYS_SIDECHAIN_PLUGIN=1 .. + +# If you want to build Testnet node +mkdir build-testnet +cd build-testnet +cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_PEERPLAYS_TESTNET=1 -DDISABLE_PEERPLAYS_SIDECHAIN_PLUGIN=1 .. + +# Update -j flag depending on your current system specs; +# Recommended 4GB of RAM per 1 CPU core +# make -j2 for 8GB RAM +# make -j4 for 16GB RAM +# make -j8 for 32GB RAM +make -j$(nproc) + +sudo make install # this can install the executable files under /usr/local +``` + ## Docker images Install docker, and add current user to docker group. diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index fe92face..3cc637aa 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -13,9 +13,13 @@ add_library( graphene_app # need to link graphene_debug_witness because plugins aren't sufficiently isolated #246 #target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness ) -target_link_libraries( graphene_app - PUBLIC graphene_net graphene_utilities - graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch graphene_es_objects graphene_generate_genesis graphene_market_history peerplays_sidechain ) +set(LIBRARIES graphene_net graphene_utilities graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch graphene_es_objects graphene_generate_genesis graphene_market_history) + +if(NOT DEFINED DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN) + list(APPEND LIBRARIES peerplays_sidechain) +endif () + +target_link_libraries( graphene_app PUBLIC ${LIBRARIES} ) target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 13f6586b..1753ee04 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -103,11 +103,15 @@ void login_api::enable_api(const std::string &api_name) { // can only enable this API if the plugin was loaded if (_app.get_plugin("affiliate_stats")) _affiliate_stats_api = std::make_shared(std::ref(_app)); +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN } else if (api_name == "sidechain_api") { // can only enable this API if the plugin was loaded if (_app.get_plugin("peerplays_sidechain")) _sidechain_api = std::make_shared(std::ref(_app)); } +#else + } +#endif return; } @@ -306,10 +310,12 @@ fc::api login_api::affiliate_sta return *_affiliate_stats_api; } +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN fc::api login_api::sidechain() const { FC_ASSERT(_sidechain_api); return *_sidechain_api; } +#endif vector history_api::get_fill_order_history(std::string asset_a, std::string asset_b, uint32_t limit) const { FC_ASSERT(_app.chain_database()); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index e5c2a3d5..19563ff7 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -36,7 +36,9 @@ #include #include #include +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN #include +#endif #include #include @@ -375,7 +377,9 @@ public: /// @brief Retrieve the affiliate_stats API (if available) fc::api affiliate_stats() const; /// @brief Retrieve the sidechain_api API (if available) +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN fc::api sidechain() const; +#endif /// @brief Called to enable an API, not reflected. void enable_api(const string &api_name); @@ -391,7 +395,9 @@ private: optional> _debug_api; optional> _bookie_api; optional> _affiliate_stats_api; +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN optional> _sidechain_api; +#endif }; }} // namespace graphene::app @@ -460,6 +466,9 @@ FC_API(graphene::app::login_api, (debug) (bookie) (affiliate_stats) - (sidechain)) +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN + (sidechain) +#endif +) // clang-format on diff --git a/libraries/plugins/CMakeLists.txt b/libraries/plugins/CMakeLists.txt index 20497629..2f44a49b 100644 --- a/libraries/plugins/CMakeLists.txt +++ b/libraries/plugins/CMakeLists.txt @@ -9,6 +9,8 @@ add_subdirectory( es_objects ) add_subdirectory( generate_genesis ) add_subdirectory( generate_uia_sharedrop_genesis ) add_subdirectory( market_history ) -add_subdirectory( peerplays_sidechain ) +if(NOT DEFINED DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN) + add_subdirectory( peerplays_sidechain ) +endif () add_subdirectory( snapshot ) add_subdirectory( witness ) diff --git a/libraries/plugins/delayed_node/CMakeLists.txt b/libraries/plugins/delayed_node/CMakeLists.txt index ab01b78d..910cc958 100644 --- a/libraries/plugins/delayed_node/CMakeLists.txt +++ b/libraries/plugins/delayed_node/CMakeLists.txt @@ -4,7 +4,14 @@ add_library( graphene_delayed_node delayed_node_plugin.cpp ) -target_link_libraries( graphene_delayed_node PRIVATE graphene_plugin graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch graphene_market_history peerplays_sidechain ) +set(LIBRARIES graphene_plugin graphene_accounts_list graphene_affiliate_stats graphene_bookie graphene_debug_witness graphene_elasticsearch graphene_market_history) + +if(NOT DEFINED DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN) + list(APPEND LIBRARIES peerplays_sidechain) +endif () + +target_link_libraries( graphene_delayed_node PRIVATE ${LIBRARIES} ) + target_include_directories( graphene_delayed_node PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/peerplays_sidechain/CMakeLists.txt b/libraries/plugins/peerplays_sidechain/CMakeLists.txt index 21fac167..5efcb96f 100644 --- a/libraries/plugins/peerplays_sidechain/CMakeLists.txt +++ b/libraries/plugins/peerplays_sidechain/CMakeLists.txt @@ -1,5 +1,8 @@ file(GLOB_RECURSE HEADERS "include/graphene/peerplays_sidechain/*.hpp") +find_package(cppzmq) +target_link_libraries(cppzmq) + add_library( peerplays_sidechain peerplays_sidechain_plugin.cpp sidechain_api.cpp @@ -44,7 +47,7 @@ endif() unset(ENABLE_PEERPLAYS_ASSET_DEPOSITS) unset(ENABLE_PEERPLAYS_ASSET_DEPOSITS CACHE) -target_link_libraries( peerplays_sidechain PRIVATE curl graphene_plugin sha3 zmq bitcoin-system bitcoin-protocol bitcoin-client bitcoin-explorer ) +target_link_libraries( peerplays_sidechain PRIVATE curl graphene_plugin sha3 zmq cppzmq bitcoin-system bitcoin-protocol bitcoin-client bitcoin-explorer ) target_include_directories( peerplays_sidechain PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index b3c10dde..84c6226d 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -2722,6 +2722,7 @@ class wallet_api */ voters_info get_voters(const string &account_name_or_id) const; +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN /** * @brief Demo plugin api * @return The hello world string @@ -2740,6 +2741,7 @@ class wallet_api * @return Gas fee in ETH */ std::string eth_estimate_withdrawal_transaction_fee() const; +#endif fc::signal lock_changed; std::shared_ptr my; @@ -2889,7 +2891,7 @@ FC_API( graphene::wallet::wallet_api, (get_son_wallets) (add_sidechain_address) (delete_sidechain_address) - (sidechain_withdrawal_transaction) + (sidechain_withdrawal_transaction) (get_sidechain_addresses_by_account) (get_sidechain_addresses_by_sidechain) (get_sidechain_address_by_account_and_sidechain) @@ -3042,7 +3044,9 @@ FC_API( graphene::wallet::wallet_api, (get_votes) (get_voters_by_id) (get_voters) +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN (get_son_listener_log) (estimate_withdrawal_transaction_fee) (eth_estimate_withdrawal_transaction_fee) +#endif ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index ca043925..601b4a4f 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -84,7 +84,9 @@ #include #include #include +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN #include +#endif #ifndef WIN32 # include @@ -3384,6 +3386,7 @@ public: //! For sidechain withdrawal check if amount is greater than fee if(to_id == _remote_db->get_global_properties().parameters.son_account()) { +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN const auto sidechain = get_sidechain_type_from_asset(asset_obj->id); const auto transaction_fee = estimate_withdrawal_transaction_fee(sidechain); @@ -3393,6 +3396,9 @@ public: ("sidechain_fee", get_asset(transaction_fee->asset_id).amount_to_pretty_string(transaction_fee->amount))("amount", get_asset(xfer_op.amount.asset_id).amount_to_pretty_string(xfer_op.amount.amount))); } } +#else + FC_THROW("Withdrawal to SON account is not supported without sidechain plugin enabled"); +#endif } return sign_transaction(tx, broadcast); @@ -3435,6 +3441,7 @@ public: //! For sidechain withdrawal check if amount is greater than fee if (to_id == _remote_db->get_global_properties().parameters.son_account()) { +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN const auto sidechain = get_sidechain_type_from_asset(asset_obj->id); const auto transaction_fee = estimate_withdrawal_transaction_fee(sidechain); @@ -3444,6 +3451,9 @@ public: ("sidechain_fee", get_asset(transaction_fee->asset_id).amount_to_pretty_string(transaction_fee->amount))("amount", get_asset(xfer_op.amount.asset_id).amount_to_pretty_string(xfer_op.amount.amount))); } } +#else + FC_THROW("Override transfer to SON account is not supported without sidechain plugin enabled"); +#endif } return sign_transaction(tx, broadcast); @@ -4201,6 +4211,7 @@ public: } } +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN void use_sidechain_api() { if( _remote_sidechain ) @@ -4220,6 +4231,7 @@ public: "\n"; } } +#endif void network_add_nodes( const vector& nodes ) { @@ -4337,6 +4349,7 @@ public: FC_CAPTURE_AND_RETHROW( (account_name_or_id) ) } +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN std::map> get_son_listener_log() { use_sidechain_api(); @@ -4371,6 +4384,7 @@ public: } FC_CAPTURE_AND_RETHROW() } +#endif string _wallet_filename; wallet_data _wallet; @@ -4386,7 +4400,9 @@ public: fc::api _remote_bookie; optional< fc::api > _remote_net_node; optional< fc::api > _remote_debug; +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN optional< fc::api > _remote_sidechain; +#endif flat_map _prototype_ops; @@ -7450,6 +7466,7 @@ voters_info wallet_api::get_voters(const string &account_name_or_id) const return my->get_voters(account_name_or_id); } +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN std::map> wallet_api::get_son_listener_log() const { return my->get_son_listener_log(); @@ -7464,6 +7481,7 @@ std::string wallet_api::eth_estimate_withdrawal_transaction_fee() const { return my->eth_estimate_withdrawal_transaction_fee(); } +#endif vesting_balance_object_with_info::vesting_balance_object_with_info() : vesting_balance_object() diff --git a/programs/witness_node/CMakeLists.txt b/programs/witness_node/CMakeLists.txt index d2235034..7606514b 100644 --- a/programs/witness_node/CMakeLists.txt +++ b/programs/witness_node/CMakeLists.txt @@ -10,8 +10,13 @@ if( GPERFTOOLS_FOUND ) endif() # We have to link against graphene_debug_witness because deficiency in our API infrastructure doesn't allow plugins to be fully abstracted #246 -target_link_libraries( witness_node - PRIVATE graphene_app graphene_egenesis_full graphene_snapshot graphene_delayed_node graphene_witness peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) +set(LIBRARIES graphene_app graphene_egenesis_full graphene_snapshot graphene_delayed_node graphene_witness ${PLATFORM_SPECIFIC_LIBS}) + +if(NOT DEFINED DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN) + list(APPEND LIBRARIES peerplays_sidechain) +endif () + +target_link_libraries( witness_node PRIVATE ${LIBRARIES} ) # also add dependencies to graphene_generate_genesis graphene_generate_uia_sharedrop_genesis if you want those plugins install( TARGETS diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index b3c0aa37..8b42164d 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -35,7 +35,9 @@ //#include #include #include +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN #include +#endif #include #include #include @@ -89,7 +91,9 @@ int main(int argc, char** argv) { auto list_plug = node->register_plugin(); auto affiliate_stats_plug = node->register_plugin(); auto bookie_plug = node->register_plugin(); +#ifdef BUILD_PEERPLAYS_SIDECHAIN_PLUGIN auto peerplays_sidechain = node->register_plugin(); +#endif auto snapshot_plug = node->register_plugin(); auto delayed_plug = node->register_plugin(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6ff915a9..e620b435 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,9 +36,11 @@ file(GLOB BETTING_TESTS "betting/*.cpp") add_executable( betting_test ${BETTING_TESTS} ) target_link_libraries( betting_test PRIVATE graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) -file(GLOB PEERPLAYS_SIDECHAIN_TESTS "peerplays_sidechain/*.cpp") -add_executable( peerplays_sidechain_test ${PEERPLAYS_SIDECHAIN_TESTS} ) -target_link_libraries( peerplays_sidechain_test PRIVATE graphene_tests_common peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) +if(NOT DEFINED DISABLE_PEERPLAYS_SIDECHAIN_PLUGIN) + file(GLOB PEERPLAYS_SIDECHAIN_TESTS "peerplays_sidechain/*.cpp") + add_executable( peerplays_sidechain_test ${PEERPLAYS_SIDECHAIN_TESTS} ) + target_link_libraries( peerplays_sidechain_test PRIVATE graphene_tests_common peerplays_sidechain ${PLATFORM_SPECIFIC_LIBS} ) +endif () file(GLOB TOURNAMENT_TESTS "tournament/*.cpp") add_executable( tournament_test ${TOURNAMENT_TESTS} )