Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sowle committed Jul 25, 2019
2 parents f494945 + 471617e commit c635502
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 105 deletions.
2 changes: 1 addition & 1 deletion contrib/epee/include/console_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ namespace epee
std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
continue;
}
log_space::get_set_log_detalisation_level(true, n);
log_space::get_set_log_detalization_level(true, n);
std::cout << "New log level set " << n;
LOG_PRINT_L2("New log level set " << n);
}else if (command.empty())
Expand Down
42 changes: 21 additions & 21 deletions contrib/epee/include/misc_log_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ namespace log_space
/************************************************************************/
/* */
/************************************************************************/
inline int get_set_log_detalisation_level(bool is_need_set = false, int log_level_to_set = LOG_LEVEL_1);
inline int get_set_log_detalization_level(bool is_need_set = false, int log_level_to_set = LOG_LEVEL_1);
inline int get_set_time_level(bool is_need_set = false, int time_log_level = LOG_LEVEL_0);
inline bool get_set_need_thread_id(bool is_need_set = false, bool is_need_val = false);
inline bool get_set_need_proc_name(bool is_need_set = false, bool is_need_val = false);
Expand Down Expand Up @@ -936,7 +936,7 @@ namespace log_space
init_default_loggers();

std::stringstream ss;
ss << get_time_string() << " Init logging. Level=" << get_set_log_detalisation_level()
ss << get_time_string() << " Init logging. Level=" << get_set_log_detalization_level()
<< "Default log path=" << m_default_log_folder << std::endl;
this->do_log_message(ss.str(), console_color_white, LOG_LEVEL_0);
return true;
Expand Down Expand Up @@ -980,10 +980,10 @@ namespace log_space
public:
friend class initializer<log_singletone>;
friend class logger;
static int get_log_detalisation_level()
static int get_log_detalization_level()
{
get_or_create_instance();//to initialize logger, if it not initialized
return get_set_log_detalisation_level();
return get_set_log_detalization_level();
}

//get_enabled_channels not thread-safe, at the moment leave it like this because it's configured in main, before other threads started
Expand Down Expand Up @@ -1174,15 +1174,15 @@ namespace log_space
}
PUSH_WARNINGS
DISABLE_GCC_WARNING(maybe-uninitialized)
static int get_set_log_detalisation_level(bool is_need_set = false, int log_level_to_set = LOG_LEVEL_1)
static int get_set_log_detalization_level(bool is_need_set = false, int log_level_to_set = LOG_LEVEL_1)
{

static int log_detalisation_level = LOG_LEVEL_1;
static int log_detalization_level = LOG_LEVEL_1;
if (is_need_set)
{
log_detalisation_level = log_level_to_set;
log_detalization_level = log_level_to_set;
}
return log_detalisation_level;
return log_detalization_level;
}
POP_WARNINGS
static int get_set_time_level(bool is_need_set = false, int time_log_level = LOG_LEVEL_0)
Expand Down Expand Up @@ -1289,7 +1289,7 @@ POP_WARNINGS
{
std::stringstream str_prefix;
//write time entry
if ( get_set_time_level() <= get_set_log_detalisation_level() )
if ( get_set_time_level() <= get_set_log_detalization_level() )
str_prefix << get_day_time_string() << " ";

//write process info
Expand All @@ -1300,10 +1300,10 @@ POP_WARNINGS
plogger = new logger();
}

//if ( get_set_need_proc_name() && get_set_process_level() <= get_set_log_detalisation_level() )
//if ( get_set_need_proc_name() && get_set_process_level() <= get_set_log_detalization_level() )
// str_prefix << "[" << plogger->m_process_name << " (id=" << GetCurrentProcessId() << ")] ";
//#ifdef _MSC_VER_EX
if ( get_set_need_thread_id() /*&& get_set_tid_level() <= get_set_log_detalisation_level()*/ )
if ( get_set_need_thread_id() /*&& get_set_tid_level() <= get_set_log_detalization_level()*/ )
str_prefix << "[tid:" << misc_utils::get_thread_string_id() << "] ";
//#endif

Expand Down Expand Up @@ -1413,7 +1413,7 @@ POP_WARNINGS
int lasterr=::GetLastError();
#endif
m_plog_name = plog_name;
if ( dlevel <= log_singletone::get_log_detalisation_level() )
if ( dlevel <= log_singletone::get_log_detalization_level() )
{
m_name = name;
std::stringstream ss;
Expand All @@ -1431,7 +1431,7 @@ POP_WARNINGS
int lasterr=::GetLastError();
#endif

if (m_level <= log_singletone::get_log_detalisation_level() )
if (m_level <= log_singletone::get_log_detalization_level() )
{
std::stringstream ss;
ss << log_space::log_singletone::get_prefix_entry() << "<<--" << m_name << std::endl;
Expand All @@ -1447,9 +1447,9 @@ POP_WARNINGS
{
return log_singletone::get_set_time_level(is_need_set, time_log_level);
}
inline int get_set_log_detalisation_level(bool is_need_set, int log_level_to_set)
inline int get_set_log_detalization_level(bool is_need_set, int log_level_to_set)
{
return log_singletone::get_set_log_detalisation_level(is_need_set, log_level_to_set);
return log_singletone::get_set_log_detalization_level(is_need_set, log_level_to_set);
}
inline std::string get_prefix_entry()
{
Expand Down Expand Up @@ -1518,22 +1518,22 @@ POP_WARNINGS

#if defined(ENABLE_LOGGING_INTERNAL)

#define LOG_PRINT_CHANNEL_NO_PREFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
#define LOG_PRINT_CHANNEL_NO_PREFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalization_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str() , y, epee::log_space::console_color_default, false, log_name);}}

#define LOG_PRINT_CHANNEL_NO_PREFIX_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
#define LOG_PRINT_CHANNEL_NO_PREFIX_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalization_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}}

#define LOG_PRINT_CHANNEL_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
#define LOG_PRINT_CHANNEL_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalization_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}}

#define LOG_PRINT_CHANNEL2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
#define LOG_PRINT_CHANNEL2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalization_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}}

#define LOG_PRINT_CHANNEL_COLOR2(log_channel, log_name, x, y, color) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
#define LOG_PRINT_CHANNEL_COLOR2(log_channel, log_name, x, y, color) {if ( y <= epee::log_space::log_singletone::get_log_detalization_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name);}}

#define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
#define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalization_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);}}


Expand Down
2 changes: 1 addition & 1 deletion src/connectivity_tool/conn_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ bool generate_and_print_keys()
int main(int argc, char* argv[])
{
string_tools::set_module_name_and_folder(argv[0]);
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
log_space::get_set_log_detalization_level(true, LOG_LEVEL_0);

// Declare the supported options.
po::options_description desc_general("General options");
Expand Down
23 changes: 21 additions & 2 deletions src/currency_core/blockchain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) : m_lmdb_adapter
m_is_in_checkpoint_zone(false),
m_donations_account(AUTO_VAL_INIT(m_donations_account)),
m_royalty_account(AUTO_VAL_INIT(m_royalty_account)),
m_is_blockchain_storing(false),
m_locker_file(0),
m_exclusive_batch_active(false)
m_exclusive_batch_active(false),
m_last_median_ts_checked_top_block_id(null_hash),
m_last_median_ts_checked(0)
{
bool r = get_donation_accounts(m_donations_account, m_royalty_account);
CHECK_AND_ASSERT_THROW_MES(r, "failed to load donation accounts");
Expand Down Expand Up @@ -2636,6 +2637,9 @@ bool blockchain_storage::check_block_timestamp(std::vector<uint64_t> timestamps,
return false;
}

m_last_median_ts_checked_top_block_id = get_block_hash(b);
m_last_median_ts_checked = median_ts;

return true;
}

Expand Down Expand Up @@ -3173,5 +3177,20 @@ bool blockchain_storage::get_global_index_details(const COMMAND_RPC_GET_TX_GLOBA
}
}
//------------------------------------------------------------------
// returns median ts of last BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW blocks
uint64_t blockchain_storage::get_blocks_ts_median()
{
CRITICAL_REGION_LOCAL(m_blockchain_lock);

if (get_top_block_id() != m_last_median_ts_checked_top_block_id)
{
auto val_ptr = m_db_blocks.back();
CHECK_AND_ASSERT_MES(val_ptr.get(), false, "m_db_blocks.back() returned null");
check_block_timestamp_main(val_ptr->bl);
CHECK_AND_ASSERT_MES(m_last_median_ts_checked_top_block_id == get_block_hash(val_ptr->bl), false, "check_block_timestamp_main did not update m_last_median_ts_checked_top_block_id");
}

return m_last_median_ts_checked;
}
//------------------------------------------------------------------
//------------------------------------------------------------------
6 changes: 4 additions & 2 deletions src/currency_core/blockchain_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ namespace currency
bool update_spent_tx_flags_for_input(uint64_t amount, uint64_t global_index, bool spent);
bool update_spent_tx_flags_for_input(const crypto::hash& tx_id, size_t n, bool spent);
bool clear();
bool is_storing_blockchain(){ return m_is_blockchain_storing; }
wide_difficulty_type block_difficulty(size_t i);
bool copy_scratchpad(std::vector<crypto::hash>& dst);//TODO: not the best way, add later update method instead of full copy
bool copy_scratchpad_as_blob(std::string& dst);
Expand All @@ -162,6 +161,7 @@ namespace currency
bool get_alt_block_rpc_details(const crypto::hash& id, block_rpc_extended_info& bei) const;
bool get_alt_block_rpc_details(const block_extended_info& bei_core, const crypto::hash& id, block_rpc_extended_info& bei) const;
bool get_global_index_details(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES_BY_AMOUNT::request& req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES_BY_AMOUNT::response & resp) const;
uint64_t get_blocks_ts_median(); // returns median of last BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW blocks


std::string print_key_image_details(const crypto::key_image& ki, bool& found);
Expand Down Expand Up @@ -261,7 +261,6 @@ namespace currency
blocks_ext_by_hash m_alternative_chains; // crypto::hash -> block_extended_info

std::atomic<bool> m_is_in_checkpoint_zone;
std::atomic<bool> m_is_blockchain_storing;

std::string m_config_folder;
account_keys m_donations_account;
Expand All @@ -271,6 +270,9 @@ namespace currency

epee::file_io_utils::native_filesystem_handle m_locker_file;

crypto::hash m_last_median_ts_checked_top_block_id;
uint64_t m_last_median_ts_checked;

// mutable members
mutable critical_section m_blockchain_lock; // TODO: add here reader/writer lock
mutable critical_section m_exclusive_batch_lock; // TODO: add here reader/writer lock
Expand Down
32 changes: 27 additions & 5 deletions src/currency_core/currency_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ namespace currency
{
if (user_data[i] != TX_USER_DATA_TAG_SWAP_ADDRESS)
{
CHECK_AND_ASSERT_MES(user_data.size() - 1 - i >= 1, false, "not enough data for TX_USER_DATA_TAG_SWAP_ADDRESS: " << user_data.size() - 1 - i);
CHECK_AND_ASSERT_MES(user_data.size() - 1 - i >= 1, false, "not enough data for user data tag " << user_data[i] << " : " << user_data.size() - 1 - i);
i += user_data[i + 1] + 2;
}
else
Expand Down Expand Up @@ -1645,16 +1645,38 @@ bool encrypt_user_data_with_tx_secret_key(const crypto::secret_key& sk, uint8_t*
return true;
}
//---------------------------------------------------------------
bool is_swap_tx(const currency::transaction& tx)
{
static std::vector<tx_destination_entry> empty_destinations;
return is_swap_tx(tx, empty_destinations);
}
//---------------------------------------------------------------
bool is_swap_tx(const currency::transaction& tx, const std::vector<tx_destination_entry>& destinations)
{
// a tx is a swap tx if it has at least one swap destination address (null_pkey output) AND swap info in extra.userdata
bool has_swap_destinations = false;
for (auto& d : destinations)

if (!destinations.empty())
{
for (auto& d : destinations)
{
if (d.addr.is_swap_address)
{
has_swap_destinations = true;
break;
}
}
}
else
{
if (d.addr.is_swap_address)
// use tx outputs if destinations was not provided
for (auto& o : tx.vout)
{
has_swap_destinations = true;
break;
if (o.target.type() == typeid(txout_to_key) && boost::get<txout_to_key>(o.target).key == null_pkey)
{
has_swap_destinations = true;
break;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/currency_core/currency_format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ namespace currency
bool get_swap_info_from_tx_extra(const transaction& tx, const crypto::secret_key& sk, account_public_address& addr);
bool get_swap_info_from_tx(const transaction& tx, const crypto::secret_key& sk, swap_transaction_info& swap_info);
bool encrypt_user_data_with_tx_secret_key(const crypto::secret_key& sk, std::vector<uint8_t>& extra);
bool is_swap_tx(const currency::transaction& tx);
bool is_swap_tx(const currency::transaction& tx, const std::vector<tx_destination_entry>& destinations);
bool encrypt_user_data_with_tx_secret_key(const crypto::secret_key& sk, std::vector<uint8_t>& extra);

Expand Down
29 changes: 23 additions & 6 deletions src/currency_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ namespace currency
//check key images for transaction if it is not kept by block
if(!kept_by_block)
{
if(have_tx_keyimges_as_spent(tx))
crypto::hash ki_tx = AUTO_VAL_INIT(ki_tx);
crypto::key_image ki = AUTO_VAL_INIT(ki);
if(have_tx_keyimges_as_spent(tx, ki_tx, ki))
{
LOG_ERROR("Transaction with id= "<< id << " used already spent key images");
LOG_ERROR("Transaction " << id << " uses already spent key image " << ki << " seen in tx " << ki_tx);
tvc.m_verifivation_failed = true;
return false;
}
Expand All @@ -81,7 +83,7 @@ namespace currency
return false;
}
}

crypto::hash max_used_block_id = null_hash;
uint64_t max_used_block_height = 0;
bool ch_inp_res = m_blockchain.check_tx_inputs(tx, max_used_block_height, max_used_block_id);
Expand Down Expand Up @@ -265,16 +267,22 @@ namespace currency
return false;
}
//---------------------------------------------------------------------------------
bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx) const
bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx, crypto::hash& ki_tx, crypto::key_image& ki) const
{
PROFILE_FUNC("tx_memory_pool::have_tx_keyimges_as_spent");
CRITICAL_REGION_LOCAL(m_transactions_lock);
BOOST_FOREACH(const auto& in, tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, true);//should never fail
if(have_tx_keyimg_as_spent(tokey_in.k_image))
auto it = m_spent_key_images.find(tokey_in.k_image);
if (it != m_spent_key_images.end())
{
if (it->second.size() > 0)
ki_tx = *(it->second.begin());
ki = tokey_in.k_image;
return true;
}
}
return false;
}
//---------------------------------------------------------------------------------
Expand Down Expand Up @@ -349,7 +357,7 @@ namespace currency
//if we here, transaction seems valid, but, anyway, check for key_images collisions with blockchain, just to be sure
if (m_blockchain.have_tx_keyimges_as_spent(txd.tx))
{
txd.decline_reason = "have_tx_keyimges_as_spent";
txd.decline_reason = "ki is spent in blockchain";
return false;
}
//transaction is ok.
Expand Down Expand Up @@ -500,6 +508,15 @@ namespace currency
bool res = tools::unserialize_obj_from_file(*this, state_file_path);
if (res)
{
if (epee::log_space::log_singletone::get_log_detalization_level() >= LOG_LEVEL_2)
{
std::stringstream ss;
ss << "tx pool loaded ok from " << state_file_path << ", loaded " << m_transactions.size() << " transactions:" << ENDL;
for (auto& tx : m_transactions)
ss << tx.first << " sz: " << std::setw(5) << tx.second.blob_size << " rcv: " << misc_utils::get_time_interval_string(time(nullptr) - tx.second.receive_time) << " ago" << ENDL;
LOG_PRINT_L2(ss.str());
}

// mem pool has just been successfully loaded from file
// delete pool file to avoid loading outdated data on the next load (in case a crash happen for ex.)
if (!boost::filesystem::remove_all(state_file_path))
Expand Down
2 changes: 1 addition & 1 deletion src/currency_core/tx_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace currency

bool have_tx(const crypto::hash &id) const;
bool have_tx_keyimg_as_spent(const crypto::key_image& key_im) const;
bool have_tx_keyimges_as_spent(const transaction& tx) const;
bool have_tx_keyimges_as_spent(const transaction& tx, crypto::hash& ki_tx, crypto::key_image& ki) const;

bool on_blockchain_inc(uint64_t new_block_height, const crypto::hash& top_block_id);
bool on_blockchain_dec(uint64_t new_block_height, const crypto::hash& top_block_id);
Expand Down
Loading

0 comments on commit c635502

Please sign in to comment.