Merge pull request #531

cbded43 core_tests: fix ring_signature_1 tests (moneromooo-monero)
c3d208f core_tests: bump default test fee to 0.02 monero (moneromooo-monero)
10da0a0 add a --fakechain argument for tests (moneromooo-monero)
eee44e6 unit_tests: fix block reward test using post hard fork settings (moneromooo-monero)
595893f blockchain: log block (not chain) height in "BLOCK SUCCESFULLY ADDED" (moneromooo-monero)
2369968 blockchain: fix off by one in get_blocks (moneromooo-monero)
8af913a db_lmdb: implement BlockchainLMDB::reset (moneromooo-monero)
4833f4f db_bdb: implement BlockchainBDB::reset (moneromooo-monero)
18bf06e tx_pool: fix "minumim" typo in message (moneromooo-monero)
44f1267 tests: fix a typo in test name (moneromooo-monero)
1494557 db_lmdb: create all needed directories, not just the leaf one (moneromooo-monero)
015b68a db_bdb: create all needed directories, not just the leaf one (moneromooo-monero)
f141869 tests: remove data-dir argument registration (moneromooo-monero)
This commit is contained in:
Riccardo Spagni
2015-12-13 22:14:50 +02:00
13 changed files with 124 additions and 41 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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
};
}

View File

@@ -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;
}

View File

@@ -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: "

View File

@@ -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; }

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
}