Revert "Merge pull request #4472"

This reverts commit 79d46c4d55, reversing
changes made to c9fc61dbb5.
This commit is contained in:
Riccardo Spagni 2018-10-08 21:39:54 +02:00
parent 3f2bfe87f7
commit ac5674524a
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
17 changed files with 185 additions and 113 deletions

View file

@ -199,9 +199,6 @@ 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
@ -677,10 +674,12 @@ 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,6 +26,20 @@
# 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
@ -105,7 +119,8 @@ 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
@ -117,8 +132,7 @@ 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,7 +37,6 @@
#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()
@ -759,12 +758,7 @@ int main(int argc, char* argv[])
{ {
core.disable_dns_checkpoints(true); core.disable_dns_checkpoints(true);
#if defined(PER_BLOCK_CHECKPOINT) if (!core.init(vm, NULL))
GetCheckpointsCallback get_checkpoints = blocks::GetCheckpointsData;
#else
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,23 +26,20 @@
# 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(GENERATED_SOURCES "") if(APPLE)
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 -n "'const\tunsigned\tchar\t${BLOB_NAME}[]={'" >> ${OUTPUT_C_SOURCE} &&
od -v -An -w1 -tu1 ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_DAT_FILE} | sed -e "':a;N;$$!ba;s/\\n/,/g'" >> ${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})

87
src/blocks/blockexports.c Normal file
View file

@ -0,0 +1,87 @@
#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

View file

@ -1,31 +0,0 @@
#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;
}
}

0
src/blocks/blocks.dat Normal file
View file

View file

@ -1,12 +1,16 @@
#ifndef SRC_BLOCKS_BLOCKS_H_ #ifndef SRC_BLOCKS_BLOCKS_H_
#define SRC_BLOCKS_BLOCKS_H_ #define SRC_BLOCKS_BLOCKS_H_
#include "cryptonote_config.h" #ifdef __cplusplus
#include "span.h" extern "C" {
#endif
namespace blocks const unsigned char *get_blocks_dat_start(int testnet, int stagenet);
{ 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,7 +30,6 @@
#pragma once #pragma once
#include <stdexcept>
#include <string> #include <string>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>

View file

@ -41,6 +41,12 @@ 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
@ -63,4 +69,5 @@ 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,6 +53,9 @@
#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"
@ -338,7 +341,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, const GetCheckpointsCallback get_checkpoints/* = nullptr*/) bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline, const cryptonote::test_options *test_options, difficulty_type fixed_difficulty)
{ {
LOG_PRINT_L3("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_tx_pool); CRITICAL_REGION_LOCAL(m_tx_pool);
@ -436,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(get_checkpoints); load_compiled_in_block_hashes();
#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());
@ -4401,21 +4404,19 @@ 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(const GetCheckpointsCallback get_checkpoints) void Blockchain::load_compiled_in_block_hashes()
{ {
if (get_checkpoints == nullptr || !m_fast_sync) const bool testnet = m_nettype == TESTNET;
const bool stagenet = m_nettype == STAGENET;
if (m_fast_sync && get_blocks_dat_start(testnet, stagenet) != nullptr && get_blocks_dat_size(testnet, stagenet) > 0)
{ {
return; MINFO("Loading precomputed blocks (" << get_blocks_dat_size(testnet, stagenet) << " bytes)");
}
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(checkpoints.data(), checkpoints.size(), hash)) if (!tools::sha256sum(get_blocks_dat_start(testnet, stagenet), get_blocks_dat_size(testnet, stagenet), hash))
{ {
MERROR("Failed to hash precomputed blocks data"); MERROR("Failed to hash precomputed blocks data");
return; return;
@ -4435,9 +4436,9 @@ void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback get_
} }
} }
if (checkpoints.size() > 4) if (get_blocks_dat_size(testnet, stagenet) > 4)
{ {
const unsigned char *p = checkpoints.data(); const unsigned char *p = get_blocks_dat_start(testnet, stagenet);
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))
{ {
@ -4445,7 +4446,7 @@ void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback get_
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 && checkpoints.size() >= size_needed) if(nblocks > 0 && nblocks > (m_db->height() + HASH_OF_HASHES_STEP - 1) / HASH_OF_HASHES_STEP && get_blocks_dat_size(testnet, stagenet) >= 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,11 +38,9 @@
#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"
@ -75,15 +73,6 @@ 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;
/************************************************************************/ /************************************************************************/
/* */ /* */
/************************************************************************/ /************************************************************************/
@ -128,11 +117,10 @@ 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, const GetCheckpointsCallback get_checkpoints = nullptr); bool init(BlockchainDB* db, const network_type nettype = MAINNET, bool offline = false, const cryptonote::test_options *test_options = NULL, difficulty_type fixed_difficulty = 0);
/** /**
* @brief Initialize the Blockchain state * @brief Initialize the Blockchain state
@ -1381,10 +1369,8 @@ 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(const GetCheckpointsCallback get_checkpoints); void load_compiled_in_block_hashes();
/** /**
* @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, const GetCheckpointsCallback get_checkpoints/* = nullptr */) bool core::init(const boost::program_options::variables_map& vm, const char *config_subdir, const cryptonote::test_options *test_options)
{ {
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, get_checkpoints); r = m_blockchain_storage.init(db.release(), m_nettype, m_offline, regtest ? &regtest_test_options : test_options, fixed_difficulty);
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,11 +244,10 @@ 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, const GetCheckpointsCallback get_checkpoints = nullptr); bool init(const boost::program_options::variables_map& vm, const char *config_subdir = NULL, const test_options *test_options = NULL);
/** /**
* @copydoc Blockchain::reset_and_set_genesis_block * @copydoc Blockchain::reset_and_set_genesis_block

View file

@ -26,6 +26,20 @@
# 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
@ -67,7 +81,9 @@ 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
@ -90,8 +106,7 @@ 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,7 +28,6 @@
#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"
@ -86,12 +85,7 @@ 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 defined(PER_BLOCK_CHECKPOINT) if (!m_core.init(m_vm_HACK, config_subdir.empty() ? NULL : config_subdir.c_str()))
cryptonote::GetCheckpointsCallback get_checkpoints = blocks::GetCheckpointsData;
#else
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,6 +58,12 @@ 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})
@ -73,4 +79,5 @@ target_link_libraries(device
ringct_basic ringct_basic
${OPENSSL_CRYPTO_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES}
PRIVATE PRIVATE
${Blocks}
${EXTRA_LIBRARIES}) ${EXTRA_LIBRARIES})