aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/password.cpp15
-rw-r--r--src/common/password.h2
-rw-r--r--src/common/util.h6
-rw-r--r--src/crypto/random.c1
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.cpp39
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.h1
-rw-r--r--src/cryptonote_basic/hardfork.h1
-rw-r--r--src/cryptonote_basic/miner.cpp16
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp12
-rw-r--r--src/cryptonote_core/tx_pool.cpp4
-rw-r--r--src/p2p/CMakeLists.txt1
-rw-r--r--src/simplewallet/simplewallet.cpp17
-rw-r--r--src/wallet/wallet2.cpp49
-rw-r--r--src/wallet/wallet2.h5
-rw-r--r--src/wallet/wallet_rpc_server.cpp5
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h3
16 files changed, 119 insertions, 58 deletions
diff --git a/src/common/password.cpp b/src/common/password.cpp
index ef026c979..9336a14fc 100644
--- a/src/common/password.cpp
+++ b/src/common/password.cpp
@@ -42,12 +42,10 @@
#include <unistd.h>
#endif
-#ifdef HAVE_READLINE
- #include "readline_buffer.h"
-#endif
-
#include "memwipe.h"
+#define EOT 0x4
+
namespace
{
#if defined(_WIN32)
@@ -134,7 +132,7 @@ namespace
while (aPass.size() < tools::password_container::max_password_size)
{
int ch = getch();
- if (EOF == ch)
+ if (EOF == ch || ch == EOT)
{
return false;
}
@@ -229,13 +227,20 @@ namespace tools
m_password.clear();
}
+ std::atomic<bool> password_container::is_prompting(false);
+
boost::optional<password_container> password_container::prompt(const bool verify, const char *message)
{
+ is_prompting = true;
password_container pass1{};
password_container pass2{};
if (is_cin_tty() ? read_from_tty(verify, message, pass1.m_password, pass2.m_password) : read_from_file(pass1.m_password))
+ {
+ is_prompting = false;
return {std::move(pass1)};
+ }
+ is_prompting = false;
return boost::none;
}
diff --git a/src/common/password.h b/src/common/password.h
index 7c29effe4..61937b93a 100644
--- a/src/common/password.h
+++ b/src/common/password.h
@@ -31,6 +31,7 @@
#pragma once
#include <string>
+#include <atomic>
#include <boost/optional/optional.hpp>
#include "wipeable_string.h"
@@ -49,6 +50,7 @@ namespace tools
//! \return A password from stdin TTY prompt or `std::cin` pipe.
static boost::optional<password_container> prompt(bool verify, const char *mesage = "Password");
+ static std::atomic<bool> is_prompting;
password_container(const password_container&) = delete;
password_container(password_container&& rhs) = default;
diff --git a/src/common/util.h b/src/common/util.h
index 5afb42c97..d3ba47a4f 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -153,8 +153,12 @@ namespace tools
}
return r;
#else
+ static struct sigaction sa;
+ memset(&sa, 0, sizeof(struct sigaction));
+ sa.sa_handler = posix_handler;
+ sa.sa_flags = 0;
/* Only blocks SIGINT, SIGTERM and SIGPIPE */
- signal(SIGINT, posix_handler);
+ sigaction(SIGINT, &sa, NULL);
signal(SIGTERM, posix_handler);
signal(SIGPIPE, SIG_IGN);
m_handler = t;
diff --git a/src/crypto/random.c b/src/crypto/random.c
index 929377943..9e1a70a2d 100644
--- a/src/crypto/random.c
+++ b/src/crypto/random.c
@@ -42,6 +42,7 @@ static void generate_system_random_bytes(size_t n, void *result);
#include <windows.h>
#include <wincrypt.h>
+#include <stdio.h>
static void generate_system_random_bytes(size_t n, void *result) {
HCRYPTPROV prov;
diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp
index aab4f380c..c668ceae5 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.cpp
+++ b/src/cryptonote_basic/cryptonote_format_utils.cpp
@@ -172,6 +172,45 @@ namespace cryptonote
return m;
}
//---------------------------------------------------------------
+ std::vector<crypto::public_key> get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end)
+ {
+ CHECK_AND_ASSERT_THROW_MES(begin <= end, "begin > end");
+
+ std::vector<crypto::public_key> pkeys;
+ pkeys.reserve(end - begin);
+ cryptonote::subaddress_index index = {account, begin};
+
+ ge_p3 p3;
+ ge_cached cached;
+ CHECK_AND_ASSERT_THROW_MES(ge_frombytes_vartime(&p3, (const unsigned char*)keys.m_account_address.m_spend_public_key.data) == 0,
+ "ge_frombytes_vartime failed to convert spend public key");
+ ge_p3_to_cached(&cached, &p3);
+
+ for (uint32_t idx = begin; idx < end; ++idx)
+ {
+ index.minor = idx;
+ if (index.is_zero())
+ {
+ pkeys.push_back(keys.m_account_address.m_spend_public_key);
+ continue;
+ }
+ const crypto::secret_key m = cryptonote::get_subaddress_secret_key(keys.m_view_secret_key, index);
+
+ // M = m*G
+ ge_scalarmult_base(&p3, (const unsigned char*)m.data);
+
+ // D = B + M
+ crypto::public_key D;
+ ge_p1p1 p1p1;
+ ge_add(&p1p1, &p3, &cached);
+ ge_p1p1_to_p3(&p3, &p1p1);
+ ge_p3_tobytes((unsigned char*)D.data, &p3);
+
+ pkeys.push_back(D);
+ }
+ return pkeys;
+ }
+ //---------------------------------------------------------------
bool generate_key_image_helper(const account_keys& ack, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, const crypto::public_key& out_key, const crypto::public_key& tx_public_key, const std::vector<crypto::public_key>& additional_tx_public_keys, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki)
{
crypto::key_derivation recv_derivation = AUTO_VAL_INIT(recv_derivation);
diff --git a/src/cryptonote_basic/cryptonote_format_utils.h b/src/cryptonote_basic/cryptonote_format_utils.h
index 29e180c41..07a3ac92a 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.h
+++ b/src/cryptonote_basic/cryptonote_format_utils.h
@@ -93,6 +93,7 @@ namespace cryptonote
bool get_tx_fee(const transaction& tx, uint64_t & fee);
uint64_t get_tx_fee(const transaction& tx);
crypto::secret_key get_subaddress_secret_key(const crypto::secret_key& a, const subaddress_index& index);
+ std::vector<crypto::public_key> get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end);
bool generate_key_image_helper(const account_keys& ack, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, const crypto::public_key& out_key, const crypto::public_key& tx_public_key, const std::vector<crypto::public_key>& additional_tx_public_keys, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki);
bool generate_key_image_helper_precomp(const account_keys& ack, const crypto::public_key& out_key, const crypto::key_derivation& recv_derivation, size_t real_output_index, const subaddress_index& received_index, keypair& in_ephemeral, crypto::key_image& ki);
void get_blob_hash(const blobdata& blob, crypto::hash& res);
diff --git a/src/cryptonote_basic/hardfork.h b/src/cryptonote_basic/hardfork.h
index 1ec601660..ee5ec0596 100644
--- a/src/cryptonote_basic/hardfork.h
+++ b/src/cryptonote_basic/hardfork.h
@@ -79,7 +79,6 @@ namespace cryptonote
* returns true if no error, false otherwise
*
* @param version the major block version for the fork
- * @param voting_version the minor block version for the fork, used for voting
* @param height The height the hardfork takes effect
* @param time Approximate time of the hardfork (seconds since epoch)
*/
diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp
index b322383a9..919872709 100644
--- a/src/cryptonote_basic/miner.cpp
+++ b/src/cryptonote_basic/miner.cpp
@@ -624,21 +624,15 @@ namespace cryptonote
continue; // if interrupted because stop called, loop should end ..
}
- boost::tribool battery_powered(on_battery_power());
- bool on_ac_power = false;
- if(indeterminate( battery_powered ))
+ bool on_ac_power = m_ignore_battery;
+ if(!m_ignore_battery)
{
- // name could be better, only ignores battery requirement if we failed
- // to get the status of the system
- if( m_ignore_battery )
+ boost::tribool battery_powered(on_battery_power());
+ if(!indeterminate( battery_powered ))
{
- on_ac_power = true;
+ on_ac_power = !battery_powered;
}
}
- else
- {
- on_ac_power = !battery_powered;
- }
if( m_is_background_mining_started )
{
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 64c14f7a2..e0430a18a 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -137,7 +137,12 @@ namespace cryptonote
};
static const command_line::arg_descriptor<bool> arg_fluffy_blocks = {
"fluffy-blocks"
- , "Relay blocks as fluffy blocks where possible (automatic on testnet)"
+ , "Relay blocks as fluffy blocks (obsolete, now default)"
+ , true
+ };
+ static const command_line::arg_descriptor<bool> arg_no_fluffy_blocks = {
+ "no-fluffy-blocks"
+ , "Relay blocks as normal blocks"
, false
};
static const command_line::arg_descriptor<size_t> arg_max_txpool_size = {
@@ -245,6 +250,7 @@ namespace cryptonote
command_line::add_arg(desc, arg_block_sync_size);
command_line::add_arg(desc, arg_check_updates);
command_line::add_arg(desc, arg_fluffy_blocks);
+ command_line::add_arg(desc, arg_no_fluffy_blocks);
command_line::add_arg(desc, arg_test_dbg_lock_sleep);
command_line::add_arg(desc, arg_offline);
command_line::add_arg(desc, arg_disable_dns_checkpoints);
@@ -280,9 +286,11 @@ namespace cryptonote
set_enforce_dns_checkpoints(command_line::get_arg(vm, arg_dns_checkpoints));
test_drop_download_height(command_line::get_arg(vm, arg_test_drop_download_height));
- m_fluffy_blocks_enabled = m_testnet || get_arg(vm, arg_fluffy_blocks);
+ m_fluffy_blocks_enabled = !get_arg(vm, arg_no_fluffy_blocks);
m_offline = get_arg(vm, arg_offline);
m_disable_dns_checkpoints = get_arg(vm, arg_disable_dns_checkpoints);
+ if (!command_line::is_arg_defaulted(vm, arg_fluffy_blocks))
+ MWARNING(arg_fluffy_blocks.name << " is obsolete, it is now default");
if (command_line::get_arg(vm, arg_test_drop_download) == true)
test_drop_download();
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 5f54e93f1..762feb5ee 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -181,7 +181,7 @@ namespace cryptonote
}
size_t tx_size_limit = get_transaction_size_limit(version);
- if (!kept_by_block && blob_size >= tx_size_limit)
+ if (!kept_by_block && blob_size > tx_size_limit)
{
LOG_PRINT_L1("transaction is too big: " << blob_size << " bytes, maximum size: " << tx_size_limit);
tvc.m_verifivation_failed = true;
@@ -1207,7 +1207,7 @@ namespace cryptonote
m_txpool_size = 0;
m_blockchain.for_all_txpool_txes([this, &remove, tx_size_limit](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata*) {
m_txpool_size += meta.blob_size;
- if (meta.blob_size >= tx_size_limit) {
+ if (meta.blob_size > tx_size_limit) {
LOG_PRINT_L1("Transaction " << txid << " is too big (" << meta.blob_size << " bytes), removing it from pool");
remove.insert(txid);
}
diff --git a/src/p2p/CMakeLists.txt b/src/p2p/CMakeLists.txt
index 9421a1477..83bdffab5 100644
--- a/src/p2p/CMakeLists.txt
+++ b/src/p2p/CMakeLists.txt
@@ -40,6 +40,7 @@ target_link_libraries(p2p
PUBLIC
epee
version
+ cryptonote_core
${UPNP_LIBRARIES}
${Boost_CHRONO_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 2d8eb97e0..aa8c66f7a 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -639,6 +639,8 @@ bool simple_wallet::change_password(const std::vector<std::string> &args)
// prompts for a new password, pass true to verify the password
const auto pwd_container = default_password_prompter(true);
+ if(!pwd_container)
+ return true;
try
{
@@ -3192,14 +3194,6 @@ void simple_wallet::on_money_spent(uint64_t height, const crypto::hash &txid, co
//----------------------------------------------------------------------------------------------------
void simple_wallet::on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx)
{
- message_writer(console_color_red, true) << "\r" <<
- tr("Height ") << height << ", " <<
- tr("transaction ") << txid << ", " <<
- tr("unsupported transaction format");
- if (m_auto_refresh_refreshing)
- m_cmd_binder.print_prompt();
- else
- m_refresh_progress_reporter.update(height, true);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::refresh_main(uint64_t start_height, bool reset, bool is_init)
@@ -4627,7 +4621,7 @@ bool simple_wallet::donate(const std::vector<std::string> &args_)
local_args.push_back(amount_str);
if (!payment_id_str.empty())
local_args.push_back(payment_id_str);
- message_writer() << tr("Donating ") << amount_str << " to The Monero Project (donate.getmonero.org/"<< MONERO_DONATION_ADDR <<").";
+ message_writer() << tr("Donating ") << amount_str << " to The Monero Project (donate.getmonero.org or "<< MONERO_DONATION_ADDR <<").";
transfer_new(local_args);
return true;
}
@@ -6811,6 +6805,11 @@ int main(int argc, char* argv[])
else
{
tools::signal_handler::install([&w](int type) {
+ if (tools::password_container::is_prompting.load())
+ {
+ // must be prompting for password so return and let the signal stop prompt
+ return;
+ }
#ifdef WIN32
if (type == CTRL_C_EVENT)
#else
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index d97e53011..87577d2fd 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -888,14 +888,12 @@ void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index)
cryptonote::subaddress_index index2;
for (index2.major = m_subaddress_labels.size(); index2.major < index.major + m_subaddress_lookahead_major; ++index2.major)
{
- for (index2.minor = 0; index2.minor < (index2.major == index.major ? index.minor : 0) + m_subaddress_lookahead_minor; ++index2.minor)
+ const uint32_t end = (index2.major == index.major ? index.minor : 0) + m_subaddress_lookahead_minor;
+ const std::vector<crypto::public_key> pkeys = cryptonote::get_subaddress_spend_public_keys(m_account.get_keys(), index2.major, 0, end);
+ for (index2.minor = 0; index2.minor < end; ++index2.minor)
{
- if (m_subaddresses_inv.count(index2) == 0)
- {
- crypto::public_key D = get_subaddress_spend_public_key(index2);
- m_subaddresses[D] = index2;
- m_subaddresses_inv[index2] = D;
- }
+ const crypto::public_key &D = pkeys[index2.minor];
+ m_subaddresses[D] = index2;
}
}
m_subaddress_labels.resize(index.major + 1, {"Untitled account"});
@@ -904,15 +902,14 @@ void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index)
else if (m_subaddress_labels[index.major].size() <= index.minor)
{
// add new subaddresses
- cryptonote::subaddress_index index2 = index;
- for (index2.minor = m_subaddress_labels[index.major].size(); index2.minor < index.minor + m_subaddress_lookahead_minor; ++index2.minor)
+ const uint32_t end = index.minor + m_subaddress_lookahead_minor;
+ const uint32_t begin = m_subaddress_labels[index.major].size();
+ cryptonote::subaddress_index index2 = {index.major, begin};
+ const std::vector<crypto::public_key> pkeys = cryptonote::get_subaddress_spend_public_keys(m_account.get_keys(), index2.major, index2.minor, end);
+ for (; index2.minor < end; ++index2.minor)
{
- if (m_subaddresses_inv.count(index2) == 0)
- {
- crypto::public_key D = get_subaddress_spend_public_key(index2);
- m_subaddresses[D] = index2;
- m_subaddresses_inv[index2] = D;
- }
+ const crypto::public_key &D = pkeys[index2.minor - begin];
+ m_subaddresses[D] = index2;
}
m_subaddress_labels[index.major].resize(index.minor + 1);
}
@@ -1218,7 +1215,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
td.m_rct = false;
}
set_unspent(m_transfers.size()-1);
- if (!m_multisig)
+ if (!m_multisig && !m_watch_only)
m_key_images[td.m_key_image] = m_transfers.size()-1;
m_pub_keys[tx_scan_info[o].in_ephemeral.pub] = m_transfers.size()-1;
if (m_multisig)
@@ -1312,11 +1309,21 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
uint64_t amount = boost::get<cryptonote::txin_to_key>(in).amount;
if (amount > 0)
{
- THROW_WALLET_EXCEPTION_IF(amount != td.amount(), error::wallet_internal_error,
- std::string("Inconsistent amount in tx input: got ") + print_money(amount) +
- std::string(", expected ") + print_money(td.amount()));
+ if(amount != td.amount())
+ {
+ MERROR("Inconsistent amount in tx input: got " << print_money(amount) <<
+ ", expected " << print_money(td.amount()));
+ // this means:
+ // 1) the same output pub key was used as destination multiple times,
+ // 2) the wallet set the highest amount among them to transfer_details::m_amount, and
+ // 3) the wallet somehow spent that output with an amount smaller than the above amount, causing inconsistency
+ td.m_amount = amount;
+ }
+ }
+ else
+ {
+ amount = td.amount();
}
- amount = td.amount();
tx_money_spent_in_ins += amount;
if (subaddr_account && *subaddr_account != td.m_subaddr_index.major)
LOG_ERROR("spent funds are from different subaddress accounts; count of incoming/outgoing payments will be incorrect");
@@ -2342,7 +2349,6 @@ bool wallet2::clear()
m_address_book.clear();
m_local_bc_height = 1;
m_subaddresses.clear();
- m_subaddresses_inv.clear();
m_subaddress_labels.clear();
return true;
}
@@ -3184,7 +3190,6 @@ bool wallet2::finalize_multisig(const epee::wipeable_string &password, std::unor
}
m_subaddresses.clear();
- m_subaddresses_inv.clear();
m_subaddress_labels.clear();
add_subaddress_account(tr("Primary account"));
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index f9995c2ee..28289842b 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -605,6 +605,7 @@ namespace tools
cryptonote::account_public_address get_subaddress(const cryptonote::subaddress_index& index) const;
cryptonote::account_public_address get_address() const { return get_subaddress({0,0}); }
crypto::public_key get_subaddress_spend_public_key(const cryptonote::subaddress_index& index) const;
+ std::vector<crypto::public_key> get_subaddress_spend_public_keys(uint32_t account, uint32_t begin, uint32_t end) const;
std::string get_subaddress_as_str(const cryptonote::subaddress_index& index) const;
std::string get_address_as_str() const { return get_subaddress_as_str({0, 0}); }
std::string get_integrated_address_as_str(const crypto::hash8& payment_id) const;
@@ -782,7 +783,8 @@ namespace tools
if (ver < 20)
return;
a & m_subaddresses;
- a & m_subaddresses_inv;
+ std::unordered_map<cryptonote::subaddress_index, crypto::public_key> dummy_subaddresses_inv;
+ a & dummy_subaddresses_inv;
a & m_subaddress_labels;
a & m_additional_tx_keys;
if(ver < 21)
@@ -1089,7 +1091,6 @@ namespace tools
std::unordered_map<crypto::public_key, size_t> m_pub_keys;
cryptonote::account_public_address m_account_public_address;
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> m_subaddresses;
- std::unordered_map<cryptonote::subaddress_index, crypto::public_key> m_subaddresses_inv;
std::vector<std::vector<std::string>> m_subaddress_labels;
std::unordered_map<crypto::hash, std::string> m_tx_notes;
std::unordered_map<std::string, std::string> m_attributes;
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 5c644983b..6d5419521 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -39,6 +39,7 @@ using namespace epee;
#include "wallet/wallet_args.h"
#include "common/command_line.h"
#include "common/i18n.h"
+#include "cryptonote_config.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/account.h"
#include "multisig/multisig.h"
@@ -1803,11 +1804,11 @@ namespace tools
return false;
}
- uint64_t min_height = 0, max_height = (uint64_t)-1;
+ uint64_t min_height = 0, max_height = CRYPTONOTE_MAX_BLOCK_NUMBER;
if (req.filter_by_height)
{
min_height = req.min_height;
- max_height = req.max_height;
+ max_height = req.max_height <= max_height ? req.max_height : max_height;
}
if (req.in)
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 82b6b78f9..e38cba5a5 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -29,6 +29,7 @@
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#pragma once
+#include "cryptonote_config.h"
#include "cryptonote_protocol/cryptonote_protocol_defs.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/subaddress_index.h"
@@ -1262,7 +1263,7 @@ namespace wallet_rpc
KV_SERIALIZE(pool);
KV_SERIALIZE(filter_by_height);
KV_SERIALIZE(min_height);
- KV_SERIALIZE(max_height);
+ KV_SERIALIZE_OPT(max_height, (uint64_t)CRYPTONOTE_MAX_BLOCK_NUMBER);
KV_SERIALIZE(account_index);
KV_SERIALIZE(subaddr_indices);
END_KV_SERIALIZE_MAP()