Updated APIs, fixed crash

- update fc to fix crash in websocket message handling
- added api to verify transactions without broadcasting them
- added api to broadcast a block produced outside the P2P network or
witness
This commit is contained in:
Daniel Larimer 2015-09-07 17:46:47 -04:00
parent b2c23cd37b
commit 9080800c5b
7 changed files with 58 additions and 13 deletions

View file

@ -629,6 +629,12 @@ namespace graphene { namespace app {
_app.p2p_node()->broadcast_transaction(trx); _app.p2p_node()->broadcast_transaction(trx);
} }
void network_broadcast_api::broadcast_block( const signed_block& b )
{
_app.chain_database()->push_block(b);
_app.p2p_node()->broadcast( net::block_message( b ));
}
void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const signed_transaction& trx) void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const signed_transaction& trx)
{ {
trx.validate(); trx.validate();
@ -1214,6 +1220,13 @@ namespace graphene { namespace app {
wdump((result)); wdump((result));
return result; return result;
} }
/**
* Validates a transaction against the current state without broadcast it on the network.
*/
processed_transaction database_api::validate_transaction( const signed_transaction& trx )const
{
return _db.validate_transaction(trx);
}
bool database_api::verify_authority( const signed_transaction& trx )const bool database_api::verify_authority( const signed_transaction& trx )const
{ {

View file

@ -708,6 +708,11 @@ void application::shutdown_plugins()
entry.second->plugin_shutdown(); entry.second->plugin_shutdown();
return; return;
} }
void application::shutdown()
{
if( my->_chain_db )
my->_chain_db->close();
}
void application::initialize_plugins( const boost::program_options::variables_map& options ) void application::initialize_plugins( const boost::program_options::variables_map& options )
{ {

View file

@ -347,6 +347,11 @@ namespace graphene { namespace app {
*/ */
bool verify_account_authority( const string& name_or_id, const flat_set<public_key_type>& signers )const; bool verify_account_authority( const string& name_or_id, const flat_set<public_key_type>& signers )const;
/**
* Validates a transaction against the current state without broadcast it on the network.
*/
processed_transaction validate_transaction( const signed_transaction& trx )const;
/** /**
* @return the set of blinded balance objects by commitment ID * @return the set of blinded balance objects by commitment ID
@ -462,6 +467,8 @@ namespace graphene { namespace app {
*/ */
void broadcast_transaction_with_callback( confirmation_callback cb, const signed_transaction& trx); void broadcast_transaction_with_callback( confirmation_callback cb, const signed_transaction& trx);
void broadcast_block( const signed_block& block );
/** /**
* @brief Not reflected, thus not accessible to API clients. * @brief Not reflected, thus not accessible to API clients.
* *
@ -595,6 +602,7 @@ FC_API(graphene::app::database_api,
(get_blinded_balances) (get_blinded_balances)
(get_required_fees) (get_required_fees)
(set_subscribe_callback) (set_subscribe_callback)
(validate_transaction)
) )
FC_API(graphene::app::history_api, FC_API(graphene::app::history_api,
(get_account_history) (get_account_history)
@ -604,6 +612,7 @@ FC_API(graphene::app::history_api,
FC_API(graphene::app::network_broadcast_api, FC_API(graphene::app::network_broadcast_api,
(broadcast_transaction) (broadcast_transaction)
(broadcast_transaction_with_callback) (broadcast_transaction_with_callback)
(broadcast_block)
) )
FC_API(graphene::app::network_node_api, FC_API(graphene::app::network_node_api,
(add_node) (add_node)

View file

@ -213,6 +213,12 @@ processed_transaction database::_push_transaction( const signed_transaction& trx
return processed_trx; return processed_trx;
} }
processed_transaction database::validate_transaction( const signed_transaction& trx )
{
auto session = _undo_db.start_undo_session();
return _apply_transaction( trx );
}
processed_transaction database::push_proposal(const proposal_object& proposal) processed_transaction database::push_proposal(const proposal_object& proposal)
{ {
transaction_evaluation_state eval_state(this); transaction_evaluation_state eval_state(this);

View file

@ -404,7 +404,13 @@ namespace graphene { namespace chain {
asset calculate_market_fee(const asset_object& recv_asset, const asset& trade_amount); asset calculate_market_fee(const asset_object& recv_asset, const asset& trade_amount);
asset pay_market_fees( const asset_object& recv_asset, const asset& receives ); asset pay_market_fees( const asset_object& recv_asset, const asset& receives );
///@} ///@}
/**
* This method validates transactions without adding it to the pending state.
* @return true if the transaction would validate
*/
processed_transaction validate_transaction( const signed_transaction& trx );
/** /**
* @} * @}
@ -429,6 +435,7 @@ namespace graphene { namespace chain {
processed_transaction _apply_transaction( const signed_transaction& trx ); processed_transaction _apply_transaction( const signed_transaction& trx );
operation_result apply_operation( transaction_evaluation_state& eval_state, const operation& op ); operation_result apply_operation( transaction_evaluation_state& eval_state, const operation& op );
///Steps involved in applying a new block ///Steps involved in applying a new block
///@{ ///@{

@ -1 +1 @@
Subproject commit c89a25a55c333bd202185cebf3f87eeae2b54761 Subproject commit 19e42ac4c41d0a2bbdc8094c2efeed5e28e0ed75

View file

@ -53,8 +53,8 @@ void write_default_logging_config_to_stream(std::ostream& out);
fc::optional<fc::logging_config> load_logging_config_from_ini_file(const fc::path& config_ini_filename); fc::optional<fc::logging_config> load_logging_config_from_ini_file(const fc::path& config_ini_filename);
int main(int argc, char** argv) { int main(int argc, char** argv) {
app::application* node = new app::application();
try { try {
app::application node;
bpo::options_description app_options("Graphene Witness Node"); bpo::options_description app_options("Graphene Witness Node");
bpo::options_description cfg_options("Graphene Witness Node"); bpo::options_description cfg_options("Graphene Witness Node");
app_options.add_options() app_options.add_options()
@ -64,14 +64,14 @@ int main(int argc, char** argv) {
bpo::variables_map options; bpo::variables_map options;
auto witness_plug = node.register_plugin<witness_plugin::witness_plugin>(); auto witness_plug = node->register_plugin<witness_plugin::witness_plugin>();
auto history_plug = node.register_plugin<account_history::account_history_plugin>(); auto history_plug = node->register_plugin<account_history::account_history_plugin>();
auto market_history_plug = node.register_plugin<market_history::market_history_plugin>(); auto market_history_plug = node->register_plugin<market_history::market_history_plugin>();
try try
{ {
bpo::options_description cli, cfg; bpo::options_description cli, cfg;
node.set_program_options(cli, cfg); node->set_program_options(cli, cfg);
app_options.add(cli); app_options.add(cli);
cfg_options.add(cfg); cfg_options.add(cfg);
bpo::store(bpo::parse_command_line(argc, argv, app_options), options); bpo::store(bpo::parse_command_line(argc, argv, app_options), options);
@ -151,26 +151,31 @@ int main(int argc, char** argv) {
} }
bpo::notify(options); bpo::notify(options);
node.initialize(data_dir, options); node->initialize(data_dir, options);
node.initialize_plugins( options ); node->initialize_plugins( options );
node.startup(); node->startup();
node.startup_plugins(); node->startup_plugins();
fc::promise<int>::ptr exit_promise = new fc::promise<int>("UNIX Signal Handler"); fc::promise<int>::ptr exit_promise = new fc::promise<int>("UNIX Signal Handler");
fc::set_signal_handler([&exit_promise](int signal) { fc::set_signal_handler([&exit_promise](int signal) {
elog( "Caught ^C attempting to exit cleanly" );
exit_promise->set_value(signal); exit_promise->set_value(signal);
}, SIGINT); }, SIGINT);
ilog("Started witness node on a chain with ${h} blocks.", ("h", node.chain_database()->head_block_num())); ilog("Started witness node on a chain with ${h} blocks.", ("h", node->chain_database()->head_block_num()));
ilog("Chain ID is ${id}", ("id", node.chain_database()->get_chain_id()) ); ilog("Chain ID is ${id}", ("id", node->chain_database()->get_chain_id()) );
int signal = exit_promise->wait(); int signal = exit_promise->wait();
ilog("Exiting from signal ${n}", ("n", signal)); ilog("Exiting from signal ${n}", ("n", signal));
node.shutdown_plugins(); node->shutdown_plugins();
node->shutdown();
delete node;
return 0; return 0;
} catch( const fc::exception& e ) { } catch( const fc::exception& e ) {
elog("Exiting with error:\n${e}", ("e", e.to_detail_string())); elog("Exiting with error:\n${e}", ("e", e.to_detail_string()));
node->shutdown();
delete node;
return 1; return 1;
} }
} }