aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp43
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp30
-rw-r--r--src/common/command_line.cpp5
-rw-r--r--src/common/command_line.h1
-rw-r--r--src/cryptonote_core/blockchain.cpp15
-rw-r--r--src/cryptonote_core/blockchain.h2
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp11
-rw-r--r--src/cryptonote_core/cryptonote_core.h1
-rw-r--r--src/cryptonote_core/tx_pool.cpp2
9 files changed, 95 insertions, 15 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index ce355ccde..07cb622a7 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -759,7 +759,7 @@ void BlockchainBDB::open(const std::string& filename, const int db_flags)
}
else
{
- if (!boost::filesystem::create_directory(direc))
+ if (!boost::filesystem::create_directories(direc))
throw0(DB_OPEN_FAILURE(std::string("Failed to create directory ").append(filename).c_str()));
}
@@ -1042,7 +1042,46 @@ void BlockchainBDB::sync()
void BlockchainBDB::reset()
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
- // TODO: this
+ check_open();
+
+ bdb_txn_safe txn;
+ if (m_env->txn_begin(NULL, txn, 0))
+ throw0(DB_ERROR("Failed to create a transaction for the db"));
+ m_write_txn = &txn;
+ try
+ {
+ uint32_t count;
+
+ m_blocks->truncate(*m_write_txn, &count, 0);
+ m_block_heights->truncate(*m_write_txn, &count, 0);
+ m_block_hashes->truncate(*m_write_txn, &count, 0);
+ m_block_timestamps->truncate(*m_write_txn, &count, 0);
+ m_block_sizes->truncate(*m_write_txn, &count, 0);
+ m_block_diffs->truncate(*m_write_txn, &count, 0);
+ m_block_coins->truncate(*m_write_txn, &count, 0);
+
+ m_txs->truncate(*m_write_txn, &count, 0);
+ m_tx_unlocks->truncate(*m_write_txn, &count, 0);
+ m_tx_heights->truncate(*m_write_txn, &count, 0);
+ m_tx_outputs->truncate(*m_write_txn, &count, 0);
+
+ m_output_txs->truncate(*m_write_txn, &count, 0);
+ m_output_indices->truncate(*m_write_txn, &count, 0);
+ m_output_amounts->truncate(*m_write_txn, &count, 0);
+ m_output_keys->truncate(*m_write_txn, &count, 0);
+
+ m_spent_keys->truncate(*m_write_txn, &count, 0);
+
+ m_hf_starting_heights->truncate(*m_write_txn, &count, 0);
+ m_hf_versions->truncate(*m_write_txn, &count, 0);
+
+ m_properties->truncate(*m_write_txn, &count, 0);
+ }
+ catch (const std::exception& e)
+ {
+ throw0(DB_ERROR(std::string("Failed to reset database: ").append(e.what()).c_str()));
+ }
+ m_write_txn = NULL;
}
std::vector<std::string> BlockchainBDB::get_filenames() const
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index fabe01d7f..9be21b039 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -943,7 +943,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
}
else
{
- if (!boost::filesystem::create_directory(direc))
+ if (!boost::filesystem::create_directories(direc))
throw0(DB_OPEN_FAILURE(std::string("Failed to create directory ").append(filename).c_str()));
}
@@ -1159,7 +1159,33 @@ void BlockchainLMDB::sync()
void BlockchainLMDB::reset()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- // TODO: this
+ check_open();
+
+ mdb_txn_safe txn;
+ if (mdb_txn_begin(m_env, NULL, 0, txn))
+ throw0(DB_ERROR("Failed to create a transaction for the db"));
+ mdb_drop(txn, m_blocks, 0);
+ mdb_drop(txn, m_block_timestamps, 0);
+ mdb_drop(txn, m_block_heights, 0);
+ mdb_drop(txn, m_block_hashes, 0);
+ mdb_drop(txn, m_block_sizes, 0);
+ mdb_drop(txn, m_block_diffs, 0);
+ mdb_drop(txn, m_block_coins, 0);
+ mdb_drop(txn, m_txs, 0);
+ mdb_drop(txn, m_tx_unlocks, 0);
+ mdb_drop(txn, m_tx_heights, 0);
+ mdb_drop(txn, m_tx_outputs, 0);
+ mdb_drop(txn, m_output_txs, 0);
+ mdb_drop(txn, m_output_indices, 0);
+ mdb_drop(txn, m_output_amounts, 0);
+ mdb_drop(txn, m_output_keys, 0);
+ mdb_drop(txn, m_spent_keys, 0);
+ mdb_drop(txn, m_hf_starting_heights, 0);
+ mdb_drop(txn, m_hf_versions, 0);
+ mdb_drop(txn, m_properties, 0);
+ txn.commit();
+ m_height = 0;
+ m_num_outputs = 0;
}
std::vector<std::string> BlockchainLMDB::get_filenames() const
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp
index 925b62a54..5e5a9ff44 100644
--- a/src/common/command_line.cpp
+++ b/src/common/command_line.cpp
@@ -91,4 +91,9 @@ namespace command_line
, "Show time-stats when processing blocks/txs and disk synchronization."
, 0
};
+ const command_line::arg_descriptor<bool> arg_fakechain = {
+ "fakechain"
+ , "Use a fake chain for testing purposes."
+ , false
+ };
}
diff --git a/src/common/command_line.h b/src/common/command_line.h
index ffac71704..8955b826e 100644
--- a/src/common/command_line.h
+++ b/src/common/command_line.h
@@ -215,4 +215,5 @@ namespace command_line
extern const arg_descriptor<uint64_t> arg_prep_blocks_threads;
extern const arg_descriptor<uint64_t> arg_db_auto_remove_logs;
extern const arg_descriptor<uint64_t> arg_show_time_stats;
+ extern const arg_descriptor<bool> arg_fakechain;
}
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 2d71b61a1..5823c86f7 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -236,7 +236,7 @@ uint64_t Blockchain::get_current_blockchain_height() const
//------------------------------------------------------------------
//FIXME: possibly move this into the constructor, to avoid accidentally
// dereferencing a null BlockchainDB pointer
-bool Blockchain::init(BlockchainDB* db, const bool testnet)
+bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain)
{
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock);
@@ -293,8 +293,11 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet)
{
}
- // ensure we fixup anything we found and fix in the future
- m_db->fixup();
+ if (!fakechain)
+ {
+ // ensure we fixup anything we found and fix in the future
+ m_db->fixup();
+ }
// check how far behind we are
uint64_t top_block_timestamp = m_db->get_top_block_timestamp();
@@ -311,7 +314,7 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet)
m_async_pool.create_thread(boost::bind(&boost::asio::io_service::run, &m_async_service));
#if defined(PER_BLOCK_CHECKPOINT)
- if (m_fast_sync && get_blocks_dat_start(testnet) != nullptr)
+ if (!fakechain && m_fast_sync && get_blocks_dat_start(testnet) != nullptr)
{
if (get_blocks_dat_size(testnet) > 4)
{
@@ -1361,7 +1364,7 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block
if(start_offset > m_db->height())
return false;
- for(size_t i = start_offset; i < start_offset + count && i <= m_db->height();i++)
+ for(size_t i = start_offset; i < start_offset + count && i < m_db->height();i++)
{
blocks.push_back(m_db->get_block_from_height(i));
}
@@ -2631,7 +2634,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
// do this after updating the hard fork state since the size limit may change due to fork
update_next_cumulative_size_limit();
- LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms");
+ LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height-1 << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms");
if(m_show_time_stats)
{
LOG_PRINT_L0("Height: " << new_height << " blob: " << coinbase_blob_size << " cumm: "
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index c83314634..f0b03ab0a 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -91,7 +91,7 @@ namespace cryptonote
Blockchain(tx_memory_pool& tx_pool);
- bool init(BlockchainDB* db, const bool testnet = false);
+ bool init(BlockchainDB* db, const bool testnet = false, const bool fakechain = false);
bool deinit();
void set_checkpoints(checkpoints&& chk_pts) { m_checkpoints = chk_pts; }
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 2f21bd4f1..960c8eff8 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -97,7 +97,7 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool core::update_checkpoints()
{
- if (m_testnet) return true;
+ if (m_testnet || m_fakechain) return true;
if (m_checkpoints_updating.test_and_set()) return true;
@@ -145,18 +145,20 @@ namespace cryptonote
command_line::add_arg(desc, command_line::arg_db_sync_mode);
command_line::add_arg(desc, command_line::arg_show_time_stats);
command_line::add_arg(desc, command_line::arg_db_auto_remove_logs);
+ command_line::add_arg(desc, command_line::arg_fakechain);
}
//-----------------------------------------------------------------------------------------------
bool core::handle_command_line(const boost::program_options::variables_map& vm)
{
m_testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
+ m_fakechain = command_line::get_arg(vm, command_line::arg_fakechain);
auto data_dir_arg = m_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
m_config_folder = command_line::get_arg(vm, data_dir_arg);
auto data_dir = boost::filesystem::path(m_config_folder);
- if (!m_testnet)
+ if (!m_testnet && !m_fakechain)
{
cryptonote::checkpoints checkpoints;
if (!cryptonote::create_checkpoints(checkpoints))
@@ -257,6 +259,9 @@ namespace cryptonote
boost::filesystem::path folder(m_config_folder);
+ if (m_fakechain)
+ folder /= "fake";
+
folder /= db->get_db_name();
LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ...");
@@ -337,7 +342,7 @@ namespace cryptonote
m_blockchain_storage.set_user_options(blocks_threads,
blocks_per_sync, sync_mode, fast_sync);
- r = m_blockchain_storage.init(db, m_testnet);
+ r = m_blockchain_storage.init(db, m_testnet, m_fakechain);
bool show_time_stats = command_line::get_arg(vm, command_line::arg_show_time_stats) != 0;
m_blockchain_storage.set_show_time_stats(show_time_stats);
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index e7a6c4154..5d665cb98 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -199,6 +199,7 @@ namespace cryptonote
uint64_t m_target_blockchain_height;
bool m_testnet;
+ bool m_fakechain;
std::string m_checkpoints_path;
time_t m_last_dns_checkpoints_update;
time_t m_last_json_checkpoints_update;
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index defbeb3b3..e2dcd35f5 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -113,7 +113,7 @@ namespace cryptonote
needed_fee *= FEE_PER_KB;
if (!kept_by_block && fee < needed_fee /*&& fee < MINING_ALLOWED_LEGACY_FEE*/)
{
- LOG_PRINT_L1("transaction fee is not enough: " << print_money(fee) << ", minumim fee: " << print_money(needed_fee));
+ LOG_PRINT_L1("transaction fee is not enough: " << print_money(fee) << ", minimum fee: " << print_money(needed_fee));
tvc.m_verifivation_failed = true;
return false;
}