Allow the wallet to access hard fork information

And make it change behavior slightly when close/after first hard fork
This commit is contained in:
moneromooo-monero 2015-12-19 14:52:30 +00:00
parent 760331b427
commit 8ea7af1ba3
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
8 changed files with 63 additions and 8 deletions

View File

@ -3173,9 +3173,9 @@ HardFork::State Blockchain::get_hard_fork_state() const
return m_hardfork->get_state(); return m_hardfork->get_state();
} }
bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
{ {
return m_hardfork->get_voting_info(version, window, votes, threshold, voting); return m_hardfork->get_voting_info(version, window, votes, threshold, earliest_height, voting);
} }
bool Blockchain::for_all_key_images(std::function<bool(const crypto::key_image&)> f) const bool Blockchain::for_all_key_images(std::function<bool(const crypto::key_image&)> f) const

View File

@ -162,7 +162,7 @@ namespace cryptonote
uint8_t get_ideal_hard_fork_version() const { return m_hardfork->get_ideal_version(); } uint8_t get_ideal_hard_fork_version() const { return m_hardfork->get_ideal_version(); }
uint8_t get_ideal_hard_fork_version(uint64_t height) const { return m_hardfork->get_ideal_version(height); } uint8_t get_ideal_hard_fork_version(uint64_t height) const { return m_hardfork->get_ideal_version(height); }
bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const; bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const;
bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const; bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const;
bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)>) const; bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)>) const;

View File

@ -355,7 +355,16 @@ uint8_t HardFork::get_ideal_version(uint64_t height) const
return original_version; return original_version;
} }
bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const uint64_t HardFork::get_earliest_ideal_height_for_version(uint8_t version) const
{
for (unsigned int n = heights.size() - 1; n > 0; --n) {
if (heights[n].version <= version)
return heights[n].height;
}
return 0;
}
bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
{ {
CRITICAL_REGION_LOCAL(lock); CRITICAL_REGION_LOCAL(lock);
@ -367,6 +376,7 @@ bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &vote
votes += last_versions[n]; votes += last_versions[n];
threshold = (window * heights[current_version].threshold + 99) / 100; threshold = (window * heights[current_version].threshold + 99) / 100;
assert((votes >= threshold) == enabled); assert((votes >= threshold) == enabled);
earliest_height = get_earliest_ideal_height_for_version(version);
voting = heights.back().version; voting = heights.back().version;
return enabled; return enabled;
} }

View File

@ -183,6 +183,11 @@ namespace cryptonote
*/ */
uint8_t get_current_version() const; uint8_t get_current_version() const;
/**
* @brief returns the earliest block a given version may activate
*/
uint64_t get_earliest_ideal_height_for_version(uint8_t version) const;
/** /**
* @brief returns information about current voting state * @brief returns information about current voting state
* *
@ -193,8 +198,9 @@ namespace cryptonote
* @param window the number of blocks considered in voting * @param window the number of blocks considered in voting
* @param votes number of votes for next version * @param votes number of votes for next version
* @param threshold number of votes needed to switch to next version * @param threshold number of votes needed to switch to next version
* @param earliest_height earliest height at which the version can take effect
*/ */
bool get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const; bool get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const;
/** /**
* @brief returns the size of the voting window in blocks * @brief returns the size of the voting window in blocks

View File

@ -890,7 +890,7 @@ namespace cryptonote
const Blockchain &blockchain = m_core.get_blockchain_storage(); const Blockchain &blockchain = m_core.get_blockchain_storage();
uint8_t version = req.version > 0 ? req.version : blockchain.get_ideal_hard_fork_version(); uint8_t version = req.version > 0 ? req.version : blockchain.get_ideal_hard_fork_version();
res.version = blockchain.get_current_hard_fork_version(); res.version = blockchain.get_current_hard_fork_version();
res.enabled = blockchain.get_hard_fork_voting_info(version, res.window, res.votes, res.threshold, res.voting); res.enabled = blockchain.get_hard_fork_voting_info(version, res.window, res.votes, res.threshold, res.earliest_height, res.voting);
res.state = blockchain.get_hard_fork_state(); res.state = blockchain.get_hard_fork_state();
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
return true; return true;

View File

@ -875,6 +875,7 @@ namespace cryptonote
uint32_t threshold; uint32_t threshold;
uint8_t voting; uint8_t voting;
uint32_t state; uint32_t state;
uint64_t earliest_height;
std::string status; std::string status;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
@ -885,6 +886,7 @@ namespace cryptonote
KV_SERIALIZE(threshold) KV_SERIALIZE(threshold)
KV_SERIALIZE(voting) KV_SERIALIZE(voting)
KV_SERIALIZE(state) KV_SERIALIZE(state)
KV_SERIALIZE(earliest_height)
KV_SERIALIZE(status) KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View File

@ -2338,10 +2338,45 @@ void wallet2::transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t n
ptx.dests = dsts; ptx.dests = dsts;
} }
//----------------------------------------------------------------------------------------------------
bool wallet2::use_fork_rules(uint8_t version)
{
cryptonote::COMMAND_RPC_GET_HEIGHT::request req = AUTO_VAL_INIT(req);
cryptonote::COMMAND_RPC_GET_HEIGHT::response res = AUTO_VAL_INIT(res);
epee::json_rpc::request<cryptonote::COMMAND_RPC_HARD_FORK_INFO::request> req_t = AUTO_VAL_INIT(req_t);
epee::json_rpc::response<cryptonote::COMMAND_RPC_HARD_FORK_INFO::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
m_daemon_rpc_mutex.lock();
bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/getheight", req, res, m_http_client);
m_daemon_rpc_mutex.unlock();
CHECK_AND_ASSERT_MES(r, false, "Failed to connect to daemon");
CHECK_AND_ASSERT_MES(res.status != CORE_RPC_STATUS_BUSY, false, "Failed to connect to daemon");
CHECK_AND_ASSERT_MES(res.status == CORE_RPC_STATUS_OK, false, "Failed to get current blockchain height");
m_daemon_rpc_mutex.lock();
req_t.jsonrpc = "2.0";
req_t.id = epee::serialization::storage_entry(0);
req_t.method = "hard_fork_info";
req_t.params.version = version;
r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
m_daemon_rpc_mutex.unlock();
CHECK_AND_ASSERT_MES(r, false, "Failed to connect to daemon");
CHECK_AND_ASSERT_MES(res.status != CORE_RPC_STATUS_BUSY, false, "Failed to connect to daemon");
CHECK_AND_ASSERT_MES(res.status == CORE_RPC_STATUS_OK, false, "Failed to get hard fork status");
bool close_enough = res.height >= resp_t.result.earliest_height - 10; // start using the rules a bit beforehand
if (close_enough)
LOG_PRINT_L2("Using HF1 rules");
else
LOG_PRINT_L2("Not using HF1 rules");
return close_enough;
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
std::vector<wallet2::pending_tx> wallet2::create_dust_sweep_transactions() std::vector<wallet2::pending_tx> wallet2::create_dust_sweep_transactions()
{ {
tx_dust_policy dust_policy(::config::DEFAULT_DUST_THRESHOLD); // From hard fork 1, we don't consider small amounts to be dust anymore
const bool hf1_rules = use_fork_rules(2); // first hard fork has version 2
tx_dust_policy dust_policy(hf1_rules ? 0 : ::config::DEFAULT_DUST_THRESHOLD);
size_t num_dust_outputs = 0; size_t num_dust_outputs = 0;
for (transfer_container::const_iterator i = m_transfers.begin(); i != m_transfers.end(); ++i) for (transfer_container::const_iterator i = m_transfers.begin(); i != m_transfers.end(); ++i)

View File

@ -372,6 +372,7 @@ namespace tools
crypto::hash get_payment_id(const pending_tx &ptx) const; crypto::hash get_payment_id(const pending_tx &ptx) const;
void check_acc_out(const cryptonote::account_keys &acc, const cryptonote::tx_out &o, const crypto::public_key &tx_pub_key, size_t i, uint64_t &money_transfered, bool &error) const; void check_acc_out(const cryptonote::account_keys &acc, const cryptonote::tx_out &o, const crypto::public_key &tx_pub_key, size_t i, uint64_t &money_transfered, bool &error) const;
void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const; void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
bool use_fork_rules(uint8_t version);
cryptonote::account_base m_account; cryptonote::account_base m_account;
std::string m_daemon_address; std::string m_daemon_address;
@ -552,7 +553,8 @@ namespace tools
// randomly select inputs for transaction // randomly select inputs for transaction
// throw if requested send amount is greater than amount available to send // throw if requested send amount is greater than amount available to send
std::list<transfer_container::iterator> selected_transfers; std::list<transfer_container::iterator> selected_transfers;
uint64_t found_money = select_transfers(needed_money, 0 == fake_outputs_count, dust_policy.dust_threshold, selected_transfers); const bool add_dust = (0 == fake_outputs_count) && !use_fork_rules(2); // first fork has version 2
uint64_t found_money = select_transfers(needed_money, add_dust, dust_policy.dust_threshold, selected_transfers);
THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee); THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry; typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry;