From 2c0a87f2ac3fe26b92dc732c5050ae664bc84e66 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 12:31:45 +0200 Subject: [PATCH 01/19] additional README info on static builds and FreeBSD --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 469538a9b..e275c0ebf 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Dependencies: GCC 4.7.3 or later, CMake 2.8.6 or later, and Boost 1.53 or later **Advanced options:** * Parallel build: run `make -j` instead of `make`. +* Statically linked release build: run `make release-static`. * Debug build: run `make build-debug`. * Test suite: run `make test-release` to run tests in addition to building. Running `make test-debug` will do the same to the debug version. * Building with Clang: it may be possible to use Clang instead of GCC, but this may not work everywhere. To build, run `export CC=clang CXX=clang++` before running `make`. @@ -87,6 +88,12 @@ msbuild Project.sln /p:Configuration=Release ``` * If you don't have your path environment variable configured with the VS paths, you may may want to run `C:\program files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat` (or equivalent) to temporarily set the environment variables. +### On FreeBSD: + +The project can be built from scratch by following instructions for Unix and Linux above. + +We expect to add Monero into the ports tree in the near future, which will aid in managing installations using ports or packages. + ## Building Documentation Monero developer documentation uses Doxygen, and is currently a work-in-progress. From 32004a756c605b322d07d6f9917c8edaf6ca8961 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 12:46:04 +0200 Subject: [PATCH 02/19] increase ABSTRACT_SERVER_SEND_QUE_MAX_COUNT to a more sane value --- contrib/epee/include/net/abstract_tcp_server2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index b8e291c32..6c613c5d5 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -48,7 +48,7 @@ #include "syncobj.h" -#define ABSTRACT_SERVER_SEND_QUE_MAX_COUNT 100 +#define ABSTRACT_SERVER_SEND_QUE_MAX_COUNT 1000 namespace epee { From 07470fd400ee30b84f6227edffb24094d03781cb Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 16 Jul 2014 13:30:15 -0400 Subject: [PATCH 03/19] Add testnet flag Source: cryptonotefoundation --- src/cryptonote_core/blockchain_storage.cpp | 40 ++++++++++++++++--- src/cryptonote_core/blockchain_storage.h | 5 ++- src/cryptonote_core/cryptonote_core.cpp | 4 +- src/cryptonote_core/cryptonote_core.h | 2 +- .../cryptonote_format_utils.cpp | 10 +++++ src/cryptonote_core/cryptonote_format_utils.h | 1 + src/daemon/daemon.cpp | 17 ++++++-- src/p2p/net_node.h | 5 ++- src/p2p/net_node.inl | 34 +++++++++------- src/simplewallet/simplewallet.cpp | 19 +++++---- src/simplewallet/simplewallet.h | 4 +- src/wallet/wallet2.cpp | 37 +++++++++++++---- src/wallet/wallet2.h | 7 +++- tests/core_proxy/core_proxy.cpp | 2 +- tests/core_tests/chaingen.h | 2 +- 15 files changed, 137 insertions(+), 52 deletions(-) diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index c80cec92c..cd20cd818 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -82,7 +82,7 @@ uint64_t blockchain_storage::get_current_blockchain_height() return m_blocks.size(); } //------------------------------------------------------------------ -bool blockchain_storage::init(const std::string& config_folder) +bool blockchain_storage::init(const std::string& config_folder, bool testnet) { CRITICAL_REGION_LOCAL(m_blockchain_lock); m_config_folder = config_folder; @@ -121,11 +121,24 @@ bool blockchain_storage::init(const std::string& config_folder) if(!m_blocks.size()) { LOG_PRINT_L0("Blockchain not loaded, generating genesis block."); - block bl = boost::value_initialized(); - block_verification_context bvc = boost::value_initialized(); - generate_genesis_block(bl); - add_new_block(bl, bvc); - CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed, false, "Failed to add genesis block to blockchain"); + + if (!store_genesis_block(testnet)) { + return false; + } + } else { + cryptonote::block b; + if (testnet) { + generate_testnet_genesis_block(b); + } else { + generate_genesis_block(b); + } + + crypto::hash genesis_hash = get_block_hash(m_blocks[0].bl); + crypto::hash testnet_genesis_hash = get_block_hash(b); + if (genesis_hash != testnet_genesis_hash) { + LOG_ERROR("Failed to init: genesis block mismatch. Probably you set --testnet flag with data dir with non-test blockchain or another network."); + return false; + } } uint64_t timestamp_diff = time(NULL) - m_blocks.back().bl.timestamp; if(!m_blocks.back().bl.timestamp) @@ -134,6 +147,21 @@ bool blockchain_storage::init(const std::string& config_folder) return true; } //------------------------------------------------------------------ +bool blockchain_storage::store_genesis_block(bool testnet) { + block bl = ::boost::value_initialized(); + block_verification_context bvc = boost::value_initialized(); + + if (testnet) { + generate_testnet_genesis_block(bl); + } else { + generate_genesis_block(bl); + } + + add_new_block(bl, bvc); + CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed, false, "Failed to add genesis block to blockchain"); + return true; +} +//------------------------------------------------------------------ bool blockchain_storage::store_blockchain() { m_is_blockchain_storing = true; diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h index 55c0cb77e..0f7295516 100644 --- a/src/cryptonote_core/blockchain_storage.h +++ b/src/cryptonote_core/blockchain_storage.h @@ -81,8 +81,8 @@ namespace cryptonote blockchain_storage(tx_memory_pool& tx_pool):m_tx_pool(tx_pool), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), m_is_blockchain_storing(false) {}; - bool init() { return init(tools::get_default_data_dir()); } - bool init(const std::string& config_folder); + bool init() { return init(tools::get_default_data_dir(), true); } + bool init(const std::string& config_folder, bool testnet = false); bool deinit(); void set_checkpoints(checkpoints&& chk_pts) { m_checkpoints = chk_pts; } @@ -242,6 +242,7 @@ namespace cryptonote uint64_t get_adjusted_time(); bool complete_timestamps_vector(uint64_t start_height, std::vector& timestamps); bool update_next_comulative_size_limit(); + bool store_genesis_block(bool testnet); }; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 637b8fea6..3ff139c95 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -116,14 +116,14 @@ namespace cryptonote return m_blockchain_storage.get_alternative_blocks_count(); } //----------------------------------------------------------------------------------------------- - bool core::init(const boost::program_options::variables_map& vm) + bool core::init(const boost::program_options::variables_map& vm, bool 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); + r = m_blockchain_storage.init(m_config_folder, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); r = m_miner.init(vm); diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 704a65cf1..f050431ef 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -70,7 +70,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 init(const boost::program_options::variables_map& vm, bool testnet); bool set_genesis_block(const block& b); bool deinit(); uint64_t get_current_blockchain_height(); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index d023561c3..47cd0e159 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -686,6 +686,16 @@ namespace cryptonote miner::find_nonce_for_given_block(bl, 1, 0); return true; } + + bool generate_testnet_genesis_block(cryptonote::block& b) { + if (!generate_genesis_block(b)) { + return false; + } + + b.nonce += 1; + return true; + } + //--------------------------------------------------------------- bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) { diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 9ed6c10a4..4457f6cc6 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -106,6 +106,7 @@ namespace cryptonote bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height); crypto::hash get_block_longhash(const block& b, uint64_t height); bool generate_genesis_block(block& bl); + bool generate_testnet_genesis_block(block& bl); bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b); bool get_inputs_money_amount(const transaction& tx, uint64_t& money); uint64_t get_outs_money_amount(const transaction& tx); diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 187970359..1041aa439 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -62,6 +62,8 @@ namespace const command_line::arg_descriptor arg_log_file = {"log-file", "", ""}; const command_line::arg_descriptor arg_log_level = {"log-level", "", LOG_LEVEL_0}; const command_line::arg_descriptor arg_console = {"no-console", "Disable daemon console commands"}; + const command_line::arg_descriptor arg_testnet_on = {"testnet", "Used to deploy test nets. Checkpoints and hardcoded seeds are ignored, " + "network id is changed. Use it with --data-dir flag. The wallet must be launched with --testnet flag.", false}; } bool command_line_preprocessor(const boost::program_options::variables_map& vm) @@ -123,7 +125,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_sett, arg_log_file); command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_console); - + command_line::add_arg(desc_cmd_sett, arg_testnet_on); cryptonote::core::init_options(desc_cmd_sett); cryptonote::core_rpc_server::init_options(desc_cmd_sett); @@ -191,7 +193,14 @@ int main(int argc, char* argv[]) //create objects and link them cryptonote::core ccore(NULL); - ccore.set_checkpoints(std::move(checkpoints)); + + bool testnet_mode = command_line::get_arg(vm, arg_testnet_on); + if (testnet_mode) { + LOG_PRINT_L0("Starting in testnet mode!"); + } else { + ccore.set_checkpoints(std::move(checkpoints)); + } + cryptonote::t_cryptonote_protocol_handler cprotocol(ccore, NULL); nodetool::node_server > p2psrv(cprotocol); cryptonote::core_rpc_server rpc_server(ccore, p2psrv); @@ -201,7 +210,7 @@ int main(int argc, char* argv[]) //initialize objects LOG_PRINT_L0("Initializing P2P server..."); - res = p2psrv.init(vm); + res = p2psrv.init(vm, testnet_mode); CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize P2P server."); LOG_PRINT_L0("P2P server initialized OK"); @@ -217,7 +226,7 @@ int main(int argc, char* argv[]) //initialize core here LOG_PRINT_L0("Initializing core..."); - res = ccore.init(vm); + res = ccore.init(vm, testnet_mode); CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core"); LOG_PRINT_L0("Core initialized OK"); diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index d7576d5dd..bca18c906 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -79,13 +79,13 @@ namespace nodetool public: typedef t_payload_net_handler payload_net_handler; // Some code - node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false) + node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false), m_network_id(MONERO_NETWORK) {} static void init_options(boost::program_options::options_description& desc); bool run(); - bool init(const boost::program_options::variables_map& vm); + bool init(const boost::program_options::variables_map& vm, bool testnet); bool deinit(); bool send_stop_signal(); uint32_t get_this_peer_port(){return m_listenning_port;} @@ -229,6 +229,7 @@ namespace nodetool uint64_t m_peer_livetime; //keep connections to initiate some interactions net_server m_net_server; + boost::uuids::uuid m_network_id; }; } diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index ee401ce42..211f5064a 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -224,19 +224,23 @@ namespace nodetool #define ADD_HARDCODED_SEED_NODE(addr) append_net_address(m_seed_nodes, addr); //----------------------------------------------------------------------------------- template - bool node_server::init(const boost::program_options::variables_map& vm) + bool node_server::init(const boost::program_options::variables_map& vm, bool testnet) { - ADD_HARDCODED_SEED_NODE("62.210.78.186:18080"); - ADD_HARDCODED_SEED_NODE("195.12.60.154:18080"); - ADD_HARDCODED_SEED_NODE("54.241.246.125:18080"); - ADD_HARDCODED_SEED_NODE("107.170.157.169:18080"); - ADD_HARDCODED_SEED_NODE("54.207.112.216:18080"); - ADD_HARDCODED_SEED_NODE("78.27.112.54:18080"); - ADD_HARDCODED_SEED_NODE("209.222.30.57:18080"); - ADD_HARDCODED_SEED_NODE("80.71.13.55:18080"); - ADD_HARDCODED_SEED_NODE("107.178.112.126:18080"); - ADD_HARDCODED_SEED_NODE("107.158.233.98:18080"); - ADD_HARDCODED_SEED_NODE("64.22.111.2:18080"); + if (!testnet) { + ADD_HARDCODED_SEED_NODE("62.210.78.186:18080"); + ADD_HARDCODED_SEED_NODE("195.12.60.154:18080"); + ADD_HARDCODED_SEED_NODE("54.241.246.125:18080"); + ADD_HARDCODED_SEED_NODE("107.170.157.169:18080"); + ADD_HARDCODED_SEED_NODE("54.207.112.216:18080"); + ADD_HARDCODED_SEED_NODE("78.27.112.54:18080"); + ADD_HARDCODED_SEED_NODE("209.222.30.57:18080"); + ADD_HARDCODED_SEED_NODE("80.71.13.55:18080"); + ADD_HARDCODED_SEED_NODE("107.178.112.126:18080"); + ADD_HARDCODED_SEED_NODE("107.158.233.98:18080"); + ADD_HARDCODED_SEED_NODE("64.22.111.2:18080"); + } else { + m_network_id.data[0] += 1; + } bool res = handle_command_line(vm); CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line"); @@ -410,7 +414,7 @@ namespace nodetool return; } - if(rsp.node_data.network_id != MONERO_NETWORK) + if(rsp.node_data.network_id != m_network_id) { LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong network! (" << epee::string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection."); return; @@ -818,7 +822,7 @@ namespace nodetool node_data.my_port = m_external_port ? m_external_port : m_listenning_port; else node_data.my_port = 0; - node_data.network_id = MONERO_NETWORK; + node_data.network_id = m_network_id; return true; } //----------------------------------------------------------------------------------- @@ -1038,7 +1042,7 @@ namespace nodetool template int node_server::handle_handshake(int command, typename COMMAND_HANDSHAKE::request& arg, typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context) { - if(arg.node_data.network_id != MONERO_NETWORK) + if(arg.node_data.network_id != m_network_id) { LOG_PRINT_CCONTEXT_L1("WRONG NETWORK AGENT CONNECTED! id=" << epee::string_tools::get_str_from_guid_a(arg.node_data.network_id)); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e822e6636..4312981e2 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -72,6 +72,7 @@ namespace const command_line::arg_descriptor arg_non_deterministic = {"non-deterministic", "creates non-deterministic view and spend keys", false}; const command_line::arg_descriptor arg_daemon_port = {"daemon-port", "Use daemon instance at port instead of 8081", 0}; const command_line::arg_descriptor arg_log_level = {"set_log", "", 0, true}; + const command_line::arg_descriptor arg_testnet = {"testnet", "Used to deploy test nets. The daemon must be launched with --testnet flag", false}; const command_line::arg_descriptor< std::vector > arg_command = {"command", ""}; @@ -334,6 +335,8 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if (m_daemon_address.empty()) m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port); + bool testnet = command_line::get_arg(vm, arg_testnet); + tools::password_container pwd_container; if (command_line::has_arg(vm, arg_password)) { @@ -378,12 +381,12 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) return false; } } - bool r = new_wallet(m_wallet_file, pwd_container.password(), m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic); + bool r = new_wallet(m_wallet_file, pwd_container.password(), m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, testnet); CHECK_AND_ASSERT_MES(r, false, "account creation failed"); } else { - bool r = open_wallet(m_wallet_file, pwd_container.password()); + bool r = open_wallet(m_wallet_file, pwd_container.password(), testnet); CHECK_AND_ASSERT_MES(r, false, "could not open account"); } @@ -423,11 +426,11 @@ bool simple_wallet::try_connect_to_daemon() } //---------------------------------------------------------------------------------------------------- -bool simple_wallet::new_wallet(const string &wallet_file, const std::string& password, const crypto::secret_key& recovery_key, bool recover, bool two_random) +bool simple_wallet::new_wallet(const string &wallet_file, const std::string& password, const crypto::secret_key& recovery_key, bool recover, bool two_random, bool testnet) { m_wallet_file = wallet_file; - m_wallet.reset(new tools::wallet2()); + m_wallet.reset(new tools::wallet2(testnet)); m_wallet->callback(this); crypto::secret_key recovery_val; @@ -471,10 +474,10 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas return true; } //---------------------------------------------------------------------------------------------------- -bool simple_wallet::open_wallet(const string &wallet_file, const std::string& password) +bool simple_wallet::open_wallet(const string &wallet_file, const std::string& password, bool testnet) { m_wallet_file = wallet_file; - m_wallet.reset(new tools::wallet2()); + m_wallet.reset(new tools::wallet2(testnet)); m_wallet->callback(this); try @@ -1075,6 +1078,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_restore_deterministic_wallet ); command_line::add_arg(desc_params, arg_non_deterministic ); command_line::add_arg(desc_params, arg_electrum_seed ); + command_line::add_arg(desc_params, arg_testnet); tools::wallet_rpc_server::init_options(desc_params); po::positional_options_description positional_options; @@ -1144,6 +1148,7 @@ int main(int argc, char* argv[]) return 1; } + bool testnet = command_line::get_arg(vm, arg_testnet); std::string wallet_file = command_line::get_arg(vm, arg_wallet_file); std::string wallet_password = command_line::get_arg(vm, arg_password); std::string daemon_address = command_line::get_arg(vm, arg_daemon_address); @@ -1156,7 +1161,7 @@ int main(int argc, char* argv[]) if (daemon_address.empty()) daemon_address = std::string("http://") + daemon_host + ":" + std::to_string(daemon_port); - tools::wallet2 wal; + tools::wallet2 wal(testnet); try { LOG_PRINT_L0("Loading wallet..."); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 41197b4bb..17affd564 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -66,8 +66,8 @@ namespace cryptonote bool run_console_handler(); - bool new_wallet(const std::string &wallet_file, const std::string& password, const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false, bool two_random = false); - bool open_wallet(const std::string &wallet_file, const std::string& password); + bool new_wallet(const std::string &wallet_file, const std::string& password, const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false, bool two_random = false, bool testnet = false); + bool open_wallet(const std::string &wallet_file, const std::string& password, bool testnet); bool close_wallet(); bool viewkey(const std::vector &args = std::vector()); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 48aa164ab..be857c78a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -420,9 +420,6 @@ bool wallet2::clear() { m_blockchain.clear(); m_transfers.clear(); - cryptonote::block b; - cryptonote::generate_genesis_block(b); - m_blockchain.push_back(get_block_hash(b)); m_local_bc_height = 1; return true; } @@ -501,6 +498,10 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str()); if(!r) LOG_PRINT_RED_L0("String with address text not saved"); + cryptonote::block b; + generate_genesis(b); + m_blockchain.push_back(get_block_hash(b)); + store(); return retval; } @@ -573,15 +574,28 @@ void wallet2::load(const std::string& wallet_, const std::string& password) m_account_public_address.m_view_public_key != m_account.get_keys().m_account_address.m_view_public_key, error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file); - if(m_blockchain.empty()) + cryptonote::block genesis; + generate_genesis(genesis); + crypto::hash genesis_hash = get_block_hash(genesis); + + if (m_blockchain.empty()) { - cryptonote::block b; - cryptonote::generate_genesis_block(b); - m_blockchain.push_back(get_block_hash(b)); + m_blockchain.push_back(genesis_hash); } + else + { + check_genesis(genesis_hash); + } + m_local_bc_height = m_blockchain.size(); } //---------------------------------------------------------------------------------------------------- +void wallet2::check_genesis(const crypto::hash& genesis_hash) { + std::string what("Genesis block missmatch. You probably use wallet without testnet flag with blockchain from test network or vice versa"); + + THROW_WALLET_EXCEPTION_IF(genesis_hash != m_blockchain[0], error::wallet_internal_error, what); +} +//---------------------------------------------------------------------------------------------------- void wallet2::store() { bool r = tools::serialize_obj_to_file(*this, m_wallet_file); @@ -918,4 +932,13 @@ std::vector wallet2::create_transactions(std::vector m_run; i_wallet2_callback* m_callback; + bool m_testnet; }; } BOOST_CLASS_VERSION(tools::wallet2, 7) diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index 5f7bbc095..098b9878a 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -112,7 +112,7 @@ int main(int argc, char* argv[]) //initialize objects LOG_PRINT_L0("Initializing p2p server..."); - bool res = p2psrv.init(vm); + bool res = p2psrv.init(vm, false); CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize p2p server."); LOG_PRINT_L0("P2p server initialized OK"); diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 685323127..d2990e009 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -487,7 +487,7 @@ inline bool do_replay_events(std::vector& events) cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects cryptonote::core c(&pr); - if (!c.init(vm)) + if (!c.init(vm, false)) { std::cout << concolor::magenta << "Failed to init core" << concolor::normal << std::endl; return false; From 79862ad1dedbae081e8facd58ef054de746c7095 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 25 Aug 2014 12:20:17 -0400 Subject: [PATCH 04/19] Add testnet constants --- src/cryptonote_config.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index d7232aa6d..251152d7e 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -36,6 +36,7 @@ #define CRYPTONOTE_MAX_TX_SIZE 1000000000 #define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0 #define CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX 18 // addresses start with "4" +#define CRYPTONOTE_TESTNET_ADDRESS_BASE58_PREFIX 19 // addresses start with "5" #define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60 #define CURRENT_TRANSACTION_VERSION 1 #define CURRENT_BLOCK_MAJOR_VERSION 1 @@ -82,7 +83,9 @@ #define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week #define P2P_DEFAULT_PORT 18080 +#define TESTNET_P2P_DEFAULT_PORT 28080 #define RPC_DEFAULT_PORT 18081 +#define TESTNET_RPC_DEFAULT_PORT 28081 #define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT 1000 #define P2P_LOCAL_WHITE_PEERLIST_LIMIT 1000 @@ -97,8 +100,21 @@ #define P2P_DEFAULT_INVOKE_TIMEOUT 60*2*1000 //2 minutes #define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT 5000 //5 seconds #define P2P_STAT_TRUSTED_PUB_KEY "0000000000000000000000000000000000000000000000000000000000000000" +#define TESTNET_P2P_STAT_TRUSTED_PUB_KEY "0000000000000000000000000000000000000000000000000000000000000000" #define P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT 70 +// reference these in src/p2p/p2p_networks.h +#define MAINNET_NETWORK_ID { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10 } +#define TESTNET_NETWORK_ID { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11 } + +// reference these in src/cryptonote_core/cryptonote_format_utils.cpp +#define MAINNET_GENESIS_HASH "010a01ff0001ffffffffffff0f029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121013c086a48c15fb637a96991bc6d53caf77068b5ba6eeb3c82357228c49790584a" +#define MAINNET_GENESIS_NONCE 10000 +#define TESTNET_GENESIS_HASH "CHANGEME" +#define TESTNET_GENESIS_NONCE CHANGEME + +// remember also to add seed nodes to src/p2p/net_node.inl for the testnet + #define ALLOW_DEBUG_COMMANDS #define CRYPTONOTE_NAME "bitmonero" From fb4146fa343399229c754331ecc78fe0c759ec7c Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Thu, 4 Sep 2014 22:14:36 -0400 Subject: [PATCH 05/19] Reorganize testnet constants --- src/connectivity_tool/conn_tool.cpp | 2 +- src/cryptonote_config.h | 52 ++++++++++++------- src/cryptonote_core/cryptonote_basic_impl.cpp | 6 +-- .../cryptonote_format_utils.cpp | 5 +- src/p2p/net_node.h | 4 +- src/p2p/net_node.inl | 4 +- src/p2p/p2p_networks.h | 36 ------------- src/rpc/core_rpc_server.cpp | 2 +- src/simplewallet/simplewallet.cpp | 4 +- src/wallet/wallet2.cpp | 2 +- tests/core_proxy/core_proxy.cpp | 5 +- .../transactions_flow_test.cpp | 12 +++-- tests/unit_tests/base58.cpp | 6 +-- tests/unit_tests/test_format_utils.cpp | 8 ++- 14 files changed, 68 insertions(+), 80 deletions(-) delete mode 100644 src/p2p/p2p_networks.h diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index c4364e225..abddd5245 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -259,7 +259,7 @@ bool handle_request_stat(po::variables_map& vm, peerid_type peer_id) pot.peer_id = peer_id; pot.time = time(NULL); crypto::public_key pubk = AUTO_VAL_INIT(pubk); - string_tools::hex_to_pod(P2P_STAT_TRUSTED_PUB_KEY, pubk); + string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pubk); crypto::hash h = tools::get_proof_of_trust_hash(pot); crypto::generate_signature(h, pubk, prvk, pot.sign); diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 251152d7e..39cf359b2 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -30,13 +30,14 @@ #pragma once +#include +#include + #define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000 #define CRYPTONOTE_MAX_BLOCK_SIZE 500000000 // block header blob limit, never used! #define CRYPTONOTE_GETBLOCKTEMPLATE_MAX_BLOCK_SIZE 196608 //size of block (bytes) that is the maximum that miners will produce #define CRYPTONOTE_MAX_TX_SIZE 1000000000 #define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0 -#define CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX 18 // addresses start with "4" -#define CRYPTONOTE_TESTNET_ADDRESS_BASE58_PREFIX 19 // addresses start with "5" #define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60 #define CURRENT_TRANSACTION_VERSION 1 #define CURRENT_BLOCK_MAJOR_VERSION 1 @@ -82,10 +83,6 @@ #define CRYPTONOTE_MEMPOOL_TX_LIVETIME 86400 //seconds, one day #define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week -#define P2P_DEFAULT_PORT 18080 -#define TESTNET_P2P_DEFAULT_PORT 28080 -#define RPC_DEFAULT_PORT 18081 -#define TESTNET_RPC_DEFAULT_PORT 28081 #define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT 1000 #define P2P_LOCAL_WHITE_PEERLIST_LIMIT 1000 @@ -99,22 +96,8 @@ #define P2P_DEFAULT_PING_CONNECTION_TIMEOUT 2000 //2 seconds #define P2P_DEFAULT_INVOKE_TIMEOUT 60*2*1000 //2 minutes #define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT 5000 //5 seconds -#define P2P_STAT_TRUSTED_PUB_KEY "0000000000000000000000000000000000000000000000000000000000000000" -#define TESTNET_P2P_STAT_TRUSTED_PUB_KEY "0000000000000000000000000000000000000000000000000000000000000000" #define P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT 70 -// reference these in src/p2p/p2p_networks.h -#define MAINNET_NETWORK_ID { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10 } -#define TESTNET_NETWORK_ID { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11 } - -// reference these in src/cryptonote_core/cryptonote_format_utils.cpp -#define MAINNET_GENESIS_HASH "010a01ff0001ffffffffffff0f029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121013c086a48c15fb637a96991bc6d53caf77068b5ba6eeb3c82357228c49790584a" -#define MAINNET_GENESIS_NONCE 10000 -#define TESTNET_GENESIS_HASH "CHANGEME" -#define TESTNET_GENESIS_NONCE CHANGEME - -// remember also to add seed nodes to src/p2p/net_node.inl for the testnet - #define ALLOW_DEBUG_COMMANDS #define CRYPTONOTE_NAME "bitmonero" @@ -126,3 +109,32 @@ #define THREAD_STACK_SIZE 5 * 1024 * 1024 +// New constants are intended to go here +namespace config +{ + uint64_t const DEFAULT_FEE_ATOMIC_XMR_PER_KB = 500; // Just a placeholder! Change me! + uint8_t const FEE_CALCULATION_MAX_RETRIES = 10; + uint64_t const DEFAULT_DUST_THRESHOLD = 5000000000; // 5 * 10^9 + std::string const P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY = "0000000000000000000000000000000000000000000000000000000000000000"; + + uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 18; // addresses start with "4" + uint16_t const P2P_DEFAULT_PORT = 18080; + uint16_t const RPC_DEFAULT_PORT = 18081; + boost::uuids::uuid const NETWORK_ID = { { + 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10 + } }; // Bender's nightmare + std::string const GENESIS_TX = "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017767aafcde9be00dcfd098715ebcf7f410daebc582fda69d24a28e9d0bc890d1"; + uint32_t const GENESIS_NONCE = 10000; + + namespace testnet + { + uint64_t const CRYPTONOTE_ADDRESS_BASE58_PREFIX = 19; // addresses start with "5" + uint16_t const P2P_DEFAULT_PORT = 28080; + uint16_t const RPC_DEFAULT_PORT = 28081; + boost::uuids::uuid const NETWORK_ID = { { + 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11 + } }; // Bender's daydream + std::string const GENESIS_TX = "CHANGEME"; + uint32_t const GENESIS_NONCE = 10001; + } +} diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp index 17e3063b4..398c63443 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.cpp +++ b/src/cryptonote_core/cryptonote_basic_impl.cpp @@ -105,7 +105,7 @@ namespace cryptonote { //----------------------------------------------------------------------- std::string get_account_address_as_str(const account_public_address& adr) { - return tools::base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(adr)); + return tools::base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(adr)); } //----------------------------------------------------------------------- bool is_coinbase(const transaction& tx) @@ -131,9 +131,9 @@ namespace cryptonote { return false; } - if (CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX != prefix) + if (config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX != prefix) { - LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX); + LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX); return false; } diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 47cd0e159..f7cddeded 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -672,8 +672,7 @@ namespace cryptonote blobdata txb = tx_to_blob(bl.miner_tx); std::string hex_tx_represent = string_tools::buff_to_hex_nodelimer(txb); - //hard code coinbase tx in genesis block, because "tru" generating tx use random, but genesis should be always the same - std::string genesis_coinbase_tx_hex = "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017767aafcde9be00dcfd098715ebcf7f410daebc582fda69d24a28e9d0bc890d1"; + std::string genesis_coinbase_tx_hex = config::GENESIS_TX; blobdata tx_bl; string_tools::parse_hexstr_to_binbuff(genesis_coinbase_tx_hex, tx_bl); @@ -682,7 +681,7 @@ namespace cryptonote bl.major_version = CURRENT_BLOCK_MAJOR_VERSION; bl.minor_version = CURRENT_BLOCK_MINOR_VERSION; bl.timestamp = 0; - bl.nonce = 10000; + bl.nonce = config::GENESIS_NONCE; miner::find_nonce_for_given_block(bl, 1, 0); return true; } diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index bca18c906..3a659dcd8 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -42,12 +42,12 @@ #include #include +#include "cryptonote_config.h" #include "warnings.h" #include "net/levin_server_cp2.h" #include "p2p_protocol_defs.h" #include "storages/levin_abstract_invoke2.h" #include "net_peerlist.h" -#include "p2p_networks.h" #include "math_helper.h" #include "net_node_common.h" #include "common/command_line.h" @@ -79,7 +79,7 @@ namespace nodetool public: typedef t_payload_net_handler payload_net_handler; // Some code - node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false), m_network_id(MONERO_NETWORK) + node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false), m_network_id(::config::NETWORK_ID) {} static void init_options(boost::program_options::options_description& desc); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 211f5064a..28c572513 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -60,7 +60,7 @@ namespace nodetool namespace { const command_line::arg_descriptor arg_p2p_bind_ip = {"p2p-bind-ip", "Interface for p2p network protocol", "0.0.0.0"}; - const command_line::arg_descriptor arg_p2p_bind_port = {"p2p-bind-port", "Port for p2p network protocol", boost::to_string(P2P_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_p2p_bind_port = {"p2p-bind-port", "Port for p2p network protocol", boost::to_string(config::P2P_DEFAULT_PORT)}; const command_line::arg_descriptor arg_p2p_external_port = {"p2p-external-port", "External port for p2p network protocol (if port forwarding used with NAT)", 0}; const command_line::arg_descriptor arg_p2p_allow_local_ip = {"allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes"}; const command_line::arg_descriptor > arg_p2p_add_peer = {"add-peer", "Manually add peer to local peerlist"}; @@ -848,7 +848,7 @@ namespace nodetool return false; } crypto::public_key pk = AUTO_VAL_INIT(pk); - epee::string_tools::hex_to_pod(P2P_STAT_TRUSTED_PUB_KEY, pk); + epee::string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pk); crypto::hash h = tools::get_proof_of_trust_hash(tr); if(!crypto::check_signature(h, pk, tr.sign)) { diff --git a/src/p2p/p2p_networks.h b/src/p2p/p2p_networks.h deleted file mode 100644 index b3193ee6a..000000000 --- a/src/p2p/p2p_networks.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2014, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - -#pragma once - -namespace nodetool -{ - const static boost::uuids::uuid MONERO_NETWORK = { { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10} }; //Bender's nightmare -} diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c74203cc3..e99f44929 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -46,7 +46,7 @@ namespace cryptonote namespace { const command_line::arg_descriptor arg_rpc_bind_ip = {"rpc-bind-ip", "", "127.0.0.1"}; - const command_line::arg_descriptor arg_rpc_bind_port = {"rpc-bind-port", "", std::to_string(RPC_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_rpc_bind_port = {"rpc-bind-port", "", std::to_string(config::RPC_DEFAULT_PORT)}; } //----------------------------------------------------------------------------------- diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 4312981e2..45bc6f847 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -331,7 +331,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if (m_daemon_host.empty()) m_daemon_host = "localhost"; if (!m_daemon_port) - m_daemon_port = RPC_DEFAULT_PORT; + m_daemon_port = config::RPC_DEFAULT_PORT; if (m_daemon_address.empty()) m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port); @@ -1157,7 +1157,7 @@ int main(int argc, char* argv[]) if (daemon_host.empty()) daemon_host = "localhost"; if (!daemon_port) - daemon_port = RPC_DEFAULT_PORT; + daemon_port = config::RPC_DEFAULT_PORT; if (daemon_address.empty()) daemon_address = std::string("http://") + daemon_host + ":" + std::to_string(daemon_port); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index be857c78a..bbf5bab61 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -543,7 +543,7 @@ bool wallet2::check_connection() net_utils::http::url_content u; net_utils::parse_url(m_daemon_address, u); if(!u.port) - u.port = RPC_DEFAULT_PORT; + u.port = config::RPC_DEFAULT_PORT; return m_http_client.connect(u.host, std::to_string(u.port), WALLET_RCP_CONNECTION_TIMEOUT); } //---------------------------------------------------------------------------------------------------- diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index 098b9878a..f973f548d 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -104,7 +104,10 @@ int main(int argc, char* argv[]) //create objects and link them tests::proxy_core pr_core; cryptonote::t_cryptonote_protocol_handler cprotocol(pr_core, NULL); - nodetool::node_server > p2psrv(cprotocol); + nodetool::node_server > p2psrv { + cprotocol + , std::move(config::NETWORK_ID) + }; cprotocol.set_p2p_endpoint(&p2psrv); //pr_core.set_cryptonote_protocol(&cprotocol); //daemon_cmmands_handler dch(p2psrv); diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 68c9f7ac7..2187ff250 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -37,6 +37,12 @@ using namespace epee; #include "wallet/wallet2.h" using namespace cryptonote; +namespace +{ + uint64_t const TEST_FEE = 5000000000; // 5 * 10^9 + uint64_t const TEST_DUST_THRESHOLD = 5000000000; // 5 * 10^9 +} + std::string generate_random_wallet_name() { std::stringstream ss; @@ -79,7 +85,7 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor, try { tools::wallet2::pending_tx ptx; - w1.transfer(dsts, mix_in_factor, 0, DEFAULT_FEE, std::vector(), tools::detail::null_split_strategy, tools::tx_dust_policy(DEFAULT_FEE), tx, ptx); + w1.transfer(dsts, mix_in_factor, 0, TEST_FEE, std::vector(), tools::detail::null_split_strategy, tools::tx_dust_policy(TEST_DUST_THRESHOLD), tx, ptx); w1.commit_tx(ptx); return true; } @@ -185,7 +191,7 @@ bool transactions_flow_test(std::string& working_folder, BOOST_FOREACH(tools::wallet2::transfer_details& td, incoming_transfers) { cryptonote::transaction tx_s; - bool r = do_send_money(w1, w1, 0, td.m_tx.vout[td.m_internal_output_index].amount - DEFAULT_FEE, tx_s, 50); + bool r = do_send_money(w1, w1, 0, td.m_tx.vout[td.m_internal_output_index].amount - TEST_FEE, tx_s, 50); CHECK_AND_ASSERT_MES(r, false, "Failed to send starter tx " << get_transaction_hash(tx_s)); LOG_PRINT_GREEN("Starter transaction sent " << get_transaction_hash(tx_s), LOG_LEVEL_0); if(++count >= FIRST_N_TRANSFERS) @@ -213,7 +219,7 @@ bool transactions_flow_test(std::string& working_folder, for(i = 0; i != transactions_count; i++) { uint64_t amount_to_tx = (amount_to_transfer - transfered_money) > transfer_size ? transfer_size: (amount_to_transfer - transfered_money); - while(w1.unlocked_balance() < amount_to_tx + DEFAULT_FEE) + while(w1.unlocked_balance() < amount_to_tx + TEST_FEE) { misc_utils::sleep_no_w(1000); LOG_PRINT_L0("not enough money, waiting for cashback or mining"); diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp index 5b82fb987..f61bb1b96 100644 --- a/tests/unit_tests/base58.cpp +++ b/tests/unit_tests/base58.cpp @@ -506,7 +506,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_prefix) TEST(get_account_address_from_str, fails_on_invalid_address_content) { - std::string addr_str = base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, test_serialized_keys.substr(1)); + std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, test_serialized_keys.substr(1)); cryptonote::account_public_address addr; ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); @@ -516,7 +516,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_spend_key) { std::string serialized_keys_copy = test_serialized_keys; serialized_keys_copy[0] = '\0'; - std::string addr_str = base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); + std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); @@ -526,7 +526,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_view_key) { std::string serialized_keys_copy = test_serialized_keys; serialized_keys_copy.back() = '\x01'; - std::string addr_str = base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); + std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); diff --git a/tests/unit_tests/test_format_utils.cpp b/tests/unit_tests/test_format_utils.cpp index bed19c315..857b5b09f 100644 --- a/tests/unit_tests/test_format_utils.cpp +++ b/tests/unit_tests/test_format_utils.cpp @@ -35,6 +35,10 @@ #include "common/util.h" #include "cryptonote_core/cryptonote_format_utils.h" +namespace +{ + uint64_t const TEST_FEE = 5000000000; // 5 * 10^9 +} TEST(parse_tx_extra, handles_empty_extra) { @@ -135,7 +139,7 @@ TEST(parse_and_validate_tx_extra, is_valid_tx_extra_parsed) cryptonote::account_base acc; acc.generate(); cryptonote::blobdata b = "dsdsdfsdfsf"; - ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1)); + ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1)); crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(tx); ASSERT_NE(tx_pub_key, cryptonote::null_pkey); } @@ -145,7 +149,7 @@ TEST(parse_and_validate_tx_extra, fails_on_big_extra_nonce) cryptonote::account_base acc; acc.generate(); cryptonote::blobdata b(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); - ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1)); + ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1)); } TEST(parse_and_validate_tx_extra, fails_on_wrong_size_in_extra_nonce) { From 98ed9a41f7bf0d904e257372f4561aea3ad12c18 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 12:51:04 -0400 Subject: [PATCH 06/19] Separate p2p port for testnet --- src/p2p/net_node.h | 5 ++++- src/p2p/net_node.inl | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 3a659dcd8..7030d93f7 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -149,7 +149,10 @@ namespace nodetool virtual void for_each_connection(std::function f); //----------------------------------------------------------------------------------------------- bool parse_peer_from_string(nodetool::net_address& pe, const std::string& node_addr); - bool handle_command_line(const boost::program_options::variables_map& vm); + bool handle_command_line( + const boost::program_options::variables_map& vm + , bool testnet + ); bool idle_worker(); bool handle_remote_peerlist(const std::list& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context); bool get_local_node_data(basic_node_data& node_data); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 28c572513..753af7321 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -60,7 +60,16 @@ namespace nodetool namespace { const command_line::arg_descriptor arg_p2p_bind_ip = {"p2p-bind-ip", "Interface for p2p network protocol", "0.0.0.0"}; - const command_line::arg_descriptor arg_p2p_bind_port = {"p2p-bind-port", "Port for p2p network protocol", boost::to_string(config::P2P_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_p2p_bind_port = { + "p2p-bind-port" + , "Port for p2p network protocol" + , std::to_string(config::P2P_DEFAULT_PORT) + }; + const command_line::arg_descriptor arg_testnet_p2p_bind_port = { + "testnet-p2p-bind-port" + , "Port for testnet p2p network protocol" + , std::to_string(config::testnet::P2P_DEFAULT_PORT) + }; const command_line::arg_descriptor arg_p2p_external_port = {"p2p-external-port", "External port for p2p network protocol (if port forwarding used with NAT)", 0}; const command_line::arg_descriptor arg_p2p_allow_local_ip = {"allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes"}; const command_line::arg_descriptor > arg_p2p_add_peer = {"add-peer", "Manually add peer to local peerlist"}; @@ -77,6 +86,7 @@ namespace nodetool { command_line::add_arg(desc, arg_p2p_bind_ip); command_line::add_arg(desc, arg_p2p_bind_port); + command_line::add_arg(desc, arg_testnet_p2p_bind_port); command_line::add_arg(desc, arg_p2p_external_port); command_line::add_arg(desc, arg_p2p_allow_local_ip); command_line::add_arg(desc, arg_p2p_add_peer); @@ -138,10 +148,15 @@ namespace nodetool } //----------------------------------------------------------------------------------- template - bool node_server::handle_command_line(const boost::program_options::variables_map& vm) + bool node_server::handle_command_line( + const boost::program_options::variables_map& vm + , bool testnet + ) { + auto p2p_bind_arg = testnet ? arg_testnet_p2p_bind_port : arg_p2p_bind_port; + m_bind_ip = command_line::get_arg(vm, arg_p2p_bind_ip); - m_port = command_line::get_arg(vm, arg_p2p_bind_port); + m_port = command_line::get_arg(vm, p2p_bind_arg); m_external_port = command_line::get_arg(vm, arg_p2p_external_port); m_allow_local_ip = command_line::get_arg(vm, arg_p2p_allow_local_ip); @@ -242,7 +257,7 @@ namespace nodetool m_network_id.data[0] += 1; } - bool res = handle_command_line(vm); + bool res = handle_command_line(vm, testnet); CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line"); m_config_folder = command_line::get_arg(vm, command_line::arg_data_dir); From 658b6690a36f6f0b3b06dca5b85021b2b344c059 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 13:07:15 -0400 Subject: [PATCH 07/19] Separate rpc port for testnet --- src/daemon/daemon.cpp | 2 +- src/rpc/core_rpc_server.cpp | 28 +++++++++++++++++++++++----- src/rpc/core_rpc_server.h | 10 ++++++++-- src/simplewallet/simplewallet.cpp | 10 +++++++--- src/wallet/wallet2.cpp | 6 +++++- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 1041aa439..04f6db4fa 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -220,7 +220,7 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Protocol initialized OK"); LOG_PRINT_L0("Initializing core RPC server..."); - res = rpc_server.init(vm); + res = rpc_server.init(vm, testnet_mode); CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core RPC server."); LOG_PRINT_GREEN("Core RPC server initialized OK on port: " << rpc_server.get_binded_port(), LOG_LEVEL_0); diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index e99f44929..197e4ff83 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -46,7 +46,16 @@ namespace cryptonote namespace { const command_line::arg_descriptor arg_rpc_bind_ip = {"rpc-bind-ip", "", "127.0.0.1"}; - const command_line::arg_descriptor arg_rpc_bind_port = {"rpc-bind-port", "", std::to_string(config::RPC_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_rpc_bind_port = { + "rpc-bind-port" + , "" + , std::to_string(config::RPC_DEFAULT_PORT) + }; + const command_line::arg_descriptor arg_testnet_rpc_bind_port = { + "testnet-rpc-bind-port" + , "" + , std::to_string(config::testnet::RPC_DEFAULT_PORT) + }; } //----------------------------------------------------------------------------------- @@ -54,22 +63,31 @@ namespace cryptonote { command_line::add_arg(desc, arg_rpc_bind_ip); command_line::add_arg(desc, arg_rpc_bind_port); + command_line::add_arg(desc, arg_testnet_rpc_bind_port); } //------------------------------------------------------------------------------------------------------------------------------ core_rpc_server::core_rpc_server(core& cr, nodetool::node_server >& p2p):m_core(cr), m_p2p(p2p) {} //------------------------------------------------------------------------------------------------------------------------------ - bool core_rpc_server::handle_command_line(const boost::program_options::variables_map& vm) + bool core_rpc_server::handle_command_line( + const boost::program_options::variables_map& vm + , bool testnet + ) { + auto p2p_bind_arg = testnet ? arg_testnet_rpc_bind_port : arg_rpc_bind_port; + m_bind_ip = command_line::get_arg(vm, arg_rpc_bind_ip); - m_port = command_line::get_arg(vm, arg_rpc_bind_port); + m_port = command_line::get_arg(vm, p2p_bind_arg); return true; } //------------------------------------------------------------------------------------------------------------------------------ - bool core_rpc_server::init(const boost::program_options::variables_map& vm) + bool core_rpc_server::init( + const boost::program_options::variables_map& vm + , bool testnet + ) { m_net_server.set_threads_prefix("RPC"); - bool r = handle_command_line(vm); + bool r = handle_command_line(vm, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to process command line in core_rpc_server"); return epee::http_server_impl_base::init(m_port, m_bind_ip); } diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 2e3f553ce..3f3d23f51 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -52,7 +52,10 @@ namespace cryptonote core_rpc_server(core& cr, nodetool::node_server >& p2p); static void init_options(boost::program_options::options_description& desc); - bool init(const boost::program_options::variables_map& vm); + bool init( + const boost::program_options::variables_map& vm + , bool testnet + ); private: CHAIN_HTTP_TO_MAP2(connection_context); //forward http requests to uri map @@ -105,7 +108,10 @@ namespace cryptonote bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_info_json(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); //----------------------- - bool handle_command_line(const boost::program_options::variables_map& vm); + bool handle_command_line( + const boost::program_options::variables_map& vm + , bool testnet + ); bool check_core_busy(); bool check_core_ready(); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 45bc6f847..6c97dc807 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -328,15 +328,19 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if(!ask_wallet_create_if_needed()) return false; } + bool testnet = command_line::get_arg(vm, arg_testnet); + if (m_daemon_host.empty()) m_daemon_host = "localhost"; + if (!m_daemon_port) - m_daemon_port = config::RPC_DEFAULT_PORT; + { + m_daemon_port = testnet ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT; + } + if (m_daemon_address.empty()) m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port); - bool testnet = command_line::get_arg(vm, arg_testnet); - tools::password_container pwd_container; if (command_line::has_arg(vm, arg_password)) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index bbf5bab61..b8b728425 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -542,8 +542,12 @@ bool wallet2::check_connection() net_utils::http::url_content u; net_utils::parse_url(m_daemon_address, u); + if(!u.port) - u.port = config::RPC_DEFAULT_PORT; + { + u.port = m_testnet ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT; + } + return m_http_client.connect(u.host, std::to_string(u.port), WALLET_RCP_CONNECTION_TIMEOUT); } //---------------------------------------------------------------------------------------------------- From 257077a96bf44dcc2b70f1c4aedf312ae6c826d5 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 13:40:28 -0400 Subject: [PATCH 08/19] Separate network id for testnet --- src/daemon/daemon.cpp | 6 +++++- src/p2p/net_node.h | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 04f6db4fa..113b2c5dc 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -42,6 +42,7 @@ using namespace epee; #include "crypto/hash.h" #include "console_handler.h" #include "p2p/net_node.h" +#include "cryptonote_config.h" #include "cryptonote_core/checkpoints_create.h" #include "cryptonote_core/cryptonote_core.h" #include "rpc/core_rpc_server.h" @@ -202,7 +203,10 @@ int main(int argc, char* argv[]) } cryptonote::t_cryptonote_protocol_handler cprotocol(ccore, NULL); - nodetool::node_server > p2psrv(cprotocol); + nodetool::node_server > p2psrv { + cprotocol + , testnet_mode ? std::move(config::testnet::NETWORK_ID) : std::move(config::NETWORK_ID) + }; cryptonote::core_rpc_server rpc_server(ccore, p2psrv); cprotocol.set_p2p_endpoint(&p2psrv); ccore.set_cryptonote_protocol(&cprotocol); diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 7030d93f7..759b21fcf 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -41,6 +41,7 @@ #include #include #include +#include #include "cryptonote_config.h" #include "warnings.h" @@ -78,8 +79,15 @@ namespace nodetool public: typedef t_payload_net_handler payload_net_handler; - // Some code - node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false), m_network_id(::config::NETWORK_ID) + + node_server( + t_payload_net_handler& payload_handler + , boost::uuids::uuid network_id + ) + : m_payload_handler(payload_handler) + , m_allow_local_ip(false) + , m_hide_my_port(false) + , m_network_id(std::move(network_id)) {} static void init_options(boost::program_options::options_description& desc); From 96eed84aad89e6e2799a9db91e2dd2e9fe0889f9 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 15:09:59 -0400 Subject: [PATCH 09/19] Pass tx and nonce to genesis block constructor --- src/cryptonote_core/blockchain_storage.cpp | 32 +++++++++++++------ .../cryptonote_format_utils.cpp | 18 ++++------- src/cryptonote_core/cryptonote_format_utils.h | 7 ++-- src/wallet/wallet2.cpp | 12 ++++--- tests/core_proxy/core_proxy.cpp | 2 +- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index cd20cd818..e664a39c5 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -114,7 +114,14 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet) LOG_PRINT_L0("Can't load blockchain storage from file, generating genesis block."); block bl = boost::value_initialized(); block_verification_context bvc = boost::value_initialized(); - generate_genesis_block(bl); + if (testnet) + { + generate_genesis_block(bl, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(bl, config::GENESIS_TX, config::GENESIS_NONCE); + } add_new_block(bl, bvc); CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed && bvc.m_added_to_main_chain, false, "Failed to add genesis block to blockchain"); } @@ -127,10 +134,14 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet) } } else { cryptonote::block b; - if (testnet) { - generate_testnet_genesis_block(b); - } else { - generate_genesis_block(b); + + if (testnet) + { + generate_genesis_block(b, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(b, config::GENESIS_TX, config::GENESIS_NONCE); } crypto::hash genesis_hash = get_block_hash(m_blocks[0].bl); @@ -151,10 +162,13 @@ bool blockchain_storage::store_genesis_block(bool testnet) { block bl = ::boost::value_initialized(); block_verification_context bvc = boost::value_initialized(); - if (testnet) { - generate_testnet_genesis_block(bl); - } else { - generate_genesis_block(bl); + if (testnet) + { + generate_genesis_block(bl, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(bl, config::GENESIS_TX, config::GENESIS_NONCE); } add_new_block(bl, bvc); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index f7cddeded..33cad30c4 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -660,7 +660,11 @@ namespace cryptonote return p; } //--------------------------------------------------------------- - bool generate_genesis_block(block& bl) + bool generate_genesis_block( + block& bl + , std::string const & genesis_tx + , uint32_t nonce + ) { //genesis block bl = boost::value_initialized(); @@ -681,20 +685,10 @@ namespace cryptonote bl.major_version = CURRENT_BLOCK_MAJOR_VERSION; bl.minor_version = CURRENT_BLOCK_MINOR_VERSION; bl.timestamp = 0; - bl.nonce = config::GENESIS_NONCE; + bl.nonce = nonce; miner::find_nonce_for_given_block(bl, 1, 0); return true; } - - bool generate_testnet_genesis_block(cryptonote::block& b) { - if (!generate_genesis_block(b)) { - return false; - } - - b.nonce += 1; - return true; - } - //--------------------------------------------------------------- bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) { diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 4457f6cc6..9fa7f0545 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -105,8 +105,11 @@ namespace cryptonote crypto::hash get_block_hash(const block& b); bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height); crypto::hash get_block_longhash(const block& b, uint64_t height); - bool generate_genesis_block(block& bl); - bool generate_testnet_genesis_block(block& bl); + bool generate_genesis_block( + block& bl + , std::string const & genesis_tx + , uint32_t nonce + ); bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b); bool get_inputs_money_amount(const transaction& tx, uint64_t& money); uint64_t get_outs_money_amount(const transaction& tx); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b8b728425..78fac0e87 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -35,6 +35,7 @@ #include "include_base_utils.h" using namespace epee; +#include "cryptonote_config.h" #include "wallet2.h" #include "cryptonote_core/cryptonote_format_utils.h" #include "rpc/core_rpc_server_commands_defs.h" @@ -939,10 +940,13 @@ std::vector wallet2::create_transactions(std::vector Date: Mon, 8 Sep 2014 16:05:16 -0400 Subject: [PATCH 10/19] Add testnet genesis tx as output by CN reference --- src/cryptonote_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 39cf359b2..eb04984b9 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -134,7 +134,7 @@ namespace config boost::uuids::uuid const NETWORK_ID = { { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11 } }; // Bender's daydream - std::string const GENESIS_TX = "CHANGEME"; + std::string const GENESIS_TX = "013c01ff0001ffffffffffff0f029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd0880712101168d0c4ca86fb55a4cf6a36d31431be1c53a3bd7411bb24e8832410289fa6f3b"; uint32_t const GENESIS_NONCE = 10001; } } From 3ef7f3330007defce68317c6f041d63e2138d356 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 16:59:42 -0400 Subject: [PATCH 11/19] Add descriptions for RPC command line params --- src/rpc/core_rpc_server.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 197e4ff83..deadd25fc 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -45,15 +45,21 @@ namespace cryptonote { namespace { - const command_line::arg_descriptor arg_rpc_bind_ip = {"rpc-bind-ip", "", "127.0.0.1"}; + const command_line::arg_descriptor arg_rpc_bind_ip = { + "rpc-bind-ip" + , "IP for RPC server" + , "127.0.0.1" + }; + const command_line::arg_descriptor arg_rpc_bind_port = { "rpc-bind-port" - , "" + , "Port for RPC server" , std::to_string(config::RPC_DEFAULT_PORT) }; + const command_line::arg_descriptor arg_testnet_rpc_bind_port = { "testnet-rpc-bind-port" - , "" + , "Port for testnet RPC server" , std::to_string(config::testnet::RPC_DEFAULT_PORT) }; } From 018e251cc089746437afb9dc88978a8a88fe64a2 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 17:30:50 -0400 Subject: [PATCH 12/19] Separate testnet default data dir --- src/common/command_line.cpp | 1 + src/common/command_line.h | 1 + src/cryptonote_core/cryptonote_core.cpp | 7 +-- src/cryptonote_core/cryptonote_core.h | 2 +- src/daemon/daemon.cpp | 64 ++++++++++++++----------- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index 6f831af55..a2e7faf9f 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -47,4 +47,5 @@ namespace command_line const arg_descriptor arg_help = {"help", "Produce help message"}; const arg_descriptor arg_version = {"version", "Output version information"}; const arg_descriptor arg_data_dir = {"data-dir", "Specify data directory"}; + const arg_descriptor arg_testnet_data_dir = {"testnet-data-dir", "Specify testnet data directory"}; } diff --git a/src/common/command_line.h b/src/common/command_line.h index ca02c6088..09ae877d3 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -203,4 +203,5 @@ namespace command_line extern const arg_descriptor arg_help; extern const arg_descriptor arg_version; extern const arg_descriptor arg_data_dir; + extern const arg_descriptor arg_testnet_data_dir; } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 3ff139c95..72e5ee209 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -75,9 +75,10 @@ namespace cryptonote { } //----------------------------------------------------------------------------------------------- - bool core::handle_command_line(const boost::program_options::variables_map& vm) + bool core::handle_command_line(const boost::program_options::variables_map& vm, bool testnet) { - m_config_folder = command_line::get_arg(vm, command_line::arg_data_dir); + auto data_dir_arg = testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; + m_config_folder = command_line::get_arg(vm, data_dir_arg); return true; } //----------------------------------------------------------------------------------------------- @@ -118,7 +119,7 @@ namespace cryptonote //----------------------------------------------------------------------------------------------- bool core::init(const boost::program_options::variables_map& vm, bool testnet) { - bool r = handle_command_line(vm); + bool r = handle_command_line(vm, testnet); r = m_mempool.init(m_config_folder); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool"); diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index f050431ef..ba2aed015 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -136,7 +136,7 @@ namespace cryptonote bool check_tx_ring_signature(const txin_to_key& tx, const crypto::hash& tx_prefix_hash, const std::vector& 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 handle_command_line(const boost::program_options::variables_map& vm, bool testnet); bool on_update_blocktemplate_interval(); bool check_tx_inputs_keyimages_diff(const transaction& tx); diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 113b2c5dc..9102e61e8 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -63,8 +63,11 @@ namespace const command_line::arg_descriptor arg_log_file = {"log-file", "", ""}; const command_line::arg_descriptor arg_log_level = {"log-level", "", LOG_LEVEL_0}; const command_line::arg_descriptor arg_console = {"no-console", "Disable daemon console commands"}; - const command_line::arg_descriptor arg_testnet_on = {"testnet", "Used to deploy test nets. Checkpoints and hardcoded seeds are ignored, " - "network id is changed. Use it with --data-dir flag. The wallet must be launched with --testnet flag.", false}; + const command_line::arg_descriptor arg_testnet_on = { + "testnet" + , "Run on testnet. The wallet must be launched with --testnet flag." + , false + }; } bool command_line_preprocessor(const boost::program_options::variables_map& vm) @@ -113,6 +116,9 @@ int main(int argc, char* argv[]) TRY_ENTRY(); + boost::filesystem::path default_data_path {tools::get_default_data_dir()}; + boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"}; + po::options_description desc_cmd_only("Command line options"); po::options_description desc_cmd_sett("Command line options and settings options"); @@ -120,7 +126,8 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_only, command_line::arg_version); command_line::add_arg(desc_cmd_only, arg_os_version); // tools::get_default_data_dir() can't be called during static initialization - command_line::add_arg(desc_cmd_only, command_line::arg_data_dir, tools::get_default_data_dir()); + command_line::add_arg(desc_cmd_only, command_line::arg_data_dir, default_data_path.string()); + command_line::add_arg(desc_cmd_only, command_line::arg_testnet_data_dir, default_testnet_data_path.string()); command_line::add_arg(desc_cmd_only, arg_config_file); command_line::add_arg(desc_cmd_sett, arg_log_file); @@ -140,29 +147,6 @@ int main(int argc, char* argv[]) bool r = command_line::handle_error_helper(desc_options, [&]() { po::store(po::parse_command_line(argc, argv, desc_options), vm); - - if (command_line::get_arg(vm, command_line::arg_help)) - { - std::cout << CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL << ENDL << ENDL; - std::cout << desc_options << std::endl; - return false; - } - - std::string data_dir = command_line::get_arg(vm, command_line::arg_data_dir); - std::string config = command_line::get_arg(vm, arg_config_file); - - boost::filesystem::path data_dir_path(data_dir); - boost::filesystem::path config_path(config); - if (!config_path.has_parent_path()) - { - config_path = data_dir_path / config_path; - } - - boost::system::error_code ec; - if (boost::filesystem::exists(config_path, ec)) - { - po::store(po::parse_config_file(config_path.string().c_str(), desc_cmd_sett), vm); - } po::notify(vm); return true; @@ -170,6 +154,33 @@ int main(int argc, char* argv[]) if (!r) return 1; + if (command_line::get_arg(vm, command_line::arg_help)) + { + std::cout << CRYPTONOTE_NAME << " v" << PROJECT_VERSION_LONG << ENDL << ENDL; + std::cout << desc_options << std::endl; + return false; + } + + bool testnet_mode = command_line::get_arg(vm, arg_testnet_on); + + auto data_dir_arg = testnet_mode ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; + + std::string data_dir = command_line::get_arg(vm, data_dir_arg); + std::string config = command_line::get_arg(vm, arg_config_file); + + boost::filesystem::path data_dir_path(data_dir); + boost::filesystem::path config_path(config); + if (!config_path.has_parent_path()) + { + config_path = data_dir_path / config_path; + } + + boost::system::error_code ec; + if (boost::filesystem::exists(config_path, ec)) + { + po::store(po::parse_config_file(config_path.string().c_str(), desc_cmd_sett), vm); + } + //set up logging options boost::filesystem::path log_file_path(command_line::get_arg(vm, arg_log_file)); if (log_file_path.empty()) @@ -195,7 +206,6 @@ int main(int argc, char* argv[]) //create objects and link them cryptonote::core ccore(NULL); - bool testnet_mode = command_line::get_arg(vm, arg_testnet_on); if (testnet_mode) { LOG_PRINT_L0("Starting in testnet mode!"); } else { From 4a6eb0a0166670cb21f58ac6f19fbb0300574ab2 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 18:33:17 -0400 Subject: [PATCH 13/19] Create testnet data dir if necessary --- src/daemon/daemon.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 9102e61e8..fd1b18356 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -166,6 +166,7 @@ int main(int argc, char* argv[]) auto data_dir_arg = testnet_mode ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; std::string data_dir = command_line::get_arg(vm, data_dir_arg); + tools::create_directories_if_necessary(data_dir); std::string config = command_line::get_arg(vm, arg_config_file); boost::filesystem::path data_dir_path(data_dir); From ee1bacc64f6e9ae05354c2646818737b18a08401 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Tue, 9 Sep 2014 09:10:30 -0400 Subject: [PATCH 14/19] Add testnet seed nodes --- src/p2p/net_node.inl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 753af7321..9655a6176 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -241,7 +241,14 @@ namespace nodetool template bool node_server::init(const boost::program_options::variables_map& vm, bool testnet) { - if (!testnet) { + if (testnet) + { + ADD_HARDCODED_SEED_NODE("107.152.187.202:28080"); + ADD_HARDCODED_SEED_NODE("197.242.158.240:28080"); + ADD_HARDCODED_SEED_NODE("107.152.130.98:28080"); + } + else + { ADD_HARDCODED_SEED_NODE("62.210.78.186:18080"); ADD_HARDCODED_SEED_NODE("195.12.60.154:18080"); ADD_HARDCODED_SEED_NODE("54.241.246.125:18080"); @@ -253,8 +260,6 @@ namespace nodetool ADD_HARDCODED_SEED_NODE("107.178.112.126:18080"); ADD_HARDCODED_SEED_NODE("107.158.233.98:18080"); ADD_HARDCODED_SEED_NODE("64.22.111.2:18080"); - } else { - m_network_id.data[0] += 1; } bool res = handle_command_line(vm, testnet); From d03308734b1487540af062ab50c94cc7bb3e668e Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Tue, 9 Sep 2014 10:58:53 -0400 Subject: [PATCH 15/19] Separate testnet address prefix --- src/cryptonote_config.h | 2 +- src/cryptonote_core/account.cpp | 4 +- src/cryptonote_core/account.h | 2 +- src/cryptonote_core/cryptonote_basic_impl.cpp | 23 +++++++++--- src/cryptonote_core/cryptonote_basic_impl.h | 14 ++++++- src/cryptonote_core/cryptonote_core.cpp | 2 +- src/cryptonote_core/miner.cpp | 4 +- src/cryptonote_core/miner.h | 2 +- src/daemon/daemon.cpp | 6 +-- src/daemon/daemon_commands_handler.h | 10 ++++- src/rpc/core_rpc_server.cpp | 21 +++++++---- src/rpc/core_rpc_server.h | 9 +++-- src/simplewallet/simplewallet.cpp | 15 +++++--- src/wallet/wallet2.cpp | 4 +- src/wallet/wallet2.h | 6 ++- src/wallet/wallet_errors.h | 37 +++++++++++++------ src/wallet/wallet_rpc_server.cpp | 4 +- tests/core_tests/transaction_tests.cpp | 4 +- tests/daemon_tests/transfers.cpp | 4 +- .../transactions_flow_test.cpp | 6 +-- tests/unit_tests/base58.cpp | 16 ++++---- 21 files changed, 126 insertions(+), 69 deletions(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index eb04984b9..f8f35470d 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -128,7 +128,7 @@ namespace config namespace testnet { - uint64_t const CRYPTONOTE_ADDRESS_BASE58_PREFIX = 19; // addresses start with "5" + uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 19; // addresses start with "5" uint16_t const P2P_DEFAULT_PORT = 28080; uint16_t const RPC_DEFAULT_PORT = 28081; boost::uuids::uuid const NETWORK_ID = { { diff --git a/src/cryptonote_core/account.cpp b/src/cryptonote_core/account.cpp index d07dad33f..36043238d 100644 --- a/src/cryptonote_core/account.cpp +++ b/src/cryptonote_core/account.cpp @@ -93,10 +93,10 @@ DISABLE_VS_WARNINGS(4244 4345) return m_keys; } //----------------------------------------------------------------- - std::string account_base::get_public_address_str() + std::string account_base::get_public_address_str(bool testnet) { //TODO: change this code into base 58 - return get_account_address_as_str(m_keys.m_account_address); + return get_account_address_as_str(testnet, m_keys.m_account_address); } //----------------------------------------------------------------- } diff --git a/src/cryptonote_core/account.h b/src/cryptonote_core/account.h index 06bd700a9..dd6618542 100644 --- a/src/cryptonote_core/account.h +++ b/src/cryptonote_core/account.h @@ -59,7 +59,7 @@ namespace cryptonote account_base(); crypto::secret_key generate(const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false, bool two_random = false); const account_keys& get_keys() const; - std::string get_public_address_str(); + std::string get_public_address_str(bool testnet); uint64_t get_createtime() const { return m_creation_timestamp; } void set_createtime(uint64_t val) { m_creation_timestamp = val; } diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp index 398c63443..9cec666f2 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.cpp +++ b/src/cryptonote_core/cryptonote_basic_impl.cpp @@ -103,9 +103,15 @@ namespace cryptonote { return summ; } //----------------------------------------------------------------------- - std::string get_account_address_as_str(const account_public_address& adr) + std::string get_account_address_as_str( + bool testnet + , account_public_address const & adr + ) { - return tools::base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(adr)); + uint64_t address_prefix = testnet ? + config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX; + + return tools::base58::encode_addr(address_prefix, t_serializable_object_to_blob(adr)); } //----------------------------------------------------------------------- bool is_coinbase(const transaction& tx) @@ -119,8 +125,15 @@ namespace cryptonote { return true; } //----------------------------------------------------------------------- - bool get_account_address_from_str(account_public_address& adr, const std::string& str) + bool get_account_address_from_str( + account_public_address& adr + , bool testnet + , std::string const & str + ) { + uint64_t address_prefix = testnet ? + config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX; + if (2 * sizeof(public_address_outer_blob) != str.size()) { blobdata data; @@ -131,9 +144,9 @@ namespace cryptonote { return false; } - if (config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX != prefix) + if (address_prefix != prefix) { - LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX); + LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << address_prefix); return false; } diff --git a/src/cryptonote_core/cryptonote_basic_impl.h b/src/cryptonote_core/cryptonote_basic_impl.h index a3184378e..ddef677cb 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.h +++ b/src/cryptonote_core/cryptonote_basic_impl.h @@ -66,8 +66,18 @@ namespace cryptonote { size_t get_max_tx_size(); bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward); uint8_t get_account_address_checksum(const public_address_outer_blob& bl); - std::string get_account_address_as_str(const account_public_address& adr); - bool get_account_address_from_str(account_public_address& adr, const std::string& str); + + std::string get_account_address_as_str( + bool testnet + , const account_public_address& adr + ); + + bool get_account_address_from_str( + account_public_address& adr + , bool testnet + , const std::string& str + ); + bool is_coinbase(const transaction& tx); bool operator ==(const cryptonote::transaction& a, const cryptonote::transaction& b); diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 72e5ee209..964d61e2f 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -127,7 +127,7 @@ namespace cryptonote r = m_blockchain_storage.init(m_config_folder, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); - r = m_miner.init(vm); + r = m_miner.init(vm, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); return load_state_data(); diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp index 81dc4a692..b2adfe39c 100644 --- a/src/cryptonote_core/miner.cpp +++ b/src/cryptonote_core/miner.cpp @@ -171,7 +171,7 @@ namespace cryptonote command_line::add_arg(desc, arg_mining_threads); } //----------------------------------------------------------------------------------------------------- - bool miner::init(const boost::program_options::variables_map& vm) + bool miner::init(const boost::program_options::variables_map& vm, bool testnet) { if(command_line::has_arg(vm, arg_extra_messages)) { @@ -198,7 +198,7 @@ namespace cryptonote if(command_line::has_arg(vm, arg_start_mining)) { - if(!cryptonote::get_account_address_from_str(m_mine_address, command_line::get_arg(vm, arg_start_mining))) + if(!cryptonote::get_account_address_from_str(m_mine_address, testnet, command_line::get_arg(vm, arg_start_mining))) { LOG_ERROR("Target account address " << command_line::get_arg(vm, arg_start_mining) << " has wrong format, starting daemon canceled"); return false; diff --git a/src/cryptonote_core/miner.h b/src/cryptonote_core/miner.h index a96d42d75..44844428c 100644 --- a/src/cryptonote_core/miner.h +++ b/src/cryptonote_core/miner.h @@ -56,7 +56,7 @@ namespace cryptonote public: miner(i_miner_handler* phandler); ~miner(); - bool init(const boost::program_options::variables_map& vm); + bool init(const boost::program_options::variables_map& vm, bool testnet); static void init_options(boost::program_options::options_description& desc); bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height); bool on_block_chain_update(); diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index fd1b18356..12990800a 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -218,10 +218,10 @@ int main(int argc, char* argv[]) cprotocol , testnet_mode ? std::move(config::testnet::NETWORK_ID) : std::move(config::NETWORK_ID) }; - cryptonote::core_rpc_server rpc_server(ccore, p2psrv); + cryptonote::core_rpc_server rpc_server {ccore, p2psrv, testnet_mode}; cprotocol.set_p2p_endpoint(&p2psrv); ccore.set_cryptonote_protocol(&cprotocol); - daemon_cmmands_handler dch(p2psrv); + daemon_cmmands_handler dch(p2psrv, testnet_mode); //initialize objects LOG_PRINT_L0("Initializing P2P server..."); @@ -235,7 +235,7 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Protocol initialized OK"); LOG_PRINT_L0("Initializing core RPC server..."); - res = rpc_server.init(vm, testnet_mode); + res = rpc_server.init(vm); CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core RPC server."); LOG_PRINT_GREEN("Core RPC server initialized OK on port: " << rpc_server.get_binded_port(), LOG_LEVEL_0); diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 5dc0be7dd..58112e166 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -50,7 +50,12 @@ class daemon_cmmands_handler { nodetool::node_server >& m_srv; public: - daemon_cmmands_handler(nodetool::node_server >& srv):m_srv(srv) + daemon_cmmands_handler( + nodetool::node_server >& srv + , bool testnet + ) + : m_srv(srv) + , m_testnet {testnet} { m_cmd_binder.set_handler("help", boost::bind(&daemon_cmmands_handler::help, this, _1), "Show this help"); m_cmd_binder.set_handler("print_pl", boost::bind(&daemon_cmmands_handler::print_pl, this, _1), "Print peer list"); @@ -84,6 +89,7 @@ public: private: epee::srv_console_handlers_binder > > m_cmd_binder; + bool m_testnet; //-------------------------------------------------------------------------------- std::string get_commands_str() @@ -368,7 +374,7 @@ private: } cryptonote::account_public_address adr; - if(!cryptonote::get_account_address_from_str(adr, args.front())) + if(!cryptonote::get_account_address_from_str(adr, m_testnet, args.front())) { std::cout << "target account address has wrong format" << std::endl; return true; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index deadd25fc..22e95a1fc 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -72,15 +72,21 @@ namespace cryptonote command_line::add_arg(desc, arg_testnet_rpc_bind_port); } //------------------------------------------------------------------------------------------------------------------------------ - core_rpc_server::core_rpc_server(core& cr, nodetool::node_server >& p2p):m_core(cr), m_p2p(p2p) + core_rpc_server::core_rpc_server( + core& cr + , nodetool::node_server >& p2p + , bool testnet + ) + : m_core(cr) + , m_p2p(p2p) + , m_testnet {testnet} {} //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::handle_command_line( const boost::program_options::variables_map& vm - , bool testnet ) { - auto p2p_bind_arg = testnet ? arg_testnet_rpc_bind_port : arg_rpc_bind_port; + auto p2p_bind_arg = m_testnet ? arg_testnet_rpc_bind_port : arg_rpc_bind_port; m_bind_ip = command_line::get_arg(vm, arg_rpc_bind_ip); m_port = command_line::get_arg(vm, p2p_bind_arg); @@ -89,11 +95,10 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::init( const boost::program_options::variables_map& vm - , bool testnet ) { m_net_server.set_threads_prefix("RPC"); - bool r = handle_command_line(vm, testnet); + bool r = handle_command_line(vm); CHECK_AND_ASSERT_MES(r, false, "Failed to process command line in core_rpc_server"); return epee::http_server_impl_base::init(m_port, m_bind_ip); } @@ -302,7 +307,7 @@ namespace cryptonote { CHECK_CORE_READY(); account_public_address adr; - if(!get_account_address_from_str(adr, req.miner_address)) + if(!get_account_address_from_str(adr, m_testnet, req.miner_address)) { res.status = "Failed, wrong address"; return true; @@ -342,7 +347,7 @@ namespace cryptonote res.speed = lMiner.get_speed(); res.threads_count = lMiner.get_threads_count(); const account_public_address& lMiningAdr = lMiner.get_mining_address(); - res.address = get_account_address_as_str(lMiningAdr); + res.address = get_account_address_as_str(m_testnet, lMiningAdr); } res.status = CORE_RPC_STATUS_OK; @@ -426,7 +431,7 @@ namespace cryptonote cryptonote::account_public_address acc = AUTO_VAL_INIT(acc); - if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(acc, req.wallet_address)) + if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(acc, m_testnet, req.wallet_address)) { error_resp.code = CORE_RPC_ERROR_CODE_WRONG_WALLET_ADDRESS; error_resp.message = "Failed to parse wallet address"; diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 3f3d23f51..02bc533c9 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -49,12 +49,15 @@ namespace cryptonote public: typedef epee::net_utils::connection_context_base connection_context; - core_rpc_server(core& cr, nodetool::node_server >& p2p); + core_rpc_server( + core& cr + , nodetool::node_server >& p2p + , bool testnet + ); static void init_options(boost::program_options::options_description& desc); bool init( const boost::program_options::variables_map& vm - , bool testnet ); private: @@ -110,7 +113,6 @@ namespace cryptonote //----------------------- bool handle_command_line( const boost::program_options::variables_map& vm - , bool testnet ); bool check_core_busy(); bool check_core_ready(); @@ -123,5 +125,6 @@ namespace cryptonote nodetool::node_server >& m_p2p; std::string m_port; std::string m_bind_ip; + bool m_testnet; }; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 6c97dc807..fbe7c4730 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -441,7 +441,9 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas try { recovery_val = m_wallet->generate(wallet_file, password, recovery_key, recover, two_random); - message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str() << std::endl << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key); + message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " + << m_wallet->get_account().get_public_address_str(m_wallet->testnet()) << std::endl << "view key: " + << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key); } catch (const std::exception& e) { @@ -487,7 +489,8 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa try { m_wallet->load(m_wallet_file, password); - message_writer(epee::log_space::console_color_white, true) << "Opened wallet: " << m_wallet->get_account().get_public_address_str(); + message_writer(epee::log_space::console_color_white, true) << "Opened wallet: " + << m_wallet->get_account().get_public_address_str(m_wallet->testnet()); } catch (const std::exception& e) { @@ -548,7 +551,7 @@ bool simple_wallet::start_mining(const std::vector& args) return true; COMMAND_RPC_START_MINING::request req; - req.miner_address = m_wallet->get_account().get_public_address_str(); + req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet()); bool ok = true; size_t max_mining_threads_count = (std::max)(std::thread::hardware_concurrency(), static_cast(2)); @@ -905,7 +908,7 @@ bool simple_wallet::transfer(const std::vector &args_) for (size_t i = 0; i < local_args.size(); i += 2) { cryptonote::tx_destination_entry de; - if(!get_account_address_from_str(de.addr, local_args[i])) + if(!get_account_address_from_str(de.addr, m_wallet->testnet(), local_args[i])) { fail_msg_writer() << "wrong address: " << local_args[i]; return true; @@ -1035,7 +1038,7 @@ bool simple_wallet::transfer(const std::vector &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::run() { - std::string addr_start = m_wallet->get_account().get_public_address_str().substr(0, 6); + std::string addr_start = m_wallet->get_account().get_public_address_str(m_wallet->testnet()).substr(0, 6); return m_cmd_binder.run_handling("[wallet " + addr_start + "]: ", ""); } //---------------------------------------------------------------------------------------------------- @@ -1047,7 +1050,7 @@ void simple_wallet::stop() //---------------------------------------------------------------------------------------------------- bool simple_wallet::print_address(const std::vector &args/* = std::vector()*/) { - success_msg_writer() << m_wallet->get_account().get_public_address_str(); + success_msg_writer() << m_wallet->get_account().get_public_address_str(m_wallet->testnet()); return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 78fac0e87..9ba6f245a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -496,7 +496,7 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri bool r = store_keys(m_keys_file, password); THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file); - r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str()); + r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet)); if(!r) LOG_PRINT_RED_L0("String with address text not saved"); cryptonote::block b; @@ -562,7 +562,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password) THROW_WALLET_EXCEPTION_IF(e || !exists, error::file_not_found, m_keys_file); load_keys(m_keys_file, password); - LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str()); + LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str(m_testnet)); //keys loaded ok! //try to load wallet file. but even if we failed, it is not big problem diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 28788f693..3311e3438 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -158,6 +158,8 @@ namespace tools void refresh(uint64_t start_height, size_t & blocks_fetched, bool& received_money); bool refresh(size_t & blocks_fetched, bool& received_money, bool& ok); + bool testnet() { return m_testnet; } + uint64_t balance(); uint64_t unlocked_balance(); template @@ -360,7 +362,7 @@ namespace tools { THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination); needed_money += dt.amount; - THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee); + THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee, m_testnet); } // randomly select inputs for transaction @@ -465,7 +467,7 @@ namespace tools } bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time); - THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time); + THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet); THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit); std::string key_images; diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index aa29f281a..7914ff8e1 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -376,11 +376,18 @@ namespace tools typedef std::vector sources_t; typedef std::vector destinations_t; - explicit tx_not_constructed(std::string&& loc, const sources_t& sources, const destinations_t& destinations, uint64_t unlock_time) - : transfer_error(std::move(loc), "transaction was not constructed") - , m_sources(sources) - , m_destinations(destinations) - , m_unlock_time(unlock_time) + explicit tx_not_constructed( + std::string && loc + , sources_t const & sources + , destinations_t const & destinations + , uint64_t unlock_time + , bool testnet + ) + : transfer_error {std::move(loc), "transaction was not constructed"} + , m_sources {sources} + , m_destinations {destinations} + , m_unlock_time {unlock_time} + , m_testnet {testnet} { } @@ -414,7 +421,7 @@ namespace tools for (size_t i = 0; i < m_destinations.size(); ++i) { const cryptonote::tx_destination_entry& dst = m_destinations[i]; - ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(dst.addr) << " " << + ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(m_testnet, dst.addr) << " " << cryptonote::print_money(dst.amount); } @@ -427,6 +434,7 @@ namespace tools sources_t m_sources; destinations_t m_destinations; uint64_t m_unlock_time; + bool m_testnet; }; //---------------------------------------------------------------------------------------------------- struct tx_rejected : public transfer_error @@ -457,10 +465,16 @@ namespace tools //---------------------------------------------------------------------------------------------------- struct tx_sum_overflow : public transfer_error { - explicit tx_sum_overflow(std::string&& loc, const std::vector& destinations, uint64_t fee) - : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits::max())) - , m_destinations(destinations) - , m_fee(fee) + explicit tx_sum_overflow( + std::string && loc + , const std::vector& destinations + , uint64_t fee + , bool testnet + ) + : transfer_error {std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits::max())} + , m_destinations {destinations} + , m_fee {fee} + , m_testnet {testnet} { } @@ -475,7 +489,7 @@ namespace tools ", destinations:"; for (const auto& dst : m_destinations) { - ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(dst.addr); + ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(m_testnet, dst.addr); } return ss.str(); } @@ -483,6 +497,7 @@ namespace tools private: std::vector m_destinations; uint64_t m_fee; + bool m_testnet; }; //---------------------------------------------------------------------------------------------------- struct tx_too_big : public transfer_error diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index fa0a5445e..995e97ede 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -101,7 +101,7 @@ namespace tools { try { - res.address = m_wallet.get_account().get_public_address_str(); + res.address = m_wallet.get_account().get_public_address_str(m_wallet.testnet()); } catch (std::exception& e) { @@ -118,7 +118,7 @@ namespace tools for (auto it = destinations.begin(); it != destinations.end(); it++) { cryptonote::tx_destination_entry de; - if(!get_account_address_from_str(de.addr, it->address)) + if(!get_account_address_from_str(de.addr, m_wallet.testnet(), it->address)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + it->address; diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index 6f0dcee43..d46d48b07 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -54,7 +54,7 @@ bool test_transaction_generation_and_ring_signature() account_base miner_acc6; miner_acc6.generate(); - std::string add_str = miner_acc3.get_public_address_str(); + std::string add_str = miner_acc3.get_public_address_str(false); account_base rv_acc; @@ -150,7 +150,7 @@ bool test_block_creation() uint64_t vszs[] = {80,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,9391,476,476,475,475,474,475,8819,8301,475,472,4302,5316,14347,16620,19583,19403,19728,19442,19852,19015,19000,19016,19795,19749,18087,19787,19704,19750,19267,19006,19050,19445,19407,19522,19546,19788,19369,19486,19329,19370,18853,19600,19110,19320,19746,19474,19474,19743,19494,19755,19715,19769,19620,19368,19839,19532,23424,28287,30707}; std::vector szs(&vszs[0], &vszs[90]); account_public_address adr; - bool r = get_account_address_from_str(adr, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2"); + bool r = get_account_address_from_str(adr, false, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2"); CHECK_AND_ASSERT_MES(r, false, "failed to import"); block b; r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, adr, b.miner_tx, blobdata(), 11); diff --git a/tests/daemon_tests/transfers.cpp b/tests/daemon_tests/transfers.cpp index 8b4addf62..ff73e1931 100644 --- a/tests/daemon_tests/transfers.cpp +++ b/tests/daemon_tests/transfers.cpp @@ -54,7 +54,7 @@ TEST(Transfers, Transfers) miner.generate(); ASSERT_TRUE(miner.init()); ASSERT_TRUE(miner.store("miner.b2wallet")); - cout << "miner: " << miner.get_account().get_public_address_str() << endl; + cout << "miner: " << miner.get_account().get_public_address_str(false) << endl; for (int i = 0; i < ACCS; i++) { ostringstream s; @@ -69,7 +69,7 @@ TEST(Transfers, Transfers) { COMMAND_RPC_START_MINE::request req; - req.miner_address = miner.get_account().get_public_address_str(); + req.miner_address = miner.get_account().get_public_address_str(false); req.threads_count = 1; COMMAND_RPC_START_MINE::response res; bool r = net_utils::http::invoke_http_json_remote_command(daemon_address + "/start_mine", req, res, http_client); diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 2187ff250..806433ab6 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -151,8 +151,8 @@ bool transactions_flow_test(std::string& working_folder, w2.init(daemon_addr_b); LOG_PRINT_GREEN("Using wallets: " << ENDL - << "Source: " << w1.get_account().get_public_address_str() << ENDL << "Path: " << working_folder + "/" + path_source_wallet << ENDL - << "Target: " << w2.get_account().get_public_address_str() << ENDL << "Path: " << working_folder + "/" + path_terget_wallet, LOG_LEVEL_1); + << "Source: " << w1.get_account().get_public_address_str(false) << ENDL << "Path: " << working_folder + "/" + path_source_wallet << ENDL + << "Target: " << w2.get_account().get_public_address_str(false) << ENDL << "Path: " << working_folder + "/" + path_terget_wallet, LOG_LEVEL_1); //lets do some money epee::net_utils::http::http_simple_client http_client; @@ -163,7 +163,7 @@ bool transactions_flow_test(std::string& working_folder, COMMAND_RPC_START_MINING::request daemon_req = AUTO_VAL_INIT(daemon_req); COMMAND_RPC_START_MINING::response daemon_rsp = AUTO_VAL_INIT(daemon_rsp); - daemon_req.miner_address = w1.get_account().get_public_address_str(); + daemon_req.miner_address = w1.get_account().get_public_address_str(false); daemon_req.threads_count = 9; r = net_utils::invoke_http_json_remote_command2(daemon_addr_a + "/start_mining", daemon_req, daemon_rsp, http_client, 10000); CHECK_AND_ASSERT_MES(r, false, "failed to get getrandom_outs"); diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp index f61bb1b96..28fb27f25 100644 --- a/tests/unit_tests/base58.cpp +++ b/tests/unit_tests/base58.cpp @@ -473,14 +473,14 @@ TEST(get_account_address_as_str, works_correctly) { cryptonote::account_public_address addr; ASSERT_TRUE(serialization::parse_binary(test_serialized_keys, addr)); - std::string addr_str = cryptonote::get_account_address_as_str(addr); + std::string addr_str = cryptonote::get_account_address_as_str(false, addr); ASSERT_EQ(addr_str, test_keys_addr_str); } TEST(get_account_address_from_str, handles_valid_address) { cryptonote::account_public_address addr; - ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, test_keys_addr_str)); + ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, false, test_keys_addr_str)); std::string blob; ASSERT_TRUE(serialization::dump_binary(addr, blob)); @@ -493,7 +493,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_format) std::string addr_str = test_keys_addr_str; addr_str[0] = '0'; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_prefix) @@ -501,7 +501,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_prefix) std::string addr_str = base58::encode_addr(0, test_serialized_keys); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_content) @@ -509,7 +509,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_content) std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, test_serialized_keys.substr(1)); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_spend_key) @@ -519,7 +519,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_spend_key) std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_view_key) @@ -529,11 +529,11 @@ TEST(get_account_address_from_str, fails_on_invalid_address_view_key) std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, parses_old_address_format) { cryptonote::account_public_address addr; - ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, "002391bbbb24dea6fd95232e97594a27769d0153d053d2102b789c498f57a2b00b69cd6f2f5c529c1660f2f4a2b50178d6640c20ce71fe26373041af97c5b10236fc")); + ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, false, "002391bbbb24dea6fd95232e97594a27769d0153d053d2102b789c498f57a2b00b69cd6f2f5c529c1660f2f4a2b50178d6640c20ce71fe26373041af97c5b10236fc")); } From 23525655faa87c1fd4e88d61e1d6cf54c12451ce Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Tue, 9 Sep 2014 12:15:42 -0400 Subject: [PATCH 16/19] Replace macro with equivalent function call Also removed useless bool return --- src/p2p/net_node.inl | 94 +++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 9655a6176..d0a150422 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -195,71 +195,67 @@ namespace nodetool return true; } //----------------------------------------------------------------------------------- - namespace + inline void add_hardcoded_seed_node( + std::vector & seed_nodes + , std::string const & addr + ) { - template - bool append_net_address(T& nodes, const std::string& addr) + using namespace boost::asio; + + size_t pos = addr.find_last_of(':'); + CHECK_AND_ASSERT_MES_NO_RET(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, "Failed to parse seed address from string: '" << addr << '\''); + std::string host = addr.substr(0, pos); + std::string port = addr.substr(pos + 1); + + io_service io_srv; + ip::tcp::resolver resolver(io_srv); + ip::tcp::resolver::query query(host, port); + boost::system::error_code ec; + ip::tcp::resolver::iterator i = resolver.resolve(query, ec); + CHECK_AND_ASSERT_MES_NO_RET(!ec, "Failed to resolve host name '" << host << "': " << ec.message() << ':' << ec.value()); + + ip::tcp::resolver::iterator iend; + for (; i != iend; ++i) { - using namespace boost::asio; - - size_t pos = addr.find_last_of(':'); - CHECK_AND_ASSERT_MES(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, false, "Failed to parse seed address from string: '" << addr << '\''); - std::string host = addr.substr(0, pos); - std::string port = addr.substr(pos + 1); - - io_service io_srv; - ip::tcp::resolver resolver(io_srv); - ip::tcp::resolver::query query(host, port); - boost::system::error_code ec; - ip::tcp::resolver::iterator i = resolver.resolve(query, ec); - CHECK_AND_NO_ASSERT_MES(!ec, false, "Failed to resolve host name '" << host << "': " << ec.message() << ':' << ec.value()); - - ip::tcp::resolver::iterator iend; - for (; i != iend; ++i) + ip::tcp::endpoint endpoint = *i; + if (endpoint.address().is_v4()) { - ip::tcp::endpoint endpoint = *i; - if (endpoint.address().is_v4()) - { - nodetool::net_address na; - na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()); - na.port = endpoint.port(); - nodes.push_back(na); - LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port); - } - else - { - LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); - } + nodetool::net_address na; + na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()); + na.port = endpoint.port(); + seed_nodes.push_back(na); + LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port); + } + else + { + LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); } - - return true; } } - #define ADD_HARDCODED_SEED_NODE(addr) append_net_address(m_seed_nodes, addr); //----------------------------------------------------------------------------------- template bool node_server::init(const boost::program_options::variables_map& vm, bool testnet) { if (testnet) { - ADD_HARDCODED_SEED_NODE("107.152.187.202:28080"); - ADD_HARDCODED_SEED_NODE("197.242.158.240:28080"); - ADD_HARDCODED_SEED_NODE("107.152.130.98:28080"); + add_hardcoded_seed_node(m_seed_nodes, "107.152.187.202:28080"); + add_hardcoded_seed_node(m_seed_nodes, "197.242.158.240:28080"); + add_hardcoded_seed_node(m_seed_nodes, "107.152.130.98:28080"); } else { - ADD_HARDCODED_SEED_NODE("62.210.78.186:18080"); - ADD_HARDCODED_SEED_NODE("195.12.60.154:18080"); - ADD_HARDCODED_SEED_NODE("54.241.246.125:18080"); - ADD_HARDCODED_SEED_NODE("107.170.157.169:18080"); - ADD_HARDCODED_SEED_NODE("54.207.112.216:18080"); - ADD_HARDCODED_SEED_NODE("78.27.112.54:18080"); - ADD_HARDCODED_SEED_NODE("209.222.30.57:18080"); - ADD_HARDCODED_SEED_NODE("80.71.13.55:18080"); - ADD_HARDCODED_SEED_NODE("107.178.112.126:18080"); - ADD_HARDCODED_SEED_NODE("107.158.233.98:18080"); - ADD_HARDCODED_SEED_NODE("64.22.111.2:18080"); + add_hardcoded_seed_node(m_seed_nodes, "62.210.78.186:18080"); + add_hardcoded_seed_node(m_seed_nodes, "195.12.60.154:18080"); + add_hardcoded_seed_node(m_seed_nodes, "54.241.246.125:18080"); + add_hardcoded_seed_node(m_seed_nodes, "107.170.157.169:18080"); + add_hardcoded_seed_node(m_seed_nodes, "54.207.112.216:18080"); + add_hardcoded_seed_node(m_seed_nodes, "78.27.112.54:18080"); + add_hardcoded_seed_node(m_seed_nodes, "209.222.30.57:18080"); + add_hardcoded_seed_node(m_seed_nodes, "80.71.13.55:18080"); + add_hardcoded_seed_node(m_seed_nodes, "107.178.112.126:18080"); + add_hardcoded_seed_node(m_seed_nodes, "107.158.233.98:18080"); + add_hardcoded_seed_node(m_seed_nodes, "64.22.111.2:18080"); } bool res = handle_command_line(vm, testnet); From 120c84d04f8a6f3b25898e930c701067ae10f6b1 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Tue, 9 Sep 2014 14:50:21 -0400 Subject: [PATCH 17/19] Make P2P use the testnet data dir --- src/p2p/net_node.inl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index d0a150422..870e7572e 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -260,7 +260,9 @@ namespace nodetool bool res = handle_command_line(vm, testnet); CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line"); - m_config_folder = command_line::get_arg(vm, command_line::arg_data_dir); + + auto config_arg = testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; + m_config_folder = command_line::get_arg(vm, config_arg); res = init_config(); CHECK_AND_ASSERT_MES(res, false, "Failed to init config."); From 95a2701ec5ae2417390a3f12f638240510decdb9 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Tue, 9 Sep 2014 16:29:24 -0400 Subject: [PATCH 18/19] Change testnet prefix --- src/cryptonote_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index f8f35470d..1ac8ab328 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -117,7 +117,7 @@ namespace config uint64_t const DEFAULT_DUST_THRESHOLD = 5000000000; // 5 * 10^9 std::string const P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY = "0000000000000000000000000000000000000000000000000000000000000000"; - uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 18; // addresses start with "4" + uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 18; uint16_t const P2P_DEFAULT_PORT = 18080; uint16_t const RPC_DEFAULT_PORT = 18081; boost::uuids::uuid const NETWORK_ID = { { @@ -128,7 +128,7 @@ namespace config namespace testnet { - uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 19; // addresses start with "5" + uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 53; uint16_t const P2P_DEFAULT_PORT = 28080; uint16_t const RPC_DEFAULT_PORT = 28081; boost::uuids::uuid const NETWORK_ID = { { From 72a80f6213fbd427e3a476f4e5a230e258d1ca38 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 15:58:22 +0200 Subject: [PATCH 19/19] fixed incorrect version reference --- src/daemon/daemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 12990800a..5eda6cb69 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -156,7 +156,7 @@ int main(int argc, char* argv[]) if (command_line::get_arg(vm, command_line::arg_help)) { - std::cout << CRYPTONOTE_NAME << " v" << PROJECT_VERSION_LONG << ENDL << ENDL; + std::cout << CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL << ENDL << ENDL; std::cout << desc_options << std::endl; return false; }