aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-30 19:21:30 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-04-04 18:10:45 +0000
commita2561653cbcba96e7e2dd352b9e0ea57cd220b2c (patch)
treeb41ef6e9785ddd3b46aa3aafff90605a8adc9b11 /src/wallet
parentMerge pull request #5318 (diff)
downloadmonero-a2561653cbcba96e7e2dd352b9e0ea57cd220b2c.tar.xz
wallet: new option to start background mining
The setup-background-mining option can be used to select background mining when a wallet loads. The user will be asked the first time the wallet is created.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp7
-rw-r--r--src/wallet/wallet2.h9
-rw-r--r--src/wallet/wallet_rpc_server.cpp56
-rw-r--r--src/wallet/wallet_rpc_server.h2
4 files changed, 74 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index d59ded49f..2ea1d8653 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -1032,6 +1032,7 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended):
m_segregation_height(0),
m_ignore_fractional_outputs(true),
m_track_uses(false),
+ m_setup_background_mining(BackgroundMiningMaybe),
m_is_initialized(false),
m_kdf_rounds(kdf_rounds),
is_old_file_format(false),
@@ -3514,6 +3515,9 @@ bool wallet2::store_keys(const std::string& keys_file_name, const epee::wipeable
value2.SetInt(m_track_uses ? 1 : 0);
json.AddMember("track_uses", value2, json.GetAllocator());
+ value2.SetInt(m_setup_background_mining);
+ json.AddMember("setup_background_mining", value2, json.GetAllocator());
+
value2.SetUint(m_subaddress_lookahead_major);
json.AddMember("subaddress_lookahead_major", value2, json.GetAllocator());
@@ -3662,6 +3666,7 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
m_segregation_height = 0;
m_ignore_fractional_outputs = true;
m_track_uses = false;
+ m_setup_background_mining = BackgroundMiningMaybe;
m_subaddress_lookahead_major = SUBADDRESS_LOOKAHEAD_MAJOR;
m_subaddress_lookahead_minor = SUBADDRESS_LOOKAHEAD_MINOR;
m_original_keys_available = false;
@@ -3816,6 +3821,8 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
m_ignore_fractional_outputs = field_ignore_fractional_outputs;
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, track_uses, int, Int, false, false);
m_track_uses = field_track_uses;
+ GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, setup_background_mining, BackgroundMiningSetupType, Int, false, BackgroundMiningMaybe);
+ m_setup_background_mining = field_setup_background_mining;
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);
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 5a67c20d0..4a3f6c7d9 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -194,6 +194,12 @@ namespace tools
AskPasswordToDecrypt = 2,
};
+ enum BackgroundMiningSetupType {
+ BackgroundMiningMaybe = 0,
+ BackgroundMiningYes = 1,
+ BackgroundMiningNo = 2,
+ };
+
static const char* tr(const char* str);
static bool has_testnet_option(const boost::program_options::variables_map& vm);
@@ -1008,6 +1014,8 @@ namespace tools
void confirm_non_default_ring_size(bool always) { m_confirm_non_default_ring_size = always; }
bool track_uses() const { return m_track_uses; }
void track_uses(bool value) { m_track_uses = value; }
+ BackgroundMiningSetupType setup_background_mining() const { return m_setup_background_mining; }
+ void setup_background_mining(BackgroundMiningSetupType value) { m_setup_background_mining = value; }
const std::string & device_name() const { return m_device_name; }
void device_name(const std::string & device_name) { m_device_name = device_name; }
const std::string & device_derivation_path() const { return m_device_derivation_path; }
@@ -1444,6 +1452,7 @@ namespace tools
uint64_t m_segregation_height;
bool m_ignore_fractional_outputs;
bool m_track_uses;
+ BackgroundMiningSetupType m_setup_background_mining;
bool m_is_initialized;
NodeRPCProxy m_node_rpc_proxy;
std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index f80263007..2a4514057 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -273,6 +273,8 @@ namespace tools
m_auto_refresh_period = DEFAULT_AUTO_REFRESH_PERIOD;
m_last_auto_refresh_time = boost::posix_time::min_date_time;
+ check_background_mining();
+
m_net_server.set_threads_prefix("RPC");
auto rng = [](size_t len, uint8_t *ptr) { return crypto::rand(len, ptr); };
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(
@@ -281,6 +283,60 @@ namespace tools
);
}
//------------------------------------------------------------------------------------------------------------------------------
+ void wallet_rpc_server::check_background_mining()
+ {
+ if (!m_wallet)
+ return;
+
+ tools::wallet2::BackgroundMiningSetupType setup = m_wallet->setup_background_mining();
+ if (setup == tools::wallet2::BackgroundMiningNo)
+ {
+ MLOG_RED(el::Level::Warning, "Background mining not enabled. Run \"set setup-background-mining 1\" in monero-wallet-cli to change.");
+ return;
+ }
+
+ if (!m_wallet->is_trusted_daemon())
+ {
+ MDEBUG("Using an untrusted daemon, skipping background mining check");
+ return;
+ }
+
+ cryptonote::COMMAND_RPC_MINING_STATUS::request req;
+ cryptonote::COMMAND_RPC_MINING_STATUS::response res;
+ bool r = m_wallet->invoke_http_json("/mining_status", req, res);
+ if (!r || res.status != CORE_RPC_STATUS_OK)
+ {
+ MERROR("Failed to query mining status: " << (r ? res.status : "No connection to daemon"));
+ return;
+ }
+ if (res.active || res.is_background_mining_enabled)
+ return;
+
+ if (setup == tools::wallet2::BackgroundMiningMaybe)
+ {
+ MINFO("The daemon is not set up to background mine.");
+ MINFO("With background mining enabled, the daemon will mine when idle and not on batttery.");
+ MINFO("Enabling this supports the network you are using, and makes you eligible for receiving new monero");
+ MINFO("Set setup-background-mining to 1 in monero-wallet-cli to change.");
+ return;
+ }
+
+ cryptonote::COMMAND_RPC_START_MINING::request req2;
+ cryptonote::COMMAND_RPC_START_MINING::response res2;
+ req2.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
+ req2.threads_count = 1;
+ req2.do_background_mining = true;
+ req2.ignore_battery = false;
+ r = m_wallet->invoke_http_json("/start_mining", req2, res);
+ if (!r || res2.status != CORE_RPC_STATUS_OK)
+ {
+ MERROR("Failed to setup background mining: " << (r ? res.status : "No connection to daemon"));
+ return;
+ }
+
+ MINFO("Background mining enabled. The daemon will mine when idle and not on batttery.");
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::not_open(epee::json_rpc::error& er)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_OPEN;
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 2b52275b8..50aa7ba0a 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -252,6 +252,8 @@ namespace tools
bool validate_transfer(const std::list<wallet_rpc::transfer_destination>& destinations, const std::string& payment_id, std::vector<cryptonote::tx_destination_entry>& dsts, std::vector<uint8_t>& extra, bool at_least_one_destination, epee::json_rpc::error& er);
+ void check_background_mining();
+
wallet2 *m_wallet;
std::string m_wallet_dir;
tools::private_file rpc_login_file;