mirror of
https://git.wownero.com/wownero/wownero.git
synced 2025-01-04 22:38:53 +00:00
commit
c074baee61
@ -50,7 +50,7 @@
|
||||
|
||||
void *memwipe(void *ptr, size_t n)
|
||||
{
|
||||
if (memset_s(ptr, n, 0, n))
|
||||
if (n > 0 && memset_s(ptr, n, 0, n))
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
fprintf(stderr, "Error: memset_s failed\n");
|
||||
@ -67,7 +67,8 @@ void *memwipe(void *ptr, size_t n)
|
||||
|
||||
void *memwipe(void *ptr, size_t n)
|
||||
{
|
||||
explicit_bzero(ptr, n);
|
||||
if (n > 0)
|
||||
explicit_bzero(ptr, n);
|
||||
SCARECROW
|
||||
return ptr;
|
||||
}
|
||||
@ -105,7 +106,8 @@ static void memory_cleanse(void *ptr, size_t len)
|
||||
|
||||
void *memwipe(void *ptr, size_t n)
|
||||
{
|
||||
memory_cleanse(ptr, n);
|
||||
if (n > 0)
|
||||
memory_cleanse(ptr, n);
|
||||
SCARECROW
|
||||
return ptr;
|
||||
}
|
||||
|
@ -1506,6 +1506,13 @@ public:
|
||||
*/
|
||||
virtual bool is_read_only() const = 0;
|
||||
|
||||
/**
|
||||
* @brief get disk space requirements
|
||||
*
|
||||
* @return the size required
|
||||
*/
|
||||
virtual uint64_t get_database_size() const = 0;
|
||||
|
||||
// TODO: this should perhaps be (or call) a series of functions which
|
||||
// progressively update through version updates
|
||||
/**
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <random>
|
||||
|
||||
#include "string_tools.h"
|
||||
#include "file_io_utils.h"
|
||||
#include "common/util.h"
|
||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||
#include "crypto/crypto.h"
|
||||
@ -1336,6 +1337,9 @@ void BlockchainLMDB::sync()
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
if (is_read_only())
|
||||
return;
|
||||
|
||||
// Does nothing unless LMDB environment was opened with MDB_NOSYNC or in part
|
||||
// MDB_NOMETASYNC. Force flush to be synchronous.
|
||||
if (auto result = mdb_env_sync(m_env, true))
|
||||
@ -3293,6 +3297,16 @@ bool BlockchainLMDB::is_read_only() const
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t BlockchainLMDB::get_database_size() const
|
||||
{
|
||||
uint64_t size = 0;
|
||||
boost::filesystem::path datafile(m_folder);
|
||||
datafile /= CRYPTONOTE_BLOCKCHAINDATA_FILENAME;
|
||||
if (!epee::file_io_utils::get_file_size(datafile.string(), size))
|
||||
size = 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
void BlockchainLMDB::fixup()
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
|
@ -157,7 +157,7 @@ struct mdb_txn_safe
|
||||
class BlockchainLMDB : public BlockchainDB
|
||||
{
|
||||
public:
|
||||
BlockchainLMDB(bool batch_transactions=false);
|
||||
BlockchainLMDB(bool batch_transactions=true);
|
||||
~BlockchainLMDB();
|
||||
|
||||
virtual void open(const std::string& filename, const int mdb_flags=0);
|
||||
@ -364,6 +364,8 @@ private:
|
||||
|
||||
virtual bool is_read_only() const;
|
||||
|
||||
virtual uint64_t get_database_size() const;
|
||||
|
||||
// fix up anything that may be wrong due to past bugs
|
||||
virtual void fixup();
|
||||
|
||||
|
@ -78,7 +78,6 @@ monero_add_library(common
|
||||
DEPENDS generate_translations_header)
|
||||
target_link_libraries(common
|
||||
PUBLIC
|
||||
epee
|
||||
cncrypto
|
||||
${UNBOUND_LIBRARY}
|
||||
${LIBUNWIND_LIBRARIES}
|
||||
|
@ -485,7 +485,7 @@ namespace cryptonote
|
||||
{
|
||||
//we lucky!
|
||||
++m_config.current_extra_message_index;
|
||||
MGINFO_GREEN("Found block for difficulty: " << local_diff);
|
||||
MGINFO_GREEN("Found block " << get_block_hash(b) << " at height " << height << " for difficulty: " << local_diff);
|
||||
if(!m_phandler->handle_block_found(b))
|
||||
{
|
||||
--m_config.current_extra_message_index;
|
||||
|
@ -3298,6 +3298,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;
|
||||
@ -3598,6 +3599,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;
|
||||
}
|
||||
@ -3627,6 +3629,7 @@ leave:
|
||||
|
||||
// appears to be a NOP *and* is called elsewhere. wat?
|
||||
m_tx_pool.on_blockchain_inc(new_height, id);
|
||||
get_difficulty_for_next_block(); // just to cache it
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -4396,9 +4399,9 @@ std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> Blockchain:: get_ou
|
||||
return m_db->get_output_histogram(amounts, unlocked, recent_cutoff, min_count);
|
||||
}
|
||||
|
||||
std::list<std::pair<Blockchain::block_extended_info,uint64_t>> Blockchain::get_alternative_chains() const
|
||||
std::list<std::pair<Blockchain::block_extended_info,std::vector<crypto::hash>>> Blockchain::get_alternative_chains() const
|
||||
{
|
||||
std::list<std::pair<Blockchain::block_extended_info,uint64_t>> chains;
|
||||
std::list<std::pair<Blockchain::block_extended_info,std::vector<crypto::hash>>> chains;
|
||||
|
||||
for (const auto &i: m_alternative_chains)
|
||||
{
|
||||
@ -4414,15 +4417,16 @@ std::list<std::pair<Blockchain::block_extended_info,uint64_t>> Blockchain::get_a
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
uint64_t length = 1;
|
||||
std::vector<crypto::hash> chain;
|
||||
auto h = i.second.bl.prev_id;
|
||||
chain.push_back(top);
|
||||
blocks_ext_by_hash::const_iterator prev;
|
||||
while ((prev = m_alternative_chains.find(h)) != m_alternative_chains.end())
|
||||
{
|
||||
chain.push_back(h);
|
||||
h = prev->second.bl.prev_id;
|
||||
++length;
|
||||
}
|
||||
chains.push_back(std::make_pair(i.second, length));
|
||||
chains.push_back(std::make_pair(i.second, chain));
|
||||
}
|
||||
}
|
||||
return chains;
|
||||
|
@ -929,7 +929,7 @@ namespace cryptonote
|
||||
*
|
||||
* @return a list of chains
|
||||
*/
|
||||
std::list<std::pair<block_extended_info,uint64_t>> get_alternative_chains() const;
|
||||
std::list<std::pair<block_extended_info,std::vector<crypto::hash>>> get_alternative_chains() const;
|
||||
|
||||
void add_txpool_tx(transaction &tx, const txpool_tx_meta_t &meta);
|
||||
void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta);
|
||||
|
@ -92,7 +92,6 @@ target_link_libraries(daemon
|
||||
daemonizer
|
||||
serialization
|
||||
daemon_rpc_server
|
||||
epee
|
||||
${EPEE_READLINE}
|
||||
version
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
|
@ -599,13 +599,13 @@ bool t_command_parser_executor::print_coinbase_tx_sum(const std::vector<std::str
|
||||
|
||||
bool t_command_parser_executor::alt_chain_info(const std::vector<std::string>& args)
|
||||
{
|
||||
if(args.size())
|
||||
if(args.size() > 1)
|
||||
{
|
||||
std::cout << "No parameters allowed" << std::endl;
|
||||
std::cout << "usage: alt_chain_info [block_hash]" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_executor.alt_chain_info();
|
||||
return m_executor.alt_chain_info(args.size() == 1 ? args[0] : "");
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_blockchain_dynamic_stats(const std::vector<std::string>& args)
|
||||
|
@ -255,6 +255,7 @@ t_command_server::t_command_server(
|
||||
m_command_lookup.set_handler(
|
||||
"alt_chain_info"
|
||||
, std::bind(&t_command_parser_executor::alt_chain_info, &m_parser, p::_1)
|
||||
, "alt_chain_info [blockhash]"
|
||||
, "Print the information about alternative chains."
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
|
@ -1625,7 +1625,7 @@ bool t_rpc_command_executor::print_coinbase_tx_sum(uint64_t height, uint64_t cou
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::alt_chain_info()
|
||||
bool t_rpc_command_executor::alt_chain_info(const std::string &tip)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
|
||||
cryptonote::COMMAND_RPC_GET_INFO::response ires;
|
||||
@ -1660,12 +1660,32 @@ bool t_rpc_command_executor::alt_chain_info()
|
||||
}
|
||||
}
|
||||
|
||||
tools::msg_writer() << boost::lexical_cast<std::string>(res.chains.size()) << " alternate chains found:";
|
||||
for (const auto &chain: res.chains)
|
||||
if (tip.empty())
|
||||
{
|
||||
uint64_t start_height = (chain.height - chain.length + 1);
|
||||
tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)
|
||||
<< " deep), diff " << chain.difficulty << ": " << chain.block_hash;
|
||||
tools::msg_writer() << boost::lexical_cast<std::string>(res.chains.size()) << " alternate chains found:";
|
||||
for (const auto &chain: res.chains)
|
||||
{
|
||||
uint64_t start_height = (chain.height - chain.length + 1);
|
||||
tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)
|
||||
<< " deep), diff " << chain.difficulty << ": " << chain.block_hash;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto i = std::find_if(res.chains.begin(), res.chains.end(), [&tip](cryptonote::COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info &info){ return info.block_hash == tip; });
|
||||
if (i != res.chains.end())
|
||||
{
|
||||
const auto &chain = *i;
|
||||
tools::success_msg_writer() << "Found alternate chain with tip " << tip;
|
||||
uint64_t start_height = (chain.height - chain.length + 1);
|
||||
tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)
|
||||
<< " deep), diff " << chain.difficulty << ":";
|
||||
for (const std::string &block_id: chain.block_hashes)
|
||||
tools::msg_writer() << " " << block_id;
|
||||
tools::msg_writer() << "Chain parent on main chain: " << chain.main_chain_parent_block;
|
||||
}
|
||||
else
|
||||
tools::fail_msg_writer() << "Block hash " << tip << " is not the tip of any known alternate chain";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public:
|
||||
|
||||
bool print_coinbase_tx_sum(uint64_t height, uint64_t count);
|
||||
|
||||
bool alt_chain_info();
|
||||
bool alt_chain_info(const std::string &tip);
|
||||
|
||||
bool print_blockchain_dynamic_stats(uint64_t nblocks);
|
||||
|
||||
|
@ -38,7 +38,6 @@ source_group(p2p FILES ${P2P})
|
||||
monero_add_library(p2p ${P2P})
|
||||
target_link_libraries(p2p
|
||||
PUBLIC
|
||||
epee
|
||||
version
|
||||
cryptonote_core
|
||||
${UPNP_LIBRARIES}
|
||||
|
@ -111,7 +111,6 @@ target_link_libraries(rpc
|
||||
common
|
||||
cryptonote_core
|
||||
cryptonote_protocol
|
||||
epee
|
||||
${Boost_REGEX_LIBRARY}
|
||||
${Boost_THREAD_LIBRARY}
|
||||
PRIVATE
|
||||
|
@ -207,6 +207,7 @@ namespace cryptonote
|
||||
boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
|
||||
res.was_bootstrap_ever_used = m_was_bootstrap_ever_used;
|
||||
}
|
||||
res.database_size = m_core.get_blockchain_storage().get_db().get_database_size();
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -1591,6 +1592,7 @@ namespace cryptonote
|
||||
boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
|
||||
res.was_bootstrap_ever_used = m_was_bootstrap_ever_used;
|
||||
}
|
||||
res.database_size = m_core.get_blockchain_storage().get_db().get_database_size();
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -1788,10 +1790,22 @@ namespace cryptonote
|
||||
PERF_TIMER(on_get_alternate_chains);
|
||||
try
|
||||
{
|
||||
std::list<std::pair<Blockchain::block_extended_info, uint64_t>> chains = m_core.get_blockchain_storage().get_alternative_chains();
|
||||
std::list<std::pair<Blockchain::block_extended_info, std::vector<crypto::hash>>> chains = m_core.get_blockchain_storage().get_alternative_chains();
|
||||
for (const auto &i: chains)
|
||||
{
|
||||
res.chains.push_back(COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info{epee::string_tools::pod_to_hex(get_block_hash(i.first.bl)), i.first.height, i.second, i.first.cumulative_difficulty});
|
||||
res.chains.push_back(COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info{epee::string_tools::pod_to_hex(get_block_hash(i.first.bl)), i.first.height, i.second.size(), i.first.cumulative_difficulty, {}, std::string()});
|
||||
res.chains.back().block_hashes.reserve(i.second.size());
|
||||
for (const crypto::hash &block_id: i.second)
|
||||
res.chains.back().block_hashes.push_back(epee::string_tools::pod_to_hex(block_id));
|
||||
if (i.first.height < i.second.size())
|
||||
{
|
||||
res.status = "Error finding alternate chain attachment point";
|
||||
return true;
|
||||
}
|
||||
cryptonote::block main_chain_parent_block;
|
||||
try { main_chain_parent_block = m_core.get_blockchain_storage().get_db().get_block_from_height(i.first.height - i.second.size()); }
|
||||
catch (const std::exception &e) { res.status = "Error finding alternate chain attachment point"; return true; }
|
||||
res.chains.back().main_chain_parent_block = epee::string_tools::pod_to_hex(get_block_hash(main_chain_parent_block));
|
||||
}
|
||||
res.status = CORE_RPC_STATUS_OK;
|
||||
}
|
||||
|
@ -964,6 +964,7 @@ namespace cryptonote
|
||||
std::string bootstrap_daemon_address;
|
||||
uint64_t height_without_bootstrap;
|
||||
bool was_bootstrap_ever_used;
|
||||
uint64_t database_size;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
@ -993,6 +994,7 @@ namespace cryptonote
|
||||
KV_SERIALIZE(bootstrap_daemon_address)
|
||||
KV_SERIALIZE(height_without_bootstrap)
|
||||
KV_SERIALIZE(was_bootstrap_ever_used)
|
||||
KV_SERIALIZE(database_size)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
@ -2075,12 +2077,16 @@ namespace cryptonote
|
||||
uint64_t height;
|
||||
uint64_t length;
|
||||
uint64_t difficulty;
|
||||
std::vector<std::string> block_hashes;
|
||||
std::string main_chain_parent_block;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(block_hash)
|
||||
KV_SERIALIZE(height)
|
||||
KV_SERIALIZE(length)
|
||||
KV_SERIALIZE(difficulty)
|
||||
KV_SERIALIZE(block_hashes)
|
||||
KV_SERIALIZE(main_chain_parent_block)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
@ -48,7 +48,6 @@ target_link_libraries(simplewallet
|
||||
cncrypto
|
||||
common
|
||||
mnemonics
|
||||
epee
|
||||
${EPEE_READLINE}
|
||||
version
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
|
@ -4108,12 +4108,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)
|
||||
|
@ -85,7 +85,6 @@ monero_add_executable(wallet_rpc_server
|
||||
target_link_libraries(wallet_rpc_server
|
||||
PRIVATE
|
||||
wallet
|
||||
epee
|
||||
rpc_base
|
||||
cryptonote_core
|
||||
cncrypto
|
||||
|
@ -1740,7 +1740,7 @@ void WalletImpl::refreshThreadFunc()
|
||||
// if auto refresh enabled, we wait for the "m_refreshIntervalSeconds" interval.
|
||||
// if not - we wait forever
|
||||
if (m_refreshIntervalMillis > 0) {
|
||||
boost::posix_time::milliseconds wait_for_ms(m_refreshIntervalMillis);
|
||||
boost::posix_time::milliseconds wait_for_ms(m_refreshIntervalMillis.load());
|
||||
m_refreshCV.timed_wait(lock, wait_for_ms);
|
||||
} else {
|
||||
m_refreshCV.wait(lock);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1028,6 +1028,16 @@ void wallet2::check_acc_out_precomp(const tx_out &o, const crypto::key_derivatio
|
||||
tx_scan_info.error = false;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::check_acc_out_precomp_once(const tx_out &o, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, size_t i, tx_scan_info_t &tx_scan_info, bool &already_seen) const
|
||||
{
|
||||
tx_scan_info.received = boost::none;
|
||||
if (already_seen)
|
||||
return;
|
||||
check_acc_out_precomp(o, derivation, additional_derivations, i, tx_scan_info);
|
||||
if (tx_scan_info.received)
|
||||
already_seen = true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
static uint64_t decodeRct(const rct::rctSig & rv, const crypto::key_derivation &derivation, unsigned int i, rct::key & mask, hw::device &hwdev)
|
||||
{
|
||||
crypto::secret_key scalar1;
|
||||
@ -1108,7 +1118,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||
// Don't try to extract tx public key if tx has no ouputs
|
||||
size_t pk_index = 0;
|
||||
std::vector<tx_scan_info_t> tx_scan_info(tx.vout.size());
|
||||
std::unordered_set<crypto::public_key> public_keys_seen;
|
||||
std::deque<bool> output_found(tx.vout.size(), false);
|
||||
while (!tx.vout.empty())
|
||||
{
|
||||
// if tx.vout is not empty, we loop through all tx pubkeys
|
||||
@ -1124,13 +1134,6 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||
break;
|
||||
}
|
||||
|
||||
if (public_keys_seen.find(pub_key_field.pub_key) != public_keys_seen.end())
|
||||
{
|
||||
MWARNING("The same transaction pubkey is present more than once, ignoring extra instance");
|
||||
continue;
|
||||
}
|
||||
public_keys_seen.insert(pub_key_field.pub_key);
|
||||
|
||||
int num_vouts_received = 0;
|
||||
tx_pub_key = pub_key_field.pub_key;
|
||||
tools::threadpool& tpool = tools::threadpool::getInstance();
|
||||
@ -1170,7 +1173,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||
}
|
||||
else if (miner_tx && m_refresh_type == RefreshOptimizeCoinbase)
|
||||
{
|
||||
check_acc_out_precomp(tx.vout[0], derivation, additional_derivations, 0, tx_scan_info[0]);
|
||||
check_acc_out_precomp_once(tx.vout[0], derivation, additional_derivations, 0, tx_scan_info[0], output_found[0]);
|
||||
THROW_WALLET_EXCEPTION_IF(tx_scan_info[0].error, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys());
|
||||
|
||||
// this assumes that the miner tx pays a single address
|
||||
@ -1180,8 +1183,8 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||
// the first one was already checked
|
||||
for (size_t i = 1; i < tx.vout.size(); ++i)
|
||||
{
|
||||
tpool.submit(&waiter, boost::bind(&wallet2::check_acc_out_precomp, this, std::cref(tx.vout[i]), std::cref(derivation), std::cref(additional_derivations), i,
|
||||
std::ref(tx_scan_info[i])));
|
||||
tpool.submit(&waiter, boost::bind(&wallet2::check_acc_out_precomp_once, this, std::cref(tx.vout[i]), std::cref(derivation), std::cref(additional_derivations), i,
|
||||
std::ref(tx_scan_info[i]), std::ref(output_found[i])));
|
||||
}
|
||||
waiter.wait();
|
||||
// then scan all outputs from 0
|
||||
@ -1203,8 +1206,8 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||
{
|
||||
for (size_t i = 0; i < tx.vout.size(); ++i)
|
||||
{
|
||||
tpool.submit(&waiter, boost::bind(&wallet2::check_acc_out_precomp, this, std::cref(tx.vout[i]), std::cref(derivation), std::cref(additional_derivations), i,
|
||||
std::ref(tx_scan_info[i])));
|
||||
tpool.submit(&waiter, boost::bind(&wallet2::check_acc_out_precomp_once, this, std::cref(tx.vout[i]), std::cref(derivation), std::cref(additional_derivations), i,
|
||||
std::ref(tx_scan_info[i]), std::ref(output_found[i])));
|
||||
}
|
||||
waiter.wait();
|
||||
|
||||
@ -1225,7 +1228,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||
{
|
||||
for (size_t i = 0; i < tx.vout.size(); ++i)
|
||||
{
|
||||
check_acc_out_precomp(tx.vout[i], derivation, additional_derivations, i, tx_scan_info[i]);
|
||||
check_acc_out_precomp_once(tx.vout[i], derivation, additional_derivations, i, tx_scan_info[i], output_found[i]);
|
||||
THROW_WALLET_EXCEPTION_IF(tx_scan_info[i].error, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys());
|
||||
if (tx_scan_info[i].received)
|
||||
{
|
||||
@ -5353,15 +5356,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;
|
||||
@ -5375,7 +5373,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");
|
||||
@ -9129,31 +9127,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
|
||||
@ -10395,15 +10377,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)
|
||||
|
@ -1110,6 +1110,7 @@ namespace tools
|
||||
bool generate_chacha_key_from_secret_keys(crypto::chacha_key &key) const;
|
||||
crypto::hash get_payment_id(const pending_tx &ptx) const;
|
||||
void check_acc_out_precomp(const cryptonote::tx_out &o, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, size_t i, tx_scan_info_t &tx_scan_info) const;
|
||||
void check_acc_out_precomp_once(const cryptonote::tx_out &o, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, size_t i, tx_scan_info_t &tx_scan_info, bool &already_seen) const;
|
||||
void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
|
||||
uint64_t get_upper_transaction_size_limit() const;
|
||||
std::vector<uint64_t> get_unspent_amounts_vector() const;
|
||||
|
@ -86,7 +86,6 @@ target_link_libraries(unit_tests
|
||||
wallet
|
||||
p2p
|
||||
version
|
||||
epee
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
${Boost_THREAD_LIBRARY}
|
||||
${GTEST_LIBRARIES}
|
||||
|
@ -122,6 +122,7 @@ public:
|
||||
virtual void remove_txpool_tx(const crypto::hash& txid) {}
|
||||
virtual bool get_txpool_tx_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const { return false; }
|
||||
virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; }
|
||||
virtual uint64_t get_database_size() const { return 0; }
|
||||
virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; }
|
||||
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user