Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet-related improvements #1199

Merged
merged 8 commits into from Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/common/scoped_message_writer.h
Expand Up @@ -44,15 +44,15 @@ class scoped_message_writer
{
private:
bool m_flush;
std::stringstream m_oss;
std::ostringstream m_oss;
epee::console_colors m_color;
bool m_bright;
el::Level m_log_level;
public:
scoped_message_writer(
epee::console_colors color = epee::console_color_default
, bool bright = false
, std::string&& prefix = std::string()
, std::string prefix = {}
, el::Level log_level = el::Level::Info
)
: m_flush(true)
Expand All @@ -68,12 +68,7 @@ class scoped_message_writer

scoped_message_writer(scoped_message_writer&& rhs)
: m_flush(std::move(rhs.m_flush))
#if defined(_MSC_VER)
, m_oss(std::move(rhs.m_oss))
#else
// GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
, m_oss(rhs.m_oss.str(), std::ios_base::out | std::ios_base::ate)
#endif
, m_color(std::move(rhs.m_color))
, m_log_level(std::move(rhs.m_log_level))
{
Expand Down
300 changes: 159 additions & 141 deletions src/cryptonote_config.h

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/cryptonote_core/blockchain.cpp
Expand Up @@ -1405,7 +1405,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl

if (!validate_governance_reward_key(
m_db->height(),
*cryptonote::get_config(m_nettype, version).GOVERNANCE_WALLET_ADDRESS,
cryptonote::get_config(m_nettype).governance_wallet_address(version),
b.miner_tx.vout.size() - 1,
std::get<txout_to_key>(b.miner_tx.vout.back().target).key,
m_nettype))
Expand Down Expand Up @@ -4794,8 +4794,7 @@ bool Blockchain::calc_batched_governance_reward(uint64_t height, uint64_t &rewar
// 0 if it's not time to pay out the batched payments (in which case we
// already returned, above).

const cryptonote::config_t &network = cryptonote::get_config(nettype(), hard_fork_version);
size_t num_blocks = network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS;
size_t num_blocks = cryptonote::get_config(nettype()).GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS;

// Fixed reward starting at HF15
if (hard_fork_version >= network_version_15_lns)
Expand Down
17 changes: 8 additions & 9 deletions src/cryptonote_core/cryptonote_tx_utils.cpp
Expand Up @@ -33,6 +33,7 @@
#include "include_base_utils.h"
#include "string_tools.h"
#include "common/apply_permutation.h"
#include "common/hex.h"
#include "cryptonote_tx_utils.h"
#include "cryptonote_config.h"
#include "blockchain.h"
Expand Down Expand Up @@ -114,7 +115,7 @@ namespace cryptonote
return true;
}

bool validate_governance_reward_key(uint64_t height, const std::string& governance_wallet_address_str, size_t output_index, const crypto::public_key& output_key, const cryptonote::network_type nettype)
bool validate_governance_reward_key(uint64_t height, std::string_view governance_wallet_address_str, size_t output_index, const crypto::public_key& output_key, const cryptonote::network_type nettype)
{
keypair gov_key = get_deterministic_keypair_from_height(height);

Expand Down Expand Up @@ -152,8 +153,7 @@ namespace cryptonote
if (hard_fork_version <= network_version_9_service_nodes)
return true;

const cryptonote::config_t &network = cryptonote::get_config(nettype, hard_fork_version);
if (height % network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS != 0)
if (height % cryptonote::get_config(nettype).GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS != 0)
{
return false;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace cryptonote
else
{
cryptonote::address_parse_info governance_wallet_address;
cryptonote::get_account_address_from_str(governance_wallet_address, nettype, *cryptonote::get_config(nettype, hard_fork_version).GOVERNANCE_WALLET_ADDRESS);
cryptonote::get_account_address_from_str(governance_wallet_address, nettype, cryptonote::get_config(nettype).governance_wallet_address(hard_fork_version));
crypto::public_key out_eph_public_key{};

if (!get_deterministic_output_key(governance_wallet_address.address, gov_key, tx.vout.size(), out_eph_public_key))
Expand Down Expand Up @@ -973,17 +973,16 @@ namespace cryptonote
//---------------------------------------------------------------
bool generate_genesis_block(
block& bl
, std::string const & genesis_tx
, std::string_view genesis_tx_hex
, uint32_t nonce
)
{
//genesis block
bl = {};

blobdata tx_bl;
bool r = epee::string_tools::parse_hexstr_to_binbuff(genesis_tx, tx_bl);
CHECK_AND_ASSERT_MES(r, false, "failed to parse coinbase tx from hard coded blob");
r = parse_and_validate_tx_from_blob(tx_bl, bl.miner_tx);
CHECK_AND_ASSERT_MES(lokimq::is_hex(genesis_tx_hex), false, "failed to parse coinbase tx from hard coded blob");
std::string tx_bl = lokimq::from_hex(genesis_tx_hex);
bool r = parse_and_validate_tx_from_blob(tx_bl, bl.miner_tx);
CHECK_AND_ASSERT_MES(r, false, "failed to parse coinbase tx from hard coded blob");
bl.major_version = 7;
bl.minor_version = 7;
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_core/cryptonote_tx_utils.h
Expand Up @@ -40,7 +40,7 @@ namespace cryptonote
//---------------------------------------------------------------
keypair get_deterministic_keypair_from_height(uint64_t height);
bool get_deterministic_output_key (const account_public_address& address, const keypair& tx_key, size_t output_index, crypto::public_key& output_key);
bool validate_governance_reward_key (uint64_t height, const std::string& governance_wallet_address_str, size_t output_index, const crypto::public_key& output_key, const cryptonote::network_type nettype);
bool validate_governance_reward_key (uint64_t height, std::string_view governance_wallet_address_str, size_t output_index, const crypto::public_key& output_key, const cryptonote::network_type nettype);

uint64_t governance_reward_formula (uint64_t base_reward, uint8_t hf_version);
bool block_has_governance_output (network_type nettype, cryptonote::block const &block);
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace cryptonote

bool generate_genesis_block(
block& bl
, std::string const & genesis_tx
, std::string_view genesis_tx_hex
, uint32_t nonce
);

Expand Down
10 changes: 5 additions & 5 deletions src/device/device_default.cpp
Expand Up @@ -194,13 +194,13 @@ namespace hw {
}

crypto::secret_key device_default::get_subaddress_secret_key(const crypto::secret_key &a, const cryptonote::subaddress_index &index) {
char data[sizeof(config::HASH_KEY_SUBADDRESS) + sizeof(crypto::secret_key) + 2 * sizeof(uint32_t)];
memcpy(data, config::HASH_KEY_SUBADDRESS, sizeof(config::HASH_KEY_SUBADDRESS));
memcpy(data + sizeof(config::HASH_KEY_SUBADDRESS), &a, sizeof(crypto::secret_key));
char data[config::HASH_KEY_SUBADDRESS.size() + sizeof(crypto::secret_key) + 2 * sizeof(uint32_t)];
memcpy(data, config::HASH_KEY_SUBADDRESS.data(), config::HASH_KEY_SUBADDRESS.size());
memcpy(data + config::HASH_KEY_SUBADDRESS.size(), &a, sizeof(crypto::secret_key));
uint32_t idx = SWAP32LE(index.major);
memcpy(data + sizeof(config::HASH_KEY_SUBADDRESS) + sizeof(crypto::secret_key), &idx, sizeof(uint32_t));
memcpy(data + config::HASH_KEY_SUBADDRESS.size() + sizeof(crypto::secret_key), &idx, sizeof(uint32_t));
idx = SWAP32LE(index.minor);
memcpy(data + sizeof(config::HASH_KEY_SUBADDRESS) + sizeof(crypto::secret_key) + sizeof(uint32_t), &idx, sizeof(uint32_t));
memcpy(data + config::HASH_KEY_SUBADDRESS.size() + sizeof(crypto::secret_key) + sizeof(uint32_t), &idx, sizeof(uint32_t));
crypto::secret_key m;
crypto::hash_to_scalar(data, sizeof(data), m);
return m;
Expand Down
4 changes: 2 additions & 2 deletions src/multisig/multisig.cpp
Expand Up @@ -47,8 +47,8 @@ namespace cryptonote
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key)
{
rct::key multisig_salt;
static_assert(sizeof(rct::key) == sizeof(config::HASH_KEY_MULTISIG), "Hash domain separator is an unexpected size");
memcpy(multisig_salt.bytes, config::HASH_KEY_MULTISIG, sizeof(rct::key));
static_assert(sizeof(rct::key) == config::HASH_KEY_MULTISIG.size(), "Hash domain separator is an unexpected size");
memcpy(multisig_salt.bytes, config::HASH_KEY_MULTISIG.data(), sizeof(rct::key));

rct::keyV data;
data.reserve(2);
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/core_rpc_server_commands_defs.h
Expand Up @@ -201,7 +201,7 @@ namespace rpc {
// Get blocks by height. Binary request.
struct GET_BLOCKS_BY_HEIGHT : PUBLIC, BINARY
{
static constexpr auto names() { return NAMES("get_blocks_by_height.bin", "getblocksbyheight.bin"); }
static constexpr auto names() { return NAMES("get_blocks_by_height.bin", "getblocks_by_height.bin"); }

struct request
{
Expand Down
11 changes: 5 additions & 6 deletions src/simplewallet/simplewallet.cpp
Expand Up @@ -4080,7 +4080,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)

cryptonote::rpc::GET_INFO::request req;
cryptonote::rpc::GET_INFO::response res;
bool r = m_wallet->invoke_http_json("/get_info", req, res);
bool r = m_wallet->invoke_http<rpc::GET_INFO>(req, res);
std::string err = interpret_rpc_response(r, res.status);
if (r && err.empty() && (res.was_bootstrap_ever_used || !res.bootstrap_daemon_address.empty()))
message_writer(epee::console_color_red, true) << boost::format(tr("Moreover, a daemon is also less secure when running in bootstrap mode"));
Expand Down Expand Up @@ -4693,7 +4693,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
}

rpc::START_MINING::response res{};
bool r = m_wallet->invoke_http_json("/start_mining", req, res);
bool r = m_wallet->invoke_http<rpc::START_MINING>(req, res);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Mining started in daemon");
Expand All @@ -4713,9 +4713,8 @@ bool simple_wallet::stop_mining(const std::vector<std::string>& args)
return true;
}

rpc::STOP_MINING::request req{};
rpc::STOP_MINING::response res{};
bool r = m_wallet->invoke_http_json("/stop_mining", req, res);
bool r = m_wallet->invoke_http<rpc::STOP_MINING>({}, res);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Mining stopped in daemon");
Expand Down Expand Up @@ -4794,7 +4793,7 @@ bool simple_wallet::save_bc(const std::vector<std::string>& args)
}
rpc::SAVE_BC::request req{};
rpc::SAVE_BC::response res{};
bool r = m_wallet->invoke_http_json("/save_bc", req, res);
bool r = m_wallet->invoke_http<rpc::SAVE_BC>(req, res);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Blockchain saved");
Expand Down Expand Up @@ -5498,7 +5497,7 @@ bool simple_wallet::process_ring_members(const std::vector<tools::wallet2::pendi
req.outputs[j].index = absolute_offsets[j];
}
rpc::GET_OUTPUTS_BIN::response res{};
bool r = m_wallet->invoke_http_bin("/get_outs.bin", req, res);
bool r = m_wallet->invoke_http<rpc::GET_OUTPUTS_BIN>(req, res);
err = interpret_rpc_response(r, res.status);
if (!err.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/node_rpc_proxy.cpp
Expand Up @@ -34,7 +34,7 @@ namespace rpc = cryptonote::rpc;
namespace tools
{

static const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::chrono::seconds(30);
static constexpr std::chrono::seconds rpc_timeout{30};

NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, std::recursive_mutex &mutex)
: m_http_client(http_client)
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/ringdb.cpp
Expand Up @@ -107,11 +107,11 @@ std::string get_rings_filename(boost::filesystem::path filename)

static crypto::chacha_iv make_iv(const crypto::key_image &key_image, const crypto::chacha_key &key, uint8_t field)
{
uint8_t buffer[sizeof(key_image) + sizeof(key) + sizeof(config::HASH_KEY_RINGDB) + sizeof(field)];
uint8_t buffer[sizeof(key_image) + sizeof(key) + config::HASH_KEY_RINGDB.size() + sizeof(field)];
memcpy(buffer, &key_image, sizeof(key_image));
memcpy(buffer + sizeof(key_image), &key, sizeof(key));
memcpy(buffer + sizeof(key_image) + sizeof(key), config::HASH_KEY_RINGDB, sizeof(config::HASH_KEY_RINGDB));
memcpy(buffer + sizeof(key_image) + sizeof(key) + sizeof(config::HASH_KEY_RINGDB), &field, sizeof(field));
memcpy(buffer + sizeof(key_image) + sizeof(key), config::HASH_KEY_RINGDB.data(), config::HASH_KEY_RINGDB.size());
memcpy(buffer + sizeof(key_image) + sizeof(key) + config::HASH_KEY_RINGDB.size(), &field, sizeof(field));
crypto::hash hash;
// if field is 0, backward compat mode: hash without the field
crypto::cn_fast_hash(buffer, sizeof(buffer) - !field, hash.data);
Expand Down