Merge pull request #4536

fd62b6e7 blocks: use auto-generated .c files instead of 'LD -r -b binary' (xiphon)
This commit is contained in:
Riccardo Spagni 2018-10-26 22:20:39 +02:00
commit 056a58d13f
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
17 changed files with 113 additions and 185 deletions

View file

@ -199,6 +199,9 @@ set(PER_BLOCK_CHECKPOINT 1)
if(PER_BLOCK_CHECKPOINT) if(PER_BLOCK_CHECKPOINT)
add_definitions("-DPER_BLOCK_CHECKPOINT") add_definitions("-DPER_BLOCK_CHECKPOINT")
set(Blocks "blocks")
else()
set(Blocks "")
endif() endif()
list(INSERT CMAKE_MODULE_PATH 0 list(INSERT CMAKE_MODULE_PATH 0
@ -672,12 +675,10 @@ else()
add_linker_flag_if_supported(-Wl,-z,noexecstack noexecstack_SUPPORTED) add_linker_flag_if_supported(-Wl,-z,noexecstack noexecstack_SUPPORTED)
if (noexecstack_SUPPORTED) if (noexecstack_SUPPORTED)
set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecstack") set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecstack")
set(LD_RAW_FLAGS ${LD_RAW_FLAGS} -z noexecstack)
endif() endif()
add_linker_flag_if_supported(-Wl,-z,noexecheap noexecheap_SUPPORTED) add_linker_flag_if_supported(-Wl,-z,noexecheap noexecheap_SUPPORTED)
if (noexecheap_SUPPORTED) if (noexecheap_SUPPORTED)
set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecheap") set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecheap")
set(LD_RAW_FLAGS ${LD_RAW_FLAGS} -z noexecheap)
endif() endif()
# some windows linker bits # some windows linker bits

View file

@ -26,20 +26,6 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set(blocksdat "")
if(PER_BLOCK_CHECKPOINT)
if(APPLE AND DEPENDS)
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && touch stub.c && ${CMAKE_C_COMPILER} --target=x86_64-apple-darwin11 -o stub.o -c stub.c COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} -r -sectcreate __DATA __blocks_dat ../blocks/checkpoints.dat -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o stub.o && rm -f stub.*)
elseif(APPLE AND NOT DEPENDS)
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && touch stub.c && ${CMAKE_C_COMPILER} -o stub.o -c stub.c COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} ${LD_RAW_FLAGS} -r -sectcreate __DATA __blocks_dat ../blocks/checkpoints.dat -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o stub.o && rm -f stub.*)
elseif(LINUX_32)
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && cp ../blocks/checkpoints.dat blocks.dat && ${CMAKE_LINKER} -m elf_i386 ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o blocks.dat && rm -f blocks.dat)
else()
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && cp ../blocks/checkpoints.dat blocks.dat && ${CMAKE_LINKER} ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o blocks.dat && rm -f blocks.dat)
endif()
set(blocksdat "blocksdat.o")
endif()
set(blockchain_import_sources set(blockchain_import_sources
blockchain_import.cpp blockchain_import.cpp
bootstrap_file.cpp bootstrap_file.cpp
@ -119,8 +105,7 @@ monero_private_headers(blockchain_depth
monero_add_executable(blockchain_import monero_add_executable(blockchain_import
${blockchain_import_sources} ${blockchain_import_sources}
${blockchain_import_private_headers} ${blockchain_import_private_headers})
${blocksdat})
target_link_libraries(blockchain_import target_link_libraries(blockchain_import
PRIVATE PRIVATE
@ -132,7 +117,8 @@ target_link_libraries(blockchain_import
${Boost_SYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY} ${Boost_THREAD_LIBRARY}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES}) ${EXTRA_LIBRARIES}
${Blocks})
if(ARCH_WIDTH) if(ARCH_WIDTH)
target_compile_definitions(blockchain_import target_compile_definitions(blockchain_import

View file

@ -37,6 +37,7 @@
#include "misc_log_ex.h" #include "misc_log_ex.h"
#include "bootstrap_file.h" #include "bootstrap_file.h"
#include "bootstrap_serialization.h" #include "bootstrap_serialization.h"
#include "blocks/blocks.h"
#include "cryptonote_basic/cryptonote_format_utils.h" #include "cryptonote_basic/cryptonote_format_utils.h"
#include "serialization/binary_utils.h" // dump_binary(), parse_binary() #include "serialization/binary_utils.h" // dump_binary(), parse_binary()
#include "serialization/json_utils.h" // dump_json() #include "serialization/json_utils.h" // dump_json()
@ -758,7 +759,12 @@ int main(int argc, char* argv[])
{ {
core.disable_dns_checkpoints(true); core.disable_dns_checkpoints(true);
if (!core.init(vm, NULL)) #if defined(PER_BLOCK_CHECKPOINT)
const GetCheckpointsCallback& get_checkpoints = blocks::GetCheckpointsData;
#else
const GetCheckpointsCallback& get_checkpoints = nullptr;
#endif
if (!core.init(vm, nullptr, nullptr, get_checkpoints))
{ {
std::cerr << "Failed to initialize core" << ENDL; std::cerr << "Failed to initialize core" << ENDL;
return 1; return 1;

View file

@ -26,20 +26,23 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if(APPLE) set(GENERATED_SOURCES "")
add_library(blocks STATIC blockexports.c)
set_target_properties(blocks PROPERTIES LINKER_LANGUAGE C)
else()
if(LINUX_32)
add_custom_command(OUTPUT blocks.o MAIN_DEPENDENCY blocks.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} -m elf_i386 ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/blocks.o blocks.dat)
add_custom_command(OUTPUT testnet_blocks.o MAIN_DEPENDENCY testnet_blocks.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} -m elf_i386 ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/testnet_blocks.o testnet_blocks.dat)
add_custom_command(OUTPUT stagenet_blocks.o MAIN_DEPENDENCY stagenet_blocks.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} -m elf_i386 ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/stagenet_blocks.o stagenet_blocks.dat)
else()
add_custom_command(OUTPUT blocks.o MAIN_DEPENDENCY blocks.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/blocks.o blocks.dat)
add_custom_command(OUTPUT testnet_blocks.o MAIN_DEPENDENCY testnet_blocks.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/testnet_blocks.o testnet_blocks.dat)
add_custom_command(OUTPUT stagenet_blocks.o MAIN_DEPENDENCY stagenet_blocks.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/stagenet_blocks.o stagenet_blocks.dat)
endif()
add_library(blocks STATIC blocks.o testnet_blocks.o stagenet_blocks.o blockexports.c)
set_target_properties(blocks PROPERTIES LINKER_LANGUAGE C)
endif()
foreach(BLOB_NAME checkpoints testnet_blocks stagenet_blocks)
set(OUTPUT_C_SOURCE "generated_${BLOB_NAME}.c")
list(APPEND GENERATED_SOURCES ${OUTPUT_C_SOURCE})
set(INPUT_DAT_FILE "${BLOB_NAME}.dat")
add_custom_command(
OUTPUT ${OUTPUT_C_SOURCE}
MAIN_DEPENDENCY ${INPUT_DAT_FILE}
COMMAND
cd ${CMAKE_CURRENT_BINARY_DIR} &&
echo "'#include\t<stddef.h>'" > ${OUTPUT_C_SOURCE} &&
echo "'const\tunsigned\tchar\t${BLOB_NAME}[]={'" >> ${OUTPUT_C_SOURCE} &&
od -v -An -tu1 ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_DAT_FILE} | sed -e "'s/[0-9]\\{1,\\}/&,/g'" -e "'$$s/.$$//'" >> ${OUTPUT_C_SOURCE} &&
echo "'};'" >> ${OUTPUT_C_SOURCE} &&
echo "'const\tsize_t\t${BLOB_NAME}_len\t=\tsizeof(${BLOB_NAME});'" >> ${OUTPUT_C_SOURCE}
)
endforeach()
add_library(blocks STATIC blocks.cpp ${GENERATED_SOURCES})

View file

@ -1,87 +0,0 @@
#include <stddef.h>
#if defined(__APPLE__)
#include <mach-o/getsect.h>
#ifdef BUILD_SHARED_LIBS
#if !defined(__LP64__)
const struct mach_header _mh_execute_header;
#else
const struct mach_header_64 _mh_execute_header;
#endif
#else
#if !defined(__LP64__)
extern const struct mach_header _mh_execute_header;
#else
extern const struct mach_header_64 _mh_execute_header;
#endif
#endif
const unsigned char *get_blocks_dat_start(int testnet, int stagenet)
{
size_t size;
if (testnet)
return getsectiondata(&_mh_execute_header, "__DATA", "__testnet_blocks_dat", &size);
else if (stagenet)
return getsectiondata(&_mh_execute_header, "__DATA", "__stagenet_blocks_dat", &size);
else
return getsectiondata(&_mh_execute_header, "__DATA", "__blocks_dat", &size);
}
size_t get_blocks_dat_size(int testnet, int stagenet)
{
size_t size;
if (testnet)
getsectiondata(&_mh_execute_header, "__DATA", "__testnet_blocks_dat", &size);
else if (stagenet)
getsectiondata(&_mh_execute_header, "__DATA", "__stagenet_blocks_dat", &size);
else
getsectiondata(&_mh_execute_header, "__DATA", "__blocks_dat", &size);
return size;
}
#else
#if defined(_WIN32) && !defined(_WIN64)
#define _binary_blocks_start binary_blocks_dat_start
#define _binary_blocks_end binary_blocks_dat_end
#define _binary_testnet_blocks_start binary_testnet_blocks_dat_start
#define _binary_testnet_blocks_end binary_testnet_blocks_dat_end
#define _binary_stagenet_blocks_start binary_stagenet_blocks_dat_start
#define _binary_stagenet_blocks_end binary_stagenet_blocks_dat_end
#else
#define _binary_blocks_start _binary_blocks_dat_start
#define _binary_blocks_end _binary_blocks_dat_end
#define _binary_testnet_blocks_start _binary_testnet_blocks_dat_start
#define _binary_testnet_blocks_end _binary_testnet_blocks_dat_end
#define _binary_stagenet_blocks_start _binary_stagenet_blocks_dat_start
#define _binary_stagenet_blocks_end _binary_stagenet_blocks_dat_end
#endif
extern const unsigned char _binary_blocks_start[];
extern const unsigned char _binary_blocks_end[];
extern const unsigned char _binary_testnet_blocks_start[];
extern const unsigned char _binary_testnet_blocks_end[];
extern const unsigned char _binary_stagenet_blocks_start[];
extern const unsigned char _binary_stagenet_blocks_end[];
const unsigned char *get_blocks_dat_start(int testnet, int stagenet)
{
if (testnet)
return _binary_testnet_blocks_start;
else if (stagenet)
return _binary_stagenet_blocks_start;
else
return _binary_blocks_start;
}
size_t get_blocks_dat_size(int testnet, int stagenet)
{
if (testnet)
return (size_t) (_binary_testnet_blocks_end - _binary_testnet_blocks_start);
else if (stagenet)
return (size_t) (_binary_stagenet_blocks_end - _binary_stagenet_blocks_start);
else
return (size_t) (_binary_blocks_end - _binary_blocks_start);
}
#endif

31
src/blocks/blocks.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "blocks.h"
#include <unordered_map>
extern const unsigned char checkpoints[];
extern const size_t checkpoints_len;
extern const unsigned char stagenet_blocks[];
extern const size_t stagenet_blocks_len;
extern const unsigned char testnet_blocks[];
extern const size_t testnet_blocks_len;
namespace blocks
{
const std::unordered_map<cryptonote::network_type, const epee::span<const unsigned char>, std::hash<size_t>> CheckpointsByNetwork = {
{cryptonote::network_type::MAINNET, {checkpoints, checkpoints_len}},
{cryptonote::network_type::STAGENET, {stagenet_blocks, stagenet_blocks_len}},
{cryptonote::network_type::TESTNET, {testnet_blocks, testnet_blocks_len}}
};
const epee::span<const unsigned char> GetCheckpointsData(cryptonote::network_type network)
{
const auto it = CheckpointsByNetwork.find(network);
if (it != CheckpointsByNetwork.end())
{
return it->second;
}
return nullptr;
}
}

View file

View file

@ -1,16 +1,12 @@
#ifndef SRC_BLOCKS_BLOCKS_H_ #ifndef SRC_BLOCKS_BLOCKS_H_
#define SRC_BLOCKS_BLOCKS_H_ #define SRC_BLOCKS_BLOCKS_H_
#ifdef __cplusplus #include "cryptonote_config.h"
extern "C" { #include "span.h"
#endif
const unsigned char *get_blocks_dat_start(int testnet, int stagenet); namespace blocks
size_t get_blocks_dat_size(int testnet, int stagenet); {
const epee::span<const unsigned char> GetCheckpointsData(cryptonote::network_type network);
#ifdef __cplusplus
} }
#endif
#endif /* SRC_BLOCKS_BLOCKS_H_ */ #endif /* SRC_BLOCKS_BLOCKS_H_ */

View file

@ -30,6 +30,7 @@
#pragma once #pragma once
#include <stdexcept>
#include <string> #include <string>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>

View file

@ -41,12 +41,6 @@ set(cryptonote_core_private_headers
tx_pool.h tx_pool.h
cryptonote_tx_utils.h) cryptonote_tx_utils.h)
if(PER_BLOCK_CHECKPOINT)
set(Blocks "blocks")
else()
set(Blocks "")
endif()
monero_private_headers(cryptonote_core monero_private_headers(cryptonote_core
${cryptonote_core_private_headers}) ${cryptonote_core_private_headers})
monero_add_library(cryptonote_core monero_add_library(cryptonote_core
@ -69,5 +63,4 @@ target_link_libraries(cryptonote_core
${Boost_SYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY} ${Boost_THREAD_LIBRARY}
PRIVATE PRIVATE
${Blocks}
${EXTRA_LIBRARIES}) ${EXTRA_LIBRARIES})

View file

@ -53,9 +53,6 @@
#include "ringct/rctSigs.h" #include "ringct/rctSigs.h"
#include "common/perf_timer.h" #include "common/perf_timer.h"
#include "common/notify.h" #include "common/notify.h"
#if defined(PER_BLOCK_CHECKPOINT)
#include "blocks/blocks.h"
#endif
#undef MONERO_DEFAULT_LOG_CATEGORY #undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "blockchain" #define MONERO_DEFAULT_LOG_CATEGORY "blockchain"
@ -341,7 +338,7 @@ uint64_t Blockchain::get_current_blockchain_height() const
//------------------------------------------------------------------ //------------------------------------------------------------------
//FIXME: possibly move this into the constructor, to avoid accidentally //FIXME: possibly move this into the constructor, to avoid accidentally
// dereferencing a null BlockchainDB pointer // dereferencing a null BlockchainDB pointer
bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline, const cryptonote::test_options *test_options, difficulty_type fixed_difficulty) bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline, const cryptonote::test_options *test_options, difficulty_type fixed_difficulty, const GetCheckpointsCallback& get_checkpoints/* = nullptr*/)
{ {
LOG_PRINT_L3("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
@ -442,7 +439,7 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
#if defined(PER_BLOCK_CHECKPOINT) #if defined(PER_BLOCK_CHECKPOINT)
if (m_nettype != FAKECHAIN) if (m_nettype != FAKECHAIN)
load_compiled_in_block_hashes(); load_compiled_in_block_hashes(get_checkpoints);
#endif #endif
MINFO("Blockchain initialized. last block: " << m_db->height() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block()); MINFO("Blockchain initialized. last block: " << m_db->height() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block());
@ -4416,19 +4413,21 @@ void Blockchain::cancel()
#if defined(PER_BLOCK_CHECKPOINT) #if defined(PER_BLOCK_CHECKPOINT)
static const char expected_block_hashes_hash[] = "954cb2bbfa2fe6f74b2cdd22a1a4c767aea249ad47ad4f7c9445f0f03260f511"; static const char expected_block_hashes_hash[] = "954cb2bbfa2fe6f74b2cdd22a1a4c767aea249ad47ad4f7c9445f0f03260f511";
void Blockchain::load_compiled_in_block_hashes() void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback& get_checkpoints)
{ {
const bool testnet = m_nettype == TESTNET; if (get_checkpoints == nullptr || !m_fast_sync)
const bool stagenet = m_nettype == STAGENET;
if (m_fast_sync && get_blocks_dat_start(testnet, stagenet) != nullptr && get_blocks_dat_size(testnet, stagenet) > 0)
{ {
MINFO("Loading precomputed blocks (" << get_blocks_dat_size(testnet, stagenet) << " bytes)"); return;
}
const epee::span<const unsigned char> &checkpoints = get_checkpoints(m_nettype);
if (!checkpoints.empty())
{
MINFO("Loading precomputed blocks (" << checkpoints.size() << " bytes)");
if (m_nettype == MAINNET) if (m_nettype == MAINNET)
{ {
// first check hash // first check hash
crypto::hash hash; crypto::hash hash;
if (!tools::sha256sum(get_blocks_dat_start(testnet, stagenet), get_blocks_dat_size(testnet, stagenet), hash)) if (!tools::sha256sum(checkpoints.data(), checkpoints.size(), hash))
{ {
MERROR("Failed to hash precomputed blocks data"); MERROR("Failed to hash precomputed blocks data");
return; return;
@ -4448,9 +4447,9 @@ void Blockchain::load_compiled_in_block_hashes()
} }
} }
if (get_blocks_dat_size(testnet, stagenet) > 4) if (checkpoints.size() > 4)
{ {
const unsigned char *p = get_blocks_dat_start(testnet, stagenet); const unsigned char *p = checkpoints.data();
const uint32_t nblocks = *p | ((*(p+1))<<8) | ((*(p+2))<<16) | ((*(p+3))<<24); const uint32_t nblocks = *p | ((*(p+1))<<8) | ((*(p+2))<<16) | ((*(p+3))<<24);
if (nblocks > (std::numeric_limits<uint32_t>::max() - 4) / sizeof(hash)) if (nblocks > (std::numeric_limits<uint32_t>::max() - 4) / sizeof(hash))
{ {
@ -4458,7 +4457,7 @@ void Blockchain::load_compiled_in_block_hashes()
return; return;
} }
const size_t size_needed = 4 + nblocks * sizeof(crypto::hash); const size_t size_needed = 4 + nblocks * sizeof(crypto::hash);
if(nblocks > 0 && nblocks > (m_db->height() + HASH_OF_HASHES_STEP - 1) / HASH_OF_HASHES_STEP && get_blocks_dat_size(testnet, stagenet) >= size_needed) if(nblocks > 0 && nblocks > (m_db->height() + HASH_OF_HASHES_STEP - 1) / HASH_OF_HASHES_STEP && checkpoints.size() >= size_needed)
{ {
p += sizeof(uint32_t); p += sizeof(uint32_t);
m_blocks_hash_of_hashes.reserve(nblocks); m_blocks_hash_of_hashes.reserve(nblocks);

View file

@ -38,9 +38,11 @@
#include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp> #include <boost/multi_index/member.hpp>
#include <atomic> #include <atomic>
#include <functional>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include "span.h"
#include "syncobj.h" #include "syncobj.h"
#include "string_tools.h" #include "string_tools.h"
#include "cryptonote_basic/cryptonote_basic.h" #include "cryptonote_basic/cryptonote_basic.h"
@ -73,6 +75,15 @@ namespace cryptonote
db_nosync //!< Leave syncing up to the backing db (safest, but slowest because of disk I/O) db_nosync //!< Leave syncing up to the backing db (safest, but slowest because of disk I/O)
}; };
/**
* @brief Callback routine that returns checkpoints data for specific network type
*
* @param network network type
*
* @return checkpoints data, empty span if there ain't any checkpoints for specific network type
*/
typedef std::function<const epee::span<const unsigned char>(cryptonote::network_type network)> GetCheckpointsCallback;
/************************************************************************/ /************************************************************************/
/* */ /* */
/************************************************************************/ /************************************************************************/
@ -117,10 +128,11 @@ namespace cryptonote
* @param offline true if running offline, else false * @param offline true if running offline, else false
* @param test_options test parameters * @param test_options test parameters
* @param fixed_difficulty fixed difficulty for testing purposes; 0 means disabled * @param fixed_difficulty fixed difficulty for testing purposes; 0 means disabled
* @param get_checkpoints if set, will be called to get checkpoints data
* *
* @return true on success, false if any initialization steps fail * @return true on success, false if any initialization steps fail
*/ */
bool init(BlockchainDB* db, const network_type nettype = MAINNET, bool offline = false, const cryptonote::test_options *test_options = NULL, difficulty_type fixed_difficulty = 0); bool init(BlockchainDB* db, const network_type nettype = MAINNET, bool offline = false, const cryptonote::test_options *test_options = NULL, difficulty_type fixed_difficulty = 0, const GetCheckpointsCallback& get_checkpoints = nullptr);
/** /**
* @brief Initialize the Blockchain state * @brief Initialize the Blockchain state
@ -1374,8 +1386,10 @@ namespace cryptonote
* A (possibly empty) set of block hashes can be compiled into the * A (possibly empty) set of block hashes can be compiled into the
* monero daemon binary. This function loads those hashes into * monero daemon binary. This function loads those hashes into
* a useful state. * a useful state.
*
* @param get_checkpoints if set, will be called to get checkpoints data
*/ */
void load_compiled_in_block_hashes(); void load_compiled_in_block_hashes(const GetCheckpointsCallback& get_checkpoints);
/** /**
* @brief expands v2 transaction data from blockchain * @brief expands v2 transaction data from blockchain

View file

@ -389,7 +389,7 @@ namespace cryptonote
return m_blockchain_storage.get_alternative_blocks_count(); return m_blockchain_storage.get_alternative_blocks_count();
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::init(const boost::program_options::variables_map& vm, const char *config_subdir, const cryptonote::test_options *test_options) bool core::init(const boost::program_options::variables_map& vm, const char *config_subdir, const cryptonote::test_options *test_options, const GetCheckpointsCallback& get_checkpoints/* = nullptr */)
{ {
start_time = std::time(nullptr); start_time = std::time(nullptr);
@ -567,7 +567,7 @@ namespace cryptonote
regtest_hard_forks regtest_hard_forks
}; };
const difficulty_type fixed_difficulty = command_line::get_arg(vm, arg_fixed_difficulty); const difficulty_type fixed_difficulty = command_line::get_arg(vm, arg_fixed_difficulty);
r = m_blockchain_storage.init(db.release(), m_nettype, m_offline, regtest ? &regtest_test_options : test_options, fixed_difficulty); r = m_blockchain_storage.init(db.release(), m_nettype, m_offline, regtest ? &regtest_test_options : test_options, fixed_difficulty, get_checkpoints);
r = m_mempool.init(max_txpool_weight); r = m_mempool.init(max_txpool_weight);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool"); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");

View file

@ -244,10 +244,11 @@ namespace cryptonote
* @param vm command line parameters * @param vm command line parameters
* @param config_subdir subdirectory for config storage * @param config_subdir subdirectory for config storage
* @param test_options configuration options for testing * @param test_options configuration options for testing
* @param get_checkpoints if set, will be called to get checkpoints data, must return checkpoints data pointer and size or nullptr if there ain't any checkpoints for specific network type
* *
* @return false if one of the init steps fails, otherwise true * @return false if one of the init steps fails, otherwise true
*/ */
bool init(const boost::program_options::variables_map& vm, const char *config_subdir = NULL, const test_options *test_options = NULL); bool init(const boost::program_options::variables_map& vm, const char *config_subdir = NULL, const test_options *test_options = NULL, const GetCheckpointsCallback& get_checkpoints = nullptr);
/** /**
* @copydoc Blockchain::reset_and_set_genesis_block * @copydoc Blockchain::reset_and_set_genesis_block

View file

@ -26,20 +26,6 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set(blocksdat "")
if(PER_BLOCK_CHECKPOINT)
if(APPLE AND DEPENDS)
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && touch stub.c && ${CMAKE_C_COMPILER} --target=x86_64-apple-darwin11 -o stub.o -c stub.c COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} -r -sectcreate __DATA __blocks_dat ../blocks/checkpoints.dat -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o stub.o && rm -f stub.*)
elseif(APPLE AND NOT DEPENDS)
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && touch stub.c && ${CMAKE_C_COMPILER} -o stub.o -c stub.c COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_LINKER} ${LD_RAW_FLAGS} -r -sectcreate __DATA __blocks_dat ../blocks/checkpoints.dat -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o stub.o && rm -f stub.*)
elseif(LINUX_32)
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && cp ../blocks/checkpoints.dat blocks.dat && ${CMAKE_LINKER} -m elf_i386 ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o blocks.dat && rm -f blocks.dat)
else()
add_custom_command(OUTPUT blocksdat.o MAIN_DEPENDENCY ../blocks/checkpoints.dat COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && cp ../blocks/checkpoints.dat blocks.dat && ${CMAKE_LINKER} ${LD_RAW_FLAGS} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o blocks.dat && rm -f blocks.dat)
endif()
set(blocksdat "blocksdat.o")
endif()
set(daemon_sources set(daemon_sources
command_parser_executor.cpp command_parser_executor.cpp
command_server.cpp command_server.cpp
@ -81,9 +67,7 @@ monero_private_headers(daemon
monero_add_executable(daemon monero_add_executable(daemon
${daemon_sources} ${daemon_sources}
${daemon_headers} ${daemon_headers}
${daemon_private_headers} ${daemon_private_headers})
${blocksdat}
)
target_link_libraries(daemon target_link_libraries(daemon
PRIVATE PRIVATE
rpc rpc
@ -106,7 +90,8 @@ target_link_libraries(daemon
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${ZMQ_LIB} ${ZMQ_LIB}
${GNU_READLINE_LIBRARY} ${GNU_READLINE_LIBRARY}
${EXTRA_LIBRARIES}) ${EXTRA_LIBRARIES}
${Blocks})
set_property(TARGET daemon set_property(TARGET daemon
PROPERTY PROPERTY
OUTPUT_NAME "monerod") OUTPUT_NAME "monerod")

View file

@ -28,6 +28,7 @@
#pragma once #pragma once
#include "blocks/blocks.h"
#include "cryptonote_core/cryptonote_core.h" #include "cryptonote_core/cryptonote_core.h"
#include "cryptonote_protocol/cryptonote_protocol_handler.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h"
#include "misc_log_ex.h" #include "misc_log_ex.h"
@ -85,7 +86,12 @@ public:
//initialize core here //initialize core here
MGINFO("Initializing core..."); MGINFO("Initializing core...");
std::string config_subdir = get_config_subdir(); std::string config_subdir = get_config_subdir();
if (!m_core.init(m_vm_HACK, config_subdir.empty() ? NULL : config_subdir.c_str())) #if defined(PER_BLOCK_CHECKPOINT)
const cryptonote::GetCheckpointsCallback& get_checkpoints = blocks::GetCheckpointsData;
#else
const cryptonote::GetCheckpointsCallback& get_checkpoints = nullptr;
#endif
if (!m_core.init(m_vm_HACK, config_subdir.empty() ? NULL : config_subdir.c_str(), nullptr, get_checkpoints))
{ {
return false; return false;
} }

View file

@ -58,12 +58,6 @@ endif()
set(device_private_headers) set(device_private_headers)
if(PER_BLOCK_CHECKPOINT)
set(Blocks "blocks")
else()
set(Blocks "")
endif()
monero_private_headers(device monero_private_headers(device
${device_private_headers}) ${device_private_headers})
@ -79,5 +73,4 @@ target_link_libraries(device
ringct_basic ringct_basic
${OPENSSL_CRYPTO_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES}
PRIVATE PRIVATE
${Blocks}
${EXTRA_LIBRARIES}) ${EXTRA_LIBRARIES})