Port plugin sanitization code

This commit is contained in:
Sandip Patel 2019-12-03 15:17:45 +05:30
parent c49ce31201
commit 5606fc5fc2
4 changed files with 34 additions and 5 deletions

View file

@ -324,7 +324,7 @@ processed_transaction database::_push_transaction( const signed_transaction& trx
temp_session.merge(); temp_session.merge();
// notify anyone listening to pending transactions // notify anyone listening to pending transactions
on_pending_transaction( trx ); notify_on_pending_transaction( trx );
return processed_trx; return processed_trx;
} }
@ -658,7 +658,7 @@ void database::_apply_block( const signed_block& next_block )
apply_debug_updates(); apply_debug_updates();
// notify observers that the block has been applied // notify observers that the block has been applied
applied_block( next_block ); //emit notify_applied_block( next_block ); //emit
_applied_ops.clear(); _applied_ops.clear();
notify_changed_objects(); notify_changed_objects();

View file

@ -33,6 +33,7 @@
#include <graphene/chain/confidential_object.hpp> #include <graphene/chain/confidential_object.hpp>
#include <graphene/chain/market_object.hpp> #include <graphene/chain/market_object.hpp>
#include <graphene/chain/committee_member_object.hpp> #include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/exceptions.hpp>
using namespace fc; using namespace fc;
using namespace graphene::chain; using namespace graphene::chain;
@ -433,6 +434,16 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
namespace graphene { namespace chain { namespace graphene { namespace chain {
void database::notify_applied_block( const signed_block& block )
{
GRAPHENE_TRY_NOTIFY( applied_block, block )
}
void database::notify_on_pending_transaction( const signed_transaction& tx )
{
GRAPHENE_TRY_NOTIFY( on_pending_transaction, tx )
}
void database::notify_changed_objects() void database::notify_changed_objects()
{ try { { try {
if( _undo_db.enabled() ) if( _undo_db.enabled() )
@ -452,7 +463,7 @@ void database::notify_changed_objects()
get_relevant_accounts(obj, new_accounts_impacted); get_relevant_accounts(obj, new_accounts_impacted);
} }
new_objects(new_ids, new_accounts_impacted); GRAPHENE_TRY_NOTIFY( new_objects, new_ids, new_accounts_impacted)
} }
// Changed // Changed
@ -466,7 +477,7 @@ void database::notify_changed_objects()
get_relevant_accounts(item.second.get(), changed_accounts_impacted); get_relevant_accounts(item.second.get(), changed_accounts_impacted);
} }
changed_objects(changed_ids, changed_accounts_impacted); GRAPHENE_TRY_NOTIFY( changed_objects, changed_ids, changed_accounts_impacted)
} }
// Removed // Removed
@ -483,7 +494,7 @@ void database::notify_changed_objects()
get_relevant_accounts(obj, removed_accounts_impacted); get_relevant_accounts(obj, removed_accounts_impacted);
} }
removed_objects(removed_ids, removed, removed_accounts_impacted); GRAPHENE_TRY_NOTIFY( removed_objects, removed_ids, removed, removed_accounts_impacted)
} }
} }
} FC_CAPTURE_AND_LOG( (0) ) } } FC_CAPTURE_AND_LOG( (0) ) }

View file

@ -469,6 +469,8 @@ namespace graphene { namespace chain {
protected: protected:
//Mark pop_undo() as protected -- we do not want outside calling pop_undo(); it should call pop_block() instead //Mark pop_undo() as protected -- we do not want outside calling pop_undo(); it should call pop_block() instead
void pop_undo() { object_database::pop_undo(); } void pop_undo() { object_database::pop_undo(); }
void notify_applied_block( const signed_block& block );
void notify_on_pending_transaction( const signed_transaction& tx );
void notify_changed_objects(); void notify_changed_objects();
private: private:

View file

@ -65,6 +65,21 @@
msg \ 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" ); \
}
namespace graphene { namespace chain { namespace graphene { namespace chain {
FC_DECLARE_EXCEPTION( chain_exception, 3000000, "blockchain exception" ) FC_DECLARE_EXCEPTION( chain_exception, 3000000, "blockchain exception" )
@ -77,6 +92,7 @@ namespace graphene { namespace chain {
FC_DECLARE_DERIVED_EXCEPTION( undo_database_exception, graphene::chain::chain_exception, 3070000, "undo database exception" ) FC_DECLARE_DERIVED_EXCEPTION( undo_database_exception, graphene::chain::chain_exception, 3070000, "undo database exception" )
FC_DECLARE_DERIVED_EXCEPTION( unlinkable_block_exception, graphene::chain::chain_exception, 3080000, "unlinkable block" ) FC_DECLARE_DERIVED_EXCEPTION( unlinkable_block_exception, graphene::chain::chain_exception, 3080000, "unlinkable block" )
FC_DECLARE_DERIVED_EXCEPTION( black_swan_exception, graphene::chain::chain_exception, 3090000, "black swan" ) FC_DECLARE_DERIVED_EXCEPTION( black_swan_exception, graphene::chain::chain_exception, 3090000, "black swan" )
FC_DECLARE_DERIVED_EXCEPTION( plugin_exception, graphene::chain::chain_exception, 3100000, "plugin exception" )
FC_DECLARE_DERIVED_EXCEPTION( tx_missing_active_auth, graphene::chain::transaction_exception, 3030001, "missing required active authority" ) FC_DECLARE_DERIVED_EXCEPTION( tx_missing_active_auth, graphene::chain::transaction_exception, 3030001, "missing required active authority" )
FC_DECLARE_DERIVED_EXCEPTION( tx_missing_owner_auth, graphene::chain::transaction_exception, 3030002, "missing required owner authority" ) FC_DECLARE_DERIVED_EXCEPTION( tx_missing_owner_auth, graphene::chain::transaction_exception, 3030002, "missing required owner authority" )