aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-03-24 08:50:08 +0200
committerRiccardo Spagni <ric@spagni.net>2015-03-24 08:53:05 +0200
commitd7286395c97afd9d33d6170c1cf24f1e38140b37 (patch)
tree5513e1477d68755a44e0b0c7d34542b1c75eb99d /src/cryptonote_core
parentupdated gtest to latest (diff)
parentMerge upstream to daemonize changes (diff)
downloadmonero-d7286395c97afd9d33d6170c1cf24f1e38140b37.tar.xz
Merge pull request #243
51e3579 Fixed bug in static linking boost on MINGW (Thomas Winget) f78bb00 Hopefully fixes build on Windows for real this time (Thomas Winget) 2b0583b Hopefully fixes build on Windows (Thomas Winget) 9dab105 DNS checkpoint loading for testnet should now be correct (Thomas Winget) 52f9629 sending commands to forked daemon works on testnet now (Thomas Winget) 76289d0 Fix tests building -- function signatures changed (Thomas Winget) db53e19 revert stop_daemon method to use correct exit (Thomas Winget) 96cbecf RPC calls for background daemon added in (Thomas Winget) 9193d6f Daemonize changes pulled in -- daemon builds (Thomas Winget)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp3
-rw-r--r--src/cryptonote_core/blockchain_storage.h1
-rw-r--r--src/cryptonote_core/checkpoints_create.cpp17
-rw-r--r--src/cryptonote_core/checkpoints_create.h2
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp41
-rw-r--r--src/cryptonote_core/cryptonote_core.h7
6 files changed, 59 insertions, 12 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index 42269e05c..72dd35df7 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -87,6 +87,7 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet)
{
CRITICAL_REGION_LOCAL(m_blockchain_lock);
m_config_folder = config_folder;
+ m_testnet = testnet;
LOG_PRINT_L0("Loading blockchain...");
const std::string filename = m_config_folder + "/" CRYPTONOTE_BLOCKCHAINDATA_FILENAME;
if(tools::unserialize_obj_from_file(*this, filename))
@@ -1840,7 +1841,7 @@ bool blockchain_storage::update_checkpoints(const std::string& file_path, bool c
else if (check_dns)
{
checkpoints dns_points;
- cryptonote::load_checkpoints_from_dns(dns_points);
+ cryptonote::load_checkpoints_from_dns(dns_points, m_testnet);
if (m_checkpoints.check_for_conflicts(dns_points))
{
check_against_checkpoints(dns_points, false);
diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h
index 1bfdf7bd0..55f54d13b 100644
--- a/src/cryptonote_core/blockchain_storage.h
+++ b/src/cryptonote_core/blockchain_storage.h
@@ -218,6 +218,7 @@ namespace cryptonote
std::atomic<bool> m_is_blockchain_storing;
bool m_enforce_dns_checkpoints;
+ bool m_testnet;
bool switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& alt_chain, bool discard_disconnected_chain);
bool pop_block_from_blockchain();
diff --git a/src/cryptonote_core/checkpoints_create.cpp b/src/cryptonote_core/checkpoints_create.cpp
index 9760098c8..2cc9a8164 100644
--- a/src/cryptonote_core/checkpoints_create.cpp
+++ b/src/cryptonote_core/checkpoints_create.cpp
@@ -113,7 +113,7 @@ bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::strin
return true;
}
-bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints)
+bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, bool testnet)
{
// All four MoneroPulse domains have DNSSEC on and valid
static const std::vector<std::string> dns_urls = { "checkpoints.moneropulse.se"
@@ -121,6 +121,12 @@ bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints)
, "checkpoints.moneropulse.net"
, "checkpoints.moneropulse.co"
};
+
+ static const std::vector<std::string> testnet_dns_urls = { "testpoints.moneropulse.se"
+ , "testpoints.moneropulse.org"
+ , "testpoints.moneropulse.net"
+ , "testpoints.moneropulse.co"
+ };
bool avail, valid;
std::vector<std::string> records;
@@ -132,7 +138,14 @@ bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints)
size_t cur_index = first_index;
do
{
- records = tools::DNSResolver::instance().get_txt_record(dns_urls[cur_index], avail, valid);
+ if (testnet)
+ {
+ records = tools::DNSResolver::instance().get_txt_record(testnet_dns_urls[cur_index], avail, valid);
+ }
+ else
+ {
+ records = tools::DNSResolver::instance().get_txt_record(dns_urls[cur_index], avail, valid);
+ }
if (records.size() == 0 || (avail && !valid))
{
cur_index++;
diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h
index 569d437cf..8422e2b33 100644
--- a/src/cryptonote_core/checkpoints_create.h
+++ b/src/cryptonote_core/checkpoints_create.h
@@ -42,7 +42,7 @@ namespace cryptonote
bool create_checkpoints(cryptonote::checkpoints& checkpoints);
bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath);
- bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints);
+ bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, bool testnet = false);
bool load_new_checkpoints(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath);
} // namespace cryptonote
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index b8b5dc008..11127290e 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -42,6 +42,8 @@ using namespace epee;
#include "cryptonote_format_utils.h"
#include "misc_language.h"
#include <csignal>
+#include "daemon/command_line_args.h"
+#include "cryptonote_core/checkpoints_create.h"
DISABLE_VS_WARNINGS(4355)
@@ -108,14 +110,41 @@ namespace cryptonote
return res;
}
//-----------------------------------------------------------------------------------
+ void core::stop()
+ {
+ graceful_exit();
+ }
+ //-----------------------------------------------------------------------------------
void core::init_options(boost::program_options::options_description& /*desc*/)
{
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_command_line(const boost::program_options::variables_map& vm, bool testnet)
+ bool core::handle_command_line(const boost::program_options::variables_map& vm)
{
- auto data_dir_arg = testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
+ m_testnet = command_line::get_arg(vm, daemon_args::arg_testnet_on);
+
+ auto data_dir_arg = m_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
m_config_folder = command_line::get_arg(vm, data_dir_arg);
+
+ auto data_dir = boost::filesystem::path(m_config_folder);
+
+ if (!m_testnet)
+ {
+ cryptonote::checkpoints checkpoints;
+ if (!cryptonote::create_checkpoints(checkpoints))
+ {
+ throw std::runtime_error("Failed to initialize checkpoints");
+ }
+ set_checkpoints(std::move(checkpoints));
+
+ boost::filesystem::path json(JSON_HASH_FILE_NAME);
+ boost::filesystem::path checkpoint_json_hashfile_fullpath = data_dir / json;
+
+ set_checkpoints_file_path(checkpoint_json_hashfile_fullpath.string());
+ }
+
+
+ set_enforce_dns_checkpoints(command_line::get_arg(vm, daemon_args::arg_dns_checkpoints));
return true;
}
//-----------------------------------------------------------------------------------------------
@@ -154,21 +183,21 @@ namespace cryptonote
return m_blockchain_storage.get_alternative_blocks_count();
}
//-----------------------------------------------------------------------------------------------
- bool core::init(const boost::program_options::variables_map& vm, bool testnet)
+ bool core::init(const boost::program_options::variables_map& vm)
{
- bool r = handle_command_line(vm, testnet);
+ bool r = handle_command_line(vm);
r = m_mempool.init(m_config_folder);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
- r = m_blockchain_storage.init(m_config_folder, testnet);
+ r = m_blockchain_storage.init(m_config_folder, m_testnet);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
// 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.");
- r = m_miner.init(vm, testnet);
+ r = m_miner.init(vm, m_testnet);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
return load_state_data();
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 748f2b665..1921ef14d 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -72,7 +72,7 @@ namespace cryptonote
miner& get_miner(){return m_miner;}
static void init_options(boost::program_options::options_description& desc);
- bool init(const boost::program_options::variables_map& vm, bool testnet);
+ bool init(const boost::program_options::variables_map& vm);
bool set_genesis_block(const block& b);
bool deinit();
uint64_t get_current_blockchain_height();
@@ -125,6 +125,8 @@ namespace cryptonote
bool update_checkpoints();
+ void stop();
+
private:
bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block);
bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block);
@@ -142,7 +144,7 @@ namespace cryptonote
bool check_tx_ring_signature(const txin_to_key& tx, const crypto::hash& tx_prefix_hash, const std::vector<crypto::signature>& sig);
bool is_tx_spendtime_unlocked(uint64_t unlock_time);
bool update_miner_block_template();
- bool handle_command_line(const boost::program_options::variables_map& vm, bool testnet);
+ bool handle_command_line(const boost::program_options::variables_map& vm);
bool on_update_blocktemplate_interval();
bool check_tx_inputs_keyimages_diff(const transaction& tx);
void graceful_exit();
@@ -163,6 +165,7 @@ namespace cryptonote
uint64_t m_target_blockchain_height;
+ bool m_testnet;
std::string m_checkpoints_path;
time_t m_last_dns_checkpoints_update;
time_t m_last_json_checkpoints_update;