Skip to content

Commit

Permalink
wallet, simplewallet: Drop support for mine-to-use RPC system
Browse files Browse the repository at this point in the history
Using post-PR wallet with pre-PR node will generate error message specific to this PR and not generic "command failed" mesages.
  • Loading branch information
jeffro256 committed Feb 26, 2023
1 parent c5d10a4 commit ed16f53
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 1,018 deletions.
387 changes: 8 additions & 379 deletions src/simplewallet/simplewallet.cpp

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions src/simplewallet/simplewallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ namespace cryptonote
bool set_export_format(const std::vector<std::string> &args = std::vector<std::string>());
bool set_load_deprecated_formats(const std::vector<std::string> &args = std::vector<std::string>());
bool set_enable_multisig(const std::vector<std::string> &args = std::vector<std::string>());
bool set_persistent_rpc_client_id(const std::vector<std::string> &args = std::vector<std::string>());
bool set_auto_mine_for_rpc_payment_threshold(const std::vector<std::string> &args = std::vector<std::string>());
bool set_credits_target(const std::vector<std::string> &args = std::vector<std::string>());
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool apropos(const std::vector<std::string> &args);
bool scan_tx(const std::vector<std::string> &args);
Expand Down Expand Up @@ -258,9 +255,6 @@ namespace cryptonote
bool thaw(const std::vector<std::string>& args);
bool frozen(const std::vector<std::string>& args);
bool lock(const std::vector<std::string>& args);
bool rpc_payment_info(const std::vector<std::string> &args);
bool start_mining_for_rpc(const std::vector<std::string> &args);
bool stop_mining_for_rpc(const std::vector<std::string> &args);
bool show_qr_code(const std::vector<std::string> &args);
bool net_stats(const std::vector<std::string>& args);
bool public_nodes(const std::vector<std::string>& args);
Expand Down Expand Up @@ -338,7 +332,6 @@ namespace cryptonote
bool check_inactivity();
bool check_refresh();
bool check_mms();
bool check_rpc_payment();

void handle_transfer_exception(const std::exception_ptr &e, bool trusted_daemon);

Expand Down Expand Up @@ -458,17 +451,6 @@ namespace cryptonote
epee::math_helper::once_a_time_seconds<1> m_inactivity_checker;
epee::math_helper::once_a_time_seconds_range<get_random_interval<80 * 1000000, 100 * 1000000>> m_refresh_checker;
epee::math_helper::once_a_time_seconds_range<get_random_interval<90 * 1000000, 110 * 1000000>> m_mms_checker;
epee::math_helper::once_a_time_seconds_range<get_random_interval<90 * 1000000, 115 * 1000000>> m_rpc_payment_checker;

std::atomic<bool> m_need_payment;
boost::posix_time::ptime m_last_rpc_payment_mining_time;
bool m_rpc_payment_mining_requested;
uint32_t m_rpc_payment_threads = 0;
bool m_daemon_rpc_payment_message_displayed;
float m_rpc_payment_hash_rate;
std::atomic<bool> m_suspend_rpc_payment_mining;

std::unordered_map<std::string, uint32_t> m_claimed_cph;

// MMS
mms::message_store& get_message_store() const { return m_wallet->get_message_store(); };
Expand Down
1 change: 0 additions & 1 deletion src/wallet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ set(wallet_sources
node_rpc_proxy.cpp
message_store.cpp
message_transporter.cpp
wallet_rpc_payments.cpp
)

monero_find_all_headers(wallet_private_headers "${CMAKE_CURRENT_SOURCE_DIR}")
Expand Down
93 changes: 1 addition & 92 deletions src/wallet/node_rpc_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@

#include "node_rpc_proxy.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "rpc/rpc_payment_signature.h"
#include "rpc/rpc_payment_costs.h"
#include "storages/http_abstract_invoke.h"

#include <boost/thread.hpp>

#define RETURN_ON_RPC_RESPONSE_ERROR(r, error, res, method) \
do { \
CHECK_AND_ASSERT_MES(error.code == 0, error.message, error.message); \
handle_payment_changes(res, std::integral_constant<bool, HasCredits<decltype(res)>::Has>()); \
CHECK_AND_ASSERT_MES(r, std::string("Failed to connect to daemon"), "Failed to connect to daemon"); \
/* empty string -> not connection */ \
CHECK_AND_ASSERT_MES(!res.status.empty(), res.status, "No connection to daemon"); \
Expand All @@ -53,9 +50,8 @@ namespace tools

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

NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, rpc_payment_state_t &rpc_payment_state, boost::recursive_mutex &mutex)
NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, boost::recursive_mutex &mutex)
: m_http_client(http_client)
, m_rpc_payment_state(rpc_payment_state)
, m_daemon_rpc_mutex(mutex)
, m_offline(false)
{
Expand All @@ -77,16 +73,8 @@ void NodeRPCProxy::invalidate()
m_block_weight_limit = 0;
m_adjusted_time = 0;
m_get_info_time = 0;
m_rpc_payment_info_time = 0;
m_rpc_payment_seed_height = 0;
m_rpc_payment_seed_hash = crypto::null_hash;
m_rpc_payment_next_seed_hash = crypto::null_hash;
m_height_time = 0;
m_target_height_time = 0;
m_rpc_payment_diff = 0;
m_rpc_payment_credits_per_hash_found = 0;
m_rpc_payment_height = 0;
m_rpc_payment_cookie = 0;
m_daemon_hard_forks.clear();
}

Expand Down Expand Up @@ -147,11 +135,8 @@ boost::optional<std::string> NodeRPCProxy::get_info()

{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
uint64_t pre_call_credits = m_rpc_payment_state.credits;
req_t.client = cryptonote::make_rpc_payment_signature(m_client_id_secret_key);
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_info", req_t, resp_t, m_http_client, rpc_timeout);
RETURN_ON_RPC_RESPONSE_ERROR(r, epee::json_rpc::error{}, resp_t, "get_info");
check_rpc_cost(m_rpc_payment_state, "get_info", resp_t.credits, pre_call_credits, COST_PER_GET_INFO);
}

m_height = resp_t.height;
Expand Down Expand Up @@ -227,11 +212,8 @@ boost::optional<std::string> NodeRPCProxy::get_earliest_height(uint8_t version,

{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
uint64_t pre_call_credits = m_rpc_payment_state.credits;
req_t.client = cryptonote::make_rpc_payment_signature(m_client_id_secret_key);
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "hard_fork_info", req_t, resp_t, m_http_client, rpc_timeout);
RETURN_ON_RPC_RESPONSE_ERROR(r, epee::json_rpc::error{}, resp_t, "hard_fork_info");
check_rpc_cost(m_rpc_payment_state, "hard_fork_info", resp_t.credits, pre_call_credits, COST_PER_HARD_FORK_INFO);
}

m_earliest_height[version] = resp_t.earliest_height;
Expand Down Expand Up @@ -259,11 +241,8 @@ boost::optional<std::string> NodeRPCProxy::get_dynamic_base_fee_estimate_2021_sc

{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
uint64_t pre_call_credits = m_rpc_payment_state.credits;
req_t.client = cryptonote::make_rpc_payment_signature(m_client_id_secret_key);
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_fee_estimate", req_t, resp_t, m_http_client, rpc_timeout);
RETURN_ON_RPC_RESPONSE_ERROR(r, epee::json_rpc::error{}, resp_t, "get_fee_estimate");
check_rpc_cost(m_rpc_payment_state, "get_fee_estimate", resp_t.credits, pre_call_credits, COST_PER_FEE_ESTIMATE);
}

m_dynamic_base_fee_estimate = resp_t.fee;
Expand Down Expand Up @@ -305,11 +284,8 @@ boost::optional<std::string> NodeRPCProxy::get_fee_quantization_mask(uint64_t &f

{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
uint64_t pre_call_credits = m_rpc_payment_state.credits;
req_t.client = cryptonote::make_rpc_payment_signature(m_client_id_secret_key);
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_fee_estimate", req_t, resp_t, m_http_client, rpc_timeout);
RETURN_ON_RPC_RESPONSE_ERROR(r, epee::json_rpc::error{}, resp_t, "get_fee_estimate");
check_rpc_cost(m_rpc_payment_state, "get_fee_estimate", resp_t.credits, pre_call_credits, COST_PER_FEE_ESTIMATE);
}

m_dynamic_base_fee_estimate = resp_t.fee;
Expand All @@ -325,71 +301,4 @@ boost::optional<std::string> NodeRPCProxy::get_fee_quantization_mask(uint64_t &f
}
return boost::optional<std::string>();
}

boost::optional<std::string> NodeRPCProxy::get_rpc_payment_info(bool mining, bool &payment_required, uint64_t &credits, uint64_t &diff, uint64_t &credits_per_hash_found, cryptonote::blobdata &blob, uint64_t &height, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, uint32_t &cookie)
{
const time_t now = time(NULL);
if (m_rpc_payment_state.stale || now >= m_rpc_payment_info_time + 5*60 || (mining && now >= m_rpc_payment_info_time + 10)) // re-cache every 10 seconds if mining, 5 minutes otherwise
{
cryptonote::COMMAND_RPC_ACCESS_INFO::request req_t = AUTO_VAL_INIT(req_t);
cryptonote::COMMAND_RPC_ACCESS_INFO::response resp_t = AUTO_VAL_INIT(resp_t);

{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
req_t.client = cryptonote::make_rpc_payment_signature(m_client_id_secret_key);
bool r = net_utils::invoke_http_json_rpc("/json_rpc", "rpc_access_info", req_t, resp_t, m_http_client, rpc_timeout);
RETURN_ON_RPC_RESPONSE_ERROR(r, epee::json_rpc::error{}, resp_t, "rpc_access_info");
m_rpc_payment_state.stale = false;
}

m_rpc_payment_diff = resp_t.diff;
m_rpc_payment_credits_per_hash_found = resp_t.credits_per_hash_found;
m_rpc_payment_height = resp_t.height;
m_rpc_payment_seed_height = resp_t.seed_height;
m_rpc_payment_cookie = resp_t.cookie;

if (m_rpc_payment_diff == 0)
{
// If no payment required daemon doesn't give us back a hashing blob
m_rpc_payment_blob.clear();
}
else if (!epee::string_tools::parse_hexstr_to_binbuff(resp_t.hashing_blob, m_rpc_payment_blob) || m_rpc_payment_blob.size() < 43)
{
MERROR("Invalid hashing blob: " << resp_t.hashing_blob);
return std::string("Invalid hashing blob");
}
if (resp_t.seed_hash.empty())
{
m_rpc_payment_seed_hash = crypto::null_hash;
}
else if (!epee::string_tools::hex_to_pod(resp_t.seed_hash, m_rpc_payment_seed_hash))
{
MERROR("Invalid seed_hash: " << resp_t.seed_hash);
return std::string("Invalid seed hash");
}
if (resp_t.next_seed_hash.empty())
{
m_rpc_payment_next_seed_hash = crypto::null_hash;
}
else if (!epee::string_tools::hex_to_pod(resp_t.next_seed_hash, m_rpc_payment_next_seed_hash))
{
MERROR("Invalid next_seed_hash: " << resp_t.next_seed_hash);
return std::string("Invalid next seed hash");
}
m_rpc_payment_info_time = now;
}

payment_required = m_rpc_payment_diff > 0;
credits = m_rpc_payment_state.credits;
diff = m_rpc_payment_diff;
credits_per_hash_found = m_rpc_payment_credits_per_hash_found;
blob = m_rpc_payment_blob;
height = m_rpc_payment_height;
seed_height = m_rpc_payment_seed_height;
seed_hash = m_rpc_payment_seed_hash;
next_seed_hash = m_rpc_payment_next_seed_hash;
cookie = m_rpc_payment_cookie;
return boost::none;
}

}
28 changes: 1 addition & 27 deletions src/wallet/node_rpc_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@
#include "include_base_utils.h"
#include "net/abstract_http_client.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "wallet_rpc_helpers.h"

namespace tools
{

class NodeRPCProxy
{
public:
NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, rpc_payment_state_t &rpc_payment_state, boost::recursive_mutex &mutex);
NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, boost::recursive_mutex &mutex);

void set_client_secret_key(const crypto::secret_key &skey) { m_client_id_secret_key = skey; }
void invalidate();
void set_offline(bool offline) { m_offline = offline; }

Expand All @@ -58,27 +56,12 @@ class NodeRPCProxy
boost::optional<std::string> get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee);
boost::optional<std::string> get_dynamic_base_fee_estimate_2021_scaling(uint64_t grace_blocks, std::vector<uint64_t> &fees);
boost::optional<std::string> get_fee_quantization_mask(uint64_t &fee_quantization_mask);
boost::optional<std::string> get_rpc_payment_info(bool mining, bool &payment_required, uint64_t &credits, uint64_t &diff, uint64_t &credits_per_hash_found, cryptonote::blobdata &blob, uint64_t &height, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, uint32_t &cookie);

private:
template<typename T> void handle_payment_changes(const T &res, std::true_type) {
if (res.status == CORE_RPC_STATUS_OK || res.status == CORE_RPC_STATUS_PAYMENT_REQUIRED)
m_rpc_payment_state.credits = res.credits;
if (res.top_hash != m_rpc_payment_state.top_hash)
{
m_rpc_payment_state.top_hash = res.top_hash;
m_rpc_payment_state.stale = true;
}
}
template<typename T> void handle_payment_changes(const T &res, std::false_type) {}

private:
boost::optional<std::string> get_info();

epee::net_utils::http::abstract_http_client &m_http_client;
rpc_payment_state_t &m_rpc_payment_state;
boost::recursive_mutex &m_daemon_rpc_mutex;
crypto::secret_key m_client_id_secret_key;
bool m_offline;

uint64_t m_height;
Expand All @@ -93,15 +76,6 @@ class NodeRPCProxy
uint64_t m_target_height;
uint64_t m_block_weight_limit;
time_t m_get_info_time;
time_t m_rpc_payment_info_time;
uint64_t m_rpc_payment_diff;
uint64_t m_rpc_payment_credits_per_hash_found;
cryptonote::blobdata m_rpc_payment_blob;
uint64_t m_rpc_payment_height;
uint64_t m_rpc_payment_seed_height;
crypto::hash m_rpc_payment_seed_hash;
crypto::hash m_rpc_payment_next_seed_hash;
uint32_t m_rpc_payment_cookie;
time_t m_height_time;
time_t m_target_height_time;
std::vector<std::pair<uint8_t, uint64_t>> m_daemon_hard_forks;
Expand Down
Loading

0 comments on commit ed16f53

Please sign in to comment.