1
0
Fork 0
forked from lthn/blockchain

Merge remote-tracking branch 'origin/master' into frontend

This commit is contained in:
wildkif 2019-01-29 17:49:18 +02:00
commit 32e2555b43
10 changed files with 116 additions and 23 deletions

View file

@ -111,6 +111,7 @@ namespace misc_utils
#if defined(__GNUC__)
#include <execinfo.h>
#include <boost/core/demangle.hpp>
#endif
inline std::string print_trace()
{
@ -125,9 +126,9 @@ namespace misc_utils
stack_depth = backtrace(stack_addrs, max_depth);
stack_strings = backtrace_symbols(stack_addrs, stack_depth);
for (size_t i = 1; i < stack_depth; i++) {
ss << stack_strings[i] << std::endl;
for (size_t i = 1; i < stack_depth; i++)
{
ss << boost::core::demangle(stack_strings[i]) << std::endl;
}
free(stack_strings); // malloc()ed by backtrace_symbols
#endif

View file

@ -104,7 +104,7 @@ struct response_schema
"\"time_started\": " << ce.time_started << ", "
"\"last_recv\": " << ce.last_recv << ", "
"\"last_send\": " << ce.last_send << ", "
"\"version\": " << ce.version << ", "
"\"version\": \"" << ce.version << "\", "
"\"is_income\": " << ce.is_income << "}";
if(rs.ns_rsp.v.connections_list.size()-1 != i)
ss << ",";

View file

@ -25,7 +25,7 @@ namespace bc_services
, m_core_runtime_config(currency::get_default_core_runtime_config())
, m_last_seen_block_id(currency::null_hash)
, m_deinitialized(false)
, m_disabled(false)
, m_disabled(true)
{}
//------------------------------------------------------------------

View file

@ -99,7 +99,8 @@ blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) :m_db(std::share
m_current_fee_median(0),
m_current_fee_median_effective_index(0),
m_is_reorganize_in_process(false),
m_deinit_is_done(false)
m_deinit_is_done(false),
m_current_scratchpad_seed(currency::null_hash)
{
@ -289,6 +290,8 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro
initialize_db_solo_options_values();
get_seed_for_scratchpad(m_db_blocks.size(), m_current_scratchpad_seed);
m_services_mgr.init(config_folder, vm);

View file

@ -27,19 +27,18 @@ namespace currency
}
crypto::hash scratchpad_keeper::get_pow_hash(const blobdata& bd, uint64_t height, const crypto::hash& scr_seed)
{
CRITICAL_REGION_LOCAL(m_lock);
crypto::hash res_hash = null_hash;
if (scr_seed != m_seed || get_scratchpad_size_for_height(height) != this->size())
{
bool r = generate(scr_seed, height);
CHECK_AND_ASSERT_THROW_MES(r, "Unable to generate scratchpad");
}
CRITICAL_REGION_BEGIN(m_lock);
CHECK_AND_ASSERT_THROW_MES(get_scratchpad_size_for_height(height) == this->size(), "Fatal error on hash calculation: scratchpad_size=" << m_scratchpad.size() << " at height=" << height << ", scr_seed=" << scr_seed << ", m_seed=" << m_seed);
CHECK_AND_ASSERT_THROW_MES(scr_seed == m_seed, "Fatal error on hash calculation: scratchpad_seed missmatch scr_seed=" << scr_seed << ", m_seed=" << m_seed);
bool res = get_wild_keccak2(bd, res_hash, m_scratchpad);
CHECK_AND_ASSERT_THROW_MES(res, "Fatal error on hash calculation: scratchpad_size=" << m_scratchpad.size());
CRITICAL_REGION_END();
return res_hash;
}
crypto::hash scratchpad_keeper::get_pow_hash(const block& b, const crypto::hash& scr_seed)

View file

@ -145,8 +145,6 @@ namespace currency
<< (0 <= diff ? std::string("behind") : std::string("ahead"))
<< "] " << ENDL << "SYNCHRONIZATION started", (is_inital ? LOG_LEVEL_0 : LOG_LEVEL_1), (is_inital ? epee::log_space::console_color_yellow : epee::log_space::console_color_magenta));
LOG_PRINT_L1("Remote top block height: " << hshd.current_height << ", id: " << hshd.top_id);
// m_synchronized = false;
LOG_PRINT_MAGENTA("Synchronized set to FALSE (process_payload_sync_data)", LOG_LEVEL_0);
/*check if current height is in remote's checkpoints zone*/
if(hshd.last_checkpoint_height
&& m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() < hshd.last_checkpoint_height
@ -422,7 +420,7 @@ namespace currency
total_blocks_parsing_time += block_parsing_time;
//to avoid concurrency in core between connections, suspend connections which delivered block later then first one
if(count == 2)
if(count = 2)
{
if(m_core.have_block(get_block_hash(b)))
{
@ -467,7 +465,7 @@ namespace currency
m_core.pause_mine();
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
boost::bind(&t_core::resume_mine, &m_core));
size_t count = 0;
for (const block_complete_entry& block_entry : arg.blocks)
{
CHECK_STOP_FLAG__DROP_AND_RETURN_IF_SET(1, "Blocks processing interrupted, connection dropped");
@ -495,6 +493,14 @@ namespace currency
block_verification_context bvc = boost::value_initialized<block_verification_context>();
m_core.handle_incoming_block(block_entry.block, bvc, false);
if (count > 2 && bvc.m_already_exists)
{
context.m_state = currency_connection_context::state_idle;
context.m_priv.m_needed_objects.clear();
context.m_priv.m_requested_objects.clear();
LOG_PRINT_L1("Connection set to idle state.");
return 1;
}
if(bvc.m_verification_failed)
{
@ -513,6 +519,7 @@ namespace currency
TIME_MEASURE_FINISH(block_process_time);
LOG_PRINT_L2("Block process time: " << block_process_time + transactions_process_time << "(" << transactions_process_time << "/" << block_process_time << ")ms");
++count;
}
}
uint64_t current_size = m_core.get_blockchain_storage().get_current_blockchain_size();

View file

@ -408,6 +408,31 @@ private:
return true;
}
//--------------------------------------------------------------------------------
bool print_block_info_by_hash(const std::string& arg)
{
crypto::hash block_hash;
if (!parse_hash256(arg, block_hash))
{
return false;
}
currency::block_rpc_extended_info bei = AUTO_VAL_INIT(bei);
bool r = m_srv.get_payload_object().get_core().get_blockchain_storage().get_main_block_rpc_details(block_hash, bei);
if (r)
{
// currency::block& block = bei.bl;
LOG_PRINT_GREEN("------------------ block_id: " << bei.id << " ------------------" << ENDL << epee::serialization::store_t_to_json(bei) , LOG_LEVEL_0);
}
else
{
LOG_PRINT_GREEN("block wasn't found: " << arg, LOG_LEVEL_0);
return false;
}
return true;
}
//--------------------------------------------------------------------------------
bool print_block_by_hash(const std::string& arg)
{
crypto::hash block_hash;
@ -473,11 +498,11 @@ private:
try
{
uint64_t height = boost::lexical_cast<uint64_t>(arg);
print_block_by_height(height);
print_block_info_by_height(height);
}
catch (boost::bad_lexical_cast&)
{
print_block_by_hash(arg);
print_block_info_by_hash(arg);
}
return true;

View file

@ -2,6 +2,6 @@
#define BUILD_COMMIT_ID "@VERSION@"
#define PROJECT_VERSION "1.0"
#define PROJECT_VERSION_BUILD_NO 6
#define PROJECT_VERSION_BUILD_NO 8
#define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO)
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"

View file

@ -14,19 +14,18 @@ using namespace epee;
#include "currency_core/blockchain_storage.h"
void run_difficulty_analysis(const std::string& path)
bool parse_file(const std::string& path, std::vector<std::vector<uint64_t>>& blocks, uint64_t reserve_size)
{
std::ifstream fstr(path);
if (!fstr.good())
{
LOG_ERROR("unable to open " << path);
return;
return false;
}
LOG_PRINT_L0("Loading array...");
std::string line;
std::vector<std::vector<uint64_t>> blocks;
blocks.reserve(140000);
blocks.reserve(reserve_size);
while (std::getline(fstr, line))
{
std::vector<uint64_t> array_num;
@ -34,10 +33,69 @@ void run_difficulty_analysis(const std::string& path)
std::transform(tok.begin(), tok.end(), std::back_inserter(array_num),
&boost::lexical_cast<uint64_t, std::string>);
array_num.push_back(0); //reserve space for hashrate value
blocks.push_back(array_num);
}
LOG_PRINT_L0("Loaded " << blocks.size() << " lines");
return true;
}
void run_difficulty_analysis(const std::string& path)
{
//hash_rate_analysis(path);
run_emulation(path);
}
void run_emulation(const std::string& path)
{
//0 - timestamp, 1 - difficulty/120, 2 net hashrate (h/s)
std::vector<std::vector<uint64_t>> blocks;
parse_file(path, blocks, 500);
}
void hash_rate_analysis(const std::string& path)
{
//0 = height, 1 - timestamp, 2 - difficulty, 3 cumulative_diff
std::vector<std::vector<uint64_t>> blocks;
parse_file(path, blocks, 140000);
LOG_PRINT_L0("Calculating hashrate...");
std::stringstream ss;
uint64_t curren_hashrate = 0;
uint64_t step = 10;
uint64_t hash_rate_range = 10;
uint64_t second_windowf_or_hashrate = 20*60;
for (size_t i = hash_rate_range; i != blocks.size(); i++)
{
if (i % step == 0)
{
//curren_hashrate = (blocks[i][3] - blocks[i - hash_rate_range][3])/(blocks[i][1] - blocks[i- hash_rate_range][1]);
// uint64_t cumul_dif = 0;
// for (size_t j = i; j != 0 && blocks[j][1] > blocks[i][1]- second_windowf_or_hashrate; j--)
// {
// cumul_dif += blocks[j][2];
// }
// curren_hashrate = cumul_dif / second_windowf_or_hashrate;
curren_hashrate = (blocks[i][3] - blocks[i - hash_rate_range][3]) / (blocks[i][1] - blocks[i - hash_rate_range][1]);
//std::setw(45) << epee::misc_utils::get_time_str(blocks[i][1])
ss << std::left << std::setw(10) << i << std::left << std::setw(15) << blocks[i][1] << std::left << std::setw(15) << blocks[i][2]/120 << std::left << std::setw(20) << curren_hashrate << ENDL;
}
//blocks[i][4] = curren_hashrate;
//ss << std::left << std::setw(10) << i << std::left << std::setw(15) << blocks[i][2] << std::left << std::setw(20) << blocks[i][4] << ENDL;
}
std::string res_path = path + "hashrate.txt";
file_io_utils::save_string_to_file(res_path, ss.str());
LOG_PRINT_L0("Done, saved to file " << res_path);
return;
}

View file

@ -1,11 +1,11 @@
{
"maj":0,
"min":3,
"maj":1,
"min":0,
"rev":0,
"build":1663,
"build":8,
"cs":[
{
"build":1662,
"build":7,
"mode":3
}
]