mirror of
https://github.com/oxen-io/oxen-core.git
synced 2023-12-14 02:22:56 +01:00
Merge commit '702a410' into LokiMergeUpstream20180821
This commit is contained in:
commit
ad8cdc1d1f
19 changed files with 183 additions and 111 deletions
|
@ -85,7 +85,6 @@ loki_add_library(common
|
|||
DEPENDS generate_translations_header)
|
||||
target_link_libraries(common
|
||||
PUBLIC
|
||||
epee
|
||||
cncrypto
|
||||
${UNBOUND_LIBRARY}
|
||||
${LIBUNWIND_LIBRARIES}
|
||||
|
|
|
@ -94,12 +94,6 @@ namespace crypto {
|
|||
}
|
||||
|
||||
/* generate a random 32-byte (256-bit) integer and copy it to res */
|
||||
static inline void random_scalar_not_thread_safe(ec_scalar &res) {
|
||||
unsigned char tmp[64];
|
||||
generate_random_bytes_not_thread_safe(64, tmp);
|
||||
sc_reduce(tmp);
|
||||
memcpy(&res, tmp, 32);
|
||||
}
|
||||
static inline void random_scalar(ec_scalar &res) {
|
||||
unsigned char tmp[64];
|
||||
generate_random_bytes_thread_safe(64, tmp);
|
||||
|
|
|
@ -2286,7 +2286,8 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
|
|||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
|
||||
bool result = find_blockchain_supplement(qblock_ids, resp.m_block_ids, resp.start_height, resp.total_height);
|
||||
resp.cumulative_difficulty = m_db->get_block_cumulative_difficulty(resp.total_height - 1);
|
||||
if (result)
|
||||
resp.cumulative_difficulty = m_db->get_block_cumulative_difficulty(resp.total_height - 1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -3508,6 +3509,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
|||
if(bl.prev_id != get_tail_id())
|
||||
{
|
||||
MERROR_VER("Block with id: " << id << std::endl << "has wrong prev_id: " << bl.prev_id << std::endl << "expected: " << get_tail_id());
|
||||
bvc.m_verifivation_failed = true;
|
||||
leave:
|
||||
m_db->block_txn_stop();
|
||||
return false;
|
||||
|
@ -3809,6 +3811,7 @@ leave:
|
|||
{
|
||||
//TODO: figure out the best way to deal with this failure
|
||||
LOG_ERROR("Error adding block with hash: " << id << " to blockchain, what = " << e.what());
|
||||
bvc.m_verifivation_failed = true;
|
||||
return_tx_to_pool(txs);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ namespace cryptonote
|
|||
crypto::hash max_used_block_id = null_hash;
|
||||
uint64_t max_used_block_height = 0;
|
||||
cryptonote::txpool_tx_meta_t meta;
|
||||
bool ch_inp_res = m_blockchain.check_tx_inputs(tx, max_used_block_height, max_used_block_id, tvc, kept_by_block);
|
||||
bool ch_inp_res = check_tx_inputs([&tx]()->cryptonote::transaction&{ return tx; }, id, max_used_block_height, max_used_block_id, tvc, kept_by_block);
|
||||
if(!ch_inp_res)
|
||||
{
|
||||
// if the transaction was valid before (kept_by_block), then it
|
||||
|
@ -1007,11 +1007,15 @@ namespace cryptonote
|
|||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::on_blockchain_inc(uint64_t new_block_height, const crypto::hash& top_block_id)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
m_input_cache.clear();
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::on_blockchain_dec(uint64_t new_block_height, const crypto::hash& top_block_id)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
m_input_cache.clear();
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
|
@ -1051,7 +1055,26 @@ namespace cryptonote
|
|||
m_transactions_lock.unlock();
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::is_transaction_ready_to_go(txpool_tx_meta_t& txd, const cryptonote::blobdata &txblob, transaction &tx) const
|
||||
bool tx_memory_pool::check_tx_inputs(const std::function<cryptonote::transaction&(void)> &get_tx, const crypto::hash &txid, uint64_t &max_used_block_height, crypto::hash &max_used_block_id, tx_verification_context &tvc, bool kept_by_block) const
|
||||
{
|
||||
if (!kept_by_block)
|
||||
{
|
||||
const std::unordered_map<crypto::hash, std::tuple<bool, tx_verification_context, uint64_t, crypto::hash>>::const_iterator i = m_input_cache.find(txid);
|
||||
if (i != m_input_cache.end())
|
||||
{
|
||||
max_used_block_height = std::get<2>(i->second);
|
||||
max_used_block_id = std::get<3>(i->second);
|
||||
tvc = std::get<1>(i->second);
|
||||
return std::get<0>(i->second);
|
||||
}
|
||||
}
|
||||
bool ret = m_blockchain.check_tx_inputs(get_tx(), max_used_block_height, max_used_block_id, tvc, kept_by_block);
|
||||
if (!kept_by_block)
|
||||
m_input_cache.insert(std::make_pair(txid, std::make_tuple(ret, tvc, max_used_block_height, max_used_block_id)));
|
||||
return ret;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::is_transaction_ready_to_go(txpool_tx_meta_t& txd, const crypto::hash &txid, const cryptonote::blobdata &txblob, transaction &tx) const
|
||||
{
|
||||
struct transction_parser
|
||||
{
|
||||
|
@ -1080,7 +1103,7 @@ namespace cryptonote
|
|||
return false;//we already sure that this tx is broken for this height
|
||||
|
||||
tx_verification_context tvc;
|
||||
if(!m_blockchain.check_tx_inputs(lazy_tx(), txd.max_used_block_height, txd.max_used_block_id, tvc))
|
||||
if(!check_tx_inputs([&lazy_tx]()->cryptonote::transaction&{ return lazy_tx(); }, txid, txd.max_used_block_height, txd.max_used_block_id, tvc))
|
||||
{
|
||||
txd.last_failed_height = m_blockchain.get_current_blockchain_height()-1;
|
||||
txd.last_failed_id = m_blockchain.get_block_id_by_height(txd.last_failed_height);
|
||||
|
@ -1097,7 +1120,7 @@ namespace cryptonote
|
|||
return false;
|
||||
//check ring signature again, it is possible (with very small chance) that this transaction become again valid
|
||||
tx_verification_context tvc;
|
||||
if(!m_blockchain.check_tx_inputs(lazy_tx(), txd.max_used_block_height, txd.max_used_block_id, tvc))
|
||||
if(!check_tx_inputs([&lazy_tx]()->cryptonote::transaction&{ return lazy_tx(); }, txid, txd.max_used_block_height, txd.max_used_block_id, tvc))
|
||||
{
|
||||
txd.last_failed_height = m_blockchain.get_current_blockchain_height()-1;
|
||||
txd.last_failed_id = m_blockchain.get_block_id_by_height(txd.last_failed_height);
|
||||
|
@ -1291,7 +1314,7 @@ namespace cryptonote
|
|||
bool ready = false;
|
||||
try
|
||||
{
|
||||
ready = is_transaction_ready_to_go(meta, txblob, tx);
|
||||
ready = is_transaction_ready_to_go(meta, sorted_it->second, txblob, tx);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
|
|
@ -505,12 +505,13 @@ namespace cryptonote
|
|||
* @brief check if a transaction is a valid candidate for inclusion in a block
|
||||
*
|
||||
* @param txd the transaction to check (and info about it)
|
||||
* @param txid the txid of the transaction to check
|
||||
* @param txblob the transaction blob to check
|
||||
* @param tx the parsed transaction, if successful
|
||||
*
|
||||
* @return true if the transaction is good to go, otherwise false
|
||||
*/
|
||||
bool is_transaction_ready_to_go(txpool_tx_meta_t& txd, const cryptonote::blobdata &txblob, transaction &tx) const;
|
||||
bool is_transaction_ready_to_go(txpool_tx_meta_t& txd, const crypto::hash &txid, const cryptonote::blobdata &txblob, transaction &tx) const;
|
||||
|
||||
/**
|
||||
* @brief mark all transactions double spending the one passed
|
||||
|
@ -563,6 +564,9 @@ private:
|
|||
*/
|
||||
sorted_tx_container::iterator find_tx_in_sorted_container(const crypto::hash& id) const;
|
||||
|
||||
//! cache/call Blockchain::check_tx_inputs results
|
||||
bool check_tx_inputs(const std::function<cryptonote::transaction&(void)> &get_tx, const crypto::hash &txid, uint64_t &max_used_block_height, crypto::hash &max_used_block_id, tx_verification_context &tvc, bool kept_by_block = false) const;
|
||||
|
||||
//! transactions which are unlikely to be included in blocks
|
||||
/*! These transactions are kept in RAM in case they *are* included
|
||||
* in a block eventually, but this container is not saved to disk.
|
||||
|
@ -573,6 +577,8 @@ private:
|
|||
|
||||
size_t m_txpool_max_size;
|
||||
size_t m_txpool_size;
|
||||
|
||||
mutable std::unordered_map<crypto::hash, std::tuple<bool, tx_verification_context, uint64_t, crypto::hash>> m_input_cache;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,6 @@ target_link_libraries(daemon
|
|||
daemonizer
|
||||
serialization
|
||||
daemon_rpc_server
|
||||
epee
|
||||
${EPEE_READLINE}
|
||||
version
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
|
|
|
@ -39,7 +39,6 @@ source_group(p2p FILES ${P2P})
|
|||
loki_add_library(p2p ${P2P})
|
||||
target_link_libraries(p2p
|
||||
PUBLIC
|
||||
epee
|
||||
version
|
||||
cryptonote_core
|
||||
${UPNP_LIBRARIES}
|
||||
|
|
|
@ -112,7 +112,6 @@ target_link_libraries(rpc
|
|||
common
|
||||
cryptonote_core
|
||||
cryptonote_protocol
|
||||
epee
|
||||
${Boost_REGEX_LIBRARY}
|
||||
${Boost_THREAD_LIBRARY}
|
||||
PRIVATE
|
||||
|
|
|
@ -50,7 +50,6 @@ target_link_libraries(simplewallet
|
|||
cncrypto
|
||||
common
|
||||
mnemonics
|
||||
epee
|
||||
${EPEE_READLINE}
|
||||
version
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
|
|
|
@ -2060,6 +2060,19 @@ bool simple_wallet::set_segregation_height(const std::vector<std::string> &args/
|
|||
return true;
|
||||
}
|
||||
|
||||
bool simple_wallet::set_ignore_fractional_outputs(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||
{
|
||||
const auto pwd_container = get_and_verify_password();
|
||||
if (pwd_container)
|
||||
{
|
||||
parse_bool_and_use(args[1], [&](bool r) {
|
||||
m_wallet->ignore_fractional_outputs(r);
|
||||
m_wallet->rewrite(m_wallet_file, pwd_container->password());
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||
{
|
||||
if(args.empty())
|
||||
|
@ -2460,6 +2473,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||
const std::pair<size_t, size_t> lookahead = m_wallet->get_subaddress_lookahead();
|
||||
success_msg_writer() << "subaddress-lookahead = " << lookahead.first << ":" << lookahead.second;
|
||||
success_msg_writer() << "segregation-height = " << m_wallet->segregation_height();
|
||||
success_msg_writer() << "ignore-fractional-outputs = " << m_wallet->ignore_fractional_outputs();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -2513,6 +2527,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||
CHECK_SIMPLE_VARIABLE("key-reuse-mitigation2", set_key_reuse_mitigation2, tr("0 or 1"));
|
||||
CHECK_SIMPLE_VARIABLE("subaddress-lookahead", set_subaddress_lookahead, tr("<major>:<minor>"));
|
||||
CHECK_SIMPLE_VARIABLE("segregation-height", set_segregation_height, tr("unsigned integer"));
|
||||
CHECK_SIMPLE_VARIABLE("ignore-fractional-outputs", set_ignore_fractional_outputs, tr("0 or 1"));
|
||||
}
|
||||
fail_msg_writer() << tr("set: unrecognized argument(s)");
|
||||
return true;
|
||||
|
@ -4258,12 +4273,7 @@ uint64_t simple_wallet::get_daemon_blockchain_height(std::string& err)
|
|||
{
|
||||
throw std::runtime_error("simple_wallet null wallet");
|
||||
}
|
||||
|
||||
COMMAND_RPC_GET_HEIGHT::request req;
|
||||
COMMAND_RPC_GET_HEIGHT::response res = boost::value_initialized<COMMAND_RPC_GET_HEIGHT::response>();
|
||||
bool r = m_wallet->invoke_http_json("/getheight", req, res);
|
||||
err = interpret_rpc_response(r, res.status);
|
||||
return res.height;
|
||||
return m_wallet->get_daemon_blockchain_height(err);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool simple_wallet::show_blockchain_height(const std::vector<std::string>& args)
|
||||
|
|
|
@ -140,6 +140,7 @@ namespace cryptonote
|
|||
bool set_key_reuse_mitigation2(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_subaddress_lookahead(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_segregation_height(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_ignore_fractional_outputs(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool help(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool start_mining(const std::vector<std::string> &args);
|
||||
bool stop_mining(const std::vector<std::string> &args);
|
||||
|
|
|
@ -86,7 +86,6 @@ loki_add_executable(wallet_rpc_server
|
|||
target_link_libraries(wallet_rpc_server
|
||||
PRIVATE
|
||||
wallet
|
||||
epee
|
||||
rpc_base
|
||||
cryptonote_core
|
||||
cncrypto
|
||||
|
|
|
@ -41,21 +41,13 @@ static const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::c
|
|||
NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::http_simple_client &http_client, boost::mutex &mutex)
|
||||
: m_http_client(http_client)
|
||||
, m_daemon_rpc_mutex(mutex)
|
||||
, m_height(0)
|
||||
, m_height_time(0)
|
||||
, m_earliest_height()
|
||||
, m_dynamic_per_kb_fee_estimate(0)
|
||||
, m_dynamic_per_kb_fee_estimate_cached_height(0)
|
||||
, m_dynamic_per_kb_fee_estimate_grace_blocks(0)
|
||||
, m_rpc_version(0)
|
||||
, m_target_height(0)
|
||||
, m_target_height_time(0)
|
||||
{}
|
||||
{
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void NodeRPCProxy::invalidate()
|
||||
{
|
||||
m_height = 0;
|
||||
m_height_time = 0;
|
||||
for (size_t n = 0; n < 256; ++n)
|
||||
m_earliest_height[n] = 0;
|
||||
m_dynamic_per_kb_fee_estimate = 0;
|
||||
|
@ -63,7 +55,8 @@ void NodeRPCProxy::invalidate()
|
|||
m_dynamic_per_kb_fee_estimate_grace_blocks = 0;
|
||||
m_rpc_version = 0;
|
||||
m_target_height = 0;
|
||||
m_target_height_time = 0;
|
||||
m_block_size_limit = 0;
|
||||
m_get_info_time = 0;
|
||||
}
|
||||
|
||||
boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version) const
|
||||
|
@ -84,36 +77,15 @@ boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version
|
|||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
boost::optional<std::string> NodeRPCProxy::get_height(uint64_t &height) const
|
||||
{
|
||||
const time_t now = time(NULL);
|
||||
if (m_height == 0 || now >= m_height_time + 30) // re-cache every 30 seconds
|
||||
{
|
||||
cryptonote::COMMAND_RPC_GET_HEIGHT::request req = AUTO_VAL_INIT(req);
|
||||
cryptonote::COMMAND_RPC_GET_HEIGHT::response res = AUTO_VAL_INIT(res);
|
||||
|
||||
m_daemon_rpc_mutex.lock();
|
||||
bool r = net_utils::invoke_http_json("/getheight", req, res, m_http_client, rpc_timeout);
|
||||
m_daemon_rpc_mutex.unlock();
|
||||
CHECK_AND_ASSERT_MES(r, std::string(), "Failed to connect to daemon");
|
||||
CHECK_AND_ASSERT_MES(res.status != CORE_RPC_STATUS_BUSY, res.status, "Failed to connect to daemon");
|
||||
CHECK_AND_ASSERT_MES(res.status == CORE_RPC_STATUS_OK, res.status, "Failed to get current blockchain height");
|
||||
m_height = res.height;
|
||||
m_height_time = now;
|
||||
}
|
||||
height = m_height;
|
||||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
void NodeRPCProxy::set_height(uint64_t h)
|
||||
{
|
||||
m_height = h;
|
||||
}
|
||||
|
||||
boost::optional<std::string> NodeRPCProxy::get_target_height(uint64_t &height) const
|
||||
boost::optional<std::string> NodeRPCProxy::get_info() const
|
||||
{
|
||||
const time_t now = time(NULL);
|
||||
if (m_target_height == 0 || now >= m_target_height_time + 30) // re-cache every 30 seconds
|
||||
if (now >= m_get_info_time + 30) // re-cache every 30 seconds
|
||||
{
|
||||
cryptonote::COMMAND_RPC_GET_INFO::request req_t = AUTO_VAL_INIT(req_t);
|
||||
cryptonote::COMMAND_RPC_GET_INFO::response resp_t = AUTO_VAL_INIT(resp_t);
|
||||
|
@ -125,13 +97,41 @@ boost::optional<std::string> NodeRPCProxy::get_target_height(uint64_t &height) c
|
|||
CHECK_AND_ASSERT_MES(r, std::string(), "Failed to connect to daemon");
|
||||
CHECK_AND_ASSERT_MES(resp_t.status != CORE_RPC_STATUS_BUSY, resp_t.status, "Failed to connect to daemon");
|
||||
CHECK_AND_ASSERT_MES(resp_t.status == CORE_RPC_STATUS_OK, resp_t.status, "Failed to get target blockchain height");
|
||||
m_height = resp_t.height;
|
||||
m_target_height = resp_t.target_height;
|
||||
m_target_height_time = now;
|
||||
m_block_size_limit = resp_t.block_size_limit;
|
||||
m_get_info_time = now;
|
||||
}
|
||||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
boost::optional<std::string> NodeRPCProxy::get_height(uint64_t &height) const
|
||||
{
|
||||
auto res = get_info();
|
||||
if (res)
|
||||
return res;
|
||||
height = m_height;
|
||||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
boost::optional<std::string> NodeRPCProxy::get_target_height(uint64_t &height) const
|
||||
{
|
||||
auto res = get_info();
|
||||
if (res)
|
||||
return res;
|
||||
height = m_target_height;
|
||||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
boost::optional<std::string> NodeRPCProxy::get_block_size_limit(uint64_t &block_size_limit) const
|
||||
{
|
||||
auto res = get_info();
|
||||
if (res)
|
||||
return res;
|
||||
block_size_limit = m_block_size_limit;
|
||||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
boost::optional<std::string> NodeRPCProxy::get_earliest_height(uint8_t version, uint64_t &earliest_height) const
|
||||
{
|
||||
if (m_earliest_height[version] == 0)
|
||||
|
|
|
@ -47,22 +47,25 @@ public:
|
|||
boost::optional<std::string> get_height(uint64_t &height) const;
|
||||
void set_height(uint64_t h);
|
||||
boost::optional<std::string> get_target_height(uint64_t &height) const;
|
||||
boost::optional<std::string> get_block_size_limit(uint64_t &block_size_limit) const;
|
||||
boost::optional<std::string> get_earliest_height(uint8_t version, uint64_t &earliest_height) const;
|
||||
boost::optional<std::string> get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks, uint64_t &fee) const;
|
||||
|
||||
private:
|
||||
boost::optional<std::string> get_info() const;
|
||||
|
||||
epee::net_utils::http::http_simple_client &m_http_client;
|
||||
boost::mutex &m_daemon_rpc_mutex;
|
||||
|
||||
mutable uint64_t m_height;
|
||||
mutable time_t m_height_time;
|
||||
mutable uint64_t m_earliest_height[256];
|
||||
mutable uint64_t m_dynamic_per_kb_fee_estimate;
|
||||
mutable uint64_t m_dynamic_per_kb_fee_estimate_cached_height;
|
||||
mutable uint64_t m_dynamic_per_kb_fee_estimate_grace_blocks;
|
||||
mutable uint32_t m_rpc_version;
|
||||
mutable uint64_t m_target_height;
|
||||
mutable time_t m_target_height_time;
|
||||
mutable uint64_t m_block_size_limit;
|
||||
mutable time_t m_get_info_time;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -675,6 +675,7 @@ wallet2::wallet2(network_type nettype, bool restricted):
|
|||
m_segregate_pre_fork_outputs(true),
|
||||
m_key_reuse_mitigation2(true),
|
||||
m_segregation_height(0),
|
||||
m_ignore_fractional_outputs(true),
|
||||
m_is_initialized(false),
|
||||
m_restricted(restricted),
|
||||
is_old_file_format(false),
|
||||
|
@ -1834,7 +1835,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
|
|||
blocks_added = 0;
|
||||
|
||||
THROW_WALLET_EXCEPTION_IF(blocks.size() != parsed_blocks.size(), error::wallet_internal_error, "size mismatch");
|
||||
THROW_WALLET_EXCEPTION_IF(!m_blockchain.is_in_bounds(current_index), error::wallet_internal_error, "Index out of bounds of hashchain");
|
||||
THROW_WALLET_EXCEPTION_IF(!m_blockchain.is_in_bounds(current_index), error::out_of_hashchain_bounds_error);
|
||||
|
||||
tools::threadpool& tpool = tools::threadpool::getInstance();
|
||||
tools::threadpool::waiter waiter;
|
||||
|
@ -2280,12 +2281,12 @@ void wallet2::update_pool_state(bool refreshed)
|
|||
MDEBUG("update_pool_state end");
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history)
|
||||
void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, bool force)
|
||||
{
|
||||
std::vector<crypto::hash> hashes;
|
||||
|
||||
const uint64_t checkpoint_height = m_checkpoints.get_max_height();
|
||||
if (stop_height > checkpoint_height && m_blockchain.size()-1 < checkpoint_height)
|
||||
if ((stop_height > checkpoint_height && m_blockchain.size()-1 < checkpoint_height) && !force)
|
||||
{
|
||||
// we will drop all these, so don't bother getting them
|
||||
uint64_t missing_blocks = m_checkpoints.get_max_height() - m_blockchain.size();
|
||||
|
@ -2450,6 +2451,7 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
|
|||
std::vector<cryptonote::block_complete_entry> next_blocks;
|
||||
std::vector<parsed_block> next_parsed_blocks;
|
||||
bool error = false;
|
||||
added_blocks = 0;
|
||||
if (!first && blocks.empty())
|
||||
{
|
||||
refreshed = false;
|
||||
|
@ -2459,7 +2461,33 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
|
|||
|
||||
if (!first)
|
||||
{
|
||||
process_parsed_blocks(blocks_start_height, blocks, parsed_blocks, added_blocks);
|
||||
try
|
||||
{
|
||||
process_parsed_blocks(blocks_start_height, blocks, parsed_blocks, added_blocks);
|
||||
}
|
||||
catch (const tools::error::out_of_hashchain_bounds_error&)
|
||||
{
|
||||
MINFO("Daemon claims next refresh block is out of hash chain bounds, resetting hash chain");
|
||||
uint64_t stop_height = m_blockchain.offset();
|
||||
std::vector<crypto::hash> tip(m_blockchain.size() - m_blockchain.offset());
|
||||
for (size_t i = m_blockchain.offset(); i < m_blockchain.size(); ++i)
|
||||
tip[i - m_blockchain.offset()] = m_blockchain[i];
|
||||
cryptonote::block b;
|
||||
generate_genesis(b);
|
||||
m_blockchain.clear();
|
||||
m_blockchain.push_back(get_block_hash(b));
|
||||
short_chain_history.clear();
|
||||
get_short_chain_history(short_chain_history);
|
||||
fast_refresh(stop_height, blocks_start_height, short_chain_history, true);
|
||||
THROW_WALLET_EXCEPTION_IF(m_blockchain.size() != stop_height, error::wallet_internal_error, "Unexpected hashchain size");
|
||||
THROW_WALLET_EXCEPTION_IF(m_blockchain.offset() != 0, error::wallet_internal_error, "Unexpected hashchain offset");
|
||||
for (const auto &h: tip)
|
||||
m_blockchain.push_back(h);
|
||||
short_chain_history.clear();
|
||||
get_short_chain_history(short_chain_history);
|
||||
start_height = stop_height;
|
||||
throw std::runtime_error(""); // loop again
|
||||
}
|
||||
blocks_fetched += added_blocks;
|
||||
}
|
||||
waiter.wait(&tpool);
|
||||
|
@ -2489,6 +2517,7 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
|
|||
if(try_count < 3)
|
||||
{
|
||||
LOG_PRINT_L1("Another try pull_blocks (try_count=" << try_count << ")...");
|
||||
first = true;
|
||||
++try_count;
|
||||
}
|
||||
else
|
||||
|
@ -2811,6 +2840,9 @@ bool wallet2::store_keys(const std::string& keys_file_name, const epee::wipeable
|
|||
value2.SetUint(m_segregation_height);
|
||||
json.AddMember("segregation_height", value2, json.GetAllocator());
|
||||
|
||||
value2.SetInt(m_ignore_fractional_outputs ? 1 : 0);
|
||||
json.AddMember("ignore_fractional_outputs", value2, json.GetAllocator());
|
||||
|
||||
value2.SetUint(m_subaddress_lookahead_major);
|
||||
json.AddMember("subaddress_lookahead_major", value2, json.GetAllocator());
|
||||
|
||||
|
@ -2893,6 +2925,7 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
|
|||
m_segregate_pre_fork_outputs = true;
|
||||
m_key_reuse_mitigation2 = true;
|
||||
m_segregation_height = 0;
|
||||
m_ignore_fractional_outputs = true;
|
||||
m_subaddress_lookahead_major = SUBADDRESS_LOOKAHEAD_MAJOR;
|
||||
m_subaddress_lookahead_minor = SUBADDRESS_LOOKAHEAD_MINOR;
|
||||
m_key_on_device = false;
|
||||
|
@ -3019,6 +3052,8 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
|
|||
m_key_reuse_mitigation2 = field_key_reuse_mitigation2;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, segregation_height, int, Uint, false, 0);
|
||||
m_segregation_height = field_segregation_height;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, ignore_fractional_outputs, int, Int, false, true);
|
||||
m_ignore_fractional_outputs = field_ignore_fractional_outputs;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, subaddress_lookahead_major, uint32_t, Uint, false, SUBADDRESS_LOOKAHEAD_MAJOR);
|
||||
m_subaddress_lookahead_major = field_subaddress_lookahead_major;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, subaddress_lookahead_minor, uint32_t, Uint, false, SUBADDRESS_LOOKAHEAD_MINOR);
|
||||
|
@ -5599,15 +5634,10 @@ uint32_t wallet2::adjust_priority(uint32_t priority)
|
|||
}
|
||||
|
||||
// get the current full reward zone
|
||||
cryptonote::COMMAND_RPC_GET_INFO::request getinfo_req = AUTO_VAL_INIT(getinfo_req);
|
||||
cryptonote::COMMAND_RPC_GET_INFO::response getinfo_res = AUTO_VAL_INIT(getinfo_res);
|
||||
m_daemon_rpc_mutex.lock();
|
||||
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_info", getinfo_req, getinfo_res, m_http_client);
|
||||
m_daemon_rpc_mutex.unlock();
|
||||
THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "get_info");
|
||||
THROW_WALLET_EXCEPTION_IF(getinfo_res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_info");
|
||||
THROW_WALLET_EXCEPTION_IF(getinfo_res.status != CORE_RPC_STATUS_OK, error::get_tx_pool_error);
|
||||
const uint64_t full_reward_zone = getinfo_res.block_size_limit / 2;
|
||||
uint64_t block_size_limit = 0;
|
||||
const auto result = m_node_rpc_proxy.get_block_size_limit(block_size_limit);
|
||||
throw_on_rpc_response_error(result, "get_info");
|
||||
const uint64_t full_reward_zone = block_size_limit / 2;
|
||||
|
||||
// get the last N block headers and sum the block sizes
|
||||
const size_t N = 10;
|
||||
|
@ -5621,7 +5651,7 @@ uint32_t wallet2::adjust_priority(uint32_t priority)
|
|||
m_daemon_rpc_mutex.lock();
|
||||
getbh_req.start_height = m_blockchain.size() - N;
|
||||
getbh_req.end_height = m_blockchain.size() - 1;
|
||||
r = net_utils::invoke_http_json_rpc("/json_rpc", "getblockheadersrange", getbh_req, getbh_res, m_http_client, rpc_timeout);
|
||||
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "getblockheadersrange", getbh_req, getbh_res, m_http_client, rpc_timeout);
|
||||
m_daemon_rpc_mutex.unlock();
|
||||
THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getblockheadersrange");
|
||||
THROW_WALLET_EXCEPTION_IF(getbh_res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getblockheadersrange");
|
||||
|
@ -7677,12 +7707,24 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
|
|||
for (uint32_t i : subaddr_indices)
|
||||
LOG_PRINT_L2("Candidate subaddress index for spending: " << i);
|
||||
|
||||
// determine threshold for fractional amount
|
||||
const size_t tx_size_one_ring = estimate_tx_size(use_rct, 1, fake_outs_count, 2, 0, bulletproof);
|
||||
const size_t tx_size_two_rings = estimate_tx_size(use_rct, 2, fake_outs_count, 2, 0, bulletproof);
|
||||
THROW_WALLET_EXCEPTION_IF(tx_size_one_ring > tx_size_two_rings, error::wallet_internal_error, "Estimated tx size with 1 input is larger than with 2 inputs!");
|
||||
const size_t tx_size_per_ring = tx_size_two_rings - tx_size_one_ring;
|
||||
const uint64_t fractional_threshold = (fee_multiplier * fee_per_kb * tx_size_per_ring) / 1024;
|
||||
|
||||
// gather all dust and non-dust outputs belonging to specified subaddresses
|
||||
size_t num_nondust_outputs = 0;
|
||||
size_t num_dust_outputs = 0;
|
||||
for (size_t i = 0; i < m_transfers.size(); ++i)
|
||||
{
|
||||
const transfer_details& td = m_transfers[i];
|
||||
if (m_ignore_fractional_outputs && td.amount() < fractional_threshold)
|
||||
{
|
||||
MDEBUG("Ignoring output " << i << " of amount " << print_money(td.amount()) << " which is below threshold " << print_money(fractional_threshold));
|
||||
continue;
|
||||
}
|
||||
if (!td.m_spent && !td.m_key_image_partial && (use_rct ? true : !td.is_rct()) && is_transfer_unlocked(td) && td.m_subaddr_index.major == subaddr_account && subaddr_indices.count(td.m_subaddr_index.minor) == 1)
|
||||
{
|
||||
const uint32_t index_minor = td.m_subaddr_index.minor;
|
||||
|
@ -9392,31 +9434,15 @@ uint64_t wallet2::get_daemon_blockchain_height(string &err) const
|
|||
|
||||
uint64_t wallet2::get_daemon_blockchain_target_height(string &err)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_GET_INFO::request req_t = AUTO_VAL_INIT(req_t);
|
||||
cryptonote::COMMAND_RPC_GET_INFO::response resp_t = AUTO_VAL_INIT(resp_t);
|
||||
m_daemon_rpc_mutex.lock();
|
||||
bool ok = net_utils::invoke_http_json_rpc("/json_rpc", "get_info", req_t, resp_t, m_http_client);
|
||||
m_daemon_rpc_mutex.unlock();
|
||||
if (ok)
|
||||
err = "";
|
||||
uint64_t target_height = 0;
|
||||
const auto result = m_node_rpc_proxy.get_target_height(target_height);
|
||||
if (result && *result != CORE_RPC_STATUS_OK)
|
||||
{
|
||||
if (resp_t.status == CORE_RPC_STATUS_BUSY)
|
||||
{
|
||||
err = "daemon is busy. Please try again later.";
|
||||
}
|
||||
else if (resp_t.status != CORE_RPC_STATUS_OK)
|
||||
{
|
||||
err = resp_t.status;
|
||||
}
|
||||
else // success, cleaning up error message
|
||||
{
|
||||
err = "";
|
||||
}
|
||||
err= *result;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "possibly lost connection to daemon";
|
||||
}
|
||||
return resp_t.target_height;
|
||||
return target_height;
|
||||
}
|
||||
|
||||
uint64_t wallet2::get_approximate_blockchain_height() const
|
||||
|
@ -10767,15 +10793,10 @@ std::vector<std::pair<uint64_t, uint64_t>> wallet2::estimate_backlog(const std::
|
|||
THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_txpool_backlog");
|
||||
THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_tx_pool_error);
|
||||
|
||||
cryptonote::COMMAND_RPC_GET_INFO::request req_t = AUTO_VAL_INIT(req_t);
|
||||
cryptonote::COMMAND_RPC_GET_INFO::response resp_t = AUTO_VAL_INIT(resp_t);
|
||||
m_daemon_rpc_mutex.lock();
|
||||
r = net_utils::invoke_http_json_rpc("/json_rpc", "get_info", req_t, resp_t, m_http_client);
|
||||
m_daemon_rpc_mutex.unlock();
|
||||
THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "get_info");
|
||||
THROW_WALLET_EXCEPTION_IF(resp_t.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_info");
|
||||
THROW_WALLET_EXCEPTION_IF(resp_t.status != CORE_RPC_STATUS_OK, error::get_tx_pool_error);
|
||||
uint64_t full_reward_zone = resp_t.block_size_limit / 2;
|
||||
uint64_t block_size_limit = 0;
|
||||
const auto result = m_node_rpc_proxy.get_block_size_limit(block_size_limit);
|
||||
throw_on_rpc_response_error(result, "get_info");
|
||||
uint64_t full_reward_zone = block_size_limit / 2;
|
||||
|
||||
std::vector<std::pair<uint64_t, uint64_t>> blocks;
|
||||
for (const auto &fee_level: fee_levels)
|
||||
|
|
|
@ -940,6 +940,8 @@ namespace tools
|
|||
void key_reuse_mitigation2(bool value) { m_key_reuse_mitigation2 = value; }
|
||||
uint64_t segregation_height() const { return m_segregation_height; }
|
||||
void segregation_height(uint64_t height) { m_segregation_height = height; }
|
||||
bool ignore_fractional_outputs() const { return m_ignore_fractional_outputs; }
|
||||
void ignore_fractional_outputs(bool value) { m_ignore_fractional_outputs = value; }
|
||||
bool confirm_non_default_ring_size() const { return m_confirm_non_default_ring_size; }
|
||||
void confirm_non_default_ring_size(bool always) { m_confirm_non_default_ring_size = always; }
|
||||
|
||||
|
@ -1182,7 +1184,7 @@ namespace tools
|
|||
bool clear();
|
||||
void pull_blocks(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::vector<cryptonote::block_complete_entry> &blocks, std::vector<cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices> &o_indices);
|
||||
void pull_hashes(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::vector<crypto::hash> &hashes);
|
||||
void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history);
|
||||
void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, bool force = false);
|
||||
void pull_and_parse_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::vector<cryptonote::block_complete_entry> &prev_blocks, const std::vector<parsed_block> &prev_parsed_blocks, std::vector<cryptonote::block_complete_entry> &blocks, std::vector<parsed_block> &parsed_blocks, bool &error);
|
||||
void process_parsed_blocks(uint64_t start_height, const std::vector<cryptonote::block_complete_entry> &blocks, const std::vector<parsed_block> &parsed_blocks, uint64_t& blocks_added);
|
||||
uint64_t select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::vector<size_t>& selected_transfers, bool trusted_daemon) const;
|
||||
|
@ -1299,6 +1301,7 @@ namespace tools
|
|||
bool m_segregate_pre_fork_outputs;
|
||||
bool m_key_reuse_mitigation2;
|
||||
uint64_t m_segregation_height;
|
||||
bool m_ignore_fractional_outputs;
|
||||
bool m_is_initialized;
|
||||
NodeRPCProxy m_node_rpc_proxy;
|
||||
std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
|
||||
|
|
|
@ -70,6 +70,7 @@ namespace tools
|
|||
// get_out_indexes_error
|
||||
// tx_parse_error
|
||||
// get_tx_pool_error
|
||||
// out_of_hashchain_bounds_error
|
||||
// transfer_error *
|
||||
// get_random_outs_general_error
|
||||
// not_enough_unlocked_money
|
||||
|
@ -403,6 +404,16 @@ namespace tools
|
|||
std::string to_string() const { return refresh_error::to_string(); }
|
||||
};
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
struct out_of_hashchain_bounds_error : public refresh_error
|
||||
{
|
||||
explicit out_of_hashchain_bounds_error(std::string&& loc)
|
||||
: refresh_error(std::move(loc), "Index out of bounds of of hashchain")
|
||||
{
|
||||
}
|
||||
|
||||
std::string to_string() const { return refresh_error::to_string(); }
|
||||
};
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
struct transfer_error : public wallet_logic_error
|
||||
{
|
||||
protected:
|
||||
|
|
|
@ -96,6 +96,10 @@ macro(config_compiler_and_linker)
|
|||
set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0")
|
||||
set(cxx_strict_flags
|
||||
"-Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
set(cxx_base_flags "-Wall -Wshadow -fPIC")
|
||||
set(cxx_exception_flags "-fexceptions")
|
||||
set(cxx_no_exception_flags "-fno-exceptions")
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
|
||||
set(cxx_exception_flags "-features=except")
|
||||
# Sun Pro doesn't provide macros to indicate whether exceptions and
|
||||
|
|
|
@ -91,7 +91,6 @@ target_link_libraries(unit_tests
|
|||
wallet
|
||||
p2p
|
||||
version
|
||||
epee
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
${Boost_THREAD_LIBRARY}
|
||||
${GTEST_LIBRARIES}
|
||||
|
|
Loading…
Reference in a new issue