From 5a922821da3591184dfe5ca6de798bb6c64657eb Mon Sep 17 00:00:00 2001 From: serkixenos Date: Thu, 16 Dec 2021 17:37:51 -0400 Subject: [PATCH 1/3] Revert change to a son_update_operation --- libraries/app/application.cpp | 4 ++-- libraries/chain/include/graphene/chain/protocol/son.hpp | 3 +-- libraries/chain/son_evaluator.cpp | 5 +---- libraries/wallet/wallet.cpp | 1 - 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 713a204a..1ecdd8f7 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -859,11 +859,11 @@ application::~application() { void application::set_program_options(boost::program_options::options_description &cli, boost::program_options::options_description &cfg) const { - cfg.add_options()("p2p-endpoint", bpo::value(), "Endpoint for P2P node to listen on"); + cfg.add_options()("p2p-endpoint", bpo::value()->default_value("0.0.0.0:9777"), "Endpoint for P2P node to listen on"); cfg.add_options()("seed-node,s", bpo::value>()->composing(), "P2P nodes to connect to on startup (may specify multiple times)"); cfg.add_options()("seed-nodes", bpo::value()->composing(), "JSON array of P2P nodes to connect to on startup"); cfg.add_options()("checkpoint,c", bpo::value>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints."); - cfg.add_options()("rpc-endpoint", bpo::value()->implicit_value("127.0.0.1:8090"), "Endpoint for websocket RPC to listen on"); + cfg.add_options()("rpc-endpoint", bpo::value()->default_value("127.0.0.1:8090"), "Endpoint for websocket RPC to listen on"); cfg.add_options()("rpc-tls-endpoint", bpo::value()->implicit_value("127.0.0.1:8089"), "Endpoint for TLS websocket RPC to listen on"); cfg.add_options()("server-pem,p", bpo::value()->implicit_value("server.pem"), "The TLS certificate file for this server"); cfg.add_options()("server-pem-password,P", bpo::value()->implicit_value(""), "Password for this certificate"); diff --git a/libraries/chain/include/graphene/chain/protocol/son.hpp b/libraries/chain/include/graphene/chain/protocol/son.hpp index 42ead5b6..9d6ef653 100644 --- a/libraries/chain/include/graphene/chain/protocol/son.hpp +++ b/libraries/chain/include/graphene/chain/protocol/son.hpp @@ -33,7 +33,6 @@ namespace graphene { namespace chain { optional new_signing_key; optional> new_sidechain_public_keys; optional new_pay_vb; - optional new_status; account_id_type fee_payer()const { return owner_account; } share_type calculate_fee(const fee_parameters_type& k)const { return 0; } @@ -105,7 +104,7 @@ FC_REFLECT(graphene::chain::son_create_operation, (fee)(owner_account)(url)(depo FC_REFLECT(graphene::chain::son_update_operation::fee_parameters_type, (fee) ) FC_REFLECT(graphene::chain::son_update_operation, (fee)(son_id)(owner_account)(new_url)(new_deposit) - (new_signing_key)(new_sidechain_public_keys)(new_pay_vb)(new_status) ) + (new_signing_key)(new_sidechain_public_keys)(new_pay_vb) ) FC_REFLECT(graphene::chain::son_deregister_operation::fee_parameters_type, (fee) ) FC_REFLECT(graphene::chain::son_deregister_operation, (fee)(son_id)(payer) ) diff --git a/libraries/chain/son_evaluator.cpp b/libraries/chain/son_evaluator.cpp index e732c145..776eb065 100644 --- a/libraries/chain/son_evaluator.cpp +++ b/libraries/chain/son_evaluator.cpp @@ -79,9 +79,6 @@ void_result update_son_evaluator::do_evaluate(const son_update_operation& op) FC_ASSERT(vbo.policy.which() == vesting_policy::tag::value, "Payment balance must have linear vesting policy"); } - if(op.new_status.valid()) { - FC_ASSERT(db().get(op.son_id).status == son_status::deregistered, "SON must be in deregistered state"); - } return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -97,7 +94,7 @@ object_id_type update_son_evaluator::do_apply(const son_update_operation& op) if(op.new_signing_key.valid()) so.signing_key = *op.new_signing_key; if(op.new_sidechain_public_keys.valid()) so.sidechain_public_keys = *op.new_sidechain_public_keys; if(op.new_pay_vb.valid()) so.pay_vb = *op.new_pay_vb; - if(op.new_status.valid()) so.status = son_status::inactive; + if(so.status == son_status::deregistered) so.status = son_status::inactive; }); } return op.son_id; diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index cc013736..8edfbd65 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2122,7 +2122,6 @@ public: son_update_operation son_update_op; son_update_op.son_id = son.id; son_update_op.owner_account = son.son_account; - son_update_op.new_status = son_status::inactive; signed_transaction tx; tx.operations.push_back( son_update_op ); set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees ); -- 2.45.2 From 43fbe982408278c30deb3a2849550d33fcf44258 Mon Sep 17 00:00:00 2001 From: Vladislav Dobromyslov Date: Fri, 28 Jan 2022 05:43:42 -0400 Subject: [PATCH 2/3] #245 Add additional catch blocks for GRAPHENE_TRY_NOTIFY --- .../include/graphene/chain/exceptions.hpp | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/libraries/chain/include/graphene/chain/exceptions.hpp b/libraries/chain/include/graphene/chain/exceptions.hpp index ee264029..406a235e 100644 --- a/libraries/chain/include/graphene/chain/exceptions.hpp +++ b/libraries/chain/include/graphene/chain/exceptions.hpp @@ -23,6 +23,7 @@ */ #pragma once +#include #include #include @@ -65,19 +66,27 @@ msg \ ) -#define GRAPHENE_TRY_NOTIFY( signal, ... ) \ - try \ - { \ - signal( __VA_ARGS__ ); \ - } \ - catch( const graphene::chain::plugin_exception& e ) \ - { \ - elog( "Caught plugin exception: ${e}", ("e", e.to_detail_string() ) ); \ - throw; \ - } \ - catch( ... ) \ - { \ - wlog( "Caught unexpected exception in plugin" ); \ +#define GRAPHENE_TRY_NOTIFY( signal, ... ) \ + try \ + { \ + signal( __VA_ARGS__ ); \ + } \ + catch( const graphene::chain::plugin_exception& e ) \ + { \ + elog( "Caught plugin exception: ${e}", ("e", e.to_detail_string() ) ); \ + throw; \ + } \ + catch( const boost::exception& e ) \ + { \ + elog( "Caught plugin boost::exception: ${e}", ("e", boost::diagnostic_information(e) ) ); \ + } \ + catch( const std::exception& e ) \ + { \ + elog( "Caught plugin std::exception: ${e}", ("e", e.what() ) ); \ + } \ + catch( ... ) \ + { \ + wlog( "Caught unexpected exception in plugin" ); \ } namespace graphene { namespace chain { -- 2.45.2 From 910362baf87db643da6b390b866d62ac6a57a2bd Mon Sep 17 00:00:00 2001 From: Vladislav Dobromyslov Date: Fri, 28 Jan 2022 05:44:29 -0400 Subject: [PATCH 3/3] #245 Add try-catch block for update_account_histories --- .../account_history_plugin.cpp | 213 ++++++++++-------- 1 file changed, 114 insertions(+), 99 deletions(-) diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 6eb3ff0c..db3fa464 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -79,123 +79,138 @@ account_history_plugin_impl::~account_history_plugin_impl() void account_history_plugin_impl::update_account_histories( const signed_block& b ) { - graphene::chain::database& db = database(); - vector >& hist = db.get_applied_operations(); - bool is_first = true; - auto skip_oho_id = [&is_first,&db,this]() { - if( is_first && db._undo_db.enabled() ) // this ensures that the current id is rolled back on undo - { - db.remove( db.create( []( operation_history_object& obj) {} ) ); - is_first = false; - } - else - _oho_index->use_next_id(); - }; - - for( optional< operation_history_object >& o_op : hist ) - { - optional oho; - - auto create_oho = [&]() { - is_first = false; - operation_history_object result = db.create( [&]( operation_history_object& h ) + try \ + { + graphene::chain::database& db = database(); + vector >& hist = db.get_applied_operations(); + bool is_first = true; + auto skip_oho_id = [&is_first,&db,this]() { + if( is_first && db._undo_db.enabled() ) // this ensures that the current id is rolled back on undo { - if( o_op.valid() ) - h = *o_op; - } ); - o_op->id = result.id; - return optional(result); + db.remove( db.create( []( operation_history_object& obj) {} ) ); + is_first = false; + } + else + _oho_index->use_next_id(); }; - if( !o_op.valid() || ( _max_ops_per_account == 0 && _partial_operations ) ) + for( optional< operation_history_object >& o_op : hist ) { - // Note: the 2nd and 3rd checks above are for better performance, when the db is not clean, - // they will break consistency of account_stats.total_ops and removed_ops and most_recent_op - skip_oho_id(); - continue; - } - else if( !_partial_operations ) - // add to the operation history index - oho = create_oho(); + optional oho; - const operation_history_object& op = *o_op; - - // get the set of accounts this operation applies to - flat_set impacted; - vector other; - // fee payer is added here - operation_get_required_authorities( op.op, impacted, impacted, other, - MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ) ); - - if( op.op.which() == operation::tag< account_create_operation >::value ) - impacted.insert( op.result.get() ); - else - graphene::chain::operation_get_impacted_accounts( op.op, impacted, - MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(db.head_block_time()) ); - if( op.op.which() == operation::tag< lottery_end_operation >::value ) - { - auto lop = op.op.get< lottery_end_operation >(); - auto asset_object = lop.lottery( db ); - impacted.insert( asset_object.issuer ); - for( auto benefactor : asset_object.lottery_options->benefactors ) - impacted.insert( benefactor.id ); - } - - for( auto& a : other ) - for( auto& item : a.account_auths ) - impacted.insert( item.first ); - - // be here, either _max_ops_per_account > 0, or _partial_operations == false, or both - // if _partial_operations == false, oho should have been created above - // so the only case should be checked here is: - // whether need to create oho if _max_ops_per_account > 0 and _partial_operations == true - - // for each operation this account applies to that is in the config link it into the history - if( _tracked_accounts.size() == 0 ) // tracking all accounts - { - // if tracking all accounts, when impacted is not empty (although it will always be), - // still need to create oho if _max_ops_per_account > 0 and _partial_operations == true - // so always need to create oho if not done - if (!impacted.empty() && !oho.valid()) { oho = create_oho(); } - - if( _max_ops_per_account > 0 ) - { - // Note: the check above is for better performance, when the db is not clean, - // it breaks consistency of account_stats.total_ops and removed_ops and most_recent_op, - // but it ensures it's safe to remove old entries in add_account_history(...) - for( auto& account_id : impacted ) + auto create_oho = [&]() { + is_first = false; + operation_history_object result = db.create( [&]( operation_history_object& h ) { - // we don't do index_account_keys here anymore, because - // that indexing now happens in observers' post_evaluate() + if( o_op.valid() ) + h = *o_op; + } ); + o_op->id = result.id; + return optional(result); + }; - // add history - add_account_history( account_id, oho->id ); - } + if( !o_op.valid() || ( _max_ops_per_account == 0 && _partial_operations ) ) + { + // Note: the 2nd and 3rd checks above are for better performance, when the db is not clean, + // they will break consistency of account_stats.total_ops and removed_ops and most_recent_op + skip_oho_id(); + continue; } - } - else // tracking a subset of accounts - { - // whether need to create oho if _max_ops_per_account > 0 and _partial_operations == true ? - // the answer: only need to create oho if a tracked account is impacted and need to save history + else if( !_partial_operations ) + // add to the operation history index + oho = create_oho(); - if( _max_ops_per_account > 0 ) + const operation_history_object& op = *o_op; + + // get the set of accounts this operation applies to + flat_set impacted; + vector other; + // fee payer is added here + operation_get_required_authorities( op.op, impacted, impacted, other, + MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ) ); + + if( op.op.which() == operation::tag< account_create_operation >::value ) + impacted.insert( op.result.get() ); + else + graphene::chain::operation_get_impacted_accounts( op.op, impacted, + MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(db.head_block_time()) ); + if( op.op.which() == operation::tag< lottery_end_operation >::value ) { - // Note: the check above is for better performance, when the db is not clean, - // it breaks consistency of account_stats.total_ops and removed_ops and most_recent_op, - // but it ensures it's safe to remove old entries in add_account_history(...) - for( auto account_id : _tracked_accounts ) + auto lop = op.op.get< lottery_end_operation >(); + auto asset_object = lop.lottery( db ); + impacted.insert( asset_object.issuer ); + for( auto benefactor : asset_object.lottery_options->benefactors ) + impacted.insert( benefactor.id ); + } + + for( auto& a : other ) + for( auto& item : a.account_auths ) + impacted.insert( item.first ); + + // be here, either _max_ops_per_account > 0, or _partial_operations == false, or both + // if _partial_operations == false, oho should have been created above + // so the only case should be checked here is: + // whether need to create oho if _max_ops_per_account > 0 and _partial_operations == true + + // for each operation this account applies to that is in the config link it into the history + if( _tracked_accounts.size() == 0 ) // tracking all accounts + { + // if tracking all accounts, when impacted is not empty (although it will always be), + // still need to create oho if _max_ops_per_account > 0 and _partial_operations == true + // so always need to create oho if not done + if (!impacted.empty() && !oho.valid()) { oho = create_oho(); } + + if( _max_ops_per_account > 0 ) { - if( impacted.find( account_id ) != impacted.end() ) + // Note: the check above is for better performance, when the db is not clean, + // it breaks consistency of account_stats.total_ops and removed_ops and most_recent_op, + // but it ensures it's safe to remove old entries in add_account_history(...) + for( auto& account_id : impacted ) { - if (!oho.valid()) { oho = create_oho(); } + // we don't do index_account_keys here anymore, because + // that indexing now happens in observers' post_evaluate() + // add history add_account_history( account_id, oho->id ); } } } + else // tracking a subset of accounts + { + // whether need to create oho if _max_ops_per_account > 0 and _partial_operations == true ? + // the answer: only need to create oho if a tracked account is impacted and need to save history + + if( _max_ops_per_account > 0 ) + { + // Note: the check above is for better performance, when the db is not clean, + // it breaks consistency of account_stats.total_ops and removed_ops and most_recent_op, + // but it ensures it's safe to remove old entries in add_account_history(...) + for( auto account_id : _tracked_accounts ) + { + if( impacted.find( account_id ) != impacted.end() ) + { + if (!oho.valid()) { oho = create_oho(); } + // add history + add_account_history( account_id, oho->id ); + } + } + } + } + if (_partial_operations && ! oho.valid()) + skip_oho_id(); } - if (_partial_operations && ! oho.valid()) - skip_oho_id(); + } + catch( const boost::exception& e ) + { + elog( "Caught account_history_plugin::update_account_histories(...) boost::exception: ${e}", ("e", boost::diagnostic_information(e) ) ); + } + catch( const std::exception& e ) + { + elog( "Caught account_history_plugin::update_account_histories(...) std::exception: ${e}", ("e", e.what() ) ); + } + catch( ... ) + { + wlog( "Caught unexpected exception in account_history_plugin::update_account_histories(...)" ); } } -- 2.45.2