aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/FindMiniupnpc.cmake198
-rw-r--r--src/blockchain_utilities/CMakeLists.txt14
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp292
-rw-r--r--src/blockchain_utilities/fake_core.h133
-rw-r--r--src/cryptonote_core/blockchain.cpp9
-rw-r--r--src/cryptonote_core/blockchain.h3
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp9
-rw-r--r--src/cryptonote_core/cryptonote_core.h8
8 files changed, 215 insertions, 451 deletions
diff --git a/cmake/FindMiniupnpc.cmake b/cmake/FindMiniupnpc.cmake
index ab525b3a7..9fad295e8 100644
--- a/cmake/FindMiniupnpc.cmake
+++ b/cmake/FindMiniupnpc.cmake
@@ -4,10 +4,7 @@
# MINIUPNP_FOUND, if false, do not try to link to miniupnp
# MINIUPNP_LIBRARY, the miniupnp variant
# MINIUPNP_INCLUDE_DIR, where to find miniupnpc.h and family)
-# MINIUPNPC_VERSION_PRE1_6 --> set if we detect the version of miniupnpc is
-# pre 1.6
-# MINIUPNPC_VERSION_PRE1_5 --> set if we detect the version of miniupnpc is
-# pre 1.5
+# MINIUPNPC_VERSION_1_7_OR_HIGHER, set if we detect the version of miniupnpc is 1.7 or higher
#
# Note that the expected include convention is
# #include "miniupnpc.h"
@@ -16,170 +13,47 @@
# This is because, the miniupnpc location is not standardized and may exist
# in locations other than miniupnpc/
-#=============================================================================
-# Copyright 2011 Mark Vejvoda
-#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
-#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-# (To distributed this file outside of CMake, substitute the full
-# License text for the above reference.)
-
if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY)
# Already in cache, be silent
set(MINIUPNP_FIND_QUIETLY TRUE)
endif ()
find_path(MINIUPNP_INCLUDE_DIR miniupnpc.h
- PATH_SUFFIXES miniupnpc)
-find_library(MINIUPNP_LIBRARY miniupnpc)
-
-if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY)
- set (MINIUPNP_FOUND TRUE)
-endif ()
-
-if (MINIUPNP_FOUND)
- include(CheckCXXSourceRuns)
- if (NOT MINIUPNP_FIND_QUIETLY)
- message (STATUS "Found the miniupnpc libraries at ${MINIUPNP_LIBRARY}")
- message (STATUS "Found the miniupnpc headers at ${MINIUPNP_INCLUDE_DIR}")
- endif ()
-
- message(STATUS "Detecting version of miniupnpc in path: ${MINIUPNP_INCLUDE_DIR}")
-
- set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
- check_cxx_source_runs("
- #include <miniwget.h>
- #include <miniupnpc.h>
- #include <upnpcommands.h>
- #include <stdio.h>
- int main()
- {
- static struct UPNPUrls urls;
- static struct IGDdatas data;
-
- GetUPNPUrls (&urls, &data, \"myurl\",0);
-
- return 0;
- }"
- MINIUPNPC_VERSION_1_7_OR_HIGHER)
-
-IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
- set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
- check_cxx_source_runs("
- #include <miniwget.h>
- #include <miniupnpc.h>
- #include <upnpcommands.h>
- #include <stdio.h>
- int main()
- {
- struct UPNPDev *devlist = NULL;
- int upnp_delay = 5000;
- const char *upnp_multicastif = NULL;
- const char *upnp_minissdpdsock = NULL;
- int upnp_sameport = 0;
- int upnp_ipv6 = 0;
- int upnp_error = 0;
- devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, &upnp_error);
-
- return 0;
- }"
- MINIUPNPC_VERSION_PRE1_7)
- ENDIF()
-
- IF (NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
- set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
- check_cxx_source_runs("
- #include <miniwget.h>
- #include <miniupnpc.h>
- #include <upnpcommands.h>
- #include <stdio.h>
- int main()
- {
- struct UPNPDev *devlist = NULL;
- int upnp_delay = 5000;
- const char *upnp_multicastif = NULL;
- const char *upnp_minissdpdsock = NULL;
- int upnp_sameport = 0;
- int upnp_ipv6 = 0;
- int upnp_error = 0;
- devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport);
-
- return 0;
- }"
- MINIUPNPC_VERSION_PRE1_6)
-
- ENDIF()
-
- IF (NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
- set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
- check_cxx_source_runs("
- #include <miniwget.h>
- #include <miniupnpc.h>
- #include <upnpcommands.h>
- #include <stdio.h>
- static struct UPNPUrls urls;
- static struct IGDdatas data;
- int main()
- {
- char externalIP[16] = \"\";
- UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIP);
-
- return 0;
- }"
- MINIUPNPC_VERSION_1_5_OR_HIGHER)
- ENDIF()
-
- IF (NOT MINIUPNPC_VERSION_1_5_OR_HIGHER AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
- set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
- check_cxx_source_runs("
- #include <miniwget.h>
- #include <miniupnpc.h>
- #include <upnpcommands.h>
- #include <stdio.h>
- static struct UPNPUrls urls;
- static struct IGDdatas data;
- int main()
- {
- char externalIP[16] = \"\";
- UPNP_GetExternalIPAddress(urls.controlURL, data.servicetype, externalIP);
-
- return 0;
- }"
- MINIUPNPC_VERSION_PRE1_5)
-
-ENDIF()
-
-IF(MINIUPNPC_VERSION_PRE1_5)
- message(STATUS "Found miniupnpc version is pre v1.5")
-ENDIF()
-IF(MINIUPNPC_VERSION_PRE1_6)
- message(STATUS "Found miniupnpc version is pre v1.6")
+ HINTS $ENV{MINIUPNP_INCLUDE_DIR}
+ PATH_SUFFIXES miniupnpc
+)
+
+find_library(MINIUPNP_LIBRARY miniupnpc
+ HINTS $ENV{MINIUPNP_LIBRARY}
+)
+
+find_library(MINIUPNP_STATIC_LIBRARY libminiupnpc.a
+ HINTS $ENV{MINIUPNP_STATIC_LIBRARY}
+)
+
+set(MINIUPNP_INCLUDE_DIRS ${MINIUPNP_INCLUDE_DIR})
+set(MINIUPNP_LIBRARIES ${MINIUPNP_LIBRARY})
+set(MINIUPNP_STATIC_LIBRARIES ${MINIUPNP_STATIC_LIBRARY})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ MiniUPnPc DEFAULT_MSG
+ MINIUPNP_INCLUDE_DIR
+ MINIUPNP_LIBRARY
+)
+
+IF(MINIUPNPC_FOUND)
+ file(STRINGS "${MINIUPNP_INCLUDE_DIR}/miniupnpc.h" MINIUPNPC_API_VERSION_STR REGEX "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+[0-9]+")
+ if(MINIUPNPC_API_VERSION_STR MATCHES "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+([0-9]+)")
+ set(MINIUPNPC_API_VERSION "${CMAKE_MATCH_1}")
+ endif()
+
+ if (${MINIUPNPC_API_VERSION} GREATER_EQUAL "10")
+ message(STATUS "Found miniupnpc API version " ${MINIUPNPC_API_VERSION})
+ set(MINIUPNP_FOUND true)
+ set(MINIUPNPC_VERSION_1_7_OR_HIGHER true)
+ endif()
ENDIF()
-IF(MINIUPNPC_VERSION_PRE1_7)
- message(STATUS "Found miniupnpc version is pre v1.7")
-ENDIF()
-
-IF(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7)
- IF(MINIUPNPC_VERSION_1_5_OR_HIGHER)
- message(STATUS "Found miniupnpc version is v1.5 or higher")
- ELSE()
- message(STATUS "Found miniupnpc version is v1.7 or higher")
- ENDIF()
-ENDIF()
-
-else ()
- message (STATUS "Could not find miniupnp")
-endif ()
-MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY)
+mark_as_advanced(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY MINIUPNP_STATIC_LIBRARY)
# --------------------------------- FindMiniupnpc End ---------------------------------
diff --git a/src/blockchain_utilities/CMakeLists.txt b/src/blockchain_utilities/CMakeLists.txt
index bb23cdc8b..628c037b3 100644
--- a/src/blockchain_utilities/CMakeLists.txt
+++ b/src/blockchain_utilities/CMakeLists.txt
@@ -26,6 +26,16 @@
# 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.
+set(blocksdat "")
+if(PER_BLOCK_CHECKPOINT)
+ if(APPLE)
+ 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} -r -sectcreate __DATA __blocks_dat ../blocks/checkpoints.dat -o ${CMAKE_CURRENT_BINARY_DIR}/blocksdat.o stub.o && rm -f stub.*)
+ 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} -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
blockchain_import.cpp
bootstrap_file.cpp
@@ -33,7 +43,6 @@ set(blockchain_import_sources
)
set(blockchain_import_private_headers
- fake_core.h
bootstrap_file.h
blocksdat_file.h
bootstrap_serialization.h
@@ -65,7 +74,8 @@ set(cn_deserialize_sources
monero_add_executable(blockchain_import
${blockchain_import_sources}
- ${blockchain_import_private_headers})
+ ${blockchain_import_private_headers}
+ ${blocksdat})
target_link_libraries(blockchain_import
PRIVATE
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index a43e2b4ad..6f908c799 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -32,6 +32,7 @@
#include <fstream>
#include <boost/filesystem.hpp>
+#include "misc_log_ex.h"
#include "bootstrap_file.h"
#include "bootstrap_serialization.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
@@ -39,11 +40,10 @@
#include "serialization/json_utils.h" // dump_json()
#include "include_base_utils.h"
#include "blockchain_db/db_types.h"
+#include "cryptonote_core/cryptonote_core.h"
#include <lmdb.h> // for db flag arguments
-#include "fake_core.h"
-
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
@@ -205,20 +205,12 @@ int parse_db_arguments(const std::string& db_arg_str, std::string& db_type, int&
}
-template <typename FakeCore>
-int pop_blocks(FakeCore& simple_core, int num_blocks)
+int pop_blocks(cryptonote::core& core, int num_blocks)
{
- bool use_batch = false;
- if (opt_batch)
- {
- if (simple_core.support_batch)
- use_batch = true;
- else
- MWARNING("WARNING: batch transactions enabled but unsupported or unnecessary for this database type - ignoring");
- }
+ bool use_batch = opt_batch;
if (use_batch)
- simple_core.batch_start();
+ core.get_blockchain_storage().get_db().batch_start();
int quit = 0;
block popped_block;
@@ -226,12 +218,11 @@ int pop_blocks(FakeCore& simple_core, int num_blocks)
for (int i=0; i < num_blocks; ++i)
{
// simple_core.m_storage.pop_block_from_blockchain() is private, so call directly through db
- simple_core.m_storage.get_db().pop_block(popped_block, popped_txs);
+ core.get_blockchain_storage().get_db().pop_block(popped_block, popped_txs);
quit = 1;
}
-
if (use_batch)
{
if (quit > 1)
@@ -241,24 +232,73 @@ int pop_blocks(FakeCore& simple_core, int num_blocks)
}
else
{
- simple_core.batch_stop();
+ core.get_blockchain_storage().get_db().batch_stop();
}
- simple_core.m_storage.get_db().show_stats();
+ core.get_blockchain_storage().get_db().show_stats();
}
return num_blocks;
}
-template <typename FakeCore>
-int import_from_file(FakeCore& simple_core, const std::string& import_file_path, uint64_t block_stop=0)
+int check_flush(cryptonote::core &core, std::list<block_complete_entry> &blocks, bool force)
{
- if (std::is_same<fake_core_db, FakeCore>::value)
+ if (blocks.empty())
+ return 0;
+ if (!force && blocks.size() < db_batch_size)
+ return 0;
+
+ core.prepare_handle_incoming_blocks(blocks);
+
+ for(const block_complete_entry& block_entry: blocks)
{
- // Reset stats, in case we're using newly created db, accumulating stats
- // from addition of genesis block.
- // This aligns internal db counts with importer counts.
- simple_core.m_storage.get_db().reset_stats();
- }
+ // process transactions
+ for(auto& tx_blob: block_entry.txs)
+ {
+ tx_verification_context tvc = AUTO_VAL_INIT(tvc);
+ core.handle_incoming_tx(tx_blob, tvc, true, true, false);
+ if(tvc.m_verifivation_failed)
+ {
+ MERROR("transaction verification failed, tx_id = "
+ << epee::string_tools::pod_to_hex(get_blob_hash(tx_blob)));
+ core.cleanup_handle_incoming_blocks();
+ return 1;
+ }
+ }
+
+ // process block
+
+ block_verification_context bvc = boost::value_initialized<block_verification_context>();
+
+ core.handle_incoming_block(block_entry.block, bvc, false); // <--- process block
+
+ if(bvc.m_verifivation_failed)
+ {
+ MERROR("Block verification failed, id = "
+ << epee::string_tools::pod_to_hex(get_blob_hash(block_entry.block)));
+ core.cleanup_handle_incoming_blocks();
+ return 1;
+ }
+ if(bvc.m_marked_as_orphaned)
+ {
+ MERROR("Block received at sync phase was marked as orphaned");
+ core.cleanup_handle_incoming_blocks();
+ return 1;
+ }
+
+ } // each download block
+ core.cleanup_handle_incoming_blocks();
+
+ blocks.clear();
+ return 0;
+}
+
+int import_from_file(cryptonote::core& core, const std::string& import_file_path, uint64_t block_stop=0)
+{
+ // Reset stats, in case we're using newly created db, accumulating stats
+ // from addition of genesis block.
+ // This aligns internal db counts with importer counts.
+ core.get_blockchain_storage().get_db().reset_stats();
+
boost::filesystem::path fs_import_file_path(import_file_path);
boost::system::error_code ec;
if (!boost::filesystem::exists(fs_import_file_path, ec))
@@ -300,7 +340,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
uint64_t start_height = 1;
if (opt_resume)
- start_height = simple_core.m_storage.get_current_blockchain_height();
+ start_height = core.get_blockchain_storage().get_current_blockchain_height();
// Note that a new blockchain will start with block number 0 (total blocks: 1)
// due to genesis block being added at initialization.
@@ -315,21 +355,16 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
MINFO("start block: " << start_height << " stop block: " <<
block_stop);
- bool use_batch = false;
- if (opt_batch)
- {
- if (simple_core.support_batch)
- use_batch = true;
- else
- MWARNING("WARNING: batch transactions enabled but unsupported or unnecessary for this database type - ignoring");
- }
+ bool use_batch = opt_batch && !opt_verify;
if (use_batch)
- simple_core.batch_start(db_batch_size);
+ core.get_blockchain_storage().get_db().batch_start(db_batch_size);
MINFO("Reading blockchain from bootstrap file...");
std::cout << ENDL;
+ std::list<block_complete_entry> blocks;
+
// Within the loop, we skip to start_height before we start adding.
// TODO: Not a bottleneck, but we can use what's done in count_blocks() and
// only do the chunk size reads, skipping the chunk content reads until we're
@@ -424,67 +459,34 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
<< std::flush;
}
- std::vector<transaction> txs;
- std::vector<transaction> archived_txs;
-
- archived_txs = bp.txs;
-
- // std::cout << refresh_string;
- // MDEBUG("txs: " << archived_txs.size());
-
- // if archived_txs is invalid
- // {
- // std::cout << refresh_string;
- // MFATAL("exception while de-archiving txs, height=" << h);
- // quit = 1;
- // break;
- // }
-
- // tx number 1: coinbase tx
- // tx number 2 onwards: archived_txs
- unsigned int tx_num = 1;
- for (transaction tx : archived_txs)
+ if (opt_verify)
{
- ++tx_num;
- // if tx is invalid
- // {
- // MFATAL("exception while indexing tx from txs, height=" << h <<", tx_num=" << tx_num);
- // quit = 1;
- // break;
- // }
-
- // std::cout << refresh_string;
- // MDEBUG("tx hash: " << get_transaction_hash(tx));
-
- // crypto::hash hsh = null_hash;
- // size_t blob_size = 0;
- // NOTE: all tx hashes except for coinbase tx are available in the block data
- // get_transaction_hash(tx, hsh, blob_size);
- // MDEBUG("tx " << tx_num << " " << hsh << " : " << ENDL);
- // MDEBUG(obj_to_json_str(tx) << ENDL);
-
- // add blocks with verification.
- // for Blockchain and blockchain_storage add_new_block().
- if (opt_verify)
+ cryptonote::blobdata block;
+ cryptonote::block_to_blob(bp.block, block);
+ std::list<cryptonote::blobdata> txs;
+ for (const auto &tx: bp.txs)
{
- // crypto::hash hsh = null_hash;
- // size_t blob_size = 0;
- // get_transaction_hash(tx, hsh, blob_size);
+ txs.push_back(cryptonote::blobdata());
+ cryptonote::tx_to_blob(tx, txs.back());
+ }
+ blocks.push_back({block, txs});
+ int ret = check_flush(core, blocks, false);
+ if (ret)
+ break;
+ }
+ else
+ {
+ std::vector<transaction> txs;
+ std::vector<transaction> archived_txs;
+ archived_txs = bp.txs;
- uint8_t version = simple_core.m_storage.get_current_hard_fork_version();
- tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- bool r = true;
- r = simple_core.m_pool.add_tx(tx, tvc, true, true, false, version);
- if (!r)
- {
- MFATAL("failed to add transaction to transaction pool, height=" << h <<", tx_num=" << tx_num);
- quit = 1;
- break;
- }
- }
- else
+ // tx number 1: coinbase tx
+ // tx number 2 onwards: archived_txs
+ for (transaction tx : archived_txs)
{
+ // add blocks with verification.
+ // for Blockchain and blockchain_storage add_new_block().
// for add_block() method, without (much) processing.
// don't add coinbase transaction to txs.
//
@@ -493,34 +495,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
// then a for loop for the transactions in txs.
txs.push_back(tx);
}
- }
- if (opt_verify)
- {
- block_verification_context bvc = boost::value_initialized<block_verification_context>();
- simple_core.m_storage.add_new_block(b, bvc);
-
- if (bvc.m_verifivation_failed)
- {
- MFATAL("Failed to add block to blockchain, verification failed, height = " << h);
- MFATAL("skipping rest of file");
- // ok to commit previously batched data because it failed only in
- // verification of potential new block with nothing added to batch
- // yet
- quit = 1;
- break;
- }
- if (! bvc.m_added_to_main_chain)
- {
- MFATAL("Failed to add block to blockchain, height = " << h);
- MFATAL("skipping rest of file");
- // make sure we don't commit partial block data
- quit = 2;
- break;
- }
- }
- else
- {
size_t block_size;
difficulty_type cumulative_difficulty;
uint64_t coins_generated;
@@ -529,14 +504,9 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
cumulative_difficulty = bp.cumulative_difficulty;
coins_generated = bp.coins_generated;
- // std::cout << refresh_string;
- // MDEBUG("block_size: " << block_size);
- // MDEBUG("cumulative_difficulty: " << cumulative_difficulty);
- // MDEBUG("coins_generated: " << coins_generated);
-
try
{
- simple_core.add_block(b, block_size, cumulative_difficulty, coins_generated, txs);
+ core.get_blockchain_storage().get_db().add_block(b, block_size, cumulative_difficulty, coins_generated, txs);
}
catch (const std::exception& e)
{
@@ -545,22 +515,22 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
quit = 2; // make sure we don't commit partial block data
break;
}
- }
- ++num_imported;
- if (use_batch)
- {
- if ((h-1) % db_batch_size == 0)
+ if (use_batch)
{
- std::cout << refresh_string;
- // zero-based height
- std::cout << ENDL << "[- batch commit at height " << h-1 << " -]" << ENDL;
- simple_core.batch_stop();
- simple_core.batch_start(db_batch_size);
- std::cout << ENDL;
- simple_core.m_storage.get_db().show_stats();
+ if ((h-1) % db_batch_size == 0)
+ {
+ std::cout << refresh_string;
+ // zero-based height
+ std::cout << ENDL << "[- batch commit at height " << h-1 << " -]" << ENDL;
+ core.get_blockchain_storage().get_db().batch_stop();
+ core.get_blockchain_storage().get_db().batch_start(db_batch_size);
+ std::cout << ENDL;
+ core.get_blockchain_storage().get_db().show_stats();
+ }
}
}
+ ++num_imported;
}
}
catch (const std::exception& e)
@@ -573,6 +543,13 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
import_file.close();
+ if (opt_verify)
+ {
+ int ret = check_flush(core, blocks, true);
+ if (ret)
+ return ret;
+ }
+
if (use_batch)
{
if (quit > 1)
@@ -582,14 +559,16 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
}
else
{
- simple_core.batch_stop();
+ core.get_blockchain_storage().get_db().batch_stop();
}
- simple_core.m_storage.get_db().show_stats();
- MINFO("Number of blocks imported: " << num_imported);
- if (h > 0)
- // TODO: if there was an error, the last added block is probably at zero-based height h-2
- MINFO("Finished at block: " << h-1 << " total blocks: " << h);
}
+
+ core.get_blockchain_storage().get_db().show_stats();
+ MINFO("Number of blocks imported: " << num_imported);
+ if (h > 0)
+ // TODO: if there was an error, the last added block is probably at zero-based height h-2
+ MINFO("Finished at block: " << h-1 << " total blocks: " << h);
+
std::cout << ENDL;
return 0;
}
@@ -649,10 +628,10 @@ int main(int argc, char* argv[])
const command_line::arg_descriptor<bool> arg_resume = {"resume",
"Resume from current height if output database already exists", true};
- command_line::add_arg(desc_cmd_sett, command_line::arg_data_dir, default_data_path.string());
- command_line::add_arg(desc_cmd_sett, command_line::arg_testnet_data_dir, default_testnet_data_path.string());
+ //command_line::add_arg(desc_cmd_sett, command_line::arg_data_dir, default_data_path.string());
+ //command_line::add_arg(desc_cmd_sett, command_line::arg_testnet_data_dir, default_testnet_data_path.string());
command_line::add_arg(desc_cmd_sett, arg_input_file);
- command_line::add_arg(desc_cmd_sett, arg_testnet_on);
+ //command_line::add_arg(desc_cmd_sett, arg_testnet_on);
command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_database);
command_line::add_arg(desc_cmd_sett, arg_batch_size);
@@ -673,6 +652,7 @@ int main(int argc, char* argv[])
po::options_description desc_options("Allowed options");
desc_options.add(desc_cmd_only).add(desc_cmd_sett);
+ cryptonote::core::init_options(desc_options);
po::variables_map vm;
bool r = command_line::handle_error_helper(desc_options, [&]()
@@ -818,26 +798,34 @@ int main(int argc, char* argv[])
return 1;
}
- // for multi_db_compile:
- fake_core_db simple_core(m_config_folder, opt_testnet, opt_batch, db_type, db_flags);
+ cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects
+ cryptonote::core core(&pr);
+ core.disable_dns_checkpoints(true);
+ if (!core.init(vm, NULL))
+ {
+ std::cerr << "Failed to initialize core" << ENDL;
+ return 1;
+ }
+ core.get_blockchain_storage().get_db().set_batch_transactions(true);
if (! vm["pop-blocks"].defaulted())
{
num_blocks = command_line::get_arg(vm, arg_pop_blocks);
- MINFO("height: " << simple_core.m_storage.get_current_blockchain_height());
- pop_blocks(simple_core, num_blocks);
- MINFO("height: " << simple_core.m_storage.get_current_blockchain_height());
+ MINFO("height: " << core.get_blockchain_storage().get_current_blockchain_height());
+ pop_blocks(core, num_blocks);
+ MINFO("height: " << core.get_blockchain_storage().get_current_blockchain_height());
return 0;
}
if (! vm["drop-hard-fork"].defaulted())
{
MINFO("Dropping hard fork tables...");
- simple_core.m_storage.get_db().drop_hard_fork_info();
+ core.get_blockchain_storage().get_db().drop_hard_fork_info();
+ core.deinit();
return 0;
}
- import_from_file(simple_core, import_file_path, block_stop);
+ import_from_file(core, import_file_path, block_stop);
}
catch (const DB_ERROR& e)
diff --git a/src/blockchain_utilities/fake_core.h b/src/blockchain_utilities/fake_core.h
deleted file mode 100644
index 809c6fe43..000000000
--- a/src/blockchain_utilities/fake_core.h
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright (c) 2014-2017, The Monero Project
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-// conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be
-// used to endorse or promote products derived from this software without specific
-// prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// 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.
-
-#pragma once
-
-#include <boost/filesystem.hpp>
-#include "cryptonote_core/blockchain.h" // BlockchainDB
-#include "cryptonote_core/tx_pool.h"
-#include "blockchain_db/blockchain_db.h"
-#include "blockchain_db/lmdb/db_lmdb.h"
-#if defined(BERKELEY_DB)
-#include "blockchain_db/berkeleydb/db_bdb.h"
-#endif
-
-using namespace cryptonote;
-
-namespace
-{
- // NOTE: These values should match blockchain.cpp
- // TODO: Refactor
- const uint64_t mainnet_hard_fork_version_1_till = 1009826;
- const uint64_t testnet_hard_fork_version_1_till = 624633;
-}
-
-
-struct fake_core_db
-{
- Blockchain m_storage;
- HardFork* m_hardfork = nullptr;
- tx_memory_pool m_pool;
- bool support_batch;
- bool support_add_block;
-
- // for multi_db_runtime:
- fake_core_db(const boost::filesystem::path &path, const bool use_testnet=false, const bool do_batch=true, const std::string& db_type="lmdb", const int db_flags=0) : m_pool(m_storage), m_storage(m_pool)
- {
- BlockchainDB* db = nullptr;
- if (db_type == "lmdb")
- db = new BlockchainLMDB();
-#if defined(BERKELEY_DB)
- else if (db_type == "berkeley")
- db = new BlockchainBDB();
-#endif
- else
- {
- LOG_ERROR("Attempted to use non-existent database type: " << db_type);
- throw std::runtime_error("Attempting to use non-existent database type");
- }
-
- boost::filesystem::path folder(path);
-
- folder /= db->get_db_name();
-
- LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ...");
-
- const std::string filename = folder.string();
- try
- {
- db->open(filename, db_flags);
- }
- catch (const std::exception& e)
- {
- LOG_PRINT_L0("Error opening database: " << e.what());
- throw;
- }
-
- db->check_hard_fork_info();
-
- uint64_t hard_fork_version_1_till = use_testnet ? testnet_hard_fork_version_1_till : mainnet_hard_fork_version_1_till;
- m_hardfork = new HardFork(*db, 1, hard_fork_version_1_till);
-
- m_storage.init(db, m_hardfork, use_testnet);
-
- m_pool.init();
-
- if (do_batch)
- m_storage.get_db().set_batch_transactions(do_batch);
- support_batch = true;
- support_add_block = true;
- }
- ~fake_core_db()
- {
- m_storage.get_db().check_hard_fork_info();
- m_storage.deinit();
- }
-
- uint64_t add_block(const block& blk
- , const size_t& block_size
- , const difficulty_type& cumulative_difficulty
- , const uint64_t& coins_generated
- , const std::vector<transaction>& txs
- )
- {
- return m_storage.get_db().add_block(blk, block_size, cumulative_difficulty, coins_generated, txs);
- }
-
- bool batch_start(uint64_t batch_num_blocks = 0)
- {
- return m_storage.get_db().batch_start(batch_num_blocks);
- }
-
- void batch_stop()
- {
- m_storage.get_db().batch_stop();
- }
-
-};
-
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 792bee8d1..e377c0f53 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -4171,6 +4171,15 @@ void Blockchain::load_compiled_in_block_hashes()
}
#endif
+bool Blockchain::is_within_compiled_block_hash_area(uint64_t height) const
+{
+#if defined(PER_BLOCK_CHECKPOINT)
+ return height < m_blocks_hash_check.size();
+#else
+ return false;
+#endif
+}
+
void Blockchain::lock()
{
m_blockchain_lock.lock();
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 564b53af3..bd8a8313c 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -865,6 +865,9 @@ namespace cryptonote
cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const;
bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const;
+ bool is_within_compiled_block_hash_area(uint64_t height) const;
+ bool is_within_compiled_block_hash_area() const { return is_within_compiled_block_hash_area(m_db->height()); }
+
void lock();
void unlock();
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 75d5f7a13..13e5badd1 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -77,6 +77,7 @@ namespace cryptonote
m_checkpoints_path(""),
m_last_dns_checkpoints_update(0),
m_last_json_checkpoints_update(0),
+ m_disable_dns_checkpoints(false),
m_threadpool(tools::thread_group::optimal()),
m_update_download(0)
{
@@ -108,7 +109,7 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool core::update_checkpoints()
{
- if (m_testnet || m_fakechain) return true;
+ if (m_testnet || m_fakechain || m_disable_dns_checkpoints) return true;
if (m_checkpoints_updating.test_and_set()) return true;
@@ -561,7 +562,11 @@ namespace cryptonote
rv.outPk[n].dest = rct::pk2rct(boost::get<txout_to_key>(tx.vout[n].target).key);
}
- if(!check_tx_semantic(tx, keeped_by_block))
+ if (keeped_by_block && get_blockchain_storage().is_within_compiled_block_hash_area())
+ {
+ MTRACE("Skipping semantics check for tx kept by block in embedded hash area");
+ }
+ else if(!check_tx_semantic(tx, keeped_by_block))
{
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to check tx " << tx_hash << " semantic, rejected");
tvc.m_verifivation_failed = true;
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 4dbd51040..171c3cb98 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -407,6 +407,13 @@ namespace cryptonote
void set_enforce_dns_checkpoints(bool enforce_dns);
/**
+ * @brief set whether or not to enable or disable DNS checkpoints
+ *
+ * @param disble whether to disable DNS checkpoints
+ */
+ void disable_dns_checkpoints(bool disable = true) { m_disable_dns_checkpoints = disable; }
+
+ /**
* @copydoc tx_memory_pool::have_tx
*
* @note see tx_memory_pool::have_tx
@@ -882,6 +889,7 @@ namespace cryptonote
time_t m_last_json_checkpoints_update; //!< time when json checkpoints were last updated
std::atomic_flag m_checkpoints_updating; //!< set if checkpoints are currently updating to avoid multiple threads attempting to update at once
+ bool m_disable_dns_checkpoints;
size_t block_sync_size;