aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp4
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp137
-rw-r--r--src/cryptonote_core/cryptonote_core.h37
-rw-r--r--src/cryptonote_core/tx_pool.cpp16
4 files changed, 139 insertions, 55 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index a81286632..d5fefffcd 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1986,12 +1986,14 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
return false;
}
+ m_db->block_txn_start(true);
resp.total_height = get_current_blockchain_height();
size_t count = 0;
for(size_t i = resp.start_height; i < resp.total_height && count < BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT; i++, count++)
{
resp.m_block_ids.push_back(m_db->get_block_hash_from_height(i));
}
+ m_db->block_txn_stop();
return true;
}
//------------------------------------------------------------------
@@ -2022,6 +2024,7 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
}
}
+ m_db->block_txn_start(true);
total_height = get_current_blockchain_height();
size_t count = 0;
for(size_t i = start_height; i < total_height && count < max_count; i++, count++)
@@ -2032,6 +2035,7 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
get_transactions(blocks.back().first.tx_hashes, blocks.back().second, mis);
CHECK_AND_ASSERT_MES(!mis.size(), false, "internal error, transaction from block not found");
}
+ m_db->block_txn_stop();
return true;
}
//------------------------------------------------------------------
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index b940dba3c..fd509b603 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -35,6 +35,8 @@ using namespace epee;
#include "cryptonote_core.h"
#include "common/command_line.h"
#include "common/util.h"
+#include "common/updates.h"
+#include "common/download.h"
#include "warnings.h"
#include "crypto/crypto.h"
#include "cryptonote_config.h"
@@ -148,6 +150,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_block_sync_size);
+ command_line::add_arg(desc, command_line::arg_check_updates);
}
//-----------------------------------------------------------------------------------------------
bool core::handle_command_line(const boost::program_options::variables_map& vm)
@@ -219,40 +222,6 @@ namespace cryptonote
return m_blockchain_storage.get_alternative_blocks_count();
}
//-----------------------------------------------------------------------------------------------
- bool core::lock_db_directory(const boost::filesystem::path &path)
- {
- // boost doesn't like locking directories...
- const boost::filesystem::path lock_path = path / ".daemon_lock";
-
- try
- {
- // ensure the file exists
- std::ofstream(lock_path.string(), std::ios::out).close();
-
- db_lock = boost::interprocess::file_lock(lock_path.string().c_str());
- LOG_PRINT_L1("Locking " << lock_path.string());
- if (!db_lock.try_lock())
- {
- LOG_ERROR("Failed to lock " << lock_path.string());
- return false;
- }
- return true;
- }
- catch (const std::exception &e)
- {
- LOG_ERROR("Error trying to lock " << lock_path.string() << ": " << e.what());
- return false;
- }
- }
- //-----------------------------------------------------------------------------------------------
- bool core::unlock_db_directory()
- {
- db_lock.unlock();
- db_lock = boost::interprocess::file_lock();
- LOG_PRINT_L1("Blockchain directory successfully unlocked");
- return true;
- }
- //-----------------------------------------------------------------------------------------------
bool core::init(const boost::program_options::variables_map& vm, const cryptonote::test_options *test_options)
{
start_time = std::time(nullptr);
@@ -276,6 +245,7 @@ namespace cryptonote
std::string db_sync_mode = command_line::get_arg(vm, command_line::arg_db_sync_mode);
bool fast_sync = command_line::get_arg(vm, command_line::arg_fast_block_sync) != 0;
uint64_t blocks_threads = command_line::get_arg(vm, command_line::arg_prep_blocks_threads);
+ std::string check_updates_string = command_line::get_arg(vm, command_line::arg_check_updates);
boost::filesystem::path folder(m_config_folder);
if (m_fakechain)
@@ -284,11 +254,6 @@ namespace cryptonote
// make sure the data directory exists, and try to lock it
CHECK_AND_ASSERT_MES (boost::filesystem::exists(folder) || boost::filesystem::create_directories(folder), false,
std::string("Failed to create directory ").append(folder.string()).c_str());
- if (!lock_db_directory (folder))
- {
- LOG_ERROR ("Failed to lock " << folder);
- return false;
- }
// check for blockchain.bin
try
@@ -418,6 +383,20 @@ namespace cryptonote
// 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.");
+ // DNS versions checking
+ if (check_updates_string == "disabled")
+ check_updates_level = UPDATES_DISABLED;
+ else if (check_updates_string == "notify")
+ check_updates_level = UPDATES_NOTIFY;
+ else if (check_updates_string == "download")
+ check_updates_level = UPDATES_DOWNLOAD;
+ else if (check_updates_string == "update")
+ check_updates_level = UPDATES_UPDATE;
+ else {
+ MERROR("Invalid argument to --dns-versions-check: " << check_updates_string);
+ return false;
+ }
+
r = m_miner.init(vm, m_testnet);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize miner instance");
@@ -440,7 +419,6 @@ namespace cryptonote
m_miner.stop();
m_mempool.deinit();
m_blockchain_storage.deinit();
- unlock_db_directory();
return true;
}
//-----------------------------------------------------------------------------------------------
@@ -639,6 +617,12 @@ namespace cryptonote
return false;
}
+ if (!check_tx_inputs_keyimages_domain(tx))
+ {
+ MERROR_VER("tx uses key image not in the valid domain");
+ return false;
+ }
+
if (tx.version >= 2)
{
const rct::rctSig &rv = tx.rct_signatures;
@@ -722,6 +706,18 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
+ bool core::check_tx_inputs_keyimages_domain(const transaction& tx) const
+ {
+ std::unordered_set<crypto::key_image> ki;
+ for(const auto& in: tx.vin)
+ {
+ CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
+ if (!(rct::scalarmultKey(rct::ki2rct(tokey_in.k_image), rct::curveOrder()) == rct::identity()))
+ return false;
+ }
+ return true;
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
crypto::hash tx_hash = get_transaction_hash(tx);
@@ -1040,6 +1036,7 @@ namespace cryptonote
m_fork_moaner.do_call(boost::bind(&core::check_fork_time, this));
m_txpool_auto_relayer.do_call(boost::bind(&core::relay_txpool_transactions, this));
+ m_check_updates_interval.do_call(boost::bind(&core::check_updates, this));
m_miner.on_idle();
m_mempool.on_idle();
return true;
@@ -1067,6 +1064,66 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
+ bool core::check_updates()
+ {
+ static const char software[] = "monerod";
+ static const char subdir[] = "cli"; // because it can never be simple
+#ifdef BUILD_TAG
+ static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG);
+#else
+ static const char buildtag[] = "source";
+#endif
+
+ if (check_updates_level == UPDATES_DISABLED)
+ return true;
+
+ std::string version, hash;
+ MDEBUG("Checking for a new " << software << " version for " << buildtag);
+ if (!tools::check_updates(software, buildtag, m_testnet, version, hash))
+ return false;
+
+ if (tools::vercmp(version.c_str(), MONERO_VERSION) <= 0)
+ return true;
+
+ std::string url = tools::get_update_url(software, subdir, buildtag, version);
+ MGINFO("Version " << version << " of " << software << " for " << buildtag << " is available: " << url << ", SHA256 hash " << hash);
+
+ if (check_updates_level == UPDATES_NOTIFY)
+ return true;
+
+ std::string filename;
+ const char *slash = strrchr(url.c_str(), '/');
+ if (slash)
+ filename = slash + 1;
+ else
+ filename = std::string(software) + "-update-" + version;
+ boost::filesystem::path path(epee::string_tools::get_current_module_folder());
+ path /= filename;
+ if (!tools::download(path.string(), url))
+ {
+ MERROR("Failed to download " << url);
+ return false;
+ }
+ crypto::hash file_hash;
+ if (!tools::sha256sum(path.string(), file_hash))
+ {
+ MERROR("Failed to hash " << path);
+ return false;
+ }
+ if (hash != epee::string_tools::pod_to_hex(file_hash))
+ {
+ MERROR("Download from " << url << " does not match the expected hash");
+ return false;
+ }
+ MGINFO("New version downloaded to " << path);
+
+ if (check_updates_level == UPDATES_DOWNLOAD)
+ return true;
+
+ MERROR("Download/update not implemented yet");
+ return true;
+ }
+ //-----------------------------------------------------------------------------------------------
void core::set_target_blockchain_height(uint64_t target_blockchain_height)
{
m_target_blockchain_height = target_blockchain_height;
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index fe1d11916..43435b0c3 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -745,6 +745,16 @@ namespace cryptonote
bool check_tx_inputs_keyimages_diff(const transaction& tx) const;
/**
+ * @brief verify that each input key image in a transaction is in
+ * the valid domain
+ *
+ * @param tx the transaction to check
+ *
+ * @return false if any key image is not in the valid domain, otherwise true
+ */
+ bool check_tx_inputs_keyimages_domain(const transaction& tx) const;
+
+ /**
* @brief checks HardFork status and prints messages about it
*
* Checks the status of HardFork and logs/prints if an update to
@@ -764,22 +774,11 @@ namespace cryptonote
bool relay_txpool_transactions();
/**
- * @brief locks a file in the BlockchainDB directory
- *
- * @param path the directory in which to place the file
- *
- * @return true if lock acquired successfully, otherwise false
- */
- bool lock_db_directory(const boost::filesystem::path &path);
-
- /**
- * @brief unlocks the db directory
+ * @brief checks DNS versions
*
- * @note see lock_db_directory()
- *
- * @return true
+ * @return true on success, false otherwise
*/
- bool unlock_db_directory();
+ bool check_updates();
bool m_test_drop_download = true; //!< whether or not to drop incoming blocks (for testing)
@@ -801,8 +800,9 @@ namespace cryptonote
cryptonote_protocol_stub m_protocol_stub; //!< cryptonote protocol stub instance
epee::math_helper::once_a_time_seconds<60*60*12, false> m_store_blockchain_interval; //!< interval for manual storing of Blockchain, if enabled
- epee::math_helper::once_a_time_seconds<60*60*2, false> m_fork_moaner; //!< interval for checking HardFork status
+ epee::math_helper::once_a_time_seconds<60*60*2, true> m_fork_moaner; //!< interval for checking HardFork status
epee::math_helper::once_a_time_seconds<60*2, false> m_txpool_auto_relayer; //!< interval for checking re-relaying txpool transactions
+ epee::math_helper::once_a_time_seconds<60*60*12, true> m_check_updates_interval; //!< interval for checking for new versions
friend class tx_validate_inputs;
std::atomic<bool> m_starter_message_showed; //!< has the "daemon will sync now" message been shown?
@@ -826,6 +826,13 @@ namespace cryptonote
time_t start_time;
std::unordered_set<crypto::hash> bad_semantics_txes;
+
+ enum {
+ UPDATES_DISABLED,
+ UPDATES_NOTIFY,
+ UPDATES_DOWNLOAD,
+ UPDATES_UPDATE,
+ } check_updates_level;
};
}
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index f48be1ff1..baceb1cb2 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -619,7 +619,11 @@ namespace cryptonote
get_block_reward(median_size, total_size, already_generated_coins, best_coinbase, version);
+#if 1
+ size_t max_total_size = (130 * median_size) / 100 - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
+#else
size_t max_total_size = 2 * median_size - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
+#endif
std::unordered_set<crypto::key_image> k_images;
LOG_PRINT_L2("Filling block template, median size " << median_size << ", " << m_txs_by_fee_and_receive_time.size() << " txes in the pool");
@@ -637,6 +641,15 @@ namespace cryptonote
continue;
}
+#if 1
+ // If we've exceeded the penalty free size,
+ // stop including more tx
+ if (total_size > median_size)
+ {
+ LOG_PRINT_L2(" would exceed median block size");
+ break;
+ }
+#else
// If we're getting lower coinbase tx,
// stop including more tx
uint64_t block_reward;
@@ -653,6 +666,7 @@ namespace cryptonote
sorted_it++;
continue;
}
+#endif
// Skip transactions that are not ready to be
// included into the blockchain or that are
@@ -667,7 +681,9 @@ namespace cryptonote
bl.tx_hashes.push_back(tx_it->first);
total_size += tx_it->second.blob_size;
fee += tx_it->second.fee;
+#if 0
best_coinbase = coinbase;
+#endif
append_key_images(k_images, tx_it->second.tx);
sorted_it++;
LOG_PRINT_L2(" added, new block size " << total_size << "/" << max_total_size << ", coinbase " << print_money(best_coinbase));