34 namespace po = boost::program_options;
39 req2.do_not_relay =
true;
55 std::vector<std::string> exclusive_nodes{
"127.0.0.1:65525"};
63 const char *test_mainnet = getenv(
"TEST_MAINNET");
64 if (!test_mainnet || atoi(test_mainnet) == 0)
70 const char *test_p2p_port = getenv(
"TEST_P2P_PORT");
71 auto p2p_port =
std::string(test_p2p_port && strlen(test_p2p_port) > 0 ? test_p2p_port :
"61340");
74 const char *test_rpc_port = getenv(
"TEST_RPC_PORT");
75 auto rpc_port =
std::string(test_rpc_port && strlen(test_rpc_port) > 0 ? test_rpc_port :
"61341");
78 const char *test_zmq_port = getenv(
"TEST_ZMQ_PORT");
79 auto zmq_port =
std::string(test_zmq_port && strlen(test_zmq_port) > 0 ? test_zmq_port :
"61342");
104 if(m_http_client.is_connected())
105 m_http_client.disconnect();
127 m_deinitalized =
false;
129 m_rpc_server.nettype(m_network_type);
137 if(m_http_client.is_connected())
138 m_http_client.disconnect();
145 if(m_http_client.is_connected())
146 m_http_client.disconnect();
150 m_rpc_server.deinit();
154 MERROR(
"Failed to deinitialize RPC server...");
165 MERROR(
"Failed to deinitialize p2p...");
172 m_protocol.set_p2p_endpoint(
nullptr);
176 MERROR(
"Failed to stop cryptonote protocol!");
179 m_deinitalized =
true;
196 const unsigned max_attempts = 3;
197 for(
unsigned attempts=0; attempts < max_attempts; ++attempts)
201 set_ports(m_vm, initial_port.get());
203 MDEBUG(
"Ports changed, RPC: " << rpc_addr());
211 catch(
const std::exception &e)
213 MWARNING(
"Could not init and start, attempt: " << attempts <<
", reason: " << e.what());
214 if (attempts + 1 >= max_attempts)
231 boost::thread stop_thread = boost::thread([
this] {
232 while (!this->m_stopped)
250 if (!zmq_server.
addTCPSocket(
"127.0.0.1", m_zmq_bind_port))
252 MERROR(
"Failed to add TCP Socket (127.0.0.1:" << m_zmq_bind_port <<
") to ZMQ RPC Server");
258 MINFO(
"Starting ZMQ server...");
261 MINFO(
"ZMQ server started at 127.0.0.1: " << m_zmq_bind_port);
270 while (!this->m_stopped)
280 catch (std::exception
const & ex)
282 MFATAL(
"Uncaught exception! " << ex.what());
287 MFATAL(
"Uncaught exception!");
302 m_rpc_server.send_stop_signal();
303 m_rpc_server.timed_wait_server_stop(5000);
309 m_server.send_stop_signal();
314 bool blocks_mined =
false;
315 const uint64_t start_height = get_height();
316 const auto mining_timeout = std::chrono::seconds(30);
317 MDEBUG(
"Current height before mining: " << start_height);
319 start_mining(miner_address);
320 auto mining_started = std::chrono::system_clock::now();
324 const uint64_t cur_height = get_height();
328 MDEBUG(
"Cur blocks: " << cur_height <<
" start: " << start_height);
333 auto current_time = std::chrono::system_clock::now();
334 if (mining_timeout < current_time - mining_started)
349 req.miner_address = miner_address;
350 req.threads_count = threads_count;
351 req.do_background_mining = do_background_mining;
352 req.ignore_battery = ignore_battery;
373 return m_core->get_blockchain_storage().get_current_blockchain_height();
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
void init_options(boost::program_options::options_description &hidden_options, boost::program_options::options_description &normal_options)
static constexpr const std::chrono::seconds rpc_timeout
auto_scope_leave_caller create_scope_leave_handler(t_scope_leave_handler f)
static void init_options(boost::program_options::options_description &option_spec)
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
#define CORE_RPC_STATUS_BUSY
uint64_t num_blocks(const std::vector< test_event_entry > &events)
const command_line::arg_descriptor< std::string > arg_zmq_rpc_bind_ip
#define CORE_RPC_STATUS_OK
void load_params(boost::program_options::variables_map const &vm)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
const command_line::arg_descriptor< bool, false > arg_testnet_on
boost::shared_ptr< call_befor_die_base > auto_scope_leave_caller
void mine_blocks(size_t num_blocks, const std::string &miner_address)
unsigned __int64 uint64_t
bool addTCPSocket(boost::string_ref address, boost::string_ref port)
static void init_options(boost::program_options::options_description &desc)
adds command line options to the given options set
static void set_ports(boost::program_options::variables_map &vm, unsigned initial_port)
void start_mining(const std::string &miner_address, uint64_t threads_count=1, bool do_background_mining=false, bool ignore_battery=true)
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const command_line::arg_descriptor< bool > arg_offline
static void default_options(boost::program_options::variables_map &vm)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request &req, COMMAND_RPC_SEND_RAW_TX::response &res, const connection_context *ctx=NULL)
void try_init_and_run(boost::optional< unsigned > initial_port=boost::none)
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
std::string to_string(t_connection_type type)
static void init_options(boost::program_options::options_description &desc)
bool on_send_raw_tx_2(const cryptonote::COMMAND_RPC_SEND_RAW_TX::request &req, cryptonote::COMMAND_RPC_SEND_RAW_TX::response &res, const cryptonote::core_rpc_server::connection_context *ctx)