aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp6
-rw-r--r--src/common/command_line.cpp6
-rw-r--r--src/common/command_line.h1
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp5
-rw-r--r--src/cryptonote_core/cryptonote_core.h9
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl4
-rw-r--r--src/daemon/rpc_command_executor.cpp12
-rw-r--r--src/simplewallet/simplewallet.cpp4
-rw-r--r--src/wallet/api/wallet.cpp69
-rw-r--r--src/wallet/api/wallet.h13
-rw-r--r--src/wallet/wallet2.cpp32
-rw-r--r--src/wallet/wallet2.h1
-rw-r--r--src/wallet/wallet2_api.h57
13 files changed, 199 insertions, 20 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 8ad875fc8..acb7d2cf6 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -1081,7 +1081,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
if (need_resize())
{
- LOG_PRINT_L0("LMDB memory map needs resized, doing that now.");
+ LOG_PRINT_L0("LMDB memory map needs to be resized, doing that now.");
do_resize();
}
@@ -1132,7 +1132,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
if (!(mdb_flags & MDB_RDONLY))
{
result = mdb_drop(txn, m_hf_starting_heights, 1);
- if (result)
+ if (result && result != MDB_NOTFOUND)
throw0(DB_ERROR(lmdb_error("Failed to drop m_hf_starting_heights: ", result).c_str()));
}
@@ -2500,7 +2500,7 @@ uint64_t BlockchainLMDB::add_block(const block& blk, const size_t& block_size, c
// for batch mode, DB resize check is done at start of batch transaction
if (! m_batch_active && need_resize())
{
- LOG_PRINT_L0("LMDB memory map needs resized, doing that now.");
+ LOG_PRINT_L0("LMDB memory map needs to be resized, doing that now.");
do_resize();
}
}
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp
index fc096abe5..b3f488447 100644
--- a/src/common/command_line.cpp
+++ b/src/common/command_line.cpp
@@ -30,6 +30,7 @@
#include "command_line.h"
#include "string_tools.h"
+#include "cryptonote_config.h"
namespace command_line
{
@@ -92,4 +93,9 @@ namespace command_line
, "Show time-stats when processing blocks/txs and disk synchronization."
, 0
};
+ const command_line::arg_descriptor<size_t> arg_block_sync_size = {
+ "block-sync-size"
+ , "How many blocks to sync at once during chain synchronization."
+ , BLOCKS_SYNCHRONIZING_DEFAULT_COUNT
+ };
}
diff --git a/src/common/command_line.h b/src/common/command_line.h
index 731b8b0bb..0ea749168 100644
--- a/src/common/command_line.h
+++ b/src/common/command_line.h
@@ -216,4 +216,5 @@ namespace command_line
extern const arg_descriptor<uint64_t> arg_prep_blocks_threads;
extern const arg_descriptor<uint64_t> arg_db_auto_remove_logs;
extern const arg_descriptor<uint64_t> arg_show_time_stats;
+ extern const arg_descriptor<size_t> arg_block_sync_size;
}
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index c289f297b..4abf6a898 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -142,6 +142,7 @@ namespace cryptonote
command_line::add_arg(desc, command_line::arg_db_sync_mode);
command_line::add_arg(desc, command_line::arg_show_time_stats);
command_line::add_arg(desc, command_line::arg_db_auto_remove_logs);
+ command_line::add_arg(desc, command_line::arg_block_sync_size);
}
//-----------------------------------------------------------------------------------------------
bool core::handle_command_line(const boost::program_options::variables_map& vm)
@@ -403,6 +404,10 @@ namespace cryptonote
m_blockchain_storage.set_show_time_stats(show_time_stats);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
+ block_sync_size = command_line::get_arg(vm, command_line::arg_block_sync_size);
+ if (block_sync_size == 0)
+ block_sync_size = BLOCKS_SYNCHRONIZING_DEFAULT_COUNT;
+
// load json & DNS checkpoints, and verify them
// with respect to what blocks we already have
CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index d16bd6553..97abf3271 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -611,6 +611,13 @@ namespace cryptonote
*/
bool are_key_images_spent(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const;
+ /**
+ * @brief get the number of blocks to sync in one go
+ *
+ * @return the number of blocks to sync in one go
+ */
+ size_t get_block_sync_size() const { return block_sync_size; }
+
private:
/**
@@ -798,6 +805,8 @@ namespace cryptonote
std::atomic_flag m_checkpoints_updating; //!< set if checkpoints are currently updating to avoid multiple threads attempting to update at once
boost::interprocess::file_lock db_lock; //!< a lock object for a file lock in the db directory
+
+ size_t block_sync_size;
};
}
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index f16dad281..6dfc9fbc5 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -650,9 +650,9 @@ namespace cryptonote
size_t count = 0;
auto it = context.m_needed_objects.begin();
- size_t count_limit = BLOCKS_SYNCHRONIZING_DEFAULT_COUNT;
+ const size_t count_limit = m_core.get_block_sync_size();
_note_c("net/req-calc" , "Setting count_limit: " << count_limit);
- while(it != context.m_needed_objects.end() && count < BLOCKS_SYNCHRONIZING_DEFAULT_COUNT)
+ while(it != context.m_needed_objects.end() && count < count_limit)
{
if( !(check_having_blocks && m_core.have_block(*it)))
{
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index ad6041fca..67e51398c 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -296,6 +296,16 @@ static std::string get_fork_extra_info(uint64_t t, uint64_t now, uint64_t block_
return "";
}
+static float get_sync_percentage(const cryptonote::COMMAND_RPC_GET_INFO::response &ires)
+{
+ uint64_t height = ires.height;
+ uint64_t target_height = ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height;
+ float pc = 100.0f * height / target_height;
+ if (height < target_height && pc > 99.9f)
+ return 99.9f; // to avoid 100% when not fully synced
+ return pc;
+}
+
bool t_rpc_command_executor::show_status() {
cryptonote::COMMAND_RPC_GET_INFO::request ireq;
cryptonote::COMMAND_RPC_GET_INFO::response ires;
@@ -356,7 +366,7 @@ bool t_rpc_command_executor::show_status() {
tools::success_msg_writer() << boost::format("Height: %llu/%llu (%.1f%%) on %s, %s, net hash %s, v%u%s, %s, %u+%u connections")
% (unsigned long long)ires.height
% (unsigned long long)(ires.target_height >= ires.height ? ires.target_height : ires.height)
- % (100.0f * ires.height / (ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height))
+ % get_sync_percentage(ires)
% (ires.testnet ? "testnet" : "mainnet")
% (mining_busy ? "syncing" : mres.active ? "mining at " + get_mining_speed(mres.speed) : "not mining")
% get_mining_speed(ires.difficulty / ires.target)
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index d3938362e..101a6e306 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -659,7 +659,7 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("viewkey", boost::bind(&simple_wallet::viewkey, this, _1), tr("Display private view key"));
m_cmd_binder.set_handler("spendkey", boost::bind(&simple_wallet::spendkey, this, _1), tr("Display private spend key"));
m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), tr("Display Electrum-style mnemonic seed"));
- m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), tr("Available options: seed language - set wallet seed language; always-confirm-transfers <1|0> - whether to confirm unsplit txes; store-tx-info <1|0> - whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference; default-mixin <n> - set default mixin (default default is 4); auto-refresh <1|0> - whether to automatically sync new blocks from the daemon; refresh-type <full|optimize-coinbase|no-coinbase|default> - set wallet refresh behaviour; priority [1|2|3] - normal/elevated/priority fee"));
+ m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), tr("Available options: seed language - set wallet seed language; always-confirm-transfers <1|0> - whether to confirm unsplit txes; store-tx-info <1|0> - whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference; default-mixin <n> - set default mixin (default is 4); auto-refresh <1|0> - whether to automatically sync new blocks from the daemon; refresh-type <full|optimize-coinbase|no-coinbase|default> - set wallet refresh behaviour; priority [1|2|3] - normal/elevated/priority fee"));
m_cmd_binder.set_handler("rescan_spent", boost::bind(&simple_wallet::rescan_spent, this, _1), tr("Rescan blockchain for spent outputs"));
m_cmd_binder.set_handler("get_tx_key", boost::bind(&simple_wallet::get_tx_key, this, _1), tr("Get transaction key (r) for a given <txid>"));
m_cmd_binder.set_handler("check_tx_key", boost::bind(&simple_wallet::check_tx_key, this, _1), tr("Check amount going to <address> in <txid>"));
@@ -2492,7 +2492,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
print_money(e.tx_amount() + e.fee()) %
print_money(e.tx_amount()) %
print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions");
+ fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees");
}
catch (const tools::error::not_enough_outs_to_mix& e)
{
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 74552bc03..eefb49e95 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -46,7 +46,9 @@ namespace Bitmonero {
namespace {
// copy-pasted from simplewallet
static const size_t DEFAULT_MIXIN = 4;
- static const int DEFAULT_REFRESH_INTERVAL_SECONDS = 10;
+ static const int DEFAULT_REFRESH_INTERVAL_MILLIS = 1000 * 10;
+ // limit maximum refresh interval as one minute
+ static const int MAX_REFRESH_INTERVAL_MILLIS = 1000 * 60 * 1;
}
struct Wallet2CallbackImpl : public tools::i_wallet2_callback
@@ -75,8 +77,12 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
{
- // TODO;
LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
+
+ if (m_listener) {
+ m_listener->newBlock(height);
+ // m_listener->updated();
+ }
}
virtual void on_money_received(uint64_t height, const cryptonote::transaction& tx, uint64_t amount)
@@ -169,7 +175,9 @@ WalletImpl::WalletImpl(bool testnet)
m_wallet->callback(m_wallet2Callback);
m_refreshThreadDone = false;
m_refreshEnabled = false;
- m_refreshIntervalSeconds = DEFAULT_REFRESH_INTERVAL_SECONDS;
+
+ m_refreshIntervalMillis = DEFAULT_REFRESH_INTERVAL_MILLIS;
+
m_refreshThread = boost::thread([this] () {
this->refreshThreadFunc();
});
@@ -272,14 +280,15 @@ bool WalletImpl::close()
{
bool result = false;
+ LOG_PRINT_L3("closing wallet...");
try {
// do not store wallet with invalid status
if (status() == Status_Ok)
m_wallet->store();
- // LOG_PRINT_L0("wallet::store done");
- // LOG_PRINT_L0("Calling wallet::stop...");
+ LOG_PRINT_L3("wallet::store done");
+ LOG_PRINT_L3("Calling wallet::stop...");
m_wallet->stop();
- // LOG_PRINT_L0("wallet::stop done");
+ LOG_PRINT_L3("wallet::stop done");
result = true;
clearStatus();
} catch (const std::exception &e) {
@@ -410,6 +419,27 @@ uint64_t WalletImpl::unlockedBalance() const
return m_wallet->unlocked_balance();
}
+uint64_t WalletImpl::blockChainHeight() const
+{
+ return m_wallet->get_blockchain_current_height();
+}
+
+uint64_t WalletImpl::daemonBlockChainHeight() const
+{
+ std::string err;
+ uint64_t result = m_wallet->get_daemon_blockchain_height(err);
+ if (!err.empty()) {
+ LOG_ERROR(__FUNCTION__ << ": " << err);
+ result = 0;
+ m_errorString = err;
+ m_status = Status_Error;
+
+ } else {
+ m_status = Status_Ok;
+ m_errorString = "";
+ }
+ return result;
+}
bool WalletImpl::refresh()
{
@@ -425,6 +455,22 @@ void WalletImpl::refreshAsync()
m_refreshCV.notify_one();
}
+void WalletImpl::setAutoRefreshInterval(int millis)
+{
+ if (millis > MAX_REFRESH_INTERVAL_MILLIS) {
+ LOG_ERROR(__FUNCTION__<< ": invalid refresh interval " << millis
+ << " ms, maximum allowed is " << MAX_REFRESH_INTERVAL_MILLIS << " ms");
+ m_refreshIntervalMillis = MAX_REFRESH_INTERVAL_MILLIS;
+ } else {
+ m_refreshIntervalMillis = millis;
+ }
+}
+
+int WalletImpl::autoRefreshInterval() const
+{
+ return m_refreshIntervalMillis;
+}
+
// TODO:
// 1 - properly handle payment id (add another menthod with explicit 'payment_id' param)
// 2 - check / design how "Transaction" can be single interface
@@ -637,7 +683,15 @@ void WalletImpl::refreshThreadFunc()
break;
}
LOG_PRINT_L3(__FUNCTION__ << ": waiting for refresh...");
- m_refreshCV.wait(lock);
+ // if auto refresh enabled, we wait for the "m_refreshIntervalSeconds" interval.
+ // if not - we wait forever
+ if (m_refreshIntervalMillis > 0) {
+ boost::posix_time::milliseconds wait_for_ms(m_refreshIntervalMillis);
+ m_refreshCV.timed_wait(lock, wait_for_ms);
+ } else {
+ m_refreshCV.wait(lock);
+ }
+
LOG_PRINT_L3(__FUNCTION__ << ": refresh lock acquired...");
LOG_PRINT_L3(__FUNCTION__ << ": m_refreshEnabled: " << m_refreshEnabled);
LOG_PRINT_L3(__FUNCTION__ << ": m_status: " << m_status);
@@ -680,6 +734,7 @@ void WalletImpl::stopRefresh()
if (!m_refreshThreadDone) {
m_refreshEnabled = false;
m_refreshThreadDone = true;
+ m_refreshCV.notify_one();
m_refreshThread.join();
}
}
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 658296c30..d97a8f3b3 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -75,8 +75,15 @@ public:
bool trustedDaemon() const;
uint64_t balance() const;
uint64_t unlockedBalance() const;
+ uint64_t blockChainHeight() const;
+ uint64_t daemonBlockChainHeight() const;
bool refresh();
void refreshAsync();
+ void setAutoRefreshInterval(int millis);
+ int autoRefreshInterval() const;
+
+
+
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
uint64_t amount, uint32_t mixin_count,
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
@@ -100,8 +107,8 @@ private:
friend class TransactionHistoryImpl;
tools::wallet2 * m_wallet;
- std::atomic<int> m_status;
- std::string m_errorString;
+ mutable std::atomic<int> m_status;
+ mutable std::string m_errorString;
std::string m_password;
TransactionHistoryImpl * m_history;
bool m_trustedDaemon;
@@ -111,7 +118,7 @@ private:
// multi-threaded refresh stuff
std::atomic<bool> m_refreshEnabled;
std::atomic<bool> m_refreshThreadDone;
- std::atomic<int> m_refreshIntervalSeconds;
+ std::atomic<int> m_refreshIntervalMillis;
// synchronizing refresh loop;
boost::mutex m_refreshMutex;
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 45102d5f2..2cbee4812 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -4226,6 +4226,38 @@ std::string wallet2::get_daemon_address() const
return m_daemon_address;
}
+uint64_t wallet2::get_daemon_blockchain_height(string &err)
+{
+ // XXX: DRY violation. copy-pasted from simplewallet.cpp:get_daemon_blockchain_height()
+ // consider to move it from simplewallet to wallet2 ?
+ COMMAND_RPC_GET_HEIGHT::request req;
+ COMMAND_RPC_GET_HEIGHT::response res = boost::value_initialized<COMMAND_RPC_GET_HEIGHT::response>();
+ m_daemon_rpc_mutex.lock();
+ bool ok = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/getheight", req, res, m_http_client);
+ m_daemon_rpc_mutex.unlock();
+ // XXX: DRY violation. copy-pasted from simplewallet.cpp:interpret_rpc_response()
+ if (ok)
+ {
+ if (res.status == CORE_RPC_STATUS_BUSY)
+ {
+ err = "daemon is busy. Please try again later.";
+ }
+ else if (res.status != CORE_RPC_STATUS_OK)
+ {
+ err = res.status;
+ }
+ else // success, cleaning up error message
+ {
+ err = "";
+ }
+ }
+ else
+ {
+ err = "possibly lost connection to daemon";
+ }
+ return res.height;
+}
+
void wallet2::set_tx_note(const crypto::hash &txid, const std::string &note)
{
m_tx_notes[txid] = note;
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index d2d5fc7fd..c1c8edcd8 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -453,6 +453,7 @@ namespace tools
std::string get_wallet_file() const;
std::string get_keys_file() const;
std::string get_daemon_address() const;
+ uint64_t get_daemon_blockchain_height(std::string& err);
std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool trusted_daemon);
std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f);
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index e880b1c68..08e2ae16b 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -114,11 +114,35 @@ struct TransactionHistory
struct WalletListener
{
virtual ~WalletListener() = 0;
+ /**
+ * @brief moneySpent - called when money spent
+ * @param txId - transaction id
+ * @param amount - amount
+ */
virtual void moneySpent(const std::string &txId, uint64_t amount) = 0;
+
+ /**
+ * @brief moneyReceived - called when money received
+ * @param txId - transaction id
+ * @param amount - amount
+ */
virtual void moneyReceived(const std::string &txId, uint64_t amount) = 0;
- // generic callback, called when any event (sent/received/block reveived/etc) happened with the wallet;
+
+ /**
+ * @brief newBlock - called when new block received
+ * @param height - block height
+ */
+ virtual void newBlock(uint64_t height) = 0;
+
+ /**
+ * @brief updated - generic callback, called when any event (sent/received/block reveived/etc) happened with the wallet;
+ */
virtual void updated() = 0;
- // called when wallet refreshed by background thread or explicitly called be calling "refresh" synchronously
+
+
+ /**
+ * @brief refreshed - called when wallet refreshed by background thread or explicitly refreshed by calling "refresh" synchronously
+ */
virtual void refreshed() = 0;
};
@@ -211,6 +235,20 @@ struct Wallet
virtual uint64_t balance() const = 0;
virtual uint64_t unlockedBalance() const = 0;
+ /**
+ * @brief blockChainHeight - returns current blockchain height
+ * @return
+ */
+ virtual uint64_t blockChainHeight() const = 0;
+
+ /**
+ * @brief daemonBlockChainHeight - returns daemon blockchain height
+ * @return 0 - in case error communicating with the daemon.
+ * status() will return Status_Error and errorString() will return verbose error description
+ */
+ virtual uint64_t daemonBlockChainHeight() const = 0;
+
+
static std::string displayAmount(uint64_t amount);
static uint64_t amountFromString(const std::string &amount);
static uint64_t amountFromDouble(double amount);
@@ -223,10 +261,25 @@ struct Wallet
* @return - true if refreshed successfully;
*/
virtual bool refresh() = 0;
+
/**
* @brief refreshAsync - refreshes wallet asynchronously.
*/
virtual void refreshAsync() = 0;
+
+ /**
+ * @brief setAutoRefreshInterval - setup interval for automatic refresh.
+ * @param seconds - interval in millis. if zero or less than zero - automatic refresh disabled;
+ */
+ virtual void setAutoRefreshInterval(int millis) = 0;
+
+ /**
+ * @brief autoRefreshInterval - returns automatic refresh interval in millis
+ * @return
+ */
+ virtual int autoRefreshInterval() const = 0;
+
+
/*!
* \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored
* \param dst_addr destination address as string