From 0c748617c488243a2e9354ad3a37919e1f10c795 Mon Sep 17 00:00:00 2001 From: wowario Date: Mon, 19 Jul 2021 20:03:02 +0300 Subject: [PATCH 1/2] revert requested_outputs_count --- src/wallet/wallet2.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6bcc55cde..f0de37c55 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -8672,12 +8672,7 @@ void wallet2::get_outs(std::vector> const uint64_t amount = td.is_rct() ? 0 : td.amount(); std::unordered_set seen_indices; // request more for rct in base recent (locked) coinbases are picked, since they're locked for longer - uint64_t approx_blockchain_height = m_nettype == TESTNET ? 0 : (time(NULL) - 1522624244)/311; - uint64_t unlock_height = td.m_block_height + std::max(CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS); - if (td.m_tx.unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER && td.m_tx.unlock_time > unlock_height) - unlock_height = td.m_tx.unlock_time; - uint64_t blocks_to_unlock = unlock_height > approx_blockchain_height ? unlock_height - approx_blockchain_height : 0; - size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? blocks_to_unlock - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0) + 288; + size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0); size_t start = req.outputs.size(); bool use_histogram = amount != 0 || !has_rct_distribution; @@ -8993,12 +8988,7 @@ void wallet2::get_outs(std::vector> for(size_t idx: selected_transfers) { const transfer_details &td = m_transfers[idx]; - uint64_t approx_blockchain_height = m_nettype == TESTNET ? 0 : (time(NULL) - 1522624244)/311; - uint64_t unlock_height = td.m_block_height + std::max(CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS); - if (td.m_tx.unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER && td.m_tx.unlock_time > unlock_height) - unlock_height = td.m_tx.unlock_time; - uint64_t blocks_to_unlock = unlock_height > approx_blockchain_height ? unlock_height - approx_blockchain_height : 0; - size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? blocks_to_unlock - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0) + 288; + size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0); outs.push_back(std::vector()); outs.back().reserve(fake_outputs_count + 1); const rct::key mask = td.is_rct() ? rct::commit(td.amount(), td.m_mask) : rct::zeroCommit(td.amount()); From 122fc4aa56f50206bf78568b13f2ebc7cce1a9bd Mon Sep 17 00:00:00 2001 From: wowario Date: Mon, 19 Jul 2021 21:21:51 +0300 Subject: [PATCH 2/2] prevent mining within wallet and node --- src/daemon/command_parser_executor.cpp | 105 +------------------------ src/simplewallet/simplewallet.cpp | 88 +-------------------- 2 files changed, 4 insertions(+), 189 deletions(-) diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 68f1923ee..9ef11cf46 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -368,110 +368,7 @@ bool t_command_parser_executor::print_transaction_pool_stats(const std::vector& args) { - if(!args.size()) - { - std::cout << "Invalid syntax: At least one parameter expected. For more details, use the help command." << std::endl; - return true; - } - - cryptonote::address_parse_info info; - cryptonote::network_type nettype = cryptonote::MAINNET; - if(!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, args.front())) - { - if(!cryptonote::get_account_address_from_str(info, cryptonote::TESTNET, args.front())) - { - if(!cryptonote::get_account_address_from_str(info, cryptonote::STAGENET, args.front())) - { - bool dnssec_valid; - std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(args.front(), dnssec_valid, - [](const std::string &url, const std::vector &addresses, bool dnssec_valid){return addresses[0];}); - if(!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, address_str)) - { - if(!cryptonote::get_account_address_from_str(info, cryptonote::TESTNET, address_str)) - { - if(!cryptonote::get_account_address_from_str(info, cryptonote::STAGENET, address_str)) - { - std::cout << "Invalid syntax: Target account address has wrong format. For more details, use the help command." << std::endl; - return true; - } - else - { - nettype = cryptonote::STAGENET; - } - } - else - { - nettype = cryptonote::TESTNET; - } - } - } - else - { - nettype = cryptonote::STAGENET; - } - } - else - { - nettype = cryptonote::TESTNET; - } - } - if (info.is_subaddress) - { - tools::fail_msg_writer() << "You can't use a subaddress to mine. You need to use your wallet's main address, which starts with \"Wo\"." << std::endl; - return true; - } - if(nettype != cryptonote::MAINNET) - std::cout << "Mining to a " << (nettype == cryptonote::TESTNET ? "testnet" : "stagenet") << " address, make sure this is intentional!" << std::endl; - uint64_t threads_count = 1; - bool do_background_mining = false; - bool ignore_battery = false; - if(args.size() > 4) - { - std::cout << "Invalid syntax: Too many parameters. For more details, use the help command." << std::endl; - return true; - } - - if(args.size() == 4) - { - if(args[3] == "true" || command_line::is_yes(args[3]) || args[3] == "1") - { - ignore_battery = true; - } - else if(args[3] != "false" && !command_line::is_no(args[3]) && args[3] != "0") - { - std::cout << "Invalid syntax: Invalid combination of parameters. For more details, use the help command." << std::endl; - return true; - } - } - - if(args.size() >= 3) - { - if(args[2] == "true" || command_line::is_yes(args[2]) || args[2] == "1") - { - do_background_mining = true; - } - else if(args[2] != "false" && !command_line::is_no(args[2]) && args[2] != "0") - { - std::cout << "Invalid syntax: Invalid combination of parameters. For more details, use the help command." << std::endl; - return true; - } - } - - if(args.size() >= 2) - { - if (args[1] == "auto" || args[1] == "autodetect") - { - threads_count = 0; - } - else - { - bool ok = epee::string_tools::get_xtype_from_string(threads_count, args[1]); - threads_count = (ok && 0 < threads_count) ? threads_count : 1; - } - } - - m_executor.start_mining(info.address, threads_count, nettype, do_background_mining, ignore_battery); - + std::cout << "You can't mine within wownerod. To mine, restart node like this: ./wownerod --start-mining YOUR-ADDRESS --spendkey SECRET-SPENDKEY" << std::endl; return true; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index df440e047..7abb5fd3f 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -3186,6 +3186,7 @@ bool simple_wallet::help(const std::vector &args/* = std::vector \" - Send WOW to an address."); message_writer() << tr("\"show_transfers [in|out|pending|failed|pool]\" - Show transactions."); message_writer() << tr("\"sweep_all
\" - Send whole balance to another wallet."); + message_writer() << tr("\"spendkey\" - Show secret spend key used for mining."); message_writer() << tr("\"seed\" - Show secret 25 words that can be used to recover this wallet."); message_writer() << tr("\"refresh\" - Synchronize wallet with the Wownero network."); message_writer() << tr("\"status\" - Check current status of wallet."); @@ -4766,9 +4767,6 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) m_wallet->callback(this); - bool skip_check_backround_mining = !command_line::get_arg(vm, arg_command).empty(); - if (!skip_check_backround_mining) - check_background_mining(password); if (welcome) message_writer(console_color_yellow, true) << tr("If you are new to Wownero, type \"welcome\" for a brief overview."); @@ -5342,34 +5340,7 @@ bool simple_wallet::save_watch_only(const std::vector &args/* = std //---------------------------------------------------------------------------------------------------- void simple_wallet::start_background_mining() { - COMMAND_RPC_MINING_STATUS::request reqq; - COMMAND_RPC_MINING_STATUS::response resq; - bool r = m_wallet->invoke_http_json("/mining_status", reqq, resq); - std::string err = interpret_rpc_response(r, resq.status); - if (!r) - return; - if (!err.empty()) - { - fail_msg_writer() << tr("Failed to query mining status: ") << err; - return; - } - if (!resq.is_background_mining_enabled) - { - 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.threads_count = 1; - req.do_background_mining = true; - req.ignore_battery = false; - bool r = m_wallet->invoke_http_json("/start_mining", req, res); - std::string err = interpret_rpc_response(r, res.status); - if (!err.empty()) - { - fail_msg_writer() << tr("Failed to setup background mining: ") << err; - return; - } - } - success_msg_writer() << tr("Background mining enabled. Thank you for supporting the Wownero network."); + message_writer(console_color_red, false) << tr("Background mining not available."); } //---------------------------------------------------------------------------------------------------- void simple_wallet::stop_background_mining() @@ -5462,60 +5433,7 @@ void simple_wallet::check_background_mining(const epee::wipeable_string &passwor //---------------------------------------------------------------------------------------------------- bool simple_wallet::start_mining(const std::vector& args) { - if (!m_wallet->is_trusted_daemon()) - { - fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon"); - return true; - } - - if (!try_connect_to_daemon()) - return true; - - if (!m_wallet) - { - fail_msg_writer() << tr("wallet is null"); - return true; - } - COMMAND_RPC_START_MINING::request req = AUTO_VAL_INIT(req); - req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->nettype()); - - bool ok = true; - size_t arg_size = args.size(); - if(arg_size >= 3) - { - if (!parse_bool_and_use(args[2], [&](bool r) { req.ignore_battery = r; })) - return true; - } - if(arg_size >= 2) - { - if (!parse_bool_and_use(args[1], [&](bool r) { req.do_background_mining = r; })) - return true; - } - if(arg_size >= 1) - { - uint16_t num = 1; - ok = string_tools::get_xtype_from_string(num, args[0]); - ok = ok && 1 <= num; - req.threads_count = num; - } - else - { - req.threads_count = 1; - } - - if (!ok) - { - PRINT_USAGE(USAGE_START_MINING); - return true; - } - - COMMAND_RPC_START_MINING::response res; - bool r = m_wallet->invoke_http_json("/start_mining", req, res); - std::string err = interpret_rpc_response(r, res.status); - if (err.empty()) - success_msg_writer() << tr("Mining started in daemon"); - else - fail_msg_writer() << tr("mining has NOT been started: ") << err; + fail_msg_writer() << tr("You can't mine within the wallet. To mine, restart node like this: ./wownerod --start-mining YOUR-ADDRESS --spendkey SECRET-SPENDKEY"); return true; } //----------------------------------------------------------------------------------------------------