Added max_weight
parameter for mining
`max_weight` allows miners to limit the weight of the blocks they mine. Default is 0 (unlimited). Added to `get_block_template` RPC, `start_mining` RPC and `start_mining` console command.
This commit is contained in:
parent
1bec71279e
commit
9c6b6076d9
@ -116,6 +116,7 @@ namespace cryptonote
|
||||
m_pausers_count(0),
|
||||
m_threads_total(0),
|
||||
m_starter_nonce(0),
|
||||
m_max_weight(0),
|
||||
m_last_hr_merge_time(0),
|
||||
m_hashes(0),
|
||||
m_total_hashes(0),
|
||||
@ -173,7 +174,7 @@ namespace cryptonote
|
||||
|
||||
uint64_t seed_height;
|
||||
crypto::hash seed_hash;
|
||||
if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce, seed_height, seed_hash))
|
||||
if(!m_phandler->get_block_template(bl, m_mine_address, m_max_weight, di, height, expected_reward, extra_nonce, seed_height, seed_hash))
|
||||
{
|
||||
LOG_ERROR("Failed to get_block_template(), stopping mining");
|
||||
return false;
|
||||
@ -368,10 +369,11 @@ namespace cryptonote
|
||||
return m_threads_total;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------
|
||||
bool miner::start(const account_public_address& adr, size_t threads_count, bool do_background, bool ignore_battery)
|
||||
bool miner::start(const account_public_address& adr, uint64_t max_weight, size_t threads_count, bool do_background, bool ignore_battery)
|
||||
{
|
||||
m_block_reward = 0;
|
||||
m_mine_address = adr;
|
||||
m_max_weight = max_weight;
|
||||
m_threads_total = static_cast<uint32_t>(threads_count);
|
||||
if (threads_count == 0)
|
||||
{
|
||||
@ -494,7 +496,7 @@ namespace cryptonote
|
||||
{
|
||||
if(m_do_mining)
|
||||
{
|
||||
start(m_mine_address, m_threads_total, get_is_background_mining_enabled(), get_ignore_battery());
|
||||
start(m_mine_address, m_max_weight, m_threads_total, get_is_background_mining_enabled(), get_ignore_battery());
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------
|
||||
|
@ -47,7 +47,7 @@ namespace cryptonote
|
||||
struct i_miner_handler
|
||||
{
|
||||
virtual bool handle_block_found(block& b, block_verification_context &bvc) = 0;
|
||||
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) = 0;
|
||||
virtual bool get_block_template(block& b, const account_public_address& adr, uint64_t max_weight, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) = 0;
|
||||
protected:
|
||||
~i_miner_handler(){};
|
||||
};
|
||||
@ -66,7 +66,7 @@ namespace cryptonote
|
||||
static void init_options(boost::program_options::options_description& desc);
|
||||
bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height, uint64_t block_reward);
|
||||
bool on_block_chain_update();
|
||||
bool start(const account_public_address& adr, size_t threads_count, bool do_background = false, bool ignore_battery = false);
|
||||
bool start(const account_public_address& adr, uint64_t max_weight, size_t threads_count, bool do_background = false, bool ignore_battery = false);
|
||||
uint64_t get_speed() const;
|
||||
uint32_t get_threads_count() const;
|
||||
void send_stop_signal();
|
||||
@ -136,6 +136,7 @@ namespace cryptonote
|
||||
i_miner_handler* m_phandler;
|
||||
get_block_hash_t m_gbh;
|
||||
account_public_address m_mine_address;
|
||||
uint64_t m_max_weight;
|
||||
epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval;
|
||||
epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval;
|
||||
epee::math_helper::once_a_time_seconds<1> m_autodetect_interval;
|
||||
|
@ -1544,7 +1544,7 @@ uint64_t Blockchain::get_current_cumulative_block_weight_median() const
|
||||
// in a lot of places. That flag is not referenced in any of the code
|
||||
// nor any of the makefiles, howeve. Need to look into whether or not it's
|
||||
// necessary at all.
|
||||
bool Blockchain::create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
bool Blockchain::create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, uint64_t max_weight, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
size_t median_weight;
|
||||
@ -1687,7 +1687,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
|
||||
|
||||
size_t txs_weight;
|
||||
uint64_t fee;
|
||||
if (!m_tx_pool.fill_block_template(b, median_weight, already_generated_coins, txs_weight, fee, expected_reward, b.major_version))
|
||||
if (!m_tx_pool.fill_block_template(b, median_weight, already_generated_coins, max_weight, txs_weight, fee, expected_reward, b.major_version))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1813,9 +1813,9 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::create_block_template(block& b, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
bool Blockchain::create_block_template(block& b, const account_public_address& miner_address, uint64_t max_weight, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
{
|
||||
return create_block_template(b, NULL, miner_address, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
|
||||
return create_block_template(b, NULL, miner_address, max_weight, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::get_miner_data(uint8_t& major_version, uint64_t& height, crypto::hash& prev_id, crypto::hash& seed_hash, difficulty_type& difficulty, uint64_t& median_weight, uint64_t& already_generated_coins, std::vector<tx_block_template_backlog_entry>& tx_backlog)
|
||||
|
@ -364,6 +364,7 @@ namespace cryptonote
|
||||
* @param b return-by-reference block to be filled in
|
||||
* @param from_block optional block hash to start mining from (main chain tip if NULL)
|
||||
* @param miner_address address new coins for the block will go to
|
||||
* @param max_weight limit the maximum weight of the created block template (0 for no limit)
|
||||
* @param di return-by-reference tells the miner what the difficulty target is
|
||||
* @param height return-by-reference tells the miner what height it's mining against
|
||||
* @param expected_reward return-by-reference the total reward awarded to the miner finding this block, including transaction fees
|
||||
@ -371,8 +372,8 @@ namespace cryptonote
|
||||
*
|
||||
* @return true if block template filled in successfully, else false
|
||||
*/
|
||||
bool create_block_template(block& b, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
|
||||
bool create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
|
||||
bool create_block_template(block& b, const account_public_address& miner_address, uint64_t max_weight, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
|
||||
bool create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, uint64_t max_weight, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
|
||||
|
||||
/**
|
||||
* @brief gets data required to create a block template and start mining on it
|
||||
|
@ -1468,14 +1468,14 @@ namespace cryptonote
|
||||
notify_txpool_event(tx_blobs, epee::to_span(tx_hashes), epee::to_span(txs), just_broadcasted);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
bool core::get_block_template(block& b, const account_public_address& adr, uint64_t max_weight, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
{
|
||||
return m_blockchain_storage.create_block_template(b, adr, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
|
||||
return m_blockchain_storage.create_block_template(b, adr, max_weight, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
bool core::get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, uint64_t max_weight, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
|
||||
{
|
||||
return m_blockchain_storage.create_block_template(b, prev_block, adr, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
|
||||
return m_blockchain_storage.create_block_template(b, prev_block, adr, max_weight, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_miner_data(uint8_t& major_version, uint64_t& height, crypto::hash& prev_id, crypto::hash& seed_hash, difficulty_type& difficulty, uint64_t& median_weight, uint64_t& already_generated_coins, std::vector<tx_block_template_backlog_entry>& tx_backlog)
|
||||
|
@ -231,8 +231,8 @@ namespace cryptonote
|
||||
*
|
||||
* @note see Blockchain::create_block_template
|
||||
*/
|
||||
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) override;
|
||||
virtual bool get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
|
||||
virtual bool get_block_template(block& b, const account_public_address& adr, uint64_t max_weight, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) override;
|
||||
virtual bool get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, uint64_t max_weight, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
|
||||
|
||||
/**
|
||||
* @copydoc Blockchain::get_miner_data
|
||||
|
@ -1605,7 +1605,7 @@ namespace cryptonote
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
//TODO: investigate whether boolean return is appropriate
|
||||
bool tx_memory_pool::fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version)
|
||||
bool tx_memory_pool::fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, uint64_t weight_limit, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||
@ -1625,6 +1625,12 @@ namespace cryptonote
|
||||
size_t max_total_weight_pre_v5 = (130 * median_weight) / 100 - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
|
||||
size_t max_total_weight_v5 = 2 * median_weight - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
|
||||
size_t max_total_weight = version >= 5 ? max_total_weight_v5 : max_total_weight_pre_v5;
|
||||
|
||||
if (weight_limit && (max_total_weight > weight_limit))
|
||||
{
|
||||
max_total_weight = weight_limit;
|
||||
}
|
||||
|
||||
std::unordered_set<crypto::key_image> k_images;
|
||||
|
||||
LOG_PRINT_L2("Filling block template, median weight " << median_weight << ", " << m_txs_by_fee_and_receive_time.size() << " txes in the pool");
|
||||
|
@ -229,7 +229,7 @@ namespace cryptonote
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
bool fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version);
|
||||
bool fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, uint64_t weight_limit, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version);
|
||||
|
||||
/**
|
||||
* @brief get a list of all transactions in the pool
|
||||
|
@ -422,16 +422,23 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg
|
||||
}
|
||||
if(nettype != cryptonote::MAINNET)
|
||||
std::cout << "Mining to a " << (nettype == cryptonote::TESTNET ? "testnet" : "stagenet") << " address, make sure this is intentional!" << std::endl;
|
||||
uint64_t max_weight = 0;
|
||||
uint64_t threads_count = 1;
|
||||
bool do_background_mining = false;
|
||||
bool ignore_battery = false;
|
||||
if(args.size() > 4)
|
||||
if(args.size() > 5)
|
||||
{
|
||||
std::cout << "Invalid syntax: Too many parameters. For more details, use the help command." << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.size() == 4)
|
||||
if(args.size() == 5)
|
||||
{
|
||||
const bool ok = epee::string_tools::get_xtype_from_string(max_weight, args[4]);
|
||||
max_weight = ok ? max_weight : 0;
|
||||
}
|
||||
|
||||
if(args.size() >= 4)
|
||||
{
|
||||
if(args[3] == "true" || command_line::is_yes(args[3]) || args[3] == "1")
|
||||
{
|
||||
@ -470,7 +477,7 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg
|
||||
}
|
||||
}
|
||||
|
||||
m_executor.start_mining(info.address, threads_count, nettype, do_background_mining, ignore_battery);
|
||||
m_executor.start_mining(info.address, threads_count, nettype, do_background_mining, ignore_battery, max_weight);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ t_command_server::t_command_server(
|
||||
m_command_lookup.set_handler(
|
||||
"start_mining"
|
||||
, std::bind(&t_command_parser_executor::start_mining, &m_parser, p::_1)
|
||||
, "start_mining <addr> [<threads>|auto] [do_background_mining] [ignore_battery]"
|
||||
, "start_mining <addr> [<threads>|auto] [do_background_mining] [ignore_battery] [max_weight]"
|
||||
, "Start mining for specified address. Defaults to 1 thread and no background mining. Use \"auto\" to autodetect optimal number of threads."
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
|
@ -1358,10 +1358,11 @@ bool t_rpc_command_executor::print_transaction_pool_stats() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining, bool ignore_battery) {
|
||||
bool t_rpc_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining, bool ignore_battery, uint64_t max_weight) {
|
||||
cryptonote::COMMAND_RPC_START_MINING::request req;
|
||||
cryptonote::COMMAND_RPC_START_MINING::response res;
|
||||
req.miner_address = cryptonote::get_account_address_as_str(nettype, false, address);
|
||||
req.max_weight = max_weight;
|
||||
req.threads_count = num_threads;
|
||||
req.do_background_mining = do_background_mining;
|
||||
req.ignore_battery = ignore_battery;
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
|
||||
bool print_transaction_pool_stats();
|
||||
|
||||
bool start_mining(cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining = false, bool ignore_battery = false);
|
||||
bool start_mining(cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining = false, bool ignore_battery = false, uint64_t max_weight = 0);
|
||||
|
||||
bool stop_mining();
|
||||
|
||||
|
@ -1449,7 +1449,7 @@ namespace cryptonote
|
||||
res.status = "Already mining";
|
||||
return true;
|
||||
}
|
||||
if(!miner.start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
|
||||
if(!miner.start(info.address, req.max_weight, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
|
||||
{
|
||||
res.status = "Failed, mining not started";
|
||||
LOG_PRINT_L0(res.status);
|
||||
@ -1845,10 +1845,10 @@ namespace cryptonote
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp)
|
||||
bool core_rpc_server::get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, uint64_t max_weight, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp)
|
||||
{
|
||||
b = boost::value_initialized<cryptonote::block>();
|
||||
if(!m_core.get_block_template(b, prev_block, address, difficulty, height, expected_reward, extra_nonce, seed_height, seed_hash))
|
||||
if(!m_core.get_block_template(b, prev_block, address, max_weight, difficulty, height, expected_reward, extra_nonce, seed_height, seed_hash))
|
||||
{
|
||||
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
|
||||
error_resp.message = "Internal error: failed to create block template";
|
||||
@ -1973,7 +1973,7 @@ namespace cryptonote
|
||||
}
|
||||
}
|
||||
crypto::hash seed_hash, next_seed_hash;
|
||||
if (!get_block_template(info.address, req.prev_block.empty() ? NULL : &prev_block, blob_reserve, reserved_offset, wdiff, res.height, res.expected_reward, b, res.seed_height, seed_hash, next_seed_hash, error_resp))
|
||||
if (!get_block_template(info.address, req.prev_block.empty() ? NULL : &prev_block, blob_reserve, req.max_weight, reserved_offset, wdiff, res.height, res.expected_reward, b, res.seed_height, seed_hash, next_seed_hash, error_resp))
|
||||
return false;
|
||||
if (b.major_version >= RX_BLOCK_VERSION)
|
||||
{
|
||||
@ -3517,7 +3517,7 @@ namespace cryptonote
|
||||
cryptonote::difficulty_type difficulty;
|
||||
uint64_t height, expected_reward;
|
||||
size_t reserved_offset;
|
||||
if (!get_block_template(m_rpc_payment->get_payment_address(), NULL, extra_nonce, reserved_offset, difficulty, height, expected_reward, b, seed_height, seed_hash, next_seed_hash, error_resp))
|
||||
if (!get_block_template(m_rpc_payment->get_payment_address(), NULL, extra_nonce, 0, reserved_offset, difficulty, height, expected_reward, b, seed_height, seed_hash, next_seed_hash, error_resp))
|
||||
return false;
|
||||
return true;
|
||||
}, hashing_blob, res.seed_height, seed_hash, top_hash, res.diff, res.credits_per_hash_found, res.credits, res.cookie))
|
||||
|
@ -285,7 +285,7 @@ private:
|
||||
enum invoke_http_mode { JON, BIN, JON_RPC };
|
||||
template <typename COMMAND_TYPE>
|
||||
bool use_bootstrap_daemon_if_necessary(const invoke_http_mode &mode, const std::string &command_name, const typename COMMAND_TYPE::request& req, typename COMMAND_TYPE::response& res, bool &r);
|
||||
bool get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp);
|
||||
bool get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, uint64_t max_weight, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp);
|
||||
bool check_payment(const std::string &client, uint64_t payment, const std::string &rpc, bool same_ts, std::string &message, uint64_t &credits, std::string &top_hash);
|
||||
|
||||
core& m_core;
|
||||
|
@ -88,7 +88,7 @@ namespace cryptonote
|
||||
// advance which version they will stop working with
|
||||
// Don't go over 32767 for any of these
|
||||
#define CORE_RPC_VERSION_MAJOR 3
|
||||
#define CORE_RPC_VERSION_MINOR 13
|
||||
#define CORE_RPC_VERSION_MINOR 14
|
||||
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
||||
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
|
||||
|
||||
@ -665,6 +665,7 @@ namespace cryptonote
|
||||
struct request_t: public rpc_request_base
|
||||
{
|
||||
std::string miner_address;
|
||||
uint64_t max_weight;
|
||||
uint64_t threads_count;
|
||||
bool do_background_mining;
|
||||
bool ignore_battery;
|
||||
@ -672,6 +673,7 @@ namespace cryptonote
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_PARENT(rpc_request_base)
|
||||
KV_SERIALIZE(miner_address)
|
||||
KV_SERIALIZE_OPT(max_weight, (uint64_t)0)
|
||||
KV_SERIALIZE(threads_count)
|
||||
KV_SERIALIZE(do_background_mining)
|
||||
KV_SERIALIZE(ignore_battery)
|
||||
@ -943,6 +945,7 @@ namespace cryptonote
|
||||
struct request_t: public rpc_request_base
|
||||
{
|
||||
uint64_t reserve_size; //max 255 bytes
|
||||
uint64_t max_weight;
|
||||
std::string wallet_address;
|
||||
std::string prev_block;
|
||||
std::string extra_nonce;
|
||||
@ -950,6 +953,7 @@ namespace cryptonote
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_PARENT(rpc_request_base)
|
||||
KV_SERIALIZE(reserve_size)
|
||||
KV_SERIALIZE_OPT(max_weight, (uint64_t)0)
|
||||
KV_SERIALIZE(wallet_address)
|
||||
KV_SERIALIZE(prev_block)
|
||||
KV_SERIALIZE(extra_nonce)
|
||||
|
@ -182,7 +182,7 @@ namespace
|
||||
|
||||
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
|
||||
|
||||
const char* USAGE_START_MINING("start_mining [<number_of_threads>] [bg_mining] [ignore_battery]");
|
||||
const char* USAGE_START_MINING("start_mining [<number_of_threads>] [bg_mining] [ignore_battery] [max_weight]");
|
||||
const char* USAGE_SET_DAEMON("set_daemon <host>[:<port>] [trusted|untrusted|this-is-probably-a-spy-node]");
|
||||
const char* USAGE_SHOW_BALANCE("balance [detail]");
|
||||
const char* USAGE_INCOMING_TRANSFERS("incoming_transfers [available|unavailable] [verbose] [uses] [index=<N1>[,<N2>[,...]]]");
|
||||
@ -5142,6 +5142,7 @@ void simple_wallet::start_background_mining()
|
||||
COMMAND_RPC_START_MINING::request req;
|
||||
COMMAND_RPC_START_MINING::response res;
|
||||
req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
|
||||
req.max_weight = 0;
|
||||
req.threads_count = 1;
|
||||
req.do_background_mining = true;
|
||||
req.ignore_battery = false;
|
||||
@ -5265,6 +5266,10 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
|
||||
|
||||
bool ok = true;
|
||||
size_t arg_size = args.size();
|
||||
if(arg_size >= 4)
|
||||
{
|
||||
ok = ok && string_tools::get_xtype_from_string(req.max_weight, args[3]);
|
||||
}
|
||||
if(arg_size >= 3)
|
||||
{
|
||||
if (!parse_bool_and_use(args[2], [&](bool r) { req.ignore_battery = r; }))
|
||||
@ -5278,7 +5283,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
|
||||
if(arg_size >= 1)
|
||||
{
|
||||
uint16_t num = 1;
|
||||
ok = string_tools::get_xtype_from_string(num, args[0]);
|
||||
ok = ok && string_tools::get_xtype_from_string(num, args[0]);
|
||||
ok = ok && 1 <= num;
|
||||
req.threads_count = num;
|
||||
}
|
||||
|
@ -1329,7 +1329,7 @@ struct WalletManager
|
||||
virtual bool isMining() = 0;
|
||||
|
||||
//! starts mining with the set number of threads
|
||||
virtual bool startMining(const std::string &address, uint32_t threads = 1, bool background_mining = false, bool ignore_battery = true) = 0;
|
||||
virtual bool startMining(const std::string &address, uint32_t threads = 1, bool background_mining = false, bool ignore_battery = true, uint64_t max_weight = 0) = 0;
|
||||
|
||||
//! stops mining
|
||||
virtual bool stopMining() = 0;
|
||||
|
@ -314,12 +314,13 @@ bool WalletManagerImpl::isMining()
|
||||
return mres.active;
|
||||
}
|
||||
|
||||
bool WalletManagerImpl::startMining(const std::string &address, uint32_t threads, bool background_mining, bool ignore_battery)
|
||||
bool WalletManagerImpl::startMining(const std::string &address, uint32_t threads, bool background_mining, bool ignore_battery, uint64_t max_weight)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_START_MINING::request mreq;
|
||||
cryptonote::COMMAND_RPC_START_MINING::response mres;
|
||||
|
||||
mreq.miner_address = address;
|
||||
mreq.max_weight = max_weight;
|
||||
mreq.threads_count = threads;
|
||||
mreq.ignore_battery = ignore_battery;
|
||||
mreq.do_background_mining = background_mining;
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
double miningHashRate() override;
|
||||
uint64_t blockTarget() override;
|
||||
bool isMining() override;
|
||||
bool startMining(const std::string &address, uint32_t threads = 1, bool background_mining = false, bool ignore_battery = true) override;
|
||||
bool startMining(const std::string &address, uint32_t threads = 1, bool background_mining = false, bool ignore_battery = true, uint64_t max_weight = 0) override;
|
||||
bool stopMining() override;
|
||||
std::string resolveOpenAlias(const std::string &address, bool &dnssec_valid) const override;
|
||||
bool setProxy(const std::string &address) override;
|
||||
|
@ -328,6 +328,7 @@ namespace tools
|
||||
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.max_weight = 0;
|
||||
req2.threads_count = 1;
|
||||
req2.do_background_mining = true;
|
||||
req2.ignore_battery = false;
|
||||
@ -3250,6 +3251,7 @@ namespace tools
|
||||
|
||||
cryptonote::COMMAND_RPC_START_MINING::request daemon_req = AUTO_VAL_INIT(daemon_req);
|
||||
daemon_req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
|
||||
daemon_req.max_weight = req.max_weight;
|
||||
daemon_req.threads_count = req.threads_count;
|
||||
daemon_req.do_background_mining = req.do_background_mining;
|
||||
daemon_req.ignore_battery = req.ignore_battery;
|
||||
|
@ -47,7 +47,7 @@
|
||||
// advance which version they will stop working with
|
||||
// Don't go over 32767 for any of these
|
||||
#define WALLET_RPC_VERSION_MAJOR 1
|
||||
#define WALLET_RPC_VERSION_MINOR 27
|
||||
#define WALLET_RPC_VERSION_MINOR 28
|
||||
#define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
||||
#define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR)
|
||||
namespace tools
|
||||
@ -2085,11 +2085,13 @@ namespace wallet_rpc
|
||||
uint64_t threads_count;
|
||||
bool do_background_mining;
|
||||
bool ignore_battery;
|
||||
uint64_t max_weight;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(threads_count)
|
||||
KV_SERIALIZE(do_background_mining)
|
||||
KV_SERIALIZE(ignore_battery)
|
||||
KV_SERIALIZE_OPT(max_weight, (uint64_t)0)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
typedef epee::misc_utils::struct_init<request_t> request;
|
||||
|
Loading…
Reference in New Issue
Block a user