2015-06-08 15:50:35 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The MIT License
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2015-06-08 15:50:35 +00:00
|
|
|
*/
|
|
|
|
|
#include <graphene/app/application.hpp>
|
2019-11-14 13:43:57 +00:00
|
|
|
#include <graphene/app/config_util.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
#include <graphene/witness/witness.hpp>
|
2017-05-24 17:16:09 +00:00
|
|
|
#include <graphene/debug_witness/debug_witness.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
#include <graphene/account_history/account_history_plugin.hpp>
|
2017-05-22 15:04:40 +00:00
|
|
|
#include <graphene/accounts_list/accounts_list_plugin.hpp>
|
2017-11-11 13:32:53 +00:00
|
|
|
#include <graphene/elasticsearch/elasticsearch_plugin.hpp>
|
2018-03-20 20:06:05 +00:00
|
|
|
#include <graphene/es_objects/es_objects.hpp>
|
2015-06-23 22:23:41 +00:00
|
|
|
#include <graphene/market_history/market_history_plugin.hpp>
|
2017-06-01 15:05:43 +00:00
|
|
|
//#include <graphene/generate_genesis/generate_genesis_plugin.hpp>
|
|
|
|
|
//#include <graphene/generate_uia_sharedrop_genesis/generate_uia_sharedrop_genesis.hpp>
|
2018-04-18 21:18:05 +00:00
|
|
|
#include <graphene/affiliate_stats/affiliate_stats_plugin.hpp>
|
2017-07-27 23:35:13 +00:00
|
|
|
#include <graphene/bookie/bookie_plugin.hpp>
|
2017-08-09 22:16:52 +00:00
|
|
|
#include <graphene/utilities/git_revision.hpp>
|
2018-10-11 11:36:49 +00:00
|
|
|
//#include <graphene/snapshot/snapshot.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
#include <fc/thread/thread.hpp>
|
|
|
|
|
#include <fc/interprocess/signals.hpp>
|
|
|
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
2015-07-15 18:37:03 +00:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
|
2019-05-21 01:32:17 +00:00
|
|
|
#include <graphene/utilities/git_revision.hpp>
|
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2015-09-04 19:22:12 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
|
# include <signal.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <csignal>
|
2015-06-08 15:50:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using namespace graphene;
|
|
|
|
|
namespace bpo = boost::program_options;
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2015-09-27 22:06:46 +00:00
|
|
|
app::application* node = new app::application();
|
|
|
|
|
fc::oexception unhandled_exception;
|
2015-06-08 15:50:35 +00:00
|
|
|
try {
|
|
|
|
|
bpo::options_description app_options("Graphene Witness Node");
|
|
|
|
|
bpo::options_description cfg_options("Graphene Witness Node");
|
|
|
|
|
app_options.add_options()
|
|
|
|
|
("help,h", "Print this help message and exit.")
|
2017-08-10 19:27:42 +00:00
|
|
|
("version", "Display the version info and exit")
|
2015-06-08 15:50:35 +00:00
|
|
|
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("witness_node_data_dir"), "Directory containing databases, configuration file, etc.")
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
bpo::variables_map options;
|
|
|
|
|
|
2015-09-07 21:46:47 +00:00
|
|
|
auto witness_plug = node->register_plugin<witness_plugin::witness_plugin>();
|
2017-05-24 17:16:09 +00:00
|
|
|
auto debug_witness_plug = node->register_plugin<debug_witness_plugin::debug_witness_plugin>();
|
2015-09-07 21:46:47 +00:00
|
|
|
auto history_plug = node->register_plugin<account_history::account_history_plugin>();
|
2017-11-11 13:32:53 +00:00
|
|
|
auto elasticsearch_plug = node->register_plugin<elasticsearch::elasticsearch_plugin>();
|
2018-03-20 20:06:05 +00:00
|
|
|
auto es_objects_plug = node->register_plugin<es_objects::es_objects_plugin>();
|
2015-09-07 21:46:47 +00:00
|
|
|
auto market_history_plug = node->register_plugin<market_history::market_history_plugin>();
|
2016-11-28 11:36:18 +00:00
|
|
|
//auto generate_genesis_plug = node->register_plugin<generate_genesis_plugin::generate_genesis_plugin>();
|
2017-06-01 15:05:43 +00:00
|
|
|
//auto generate_uia_sharedrop_genesis_plug = node->register_plugin<generate_uia_sharedrop_genesis::generate_uia_sharedrop_genesis_plugin>();
|
2017-05-22 15:04:40 +00:00
|
|
|
auto list_plug = node->register_plugin<accounts_list::accounts_list_plugin>();
|
2018-04-18 21:18:05 +00:00
|
|
|
auto affiliate_stats_plug = node->register_plugin<affiliate_stats::affiliate_stats_plugin>();
|
2017-07-27 23:35:13 +00:00
|
|
|
auto bookie_plug = node->register_plugin<bookie::bookie_plugin>();
|
2018-10-11 11:36:49 +00:00
|
|
|
// auto snapshot_plug = node->register_plugin<snapshot_plugin::snapshot_plugin>();
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-01 13:55:41 +00:00
|
|
|
try
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
|
|
|
|
bpo::options_description cli, cfg;
|
2015-09-07 21:46:47 +00:00
|
|
|
node->set_program_options(cli, cfg);
|
2015-06-08 15:50:35 +00:00
|
|
|
app_options.add(cli);
|
|
|
|
|
cfg_options.add(cfg);
|
|
|
|
|
bpo::store(bpo::parse_command_line(argc, argv, app_options), options);
|
|
|
|
|
}
|
2015-07-01 13:55:41 +00:00
|
|
|
catch (const boost::program_options::error& e)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "Error parsing command line: " << e.what() << "\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
if( options.count("help") )
|
|
|
|
|
{
|
|
|
|
|
std::cout << app_options << "\n";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2017-08-09 22:16:52 +00:00
|
|
|
if (options.count("version"))
|
|
|
|
|
{
|
|
|
|
|
std::string witness_version(graphene::utilities::git_revision_description);
|
|
|
|
|
const size_t pos = witness_version.find('/');
|
|
|
|
|
if( pos != std::string::npos && witness_version.size() > pos )
|
|
|
|
|
witness_version = witness_version.substr( pos + 1 );
|
|
|
|
|
std::cerr << "Version: " << witness_version << "\n";
|
|
|
|
|
std::cerr << "Git Revision: " << graphene::utilities::git_revision_sha << "\n";
|
|
|
|
|
std::cerr << "Built: " << __DATE__ " at " __TIME__ << "\n";
|
2019-05-21 01:32:17 +00:00
|
|
|
std::cout << "SSL: " << OPENSSL_VERSION_TEXT << "\n";
|
|
|
|
|
std::cout << "Boost: " << boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".") << "\n";
|
2017-08-09 22:16:52 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
fc::path data_dir;
|
|
|
|
|
if( options.count("data-dir") )
|
|
|
|
|
{
|
|
|
|
|
data_dir = options["data-dir"].as<boost::filesystem::path>();
|
|
|
|
|
if( data_dir.is_relative() )
|
|
|
|
|
data_dir = fc::current_path() / data_dir;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-14 11:32:54 +00:00
|
|
|
app::load_configuration_options(data_dir, cfg_options, options);
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
bpo::notify(options);
|
2015-09-07 21:46:47 +00:00
|
|
|
node->initialize(data_dir, options);
|
|
|
|
|
node->initialize_plugins( options );
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-09-07 21:46:47 +00:00
|
|
|
node->startup();
|
|
|
|
|
node->startup_plugins();
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
fc::promise<int>::ptr exit_promise = new fc::promise<int>("UNIX Signal Handler");
|
2015-10-14 20:25:37 +00:00
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
fc::set_signal_handler([&exit_promise](int signal) {
|
2015-10-14 20:25:37 +00:00
|
|
|
elog( "Caught SIGINT attempting to exit cleanly" );
|
2015-06-08 15:50:35 +00:00
|
|
|
exit_promise->set_value(signal);
|
|
|
|
|
}, SIGINT);
|
|
|
|
|
|
2015-10-14 20:25:37 +00:00
|
|
|
fc::set_signal_handler([&exit_promise](int signal) {
|
|
|
|
|
elog( "Caught SIGTERM attempting to exit cleanly" );
|
|
|
|
|
exit_promise->set_value(signal);
|
|
|
|
|
}, SIGTERM);
|
|
|
|
|
|
2017-05-24 17:16:09 +00:00
|
|
|
ilog("Started BitShares node on a chain with ${h} blocks.", ("h", node->chain_database()->head_block_num()));
|
2015-09-07 21:46:47 +00:00
|
|
|
ilog("Chain ID is ${id}", ("id", node->chain_database()->get_chain_id()) );
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
int signal = exit_promise->wait();
|
|
|
|
|
ilog("Exiting from signal ${n}", ("n", signal));
|
2015-09-07 21:46:47 +00:00
|
|
|
node->shutdown_plugins();
|
|
|
|
|
node->shutdown();
|
|
|
|
|
delete node;
|
2015-06-08 15:50:35 +00:00
|
|
|
return 0;
|
|
|
|
|
} catch( const fc::exception& e ) {
|
2015-09-27 22:06:46 +00:00
|
|
|
// deleting the node can yield, so do this outside the exception handler
|
|
|
|
|
unhandled_exception = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unhandled_exception)
|
|
|
|
|
{
|
|
|
|
|
elog("Exiting with error:\n${e}", ("e", unhandled_exception->to_detail_string()));
|
2015-09-07 21:46:47 +00:00
|
|
|
node->shutdown();
|
|
|
|
|
delete node;
|
2015-06-08 15:50:35 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2017-05-24 17:16:09 +00:00
|
|
|
}
|