mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 03:59:33 +00:00
wallet2: skip reorgs exceeding max-reorg-depth wallet setting
This commit is contained in:
parent
d27d4526fe
commit
ec14e4b8cd
5 changed files with 56 additions and 0 deletions
|
@ -2705,6 +2705,24 @@ bool simple_wallet::set_unit(const std::vector<std::string> &args/* = std::vecto
|
|||
return true;
|
||||
}
|
||||
|
||||
bool simple_wallet::set_max_reorg_depth(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||
{
|
||||
uint64_t depth;
|
||||
if (!epee::string_tools::get_xtype_from_string(depth, args[1]))
|
||||
{
|
||||
fail_msg_writer() << tr("invalid value");
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto pwd_container = get_and_verify_password();
|
||||
if (pwd_container)
|
||||
{
|
||||
m_wallet->max_reorg_depth(depth);
|
||||
m_wallet->rewrite(m_wallet_file, pwd_container->password());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool simple_wallet::set_min_output_count(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||
{
|
||||
uint32_t count;
|
||||
|
@ -3783,6 +3801,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||
success_msg_writer() << "priority = " << priority<< " (" << priority_string << ")";
|
||||
success_msg_writer() << "ask-password = " << m_wallet->ask_password() << " (" << ask_password_string << ")";
|
||||
success_msg_writer() << "unit = " << cryptonote::get_unit(cryptonote::get_default_decimal_point());
|
||||
success_msg_writer() << "max-reorg-depth = " << m_wallet->max_reorg_depth();
|
||||
success_msg_writer() << "min-outputs-count = " << m_wallet->get_min_output_count();
|
||||
success_msg_writer() << "min-outputs-value = " << cryptonote::print_money(m_wallet->get_min_output_value());
|
||||
success_msg_writer() << "merge-destinations = " << m_wallet->merge_destinations();
|
||||
|
@ -3853,6 +3872,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||
CHECK_SIMPLE_VARIABLE("priority", set_default_priority, tr("0, 1, 2, 3, or 4, or one of ") << join_priority_strings(", "));
|
||||
CHECK_SIMPLE_VARIABLE("ask-password", set_ask_password, tr("0|1|2 (or never|action|decrypt)"));
|
||||
CHECK_SIMPLE_VARIABLE("unit", set_unit, tr("monero, millinero, micronero, nanonero, piconero"));
|
||||
CHECK_SIMPLE_VARIABLE("max-reorg-depth", set_max_reorg_depth, tr("unsigned integer"));
|
||||
CHECK_SIMPLE_VARIABLE("min-outputs-count", set_min_output_count, tr("unsigned integer"));
|
||||
CHECK_SIMPLE_VARIABLE("min-outputs-value", set_min_output_value, tr("amount"));
|
||||
CHECK_SIMPLE_VARIABLE("merge-destinations", set_merge_destinations, tr("0 or 1"));
|
||||
|
|
|
@ -131,6 +131,7 @@ namespace cryptonote
|
|||
bool set_confirm_missing_payment_id(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_ask_password(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_unit(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_max_reorg_depth(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_min_output_count(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_min_output_value(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_merge_destinations(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
|
|
|
@ -1158,6 +1158,7 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std
|
|||
m_explicit_refresh_from_block_height(true),
|
||||
m_confirm_non_default_ring_size(true),
|
||||
m_ask_password(AskPasswordToDecrypt),
|
||||
m_max_reorg_depth(ORPHANED_BLOCKS_MAX_COUNT),
|
||||
m_min_output_count(0),
|
||||
m_min_output_value(0),
|
||||
m_merge_destinations(false),
|
||||
|
@ -3465,6 +3466,15 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
|
|||
throw std::runtime_error("proxy exception in refresh thread");
|
||||
}
|
||||
|
||||
if (!next_blocks.empty())
|
||||
{
|
||||
const uint64_t expected_start_height = std::max(static_cast<uint64_t>(m_blockchain.size()), uint64_t(1)) - 1;
|
||||
const uint64_t reorg_depth = expected_start_height - std::min(expected_start_height, next_blocks_start_height);
|
||||
THROW_WALLET_EXCEPTION_IF(reorg_depth > m_max_reorg_depth, error::reorg_depth_error,
|
||||
tr("reorg exceeds maximum allowed depth, use 'set max-reorg-depth N' to allow it, reorg depth: ") +
|
||||
std::to_string(reorg_depth));
|
||||
}
|
||||
|
||||
// if we've got at least 10 blocks to refresh, assume we're starting
|
||||
// a long refresh, and setup a tracking output cache if we need to
|
||||
if (m_track_uses && (!output_tracker_cache || output_tracker_cache->empty()) && next_blocks.size() >= 10)
|
||||
|
@ -3487,6 +3497,11 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
|
|||
THROW_WALLET_EXCEPTION_IF(!waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
|
||||
throw;
|
||||
}
|
||||
catch (const error::reorg_depth_error&)
|
||||
{
|
||||
THROW_WALLET_EXCEPTION_IF(!waiter.wait(), error::wallet_internal_error, "Exception in thread pool");
|
||||
throw;
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
blocks_fetched += added_blocks;
|
||||
|
@ -3863,6 +3878,9 @@ boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee:
|
|||
value2.SetInt(m_ask_password);
|
||||
json.AddMember("ask_password", value2, json.GetAllocator());
|
||||
|
||||
value2.SetUint64(m_max_reorg_depth);
|
||||
json.AddMember("max_reorg_depth", value2, json.GetAllocator());
|
||||
|
||||
value2.SetUint(m_min_output_count);
|
||||
json.AddMember("min_output_count", value2, json.GetAllocator());
|
||||
|
||||
|
@ -4081,6 +4099,7 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
|
|||
m_confirm_non_default_ring_size = true;
|
||||
m_ask_password = AskPasswordToDecrypt;
|
||||
cryptonote::set_default_decimal_point(CRYPTONOTE_DISPLAY_DECIMAL_POINT);
|
||||
m_max_reorg_depth = ORPHANED_BLOCKS_MAX_COUNT;
|
||||
m_min_output_count = 0;
|
||||
m_min_output_value = 0;
|
||||
m_merge_destinations = false;
|
||||
|
@ -4233,6 +4252,8 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
|
|||
m_ask_password = field_ask_password;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, default_decimal_point, int, Int, false, CRYPTONOTE_DISPLAY_DECIMAL_POINT);
|
||||
cryptonote::set_default_decimal_point(field_default_decimal_point);
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, max_reorg_depth, uint64_t, Uint64, false, ORPHANED_BLOCKS_MAX_COUNT);
|
||||
m_max_reorg_depth = field_max_reorg_depth;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, min_output_count, uint32_t, Uint, false, 0);
|
||||
m_min_output_count = field_min_output_count;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, min_output_value, uint64_t, Uint64, false, 0);
|
||||
|
|
|
@ -853,6 +853,9 @@ private:
|
|||
void explicit_refresh_from_block_height(bool expl) {m_explicit_refresh_from_block_height = expl;}
|
||||
bool explicit_refresh_from_block_height() const {return m_explicit_refresh_from_block_height;}
|
||||
|
||||
void max_reorg_depth(uint64_t depth) {m_max_reorg_depth = depth;}
|
||||
uint64_t max_reorg_depth() const {return m_max_reorg_depth;}
|
||||
|
||||
bool deinit();
|
||||
bool init(std::string daemon_address = "http://localhost:8080",
|
||||
boost::optional<epee::net_utils::http::login> daemon_login = boost::none,
|
||||
|
@ -1726,6 +1729,7 @@ private:
|
|||
bool m_explicit_refresh_from_block_height;
|
||||
bool m_confirm_non_default_ring_size;
|
||||
AskPasswordType m_ask_password;
|
||||
uint64_t m_max_reorg_depth;
|
||||
uint32_t m_min_output_count;
|
||||
uint64_t m_min_output_value;
|
||||
bool m_merge_destinations;
|
||||
|
|
|
@ -428,6 +428,16 @@ namespace tools
|
|||
std::string to_string() const { return refresh_error::to_string(); }
|
||||
};
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
struct reorg_depth_error : public refresh_error
|
||||
{
|
||||
explicit reorg_depth_error(std::string&& loc, const std::string& message)
|
||||
: refresh_error(std::move(loc), message)
|
||||
{
|
||||
}
|
||||
|
||||
std::string to_string() const { return refresh_error::to_string(); }
|
||||
};
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
struct signature_check_failed : public wallet_logic_error
|
||||
{
|
||||
explicit signature_check_failed(std::string&& loc, const std::string& message)
|
||||
|
|
Loading…
Reference in a new issue