Merge pull request #3473

eaa8bfe7 wallet2: set from_height of GET_OUTPUT_DISTRIBUTION correctly The previous expression (stoffu)
0a619f78 wallet2: enable the mitigation only after the fork height (stoffu)
This commit is contained in:
Riccardo Spagni 2018-04-12 11:05:31 +02:00
commit 1b4dc46129
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD

View File

@ -5819,6 +5819,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
boost::optional<std::string> result = m_node_rpc_proxy.get_height(height); boost::optional<std::string> result = m_node_rpc_proxy.get_height(height);
throw_on_rpc_response_error(result, "get_info"); throw_on_rpc_response_error(result, "get_info");
bool is_shortly_after_segregation_fork = height >= segregation_fork_height && height < segregation_fork_height + SEGREGATION_FORK_VICINITY; bool is_shortly_after_segregation_fork = height >= segregation_fork_height && height < segregation_fork_height + SEGREGATION_FORK_VICINITY;
bool is_after_segregation_fork = height >= segregation_fork_height;
// get histogram for the amounts we need // get histogram for the amounts we need
cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request req_t = AUTO_VAL_INIT(req_t); cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request req_t = AUTO_VAL_INIT(req_t);
@ -5839,7 +5840,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
// if we want to segregate fake outs pre or post fork, get distribution // if we want to segregate fake outs pre or post fork, get distribution
std::unordered_map<uint64_t, std::pair<uint64_t, uint64_t>> segregation_limit; std::unordered_map<uint64_t, std::pair<uint64_t, uint64_t>> segregation_limit;
if (m_segregate_pre_fork_outputs || m_key_reuse_mitigation2) if (is_after_segregation_fork && (m_segregate_pre_fork_outputs || m_key_reuse_mitigation2))
{ {
cryptonote::COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request req_t = AUTO_VAL_INIT(req_t); cryptonote::COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request req_t = AUTO_VAL_INIT(req_t);
cryptonote::COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response resp_t = AUTO_VAL_INIT(resp_t); cryptonote::COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response resp_t = AUTO_VAL_INIT(resp_t);
@ -5848,7 +5849,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
std::sort(req_t.amounts.begin(), req_t.amounts.end()); std::sort(req_t.amounts.begin(), req_t.amounts.end());
auto end = std::unique(req_t.amounts.begin(), req_t.amounts.end()); auto end = std::unique(req_t.amounts.begin(), req_t.amounts.end());
req_t.amounts.resize(std::distance(req_t.amounts.begin(), end)); req_t.amounts.resize(std::distance(req_t.amounts.begin(), end));
req_t.from_height = segregation_fork_height >= RECENT_OUTPUT_ZONE ? height >= (segregation_fork_height ? segregation_fork_height : height) - RECENT_OUTPUT_BLOCKS : 0; req_t.from_height = std::max<uint64_t>(segregation_fork_height, RECENT_OUTPUT_BLOCKS) - RECENT_OUTPUT_BLOCKS;
req_t.cumulative = true; req_t.cumulative = true;
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_output_distribution", req_t, resp_t, m_http_client, rpc_timeout); bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_output_distribution", req_t, resp_t, m_http_client, rpc_timeout);
@ -5906,7 +5907,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
float pre_fork_num_out_ratio = 0.0f; float pre_fork_num_out_ratio = 0.0f;
float post_fork_num_out_ratio = 0.0f; float post_fork_num_out_ratio = 0.0f;
if (m_segregate_pre_fork_outputs && output_is_pre_fork) if (is_after_segregation_fork && m_segregate_pre_fork_outputs && output_is_pre_fork)
{ {
num_outs = segregation_limit[amount].first; num_outs = segregation_limit[amount].first;
num_recent_outs = segregation_limit[amount].second; num_recent_outs = segregation_limit[amount].second;
@ -5926,7 +5927,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
break; break;
} }
} }
if (m_key_reuse_mitigation2) if (is_after_segregation_fork && m_key_reuse_mitigation2)
{ {
if (output_is_pre_fork) if (output_is_pre_fork)
{ {
@ -6141,7 +6142,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
uint64_t num_outs = 0; uint64_t num_outs = 0;
const uint64_t amount = td.is_rct() ? 0 : td.amount(); const uint64_t amount = td.is_rct() ? 0 : td.amount();
const bool output_is_pre_fork = td.m_block_height < segregation_fork_height; const bool output_is_pre_fork = td.m_block_height < segregation_fork_height;
if (m_segregate_pre_fork_outputs && output_is_pre_fork) if (is_after_segregation_fork && m_segregate_pre_fork_outputs && output_is_pre_fork)
num_outs = segregation_limit[amount].first; num_outs = segregation_limit[amount].first;
else for (const auto &he: resp_t.histogram) else for (const auto &he: resp_t.histogram)
{ {