aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-09-02 11:32:46 +0200
committerRiccardo Spagni <ric@spagni.net>2017-09-02 11:32:46 +0200
commit02e5dcd2fab07c46b4943028cfabecbba4745b58 (patch)
treefc1b6e736d2836a6cd62bcf986a074ce67ff8c0f
parentMerge pull request #2374 (diff)
parentblockchain_import: warn for chunks over 500000, not 100000 (diff)
downloadmonero-02e5dcd2fab07c46b4943028cfabecbba4745b58.tar.xz
Merge pull request #2384
4e0e4e99 blockchain_import: warn for chunks over 500000, not 100000 (moneromooo-monero) 5b29e87f blockchain_import: properly cleanup core/db on exit (moneromooo-monero) e167c4d9 blockchain_import: do not error out on truncated files (moneromooo-monero)
Diffstat (limited to '')
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp48
-rw-r--r--src/blockchain_utilities/blockchain_utilities.h1
-rw-r--r--src/blockchain_utilities/bootstrap_file.cpp4
3 files changed, 27 insertions, 26 deletions
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index 14f318768..635a70b10 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -317,9 +317,9 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
MWARNING("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
throw std::runtime_error("Aborting: chunk size exceeds buffer size");
}
- if (chunk_size > 100000)
+ if (chunk_size > CHUNK_SIZE_WARNING_THRESHOLD)
{
- MINFO("NOTE: chunk_size " << chunk_size << " > 100000");
+ MINFO("NOTE: chunk_size " << chunk_size << " > " << CHUNK_SIZE_WARNING_THRESHOLD);
}
else if (chunk_size == 0) {
MFATAL("ERROR: chunk_size == 0");
@@ -327,9 +327,19 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
}
import_file.read(buffer_block, chunk_size);
if (! import_file) {
- MFATAL("ERROR: unexpected end of file: bytes read before error: "
- << import_file.gcount() << " of chunk_size " << chunk_size);
- return 2;
+ if (import_file.eof())
+ {
+ std::cout << refresh_string;
+ MINFO("End of file reached - file was truncated");
+ quit = 1;
+ break;
+ }
+ else
+ {
+ MFATAL("ERROR: unexpected end of file: bytes read before error: "
+ << import_file.gcount() << " of chunk_size " << chunk_size);
+ return 2;
+ }
}
bytes_read += chunk_size;
MDEBUG("Total bytes read: " << bytes_read);
@@ -686,18 +696,12 @@ int main(int argc, char* argv[])
MINFO("bootstrap file path: " << import_file_path);
MINFO("database path: " << m_config_folder);
+ cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects
+ cryptonote::core core(&pr);
+
try
{
- // fake_core needed for verification to work when enabled.
- //
- // NOTE: don't need fake_core method of doing things when we're going to call
- // BlockchainDB add_block() directly and have available the 3 block
- // properties to do so. Both ways work, but fake core isn't necessary in that
- // circumstance.
-
- 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))
{
@@ -725,23 +729,19 @@ int main(int argc, char* argv[])
import_from_file(core, import_file_path, block_stop);
+ // ensure db closed
+ // - transactions properly checked and handled
+ // - disk sync if needed
+ //
+ core.deinit();
}
catch (const DB_ERROR& e)
{
std::cout << std::string("Error loading blockchain db: ") + e.what() + " -- shutting down now" << ENDL;
+ core.deinit();
return 1;
}
- // destructors called at exit:
- //
- // ensure db closed
- // - transactions properly checked and handled
- // - disk sync if needed
- //
- // fake_core object's destructor is called when it goes out of scope. For an
- // LMDB fake_core, it calls Blockchain::deinit() on its object, which in turn
- // calls delete on its BlockchainDB derived class' object, which closes its
- // files.
return 0;
CATCH_ENTRY("Import error", 1);
diff --git a/src/blockchain_utilities/blockchain_utilities.h b/src/blockchain_utilities/blockchain_utilities.h
index af934bf29..6fb5e1131 100644
--- a/src/blockchain_utilities/blockchain_utilities.h
+++ b/src/blockchain_utilities/blockchain_utilities.h
@@ -34,6 +34,7 @@
// bounds checking is done before writing to buffer, but buffer size
// should be a sensible maximum
#define BUFFER_SIZE 1000000
+#define CHUNK_SIZE_WARNING_THRESHOLD 500000
#define NUM_BLOCKS_PER_CHUNK 1
#define BLOCKCHAIN_RAW "blockchain.raw"
diff --git a/src/blockchain_utilities/bootstrap_file.cpp b/src/blockchain_utilities/bootstrap_file.cpp
index d5bb37d93..2b1a5d6c7 100644
--- a/src/blockchain_utilities/bootstrap_file.cpp
+++ b/src/blockchain_utilities/bootstrap_file.cpp
@@ -436,10 +436,10 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
<< " height: " << h-1);
throw std::runtime_error("Aborting: chunk size exceeds buffer size");
}
- if (chunk_size > 100000)
+ if (chunk_size > CHUNK_SIZE_WARNING_THRESHOLD)
{
std::cout << refresh_string;
- MDEBUG("NOTE: chunk_size " << chunk_size << " > 100000" << " height: "
+ MDEBUG("NOTE: chunk_size " << chunk_size << " > " << CHUNK_SIZE_WARNING_THRESHOLD << " << height: "
<< h-1);
}
else if (chunk_size <= 0) {