1
0
Fork 0
forked from lthn/blockchain

Refactor config system and move currency_config.h

Moved currency_config.h and related CMake/config files to a new src/config directory, creating a dedicated config CMake target. Updated all includes and build scripts to reference the new config location. Removed obsolete cmake/ChainConfig.cmake and example currency config, and restructured genesis generator and premine wallet logic into the new config system for improved modularity and maintainability.
This commit is contained in:
Snider 2025-09-29 19:04:52 +01:00
parent c001204629
commit 6a7b6dd2df
27 changed files with 139 additions and 122 deletions

View file

@ -295,8 +295,6 @@ else()
endif()
endif()
include(ChainConfig)
set(BUILD_TESTS FALSE CACHE BOOL "Build Lethean tests")
set(DISABLE_MDBX FALSE CACHE BOOL "Exclude mdbx from build(need for a first time)")
if(NOT DISABLE_MDBX)
@ -311,4 +309,4 @@ if (BUILD_TESTS)
add_subdirectory(tests)
endif()
include(CPackConfig)
include(CPackConfig)

View file

@ -1,4 +1,4 @@
include(${CMAKE_SOURCE_DIR}/cmake/config-vars.cmake)
#include(${CMAKE_SOURCE_DIR}/cmake/config-vars.cmake)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CPACK_PACKAGE_NAME "${package_name}")

View file

@ -1,64 +0,0 @@
include_directories (${CMAKE_BINARY_DIR}/src ${CMAKE_BINARY_DIR}/src/currency_core)
include(${CMAKE_SOURCE_DIR}/cmake/config-vars.cmake)
#include(${CMAKE_SOURCE_DIR}/cmake/currency_configs/example.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/check-config-vars.cmake)
configure_file("src/currency_core/currency_config.h.in" "src/currency_core/currency_config.h")
# CAUTION - wallet generation will only work properly in UNIX line environment
set(GENERATE_FRESH_GENESIS OFF CACHE BOOL "Generate new genesis block")
set(GENESIS_PREMINE_ADDRESS "" CACHE STRING "Premine wallet address")
set(GENESIS_PROOF "" CACHE STRING "Genesis proof string")
set(GENERATE_PREMINE_WALLET OFF CACHE BOOL "Generate premine wallet")
set(PREMINE_WALLET_PASSWORD "" CACHE STRING "Premine wallet password")
if (GENERATE_PREMINE_WALLET AND GENERATE_FRESH_GENESIS)
message(FATAL_ERROR "Genesis can not be generated together with premine wallet")
endif()
if (GENERATE_PREMINE_WALLET)
unset(GENERATE_PREMINE_WALLET CACHE)
message(WARNING "Generating premine wallet")
if (NOT DEFINED PREMINE_WALLET_PASSWORD OR PREMINE_WALLET_PASSWORD STREQUAL "")
message(FATAL_ERROR "set PREMINE_WALLET_PASSWORD or GENESIS_PREMINE_ADDRESS to generate genesis block")
endif()
# Make wallet directory
add_custom_target(
premine_wallet
"${CMAKE_COMMAND}" -E make_directory "${CMAKE_SOURCE_DIR}/premine_wallet"
COMMENT "Creating premine wallet directory"
)
# Generate wallet
add_custom_command(TARGET premine_wallet POST_BUILD
COMMAND echo ${PREMINE_WALLET_PASSWORD} | ${CMAKE_BINARY_DIR}/src/lethean-wallet-cli --generate-new-wallet ${CMAKE_SOURCE_DIR}/premine_wallet/premine_wallet
COMMENT "Generating premine wallet in ${CMAKE_SOURCE_DIR}/premine_wallet"
)
add_dependencies(premine_wallet simplewallet)
endif()
if (GENERATE_FRESH_GENESIS)
unset(GENERATE_FRESH_GENESIS CACHE)
add_executable(genesis_generator ${GENESIS_GENERATOR})
target_link_libraries(genesis_generator currency_core crypto common zlibstatic ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
if (NOT DEFINED GENESIS_PREMINE_ADDRESS OR GENESIS_PREMINE_ADDRESS STREQUAL "")
message(WARNING "GENESIS_PREMINE_ADDRESS not set, loading from ${CMAKE_SOURCE_DIR}/premine_wallet/premine_wallet.address")
file(READ "${CMAKE_SOURCE_DIR}/premine_wallet/premine_wallet.address" GENESIS_PREMINE_ADDRESS)
if (NOT DEFINED GENESIS_PREMINE_ADDRESS OR GENESIS_PREMINE_ADDRESS STREQUAL "")
message(FATAL_ERROR "GENESIS_PREMINE_ADDRESS not set")
endif()
else()
add_custom_command(TARGET genesis_generator POST_BUILD
COMMAND ${CMAKE_BINARY_DIR}/src/genesis_generator --address ${GENESIS_PREMINE_ADDRESS} --proof ${GENESIS_PROOF} --output ${CMAKE_SOURCE_DIR}/src/currency_core/generated/
COMMENT "Generating genesis data in ${CMAKE_SOURCE_DIR}/src/currency_core/"
)
endif()
endif()

View file

@ -1,20 +0,0 @@
set(currency_display_decimal_point 12)
set(coin 1000000000000)
set(base_reward_dust_threshold 1000000)
set(default_dust_threshold 0)
set(tx_default_fee 10000000000)
set(tx_minimum_fee 10000000000)
set(difficulty_pow_starter 1)
set(difficulty_pos_target 120)
set(difficulty_pow_target 120)
set(difficulty_window 720)
set(difficulty_lag 15)
set(difficulty_cut 60)
set(p2p_default_port 36942)
set(rpc_default_port 36941)
set(stratum_default_port 36940)
set(p2p_maintainers_pub_key "8f138bb73f6d663a3746a542770781a09579a7b84cb4125249e95530824ee607")
set(currency_name_abr "NF")
set(currency_name_base "NotFake")
set(currency_name_short_base "NotFake")
set(premine_amount 4000000000000000000)

View file

@ -65,7 +65,6 @@ file(GLOB_RECURSE SIMPLEWALLET simplewallet/*)
file(GLOB_RECURSE CONN_TOOL connectivity_tool/*)
file(GLOB_RECURSE WALLET wallet/*)
file(GLOB_RECURSE MINER miner/*)
file(GLOB_RECURSE GENESIS_GENERATOR genesis_generator/*)
source_group(pch FILES ${PCH})
@ -80,14 +79,16 @@ source_group(stratum FILES ${STRATUM})
source_group(simplewallet FILES ${SIMPLEWALLET})
source_group(connectivity-tool FILES ${CONN_TOOL})
source_group(wallet FILES ${WALLET})
source_group(genesis_generator FILES ${GENESIS_GENERATOR})
INIT_SHARED_PCH()
add_subdirectory(config)
add_subdirectory(genesis_generator)
add_library(common ${COMMON})
add_dependencies(common version ${PCH_LIB_NAME})
target_link_libraries(common PUBLIC ${Boost_LIBRARIES})
add_dependencies(common version config ${PCH_LIB_NAME})
target_link_libraries(common PUBLIC ${Boost_LIBRARIES} config)
ENABLE_SHARED_PCH(common COMMON)
if(NOT MSVC AND NOT APPLE AND NOT CLANG) # TODO(unassigned): do we really need the clang equivalent?
@ -107,15 +108,16 @@ endif()
add_library(crypto ${CRYPTO})
if(USE_BITCOIN_SECP256K1_FOR_ECDSA)
add_dependencies(crypto secp256k1)
target_link_libraries(crypto secp256k1 ${BCRYPT_LIB})
add_dependencies(crypto secp256k1 config)
target_link_libraries(crypto config secp256k1 ${BCRYPT_LIB})
else()
add_dependencies(crypto OpenSSL::Crypto)
target_link_libraries(crypto OpenSSL::Crypto ${BCRYPT_LIB})
add_dependencies(crypto OpenSSL::Crypto config)
target_link_libraries(crypto PUBLIC config OpenSSL::Crypto ${BCRYPT_LIB})
endif()
add_library(currency_core ${CURRENCY_CORE})
add_dependencies(currency_core version ${PCH_LIB_NAME})
add_dependencies(currency_core version config ${PCH_LIB_NAME})
target_link_libraries(currency_core config)
ENABLE_SHARED_PCH(currency_core CURRENCY_CORE)
add_library(wallet ${WALLET})
@ -123,7 +125,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Android" )
add_dependencies(wallet version ${PCH_LIB_NAME})
target_link_libraries(wallet currency_core crypto common ZLIB::ZLIB ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} android log OpenSSL::SSL OpenSSL::Crypto)
else()
add_dependencies(wallet version ${PCH_LIB_NAME})
add_dependencies(wallet version config ${PCH_LIB_NAME})
target_link_libraries(wallet config)
ENABLE_SHARED_PCH(wallet WALLET)
endif()
@ -146,25 +149,27 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
endif()
add_library(rpc ${RPC})
add_dependencies(rpc version ${PCH_LIB_NAME})
add_dependencies(rpc version config ${PCH_LIB_NAME})
target_link_libraries(rpc config)
ENABLE_SHARED_PCH(rpc RPC)
add_library(stratum ${STRATUM})
add_dependencies(stratum version ${PCH_LIB_NAME})
add_dependencies(stratum version config ${PCH_LIB_NAME})
target_link_libraries(stratum config)
ENABLE_SHARED_PCH(stratum STRATUM)
target_link_libraries(currency_core lmdb mdbx)
target_link_libraries(currency_core config lmdb mdbx)
add_executable(daemon ${DAEMON} ${P2P} ${CURRENCY_PROTOCOL})
add_dependencies(daemon version)
target_link_libraries(daemon rpc stratum currency_core crypto common miniupnpc::miniupnpc ZLIB::ZLIB ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(daemon rpc stratum currency_core crypto common miniupnpc::miniupnpc ZLIB::ZLIB ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
ENABLE_SHARED_PCH(daemon DAEMON)
ENABLE_SHARED_PCH_EXECUTABLE(daemon)
add_executable(connectivity_tool ${CONN_TOOL})
add_dependencies(connectivity_tool version)
target_link_libraries(connectivity_tool currency_core crypto common ZLIB::ZLIB ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(connectivity_tool currency_core crypto common ZLIB::ZLIB ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
ENABLE_SHARED_PCH(connectivity_tool CONN_TOOL)
ENABLE_SHARED_PCH_EXECUTABLE(connectivity_tool)
@ -190,4 +195,3 @@ endif ()
install(TARGETS daemon simplewallet
RUNTIME DESTINATION bin)

View file

@ -17,7 +17,7 @@
#include "command_line.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
namespace command_line
{

View file

@ -16,7 +16,7 @@
//
#include "db_backend_selector.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "command_line.h"
#include "db_backend_lmdb.h"
#include "db_backend_mdbx.h"

View file

@ -28,7 +28,7 @@ extern "C" {
}
#include "misc_language.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "version.h"
namespace tools

View file

@ -20,7 +20,7 @@
using namespace epee;
#include "util.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "version.h"
#define UTF_CPP_CPLUSPLUS 201703L
#include "utf8.h"

63
src/config/CMakeLists.txt Normal file
View file

@ -0,0 +1,63 @@
# This file is responsible for generating currency_config.h
# and providing it to other targets.
add_library(config INTERFACE)
include(${CMAKE_CURRENT_SOURCE_DIR}/default.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/check-config.cmake)
# This generates the header file from the template.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/currency_config.h.in"
"${CMAKE_BINARY_DIR}/src/config/currency_config.h"
)
# This tells any target linking against 'config' where to find headers.
target_include_directories(config INTERFACE
# For targets within this build tree, add the directory containing the *generated* header.
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src>
# Also add the main 'src' directory for other headers.
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
)
#add_custom_target(gen_config_header
# DEPENDS "${CMAKE_BINARY_DIR}/src/config/currency_config.h"
#)
file(WRITE "${CMAKE_BINARY_DIR}/src/config/currency_config_dummy.cpp" "")
add_library(currency_config OBJECT
"${CMAKE_BINARY_DIR}/src/config/currency_config.h"
"${CMAKE_BINARY_DIR}/src/config/currency_config_dummy.cpp"
)
add_dependencies(currency_config config)
set(GENERATE_PREMINE_WALLET OFF CACHE BOOL "Generate premine wallet")
set(PREMINE_WALLET_PASSWORD "" CACHE STRING "Premine wallet password")
if (GENERATE_PREMINE_WALLET AND GENERATE_FRESH_GENESIS)
message(FATAL_ERROR "Genesis can not be generated together with premine wallet")
endif()
if (GENERATE_PREMINE_WALLET)
unset(GENERATE_PREMINE_WALLET CACHE)
message(WARNING "Generating premine wallet")
if (NOT DEFINED PREMINE_WALLET_PASSWORD OR PREMINE_WALLET_PASSWORD STREQUAL "")
message(FATAL_ERROR "set PREMINE_WALLET_PASSWORD or GENESIS_PREMINE_ADDRESS to generate genesis block")
endif()
# Make wallet directory
add_custom_target(
premine_wallet
"${CMAKE_COMMAND}" -E make_directory "${CMAKE_SOURCE_DIR}/premine_wallet"
COMMENT "Creating premine wallet directory"
)
# Generate wallet
add_custom_command(TARGET premine_wallet POST_BUILD
COMMAND echo ${PREMINE_WALLET_PASSWORD} | $<TARGET_FILE:simplewallet> --generate-new-wallet ${CMAKE_SOURCE_DIR}/premine_wallet/premine_wallet
COMMENT "Generating premine wallet in ${CMAKE_SOURCE_DIR}/premine_wallet"
)
add_dependencies(premine_wallet simplewallet)
endif()

View file

@ -49,4 +49,3 @@ set(package_macos_installer "PKG" CACHE STRING "CPACK_GENERATOR" )
set(package_macos_dmg_background "DMG" CACHE STRING "CPACK_DMG_BACKGROUND_IMAGE" )
set(package_macos_pkg_productbuild_identifier "com.lethean.blockchainnode" CACHE STRING "CPACK_PRODUCTBUILD_IDENTIFIER" )
set(package_macos_pkg_productbuild_signer "Developer ID Installer: Your Company (TEAMID)" CACHE STRING "CPACK_PRODUCTBUILD_SIGNING_IDENTITY" )

View file

@ -16,7 +16,7 @@
//
#include "one_out_of_many_proofs.h"
#include "../currency_core/crypto_config.h"
#include "../currency_core/currency_config.h" // for static asset checks
#include "config/currency_config.h" // for static asset checks
#include "epee/include/misc_log_ex.h"
//DISABLE_GCC_AND_CLANG_WARNING(unused-function)

View file

@ -23,7 +23,7 @@ using namespace epee;
#include "currency_format_utils.h"
#include "serialization/binary_utils.h"
#include "serialization/stl_containers.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "crypto/crypto.h"
#include "crypto/hash.h"
#include "common/int-util.h"

View file

@ -32,7 +32,7 @@
#include "blockchain_storage.h"
#include "currency_format_utils.h"
#include "currency_boost_serialization.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "miner.h"
#include "misc_language.h"
#include "profile_tools.h"

View file

@ -46,7 +46,7 @@
#include "serialization/debug_archive.h"
#include "serialization/keyvalue_serialization.h" // epee key-value serialization
#include "string_tools.h"
#include "currency_config.h"
#include "config/currency_config.h"
#include "crypto/crypto.h"
#include "crypto/hash.h"
#include "crypto/range_proofs.h"

View file

@ -25,7 +25,7 @@ using namespace epee;
#include "common/util.h"
#include "warnings.h"
#include "crypto/crypto.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "currency_format_utils.h"
#include "misc_language.h"
#include "string_coding.h"

View file

@ -27,7 +27,7 @@ using namespace epee;
#include "currency_format_utils_transactions.h"
#include "serialization/binary_utils.h"
#include "serialization/stl_containers.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "miner.h"
#include "crypto/crypto.h"
#include "crypto/hash.h"

View file

@ -25,7 +25,7 @@
#include "common/int-util.h"
#include "crypto/hash.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "difficulty.h"
#include "profile_tools.h"

View file

@ -23,7 +23,7 @@
#include "common/db_backend_selector.h"
#include "tx_pool.h"
#include "currency_boost_serialization.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "blockchain_storage.h"
#include "common/boost_serialization_helper.h"
#include "common/int-util.h"

View file

@ -0,0 +1,37 @@
add_executable(genesis_generator EXCLUDE_FROM_ALL generate_test_genesis.cpp)
target_link_libraries(genesis_generator
PRIVATE
config
currency_core
crypto
common
zlibstatic
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES}
OpenSSL::SSL
OpenSSL::Crypto
)
set_property(TARGET genesis_generator PROPERTY FOLDER "prog")
if (GENERATE_FRESH_GENESIS)
if (NOT DEFINED GENESIS_PREMINE_ADDRESS OR GENESIS_PREMINE_ADDRESS STREQUAL "")
set(address_file "${CMAKE_SOURCE_DIR}/premine_wallet/premine_wallet.address")
message(STATUS "GENESIS_PREMINE_ADDRESS not set, attempting to load from ${address_file}")
if(EXISTS "${address_file}")
file(READ "${address_file}" GENESIS_PREMINE_ADDRESS)
string(STRIP "${GENESIS_PREMINE_ADDRESS}" GENESIS_PREMINE_ADDRESS)
endif()
endif()
if (NOT DEFINED GENESIS_PREMINE_ADDRESS OR GENESIS_PREMINE_ADDRESS STREQUAL "")
message(FATAL_ERROR "GENESIS_PREMINE_ADDRESS is not set and could not be read from file. Please set it via -DGENESIS_PREMINE_ADDRESS=<address>")
else()
add_custom_command(TARGET genesis_generator POST_BUILD
COMMAND $<TARGET_FILE:genesis_generator> --address ${GENESIS_PREMINE_ADDRESS} --proof "${GENESIS_PROOF}" --output "${CMAKE_SOURCE_DIR}/src/currency_core/generated/"
COMMENT "Generating genesis data..."
VERBATIM
)
endif()
endif()

View file

@ -38,7 +38,7 @@
#include "math_helper.h"
#include "net_node_common.h"
#include "maintainers_info_boost_serialization.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
using namespace epee;
#undef LOG_DEFAULT_CHANNEL

View file

@ -35,7 +35,7 @@
#include "syncobj.h"
#include "net/local_ip.h"
#include "p2p_protocol_defs.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "net_peerlist_boost_serialization.h"
#include "common/boost_serialization_helper.h"

View file

@ -20,7 +20,7 @@
#include <boost/uuid/uuid.hpp>
#include "serialization/keyvalue_serialization.h"
#include "misc_language.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "crypto/crypto.h"
namespace nodetool

View file

@ -18,7 +18,7 @@
#include "stratum_server.h"
#include "stratum_helpers.h"
#include "net/abstract_tcp_server2.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "currency_core/currency_core.h"
#include "common/command_line.h"
#include "common/int-util.h"

View file

@ -21,7 +21,7 @@
#endif
#include "plain_wallet_api.h"
#include "plain_wallet_api_defs.h"
#include "currency_core/currency_config.h"
#include "config/currency_config.h"
#include "version.h"
#include "string_tools.h"
#include "currency_core/currency_format_utils.h"