forked from lthn/blockchain
wallet2: advanced logging for difficult issues
This commit is contained in:
parent
aff66bf0a4
commit
5dd8f584cc
6 changed files with 29 additions and 11 deletions
|
|
@ -145,9 +145,10 @@ namespace currency
|
|||
//check key images for transaction if it is not kept by block
|
||||
if(!from_core && !kept_by_block)
|
||||
{
|
||||
if(have_tx_keyimges_as_spent(tx))
|
||||
crypto::key_image spent_ki = AUTO_VAL_INIT(spent_ki);
|
||||
if(have_tx_keyimges_as_spent(tx, &spent_ki))
|
||||
{
|
||||
LOG_ERROR("Transaction with id= "<< id << " used already spent key images");
|
||||
LOG_ERROR("Transaction " << id << " uses already spent key image " << spent_ki);
|
||||
tvc.m_verification_failed = true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -735,15 +736,19 @@ 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::key_image* p_spent_ki /* = nullptr */) const
|
||||
{
|
||||
for(const auto& in : tx.vin)
|
||||
{
|
||||
if (in.type() == typeid(txin_to_key))
|
||||
{
|
||||
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))
|
||||
return true;
|
||||
if (have_tx_keyimg_as_spent(tokey_in.k_image))
|
||||
{
|
||||
if (p_spent_ki)
|
||||
*p_spent_ki = tokey_in.k_image;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -761,8 +766,10 @@ namespace currency
|
|||
auto ki_entry_ptr = m_db_key_images_set.get(tokey_in.k_image);
|
||||
if (ki_entry_ptr.get())
|
||||
count = *ki_entry_ptr;
|
||||
uint64_t count_before = count;
|
||||
++count;
|
||||
m_db_key_images_set.set(tokey_in.k_image, count);
|
||||
LOG_PRINT_L2("tx pool: key image added: " << tokey_in.k_image << ", from tx " << get_transaction_hash(tx) << ", counter: " << count_before << " -> " << count);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -828,11 +835,13 @@ namespace currency
|
|||
continue;
|
||||
}
|
||||
count = *ki_entry_ptr;
|
||||
uint64_t count_before = count;
|
||||
--count;
|
||||
if (count)
|
||||
m_db_key_images_set.set(tokey_in.k_image, count);
|
||||
else
|
||||
m_db_key_images_set.erase(tokey_in.k_image);
|
||||
LOG_PRINT_L2("tx pool: key image removed: " << tokey_in.k_image << ", from tx " << get_transaction_hash(tx) << ", counter: " << count_before << " -> " << count);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -92,7 +92,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::key_image* p_spent_ki = nullptr) const;
|
||||
const performnce_data& get_performnce_data() const { return m_performance_data; }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1595,8 +1595,8 @@ std::string daemon_backend::get_wallet_log_prefix(size_t wallet_id) const
|
|||
CRITICAL_REGION_LOCAL(m_wallets_lock);
|
||||
auto it = m_wallets.find(wallet_id);
|
||||
if (it == m_wallets.end())
|
||||
return std::string("[W:???id=") + epee::string_tools::num_to_string_fast(wallet_id) + "]";
|
||||
return std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":???]";
|
||||
|
||||
return std::string("[W:") + it->second.w->get()->get_account().get_public_address_str().substr(0, 6) + "]";
|
||||
return std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":" + it->second.w->get()->get_account().get_public_address_str().substr(0, 6) + "]";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -571,7 +571,7 @@ bool MainWindow::update_wallet_status(const view::wallet_status_info& wsi)
|
|||
m_wallet_states->operator [](wsi.wallet_id) = wsi.wallet_state;
|
||||
std::string json_str;
|
||||
epee::serialization::store_t_to_json(wsi, json_str);
|
||||
LOG_PRINT_L0("SENDING SIGNAL -> [update_wallet_status]:" << std::endl << json_str );
|
||||
LOG_PRINT_L0(get_wallet_log_prefix(wsi.wallet_id) + "SENDING SIGNAL -> [update_wallet_status]:" << std::endl << json_str );
|
||||
QMetaObject::invokeMethod(this, "update_wallet_status", Qt::QueuedConnection, Q_ARG(QString, json_str.c_str()));
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1757,6 +1757,11 @@ namespace
|
|||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::init_log_prefix()
|
||||
{
|
||||
m_log_prefix = m_account.get_public_address_str().substr(0, 6);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::load_keys(const std::string& buff, const std::string& password)
|
||||
{
|
||||
wallet2::keys_file_data keys_file_data;
|
||||
|
|
@ -1781,14 +1786,14 @@ void wallet2::load_keys(const std::string& buff, const std::string& password)
|
|||
WLT_LOG_L0("Wrong password for wallet " << string_encoding::convert_to_ansii(m_wallet_file));
|
||||
tools::error::throw_wallet_ex<error::invalid_password>(std::string(__FILE__ ":" STRINGIZE(__LINE__)));
|
||||
}
|
||||
|
||||
m_log_prefix = m_account.get_public_address_str().substr(0, 6);
|
||||
init_log_prefix();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::assign_account(const currency::account_base& acc)
|
||||
{
|
||||
clear();
|
||||
m_account = acc;
|
||||
init_log_prefix();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::generate(const std::wstring& path, const std::string& pass)
|
||||
|
|
@ -1797,6 +1802,7 @@ void wallet2::generate(const std::wstring& path, const std::string& pass)
|
|||
m_wallet_file = path;
|
||||
m_password = pass;
|
||||
m_account.generate();
|
||||
init_log_prefix();
|
||||
boost::system::error_code ignored_ec;
|
||||
THROW_IF_TRUE_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, epee::string_encoding::convert_to_ansii(m_wallet_file));
|
||||
store();
|
||||
|
|
@ -1808,6 +1814,7 @@ void wallet2::restore(const std::wstring& path, const std::string& pass, const s
|
|||
m_wallet_file = path;
|
||||
m_password = pass;
|
||||
bool r = m_account.restore_keys_from_braindata(restore_key);
|
||||
init_log_prefix();
|
||||
THROW_IF_TRUE_WALLET_EX(!r, error::wallet_internal_error, epee::string_encoding::convert_to_ansii(m_wallet_file));
|
||||
boost::system::error_code ignored_ec;
|
||||
THROW_IF_TRUE_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, epee::string_encoding::convert_to_ansii(m_wallet_file));
|
||||
|
|
|
|||
|
|
@ -599,6 +599,8 @@ private:
|
|||
void fill_transfer_details(const currency::transaction& tx, const tools::money_transfer2_details& td, tools::wallet_rpc::wallet_transfer_info_details& res_td) const;
|
||||
void print_source_entry(const currency::tx_source_entry& src) const;
|
||||
|
||||
void init_log_prefix();
|
||||
|
||||
struct construct_tx_param
|
||||
{
|
||||
std::vector<currency::tx_destination_entry> dsts;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue