Merge pull request #230 from peerplays-network/feature/GRPH-163

[GRPH-163] Port plugin sanitization code
This commit is contained in:
pbattu123 2020-02-13 10:43:59 -04:00 committed by GitHub
commit d5df44935a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 5 deletions

View file

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

View file

@ -33,6 +33,7 @@
#include <graphene/chain/confidential_object.hpp>
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
@ -40,6 +41,7 @@
#include <graphene/chain/transaction_object.hpp>
#include <graphene/chain/impacted.hpp>
using namespace fc;
using namespace graphene::chain;
@ -439,6 +441,16 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
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()
{ try {
if( _undo_db.enabled() )
@ -458,7 +470,7 @@ void database::notify_changed_objects()
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
@ -472,7 +484,7 @@ void database::notify_changed_objects()
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
@ -489,7 +501,7 @@ void database::notify_changed_objects()
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) ) }

View file

@ -469,6 +469,8 @@ namespace graphene { namespace chain {
protected:
//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 notify_applied_block( const signed_block& block );
void notify_on_pending_transaction( const signed_transaction& tx );
void notify_changed_objects();
private:

View file

@ -65,6 +65,21 @@
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 {
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( 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( 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_owner_auth, graphene::chain::transaction_exception, 3030002, "missing required owner authority" )