aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_utilities/bootstrap_file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/blockchain_utilities/bootstrap_file.cpp')
-rw-r--r--src/blockchain_utilities/bootstrap_file.cpp68
1 files changed, 35 insertions, 33 deletions
diff --git a/src/blockchain_utilities/bootstrap_file.cpp b/src/blockchain_utilities/bootstrap_file.cpp
index 61bd35a6f..add2c65e6 100644
--- a/src/blockchain_utilities/bootstrap_file.cpp
+++ b/src/blockchain_utilities/bootstrap_file.cpp
@@ -32,6 +32,8 @@
#include "bootstrap_file.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
namespace po = boost::program_options;
@@ -59,7 +61,7 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
{
if (!boost::filesystem::is_directory(dir_path))
{
- LOG_PRINT_RED_L0("export directory path is a file: " << dir_path);
+ MFATAL("export directory path is a file: " << dir_path);
return false;
}
}
@@ -67,7 +69,7 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
{
if (!boost::filesystem::create_directory(dir_path))
{
- LOG_PRINT_RED_L0("Failed to create directory " << dir_path);
+ MFATAL("Failed to create directory " << dir_path);
return false;
}
}
@@ -80,14 +82,14 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
if (! boost::filesystem::exists(file_path))
{
- LOG_PRINT_L0("creating file");
+ MDEBUG("creating file");
do_initialize_file = true;
num_blocks = 0;
}
else
{
num_blocks = count_blocks(file_path.string());
- LOG_PRINT_L0("appending to existing file with height: " << num_blocks-1 << " total blocks: " << num_blocks);
+ MDEBUG("appending to existing file with height: " << num_blocks-1 << " total blocks: " << num_blocks);
}
m_height = num_blocks;
@@ -138,7 +140,7 @@ bool BootstrapFile::initialize_file()
uint32_t bd_size = 0;
blobdata bd = t_serializable_object_to_blob(bfi);
- LOG_PRINT_L1("bootstrap::file_info size: " << bd.size());
+ MDEBUG("bootstrap::file_info size: " << bd.size());
bd_size = bd.size();
if (! ::serialization::dump_binary(bd_size, blob))
@@ -149,7 +151,7 @@ bool BootstrapFile::initialize_file()
*output_stream_header << bd;
bd = t_serializable_object_to_blob(bbi);
- LOG_PRINT_L1("bootstrap::blocks_info size: " << bd.size());
+ MDEBUG("bootstrap::blocks_info size: " << bd.size());
bd_size = bd.size();
if (! ::serialization::dump_binary(bd_size, blob))
@@ -172,10 +174,10 @@ void BootstrapFile::flush_chunk()
m_output_stream->flush();
uint32_t chunk_size = m_buffer.size();
- // LOG_PRINT_L0("chunk_size " << chunk_size);
+ // MTRACE("chunk_size " << chunk_size);
if (chunk_size > BUFFER_SIZE)
{
- LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
+ MWARNING("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
}
std::string blob;
@@ -196,14 +198,14 @@ void BootstrapFile::flush_chunk()
long num_chars_written = pos_after - pos_before;
if (static_cast<unsigned long>(num_chars_written) != chunk_size)
{
- LOG_PRINT_RED_L0("Error writing chunk: height: " << m_cur_height << " chunk_size: " << chunk_size << " num chars written: " << num_chars_written);
+ MFATAL("Error writing chunk: height: " << m_cur_height << " chunk_size: " << chunk_size << " num chars written: " << num_chars_written);
throw std::runtime_error("Error writing chunk");
}
m_buffer.clear();
delete m_output_stream;
m_output_stream = new boost::iostreams::stream<boost::iostreams::back_insert_device<buffer_type>>(m_buffer);
- LOG_PRINT_L1("flushed chunk: chunk_size: " << chunk_size);
+ MDEBUG("flushed chunk: chunk_size: " << chunk_size);
}
void BootstrapFile::write_block(block& block)
@@ -267,10 +269,10 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
m_blockchain_storage = _blockchain_storage;
m_tx_pool = _tx_pool;
uint64_t progress_interval = 100;
- LOG_PRINT_L0("Storing blocks raw data...");
+ MINFO("Storing blocks raw data...");
if (!BootstrapFile::open_writer(output_file))
{
- LOG_PRINT_RED_L0("failed to open raw file for write");
+ MFATAL("failed to open raw file for write");
return false;
}
block b;
@@ -280,16 +282,16 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
// height.
uint64_t block_start = m_height;
uint64_t block_stop = 0;
- LOG_PRINT_L0("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1);
+ MINFO("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1);
if ((requested_block_stop > 0) && (requested_block_stop < m_blockchain_storage->get_current_blockchain_height()))
{
- LOG_PRINT_L0("Using requested block height: " << requested_block_stop);
+ MINFO("Using requested block height: " << requested_block_stop);
block_stop = requested_block_stop;
}
else
{
block_stop = m_blockchain_storage->get_current_blockchain_height() - 1;
- LOG_PRINT_L0("Using block height of source blockchain: " << block_stop);
+ MINFO("Using block height of source blockchain: " << block_stop);
}
for (m_cur_height = block_start; m_cur_height <= block_stop; ++m_cur_height)
{
@@ -315,9 +317,9 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
std::cout << refresh_string;
std::cout << "block " << m_cur_height-1 << "/" << block_stop << ENDL;
- LOG_PRINT_L0("Number of blocks exported: " << num_blocks_written);
+ MINFO("Number of blocks exported: " << num_blocks_written);
if (num_blocks_written > 0)
- LOG_PRINT_L0("Largest chunk: " << m_max_chunk << " bytes");
+ MINFO("Largest chunk: " << m_max_chunk << " bytes");
return BootstrapFile::close();
}
@@ -338,11 +340,11 @@ uint64_t BootstrapFile::seek_to_first_chunk(std::ifstream& import_file)
if (file_magic != blockchain_raw_magic)
{
- LOG_PRINT_RED_L0("bootstrap file not recognized");
+ MFATAL("bootstrap file not recognized");
throw std::runtime_error("Aborting");
}
else
- LOG_PRINT_L0("bootstrap file recognized");
+ MINFO("bootstrap file recognized");
uint32_t buflen_file_info;
@@ -352,7 +354,7 @@ uint64_t BootstrapFile::seek_to_first_chunk(std::ifstream& import_file)
throw std::runtime_error("Error reading expected number of bytes");
if (! ::serialization::parse_binary(str1, buflen_file_info))
throw std::runtime_error("Error in deserialization of buflen_file_info");
- LOG_PRINT_L1("bootstrap::file_info size: " << buflen_file_info);
+ MINFO("bootstrap::file_info size: " << buflen_file_info);
if (buflen_file_info > sizeof(buf1))
throw std::runtime_error("Error: bootstrap::file_info size exceeds buffer size");
@@ -363,9 +365,9 @@ uint64_t BootstrapFile::seek_to_first_chunk(std::ifstream& import_file)
bootstrap::file_info bfi;
if (! ::serialization::parse_binary(str1, bfi))
throw std::runtime_error("Error in deserialization of bootstrap::file_info");
- LOG_PRINT_L0("bootstrap file v" << unsigned(bfi.major_version) << "." << unsigned(bfi.minor_version));
- LOG_PRINT_L0("bootstrap magic size: " << sizeof(file_magic));
- LOG_PRINT_L0("bootstrap header size: " << bfi.header_size);
+ MINFO("bootstrap file v" << unsigned(bfi.major_version) << "." << unsigned(bfi.minor_version));
+ MINFO("bootstrap magic size: " << sizeof(file_magic));
+ MINFO("bootstrap header size: " << bfi.header_size);
uint64_t full_header_size = sizeof(file_magic) + bfi.header_size;
import_file.seekg(full_header_size);
@@ -379,7 +381,7 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
boost::system::error_code ec;
if (!boost::filesystem::exists(raw_file_path, ec))
{
- LOG_PRINT_L0("bootstrap file not found: " << raw_file_path);
+ MFATAL("bootstrap file not found: " << raw_file_path);
throw std::runtime_error("Aborting");
}
std::ifstream import_file;
@@ -388,14 +390,14 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
uint64_t h = 0;
if (import_file.fail())
{
- LOG_PRINT_L0("import_file.open() fail");
+ MFATAL("import_file.open() fail");
throw std::runtime_error("Aborting");
}
uint64_t full_header_size; // 4 byte magic + length of header structures
full_header_size = seek_to_first_chunk(import_file);
- LOG_PRINT_L0("Scanning blockchain from bootstrap file...");
+ MINFO("Scanning blockchain from bootstrap file...");
block b;
bool quit = false;
uint64_t bytes_read = 0;
@@ -409,7 +411,7 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
import_file.read(buf1, sizeof(chunk_size));
if (!import_file) {
std::cout << refresh_string;
- LOG_PRINT_L1("End of file reached");
+ MDEBUG("End of file reached");
quit = true;
break;
}
@@ -425,38 +427,38 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
str1.assign(buf1, sizeof(chunk_size));
if (! ::serialization::parse_binary(str1, chunk_size))
throw std::runtime_error("Error in deserialization of chunk_size");
- LOG_PRINT_L3("chunk_size: " << chunk_size);
+ MDEBUG("chunk_size: " << chunk_size);
if (chunk_size > BUFFER_SIZE)
{
std::cout << refresh_string;
- LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE
+ MWARNING("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE
<< " height: " << h-1);
throw std::runtime_error("Aborting: chunk size exceeds buffer size");
}
if (chunk_size > 100000)
{
std::cout << refresh_string;
- LOG_PRINT_L0("NOTE: chunk_size " << chunk_size << " > 100000" << " height: "
+ MDEBUG("NOTE: chunk_size " << chunk_size << " > 100000" << " height: "
<< h-1);
}
else if (chunk_size <= 0) {
std::cout << refresh_string;
- LOG_PRINT_L0("ERROR: chunk_size " << chunk_size << " <= 0" << " height: " << h-1);
+ MDEBUG("ERROR: chunk_size " << chunk_size << " <= 0" << " height: " << h-1);
throw std::runtime_error("Aborting");
}
// skip to next expected block size value
import_file.seekg(chunk_size, std::ios_base::cur);
if (! import_file) {
std::cout << refresh_string;
- LOG_PRINT_L0("ERROR: unexpected end of file: bytes read before error: "
+ MFATAL("ERROR: unexpected end of file: bytes read before error: "
<< import_file.gcount() << " of chunk_size " << chunk_size);
throw std::runtime_error("Aborting");
}
bytes_read += chunk_size;
// std::cout << refresh_string;
- LOG_PRINT_L3("Number bytes scanned: " << bytes_read);
+ MINFO("Number bytes scanned: " << bytes_read);
}
import_file.close();