From 54bb60cb08bab310fe98916dad6a63f350888fed Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 13 Mar 2019 11:03:01 -0600 Subject: [PATCH] Issue #210: Formatting and build fixes --- libraries/app/database_api.cpp | 74 ++++++------ libraries/chain/db_notify.cpp | 46 ++++---- .../chain/include/graphene/chain/impacted.hpp | 12 +- libraries/chain/proposal_evaluator.cpp | 97 ++++++++-------- libraries/chain/proposal_object.cpp | 10 +- .../account_history_plugin.cpp | 9 +- .../elasticsearch/elasticsearch_plugin.cpp | 9 +- .../include/graphene/protocol/custom.hpp | 2 +- .../include/graphene/protocol/operations.hpp | 10 +- .../include/graphene/protocol/transaction.hpp | 69 ++++++------ libraries/protocol/operations.cpp | 46 ++++---- libraries/protocol/transaction.cpp | 106 +++++++++--------- tests/tests/authority_tests.cpp | 4 +- 13 files changed, 253 insertions(+), 241 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index a60a93302c..ce77752697 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1923,71 +1923,71 @@ set
database_api::get_potential_address_signatures( const signed_transa return my->get_potential_address_signatures( trx ); } -set database_api_impl::get_potential_signatures(const signed_transaction& trx) const +set database_api_impl::get_potential_signatures( const signed_transaction& trx )const { auto chain_time = _db.head_block_time(); - bool allow_non_immediate_owner = (chain_time >= HARDFORK_CORE_584_TIME); - bool ignore_custom_op_reqd_auths = MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(chain_time); + bool allow_non_immediate_owner = ( chain_time >= HARDFORK_CORE_584_TIME ); + bool ignore_custom_op_reqd_auths = MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( chain_time ); set result; - auto get_active = [this, &result](account_id_type id) { - const auto& auth = id(_db).active; - for (const auto& k : auth.get_keys()) - result.insert(k); + auto get_active = [this, &result]( account_id_type id ){ + const auto& auth = id( _db ).active; + for( const auto& k : auth.get_keys() ) + result.insert( k ); return &auth; }; - auto get_owner = [this, &result](account_id_type id) { - const auto& auth = id(_db).owner; - for (const auto& k : auth.get_keys()) - result.insert(k); + auto get_owner = [this, &result]( account_id_type id ){ + const auto& auth = id( _db ).owner; + for( const auto& k : auth.get_keys() ) + result.insert( k ); return &auth; }; - trx.get_required_signatures(_db.get_chain_id(), - flat_set(), - get_active, get_owner, - allow_non_immediate_owner, - ignore_custom_op_reqd_auths, - _db.get_global_properties().parameters.max_authority_depth); + trx.get_required_signatures( _db.get_chain_id(), + flat_set(), + get_active, get_owner, + allow_non_immediate_owner, + ignore_custom_op_reqd_auths, + _db.get_global_properties().parameters.max_authority_depth ); // Insert keys in required "other" authories flat_set required_active; flat_set required_owner; vector other; - trx.get_required_authorities(required_active, required_owner, other, ignore_custom_op_reqd_auths); - for (const auto& auth : other) - for (const auto& key : auth.get_keys()) - result.insert(key); + trx.get_required_authorities( required_active, required_owner, other, ignore_custom_op_reqd_auths ); + for( const auto& auth : other ) + for( const auto& key : auth.get_keys() ) + result.insert( key ); return result; } -set
database_api_impl::get_potential_address_signatures(const signed_transaction& trx)const +set
database_api_impl::get_potential_address_signatures( const signed_transaction& trx )const { auto chain_time = _db.head_block_time(); - bool allow_non_immediate_owner = (chain_time >= HARDFORK_CORE_584_TIME); - bool ignore_custom_op_reqd_auths = MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(chain_time); + bool allow_non_immediate_owner = ( chain_time >= HARDFORK_CORE_584_TIME ); + bool ignore_custom_op_reqd_auths = MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( chain_time ); set
result; - auto get_active = [this, &result](account_id_type id) { - const auto& auth = id(_db).active; - for (const auto& k : auth.get_addresses()) - result.insert(k); + auto get_active = [this, &result]( account_id_type id ){ + const auto& auth = id( _db ).active; + for( const auto& k : auth.get_addresses() ) + result.insert( k ); return &auth; }; - auto get_owner = [this, &result](account_id_type id) { - const auto& auth = id(_db).owner; + auto get_owner = [this, &result]( account_id_type id ) { + const auto& auth = id( _db ).owner; for (const auto& k : auth.get_addresses()) - result.insert(k); + result.insert( k ); return &auth; }; - trx.get_required_signatures(_db.get_chain_id(), - flat_set(), - get_active, get_owner, - allow_non_immediate_owner, - ignore_custom_op_reqd_auths, - _db.get_global_properties().parameters.max_authority_depth); + trx.get_required_signatures( _db.get_chain_id(), + flat_set(), + get_active, get_owner, + allow_non_immediate_owner, + ignore_custom_op_reqd_auths, + _db.get_global_properties().parameters.max_authority_depth ); return result; } diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index e0b46730f6..791367267d 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -27,8 +27,8 @@ struct get_impacted_account_visitor flat_set& _impacted; bool _ignore_custom_op_reqd_auths; - get_impacted_account_visitor(flat_set& impact, bool ignore_custom_operation_required_auths) - : _impacted(impact), _ignore_custom_op_reqd_auths(ignore_custom_operation_required_auths) + get_impacted_account_visitor( flat_set& impact, bool ignore_custom_operation_required_auths ) + : _impacted( impact ), _ignore_custom_op_reqd_auths( ignore_custom_operation_required_auths ) {} using result_type = void; @@ -158,10 +158,10 @@ struct get_impacted_account_visitor { _impacted.insert( op.fee_payer() ); // fee_paying_account vector other; - for (const auto& proposed_op : op.proposed_ops) - operation_get_required_authorities(proposed_op.op, _impacted, _impacted, other, _ignore_custom_op_reqd_auths); - for (auto& o : other) - add_authority_accounts(_impacted, o); + for( const auto& proposed_op : op.proposed_ops ) + operation_get_required_authorities( proposed_op.op, _impacted, _impacted, other, _ignore_custom_op_reqd_auths ); + for( auto& o : other ) + add_authority_accounts( _impacted, o ); } void operator()( const proposal_update_operation& op ) { @@ -218,9 +218,9 @@ struct get_impacted_account_visitor } void operator()( const custom_operation& op ) { - _impacted.insert(op.fee_payer()); // payer - if (!_ignore_custom_op_reqd_auths) - _impacted.insert(op.required_auths.begin(), op.required_auths.end()); + _impacted.insert( op.fee_payer() ); // payer + if( !_ignore_custom_op_reqd_auths ) + _impacted.insert( op.required_auths.begin(), op.required_auths.end() ); } void operator()( const assert_operation& op ) { @@ -290,17 +290,17 @@ struct get_impacted_account_visitor } }; -void graphene::chain::operation_get_impacted_accounts(const operation& op, flat_set& result, bool ignore_custom_operation_required_auths) { - get_impacted_account_visitor vtor = get_impacted_account_visitor(result, ignore_custom_operation_required_auths); - op.visit(vtor); +void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set& result, bool ignore_custom_operation_required_auths ) { + get_impacted_account_visitor vtor = get_impacted_account_visitor( result, ignore_custom_operation_required_auths ); + op.visit( vtor ); } -void graphene::chain::transaction_get_impacted_accounts(const transaction& tx, flat_set& result, bool ignore_custom_operation_required_auths) { - for (const auto& op : tx.operations) - operation_get_impacted_accounts(op, result, ignore_custom_operation_required_auths); +void graphene::chain::transaction_get_impacted_accounts( const transaction& tx, flat_set& result, bool ignore_custom_operation_required_auths ) { + for( const auto& op : tx.operations ) + operation_get_impacted_accounts( op, result, ignore_custom_operation_required_auths ); } -void get_relevant_accounts(const object* obj, flat_set& accounts, bool ignore_custom_operation_required_auths) { +void get_relevant_accounts( const object* obj, flat_set& accounts, bool ignore_custom_operation_required_auths ) { if( obj->id.space() == protocol_ids ) { switch( (object_type)obj->id.type() ) @@ -346,14 +346,14 @@ void get_relevant_accounts(const object* obj, flat_set& account } case proposal_object_type:{ const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); - transaction_get_impacted_accounts(aobj->proposed_transaction, accounts, - ignore_custom_operation_required_auths); + transaction_get_impacted_accounts( aobj->proposed_transaction, accounts, + ignore_custom_operation_required_auths ); break; } case operation_history_object_type:{ const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); - operation_get_impacted_accounts(aobj->op, accounts, - ignore_custom_operation_required_auths); + operation_get_impacted_accounts( aobj->op, accounts, + ignore_custom_operation_required_auths ); break; } case withdraw_permission_object_type:{ const auto& aobj = dynamic_cast(obj); @@ -410,8 +410,8 @@ void get_relevant_accounts(const object* obj, flat_set& account } case impl_transaction_history_object_type:{ const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); - transaction_get_impacted_accounts(aobj->trx, accounts, - ignore_custom_operation_required_auths); + transaction_get_impacted_accounts( aobj->trx, accounts, + ignore_custom_operation_required_auths ); break; } case impl_blinded_balance_object_type:{ const auto& aobj = dynamic_cast(obj); @@ -517,7 +517,7 @@ void database::notify_changed_objects() } if( removed_ids.size() ) - GRAPHENE_TRY_NOTIFY(removed_objects, removed_ids, removed, removed_accounts_impacted) + GRAPHENE_TRY_NOTIFY( removed_objects, removed_ids, removed, removed_accounts_impacted ) } } } FC_CAPTURE_AND_LOG( (0) ) } diff --git a/libraries/chain/include/graphene/chain/impacted.hpp b/libraries/chain/include/graphene/chain/impacted.hpp index e5b0ea35b7..6bb43048ac 100644 --- a/libraries/chain/include/graphene/chain/impacted.hpp +++ b/libraries/chain/include/graphene/chain/impacted.hpp @@ -30,12 +30,12 @@ namespace graphene { namespace chain { -void operation_get_impacted_accounts(const graphene::chain::operation& op, - fc::flat_set& result, - bool ignore_custom_operation_required_auths); +void operation_get_impacted_accounts( const graphene::chain::operation& op, + fc::flat_set& result, + bool ignore_custom_operation_required_auths ); -void transaction_get_impacted_accounts(const graphene::chain::transaction& tx, - fc::flat_set& result, - bool ignore_custom_operation_required_auths); +void transaction_get_impacted_accounts( const graphene::chain::transaction& tx, + fc::flat_set& result, + bool ignore_custom_operation_required_auths ); } } // graphene::app diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp index 4f51e9091d..39f838183a 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -160,103 +160,108 @@ void hardfork_visitor_1479::operator()(const graphene::chain::proposal_create_op op.op.visit(*this); } -void_result proposal_create_evaluator::do_evaluate(const proposal_create_operation& o) +void_result proposal_create_evaluator::do_evaluate( const proposal_create_operation& o ) { try { const database& d = db(); // Calling the proposal hardfork visitor const fc::time_point_sec block_time = d.head_block_time(); - proposal_operation_hardfork_visitor vtor(d, block_time); - vtor(o); - if (block_time < HARDFORK_CORE_214_TIME) { + proposal_operation_hardfork_visitor vtor( d, block_time ); + vtor( o ); + if( block_time < HARDFORK_CORE_214_TIME ) + { // cannot be removed after hf, unfortunately hardfork_visitor_214 hf214; - for (const op_wrapper &op : o.proposed_ops) - op.op.visit(hf214); + for( const op_wrapper &op : o.proposed_ops ) + op.op.visit( hf214 ); } - vtor_1479(o); + vtor_1479( o ); const auto& global_parameters = d.get_global_properties().parameters; - FC_ASSERT (o.expiration_time > block_time, "Proposal has already expired on creation."); - FC_ASSERT (o.expiration_time <= block_time + global_parameters.maximum_proposal_lifetime, - "Proposal expiration time is too far in the future."); - FC_ASSERT (!o.review_period_seconds || fc::seconds(*o.review_period_seconds) < (o.expiration_time - block_time), - "Proposal review period must be less than its overall lifetime."); + FC_ASSERT( o.expiration_time > block_time, "Proposal has already expired on creation." ); + FC_ASSERT( o.expiration_time <= block_time + global_parameters.maximum_proposal_lifetime, + "Proposal expiration time is too far in the future." ); + FC_ASSERT( !o.review_period_seconds || fc::seconds( *o.review_period_seconds ) < ( o.expiration_time - block_time ), + "Proposal review period must be less than its overall lifetime." ); // Find all authorities required by the proposed operations flat_set tmp_required_active_auths; vector other; - for (auto& op : o.proposed_ops) { - operation_get_required_authorities(op.op, tmp_required_active_auths, _required_owner_auths, other, - MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(block_time)); + for( auto& op : o.proposed_ops ) + { + operation_get_required_authorities( op.op, tmp_required_active_auths, _required_owner_auths, other, + MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( block_time ) ); } // All accounts which must provide both owner and active authority should be omitted from the active authority set; // owner authority approval implies active authority approval. - std::set_difference(tmp_required_active_auths.begin(), tmp_required_active_auths.end(), - _required_owner_auths.begin(), _required_owner_auths.end(), - std::inserter(_required_active_auths, _required_active_auths.begin())); + std::set_difference( tmp_required_active_auths.begin(), tmp_required_active_auths.end(), + _required_owner_auths.begin(), _required_owner_auths.end(), + std::inserter( _required_active_auths, _required_active_auths.begin() ) ); // TODO: what about other??? - FC_ASSERT (other.empty(), - "Proposals containing operations requiring non-account authorities are not yet implemented."); + FC_ASSERT ( other.empty(), + "Proposals containing operations requiring non-account authorities are not yet implemented." ); // If we're dealing with the committee authority, make sure this transaction has a sufficient review period. - if (_required_active_auths.count(GRAPHENE_COMMITTEE_ACCOUNT) || - _required_owner_auths.count(GRAPHENE_COMMITTEE_ACCOUNT)) { - GRAPHENE_ASSERT(o.review_period_seconds.valid(), - proposal_create_review_period_required, - "Review period not given, but at least ${min} required", - ("min", global_parameters.committee_proposal_review_period)); - GRAPHENE_ASSERT(*o.review_period_seconds >= global_parameters.committee_proposal_review_period, - proposal_create_review_period_insufficient, - "Review period of ${t} specified, but at least ${min} required", - ("t", *o.review_period_seconds) - ("min", global_parameters.committee_proposal_review_period)); + if( _required_active_auths.count( GRAPHENE_COMMITTEE_ACCOUNT ) || + _required_owner_auths.count( GRAPHENE_COMMITTEE_ACCOUNT ) ) + { + GRAPHENE_ASSERT( o.review_period_seconds.valid(), + proposal_create_review_period_required, + "Review period not given, but at least ${min} required", + ("min", global_parameters.committee_proposal_review_period) ); + GRAPHENE_ASSERT( *o.review_period_seconds >= global_parameters.committee_proposal_review_period, + proposal_create_review_period_insufficient, + "Review period of ${t} specified, but at least ${min} required", + ("t", *o.review_period_seconds) + ("min", global_parameters.committee_proposal_review_period) ); } - for (const op_wrapper& op : o.proposed_ops) - _proposed_trx.operations.push_back(op.op); + for( const op_wrapper& op : o.proposed_ops ) + _proposed_trx.operations.push_back( op.op ); _proposed_trx.validate(); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } -object_id_type proposal_create_evaluator::do_apply(const proposal_create_operation& o) +object_id_type proposal_create_evaluator::do_apply( const proposal_create_operation& o ) { try { database& d = db(); + auto chain_time = d.head_block_time(); - const proposal_object& proposal = d.create([&](proposal_object& proposal) { + const proposal_object& proposal = d.create( [&o, this, chain_time](proposal_object& proposal) { _proposed_trx.expiration = o.expiration_time; proposal.proposed_transaction = _proposed_trx; proposal.expiration_time = o.expiration_time; proposal.proposer = o.fee_paying_account; - if (o.review_period_seconds) + if( o.review_period_seconds ) proposal.review_period_time = o.expiration_time - *o.review_period_seconds; //Populate the required approval sets - proposal.required_owner_approvals.insert(_required_owner_auths.begin(), _required_owner_auths.end()); - proposal.required_active_approvals.insert(_required_active_auths.begin(), _required_active_auths.end()); + proposal.required_owner_approvals.insert( _required_owner_auths.begin(), _required_owner_auths.end() ); + proposal.required_active_approvals.insert( _required_active_auths.begin(), _required_active_auths.end() ); - if (d.head_block_time() > HARDFORK_CORE_1479_TIME) - FC_ASSERT (vtor_1479.nested_update_count == 0 || proposal.id.instance() > vtor_1479.max_update_instance, - "Cannot update/delete a proposal with a future id!"); - else if (vtor_1479.nested_update_count > 0 && proposal.id.instance() <= vtor_1479.max_update_instance) { + if( chain_time > HARDFORK_CORE_1479_TIME ) + FC_ASSERT( vtor_1479.nested_update_count == 0 || proposal.id.instance() > vtor_1479.max_update_instance, + "Cannot update/delete a proposal with a future id!" ); + else if( vtor_1479.nested_update_count > 0 && proposal.id.instance() <= vtor_1479.max_update_instance ) + { // prevent approval transfer_operation top; top.from = GRAPHENE_NULL_ACCOUNT; top.to = GRAPHENE_RELAXED_COMMITTEE_ACCOUNT; - top.amount = asset(GRAPHENE_MAX_SHARE_SUPPLY); - proposal.proposed_transaction.operations.emplace_back(top); - wlog("Issue 1479: ${p}", ("p",proposal)); + top.amount = asset( GRAPHENE_MAX_SHARE_SUPPLY ); + proposal.proposed_transaction.operations.emplace_back( top ); + wlog( "Issue 1479: ${p}", ("p",proposal) ); } }); return proposal.id; } FC_CAPTURE_AND_RETHROW( (o) ) } -void_result proposal_update_evaluator::do_evaluate(const proposal_update_operation& o) +void_result proposal_update_evaluator::do_evaluate( const proposal_update_operation& o ) { try { database& d = db(); diff --git a/libraries/chain/proposal_object.cpp b/libraries/chain/proposal_object.cpp index d87e331d9e..1b192d8475 100644 --- a/libraries/chain/proposal_object.cpp +++ b/libraries/chain/proposal_object.cpp @@ -29,16 +29,16 @@ namespace graphene { namespace chain { -bool proposal_object::is_authorized_to_execute(database& db) const +bool proposal_object::is_authorized_to_execute( database& db ) const { - transaction_evaluation_state dry_run_eval(&db); + transaction_evaluation_state dry_run_eval( &db ); try { bool allow_non_immediate_owner = ( db.head_block_time() >= HARDFORK_CORE_584_TIME ); - verify_authority( proposed_transaction.operations, + verify_authority( proposed_transaction.operations, available_key_approvals, - [&]( account_id_type id ){ return &id(db).active; }, - [&]( account_id_type id ){ return &id(db).owner; }, + [&db]( account_id_type id ){ return &id( db ).active; }, + [&db]( account_id_type id ){ return &id( db ).owner; }, allow_non_immediate_owner, MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ), db.get_global_properties().parameters.max_authority_depth, diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 95c36a1fe7..2a6e62114e 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -129,14 +129,15 @@ void account_history_plugin_impl::update_account_histories( const signed_block& // get the set of accounts this operation applies to flat_set impacted; vector other; - operation_get_required_authorities(op.op, impacted, impacted, other, - MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(db.head_block_time())); // fee_payer is added here + // 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.is_type< account_create_operation >() ) impacted.insert( op.result.get() ); else - operation_get_impacted_accounts(op.op, impacted, - MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(db.head_block_time())); + operation_get_impacted_accounts( op.op, impacted, + MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ) ); for( auto& a : other ) for( auto& item : a.account_auths ) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 529ad989d8..33dd94ee96 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -156,14 +156,15 @@ bool elasticsearch_plugin_impl::update_account_histories( const signed_block& b // get the set of accounts this operation applies to flat_set impacted; vector other; - operation_get_required_authorities(op.op, impacted, impacted, other, - MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(db.head_block_time())); // fee_payer is added here + // 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.is_type< account_create_operation >() ) impacted.insert( op.result.get() ); else - operation_get_impacted_accounts(op.op, impacted, - MUST_IGNORE_CUSTOM_OP_REQD_AUTHS(db.head_block_time())); + operation_get_impacted_accounts( op.op, impacted, + MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ) ); for( auto& a : other ) for( auto& item : a.account_auths ) diff --git a/libraries/protocol/include/graphene/protocol/custom.hpp b/libraries/protocol/include/graphene/protocol/custom.hpp index ff9912e159..59ef3757db 100644 --- a/libraries/protocol/include/graphene/protocol/custom.hpp +++ b/libraries/protocol/include/graphene/protocol/custom.hpp @@ -52,7 +52,7 @@ namespace graphene { namespace protocol { void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; void get_required_active_authorities( flat_set& auths )const { - auths.insert(required_auths.begin(), required_auths.end()); + auths.insert( required_auths.begin(), required_auths.end() ); } }; diff --git a/libraries/protocol/include/graphene/protocol/operations.hpp b/libraries/protocol/include/graphene/protocol/operations.hpp index 7d9b45d2c7..f7ddc01a02 100644 --- a/libraries/protocol/include/graphene/protocol/operations.hpp +++ b/libraries/protocol/include/graphene/protocol/operations.hpp @@ -112,11 +112,11 @@ namespace graphene { namespace protocol { * * @return a set of required authorities for @ref op */ - void operation_get_required_authorities(const operation& op, - flat_set& active, - flat_set& owner, - vector& other, - bool ignore_custom_operation_required_auths); + void operation_get_required_authorities( const operation& op, + flat_set& active, + flat_set& owner, + vector& other, + bool ignore_custom_operation_required_auths ); void operation_validate( const operation& op ); diff --git a/libraries/protocol/include/graphene/protocol/transaction.hpp b/libraries/protocol/include/graphene/protocol/transaction.hpp index fd63171cc1..505c3bebef 100644 --- a/libraries/protocol/include/graphene/protocol/transaction.hpp +++ b/libraries/protocol/include/graphene/protocol/transaction.hpp @@ -109,10 +109,10 @@ namespace graphene { namespace protocol { return results; } - void get_required_authorities(flat_set& active, - flat_set& owner, - vector& other, - bool ignore_custom_operation_required_auths)const; + void get_required_authorities( flat_set& active, + flat_set& owner, + vector& other, + bool ignore_custom_operation_required_auths )const; virtual uint64_t get_packed_size()const; @@ -145,13 +145,14 @@ namespace graphene { namespace protocol { * signatures, but any non-minimal result will still pass * validation. */ - set get_required_signatures(const chain_id_type& chain_id, - const flat_set& available_keys, - const std::function& get_active, - const std::function& get_owner, - bool allow_non_immediate_owner, - bool ignore_custom_operation_required_authorities, - uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH)const; + set get_required_signatures( + const chain_id_type& chain_id, + const flat_set& available_keys, + const std::function& get_active, + const std::function& get_owner, + bool allow_non_immediate_owner, + bool ignore_custom_operation_required_authorities, + uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH )const; /** * Checks whether signatures in this signed transaction are sufficient to authorize the transaction. @@ -167,12 +168,13 @@ namespace graphene { namespace protocol { * @param max_recursion maximum level of recursion when verifying, since an account * can have another account in active authorities and/or owner authorities */ - void verify_authority(const chain_id_type& chain_id, - const std::function& get_active, - const std::function& get_owner, - bool allow_non_immediate_owner, - bool ignore_custom_operation_required_auths, - uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH)const; + void verify_authority( + const chain_id_type& chain_id, + const std::function& get_active, + const std::function& get_owner, + bool allow_non_immediate_owner, + bool ignore_custom_operation_required_auths, + uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH )const; /** * This is a slower replacement for get_required_signatures() @@ -180,13 +182,14 @@ namespace graphene { namespace protocol { * some cases where get_required_signatures() returns a * non-minimal set. */ - set minimize_required_signatures(const chain_id_type& chain_id, - const flat_set& available_keys, - const std::function& get_active, - const std::function& get_owner, - bool allow_non_immediate_owner, - bool ignore_custom_operation_required_auths, - uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH) const; + set minimize_required_signatures( + const chain_id_type& chain_id, + const flat_set& available_keys, + const std::function& get_active, + const std::function& get_owner, + bool allow_non_immediate_owner, + bool ignore_custom_operation_required_auths, + uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH) const; /** * @brief Extract public keys from signatures with given chain ID. @@ -252,15 +255,15 @@ namespace graphene { namespace protocol { * @param active_approvals accounts that approved the operations with their active authories * @param owner_approvals accounts that approved the operations with their owner authories */ - void verify_authority(const vector& ops, const flat_set& sigs, - const std::function& get_active, - const std::function& get_owner, - bool allow_non_immediate_owner, - bool ignore_custom_operation_required_auths, - uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH, - bool allow_committee = false, - const flat_set& active_aprovals = flat_set(), - const flat_set& owner_approvals = flat_set()); + void verify_authority( const vector& ops, const flat_set& sigs, + const std::function& get_active, + const std::function& get_owner, + bool allow_non_immediate_owner, + bool ignore_custom_operation_required_auths, + uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH, + bool allow_committee = false, + const flat_set& active_aprovals = flat_set(), + const flat_set& owner_approvals = flat_set() ); /** * @brief captures the result of evaluating the operations contained in the transaction diff --git a/libraries/protocol/operations.cpp b/libraries/protocol/operations.cpp index a5ab893e1e..edff2b6305 100644 --- a/libraries/protocol/operations.cpp +++ b/libraries/protocol/operations.cpp @@ -69,28 +69,28 @@ struct operation_get_required_auth bool ignore_custom_op_reqd_auths; - operation_get_required_auth(flat_set& a, - flat_set& own, - vector& oth, - bool ignore_custom_operation_required_auths) - : active(a), owner(own), other(oth), - ignore_custom_op_reqd_auths(ignore_custom_operation_required_auths) + operation_get_required_auth( flat_set& a, + flat_set& own, + vector& oth, + bool ignore_custom_operation_required_auths ) + : active( a ), owner( own ), other( oth ), + ignore_custom_op_reqd_auths( ignore_custom_operation_required_auths ) {} template - void operator()(const T& v) const { - active.insert(v.fee_payer()); - v.get_required_active_authorities(active); - v.get_required_owner_authorities(owner); - v.get_required_authorities(other); + void operator()( const T& v ) const { + active.insert( v.fee_payer() ); + v.get_required_active_authorities( active ); + v.get_required_owner_authorities( owner ); + v.get_required_authorities( other ); } - void operator()(const custom_operation& op) const { - active.insert(op.fee_payer()); - if (!ignore_custom_op_reqd_auths) { - op.get_required_active_authorities(active); - op.get_required_owner_authorities(owner); - op.get_required_authorities(other); + void operator()( const custom_operation& op ) const { + active.insert( op.fee_payer() ); + if( !ignore_custom_op_reqd_auths ) { + op.get_required_active_authorities( active ); + op.get_required_owner_authorities( owner ); + op.get_required_authorities( other ); } } }; @@ -100,13 +100,13 @@ void operation_validate( const operation& op ) op.visit( operation_validator() ); } -void operation_get_required_authorities(const operation& op, - flat_set& active, - flat_set& owner, - vector& other, - bool ignore_custom_operation_required_auths) +void operation_get_required_authorities( const operation& op, + flat_set& active, + flat_set& owner, + vector& other, + bool ignore_custom_operation_required_auths ) { - op.visit(operation_get_required_auth(active, owner, other, ignore_custom_operation_required_auths)); + op.visit( operation_get_required_auth( active, owner, other, ignore_custom_operation_required_auths ) ); } } } // namespace graphene::protocol diff --git a/libraries/protocol/transaction.cpp b/libraries/protocol/transaction.cpp index 2644e568fa..153bed7ea5 100644 --- a/libraries/protocol/transaction.cpp +++ b/libraries/protocol/transaction.cpp @@ -99,15 +99,15 @@ void transaction::set_reference_block( const block_id_type& reference_block ) ref_block_prefix = reference_block._hash[1].value(); } -void transaction::get_required_authorities(flat_set& active, - flat_set& owner, - vector& other, - bool ignore_custom_operation_required_auths)const +void transaction::get_required_authorities( flat_set& active, + flat_set& owner, + vector& other, + bool ignore_custom_operation_required_auths )const { - for (const auto& op : operations) - operation_get_required_authorities(op, active, owner, other, ignore_custom_operation_required_auths); - for (const auto& account : owner) - active.erase(account); + for( const auto& op : operations ) + operation_get_required_authorities( op, active, owner, other, ignore_custom_operation_required_auths ); + for( const auto& account : owner ) + active.erase( account ); } @@ -265,22 +265,23 @@ struct sign_state }; -void verify_authority(const vector& ops, const flat_set& sigs, - const std::function& get_active, - const std::function& get_owner, - bool allow_non_immediate_owner, - bool ignore_custom_operation_required_auths, - uint32_t max_recursion_depth, - bool allow_committee, - const flat_set& active_aprovals, - const flat_set& owner_approvals) +void verify_authority( const vector& ops, const flat_set& sigs, + const std::function& get_active, + const std::function& get_owner, + bool allow_non_immediate_owner, + bool ignore_custom_operation_required_auths, + uint32_t max_recursion_depth, + bool allow_committee, + const flat_set& active_aprovals, + const flat_set& owner_approvals ) { try { flat_set required_active; flat_set required_owner; vector other; - for (const auto& op : ops) { - operation_get_required_authorities(op, required_active, required_owner, other, ignore_custom_operation_required_auths); + for( const auto& op : ops ) { + operation_get_required_authorities( op, required_active, required_owner, other, + ignore_custom_operation_required_auths ); } if( !allow_committee ) @@ -338,37 +339,37 @@ const flat_set& signed_transaction::get_signature_keys( const c } FC_CAPTURE_AND_RETHROW() } -set signed_transaction::get_required_signatures(const chain_id_type& chain_id, - const flat_set& available_keys, - const std::function& get_active, - const std::function& get_owner, - bool allow_non_immediate_owner, - bool ignore_custom_operation_required_authorities, - uint32_t max_recursion_depth)const +set signed_transaction::get_required_signatures( const chain_id_type& chain_id, + const flat_set& available_keys, + const std::function& get_active, + const std::function& get_owner, + bool allow_non_immediate_owner, + bool ignore_custom_operation_required_authorities, + uint32_t max_recursion_depth )const { flat_set required_active; flat_set required_owner; vector other; - get_required_authorities(required_active, required_owner, other, ignore_custom_operation_required_authorities); + get_required_authorities( required_active, required_owner, other, ignore_custom_operation_required_authorities ); const flat_set& signature_keys = get_signature_keys(chain_id); - sign_state s(signature_keys, get_active, get_owner, allow_non_immediate_owner, max_recursion_depth, available_keys); + sign_state s( signature_keys, get_active, get_owner, allow_non_immediate_owner, max_recursion_depth, available_keys ); - for (const auto& auth : other) - s.check_authority(&auth); - for (auto& owner : required_owner) - s.check_authority(get_owner(owner)); - for (auto& active : required_active) - s.check_authority(active) || s.check_authority(get_owner(active)); + for( const auto& auth : other ) + s.check_authority( &auth ); + for( auto& owner : required_owner ) + s.check_authority( get_owner( owner ) ); + for( auto& active : required_active ) + s.check_authority( active ) || s.check_authority( get_owner( active ) ); s.remove_unused_signatures(); set result; - for (auto& provided_sig : s.provided_signatures) - if (available_keys.find(provided_sig.first) != available_keys.end() - && signature_keys.find(provided_sig.first) == signature_keys.end()) - result.insert(provided_sig.first); + for( auto& provided_sig : s.provided_signatures ) + if( available_keys.find( provided_sig.first ) != available_keys.end() + && signature_keys.find( provided_sig.first ) == signature_keys.end() ) + result.insert( provided_sig.first ); return result; } @@ -392,16 +393,16 @@ set signed_transaction::minimize_required_signatures( try { graphene::protocol::verify_authority( operations, result, get_active, get_owner, - ignore_custom_operation_required_auths, - allow_non_immediate_owner, max_recursion ); + allow_non_immediate_owner,ignore_custom_operation_required_auths, + max_recursion ); continue; // element stays erased if verify_authority is ok } - catch(const tx_missing_owner_auth& e) {} - catch(const tx_missing_active_auth& e) {} - catch(const tx_missing_other_auth& e) {} - result.insert(k); + catch( const tx_missing_owner_auth& e ) {} + catch( const tx_missing_active_auth& e ) {} + catch( const tx_missing_other_auth& e ) {} + result.insert( k ); } - return set(result.begin(), result.end()); + return set( result.begin(), result.end() ); } const transaction_id_type& precomputable_transaction::id()const @@ -434,15 +435,16 @@ const flat_set& precomputable_transaction::get_signature_keys( return _signees; } -void signed_transaction::verify_authority(const chain_id_type& chain_id, - const std::function& get_active, - const std::function& get_owner, - bool allow_non_immediate_owner, - bool ignore_custom_operation_required_auths, - uint32_t max_recursion)const +void signed_transaction::verify_authority( const chain_id_type& chain_id, + const std::function& get_active, + const std::function& get_owner, + bool allow_non_immediate_owner, + bool ignore_custom_operation_required_auths, + uint32_t max_recursion )const { try { graphene::protocol::verify_authority( operations, get_signature_keys( chain_id ), get_active, get_owner, - allow_non_immediate_owner, ignore_custom_operation_required_auths, max_recursion ); + allow_non_immediate_owner, ignore_custom_operation_required_auths, + max_recursion ); } FC_CAPTURE_AND_RETHROW( (*this) ) } } } // graphene::protocol diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index 5ded8e6e36..c5e4031fe3 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -1906,7 +1906,7 @@ BOOST_AUTO_TEST_CASE( custom_operation_required_auths_before_fork ) { db.push_transaction(trx); // The proposal should have processed. Check it's not still in the database - BOOST_REQUIRE_EQUAL(db.find(pid), nullptr); + BOOST_REQUIRE(db.find(pid) == nullptr); } catch (fc::exception& e) { edump((e.to_detail_string())); throw; @@ -1975,7 +1975,7 @@ BOOST_AUTO_TEST_CASE( custom_operation_required_auths_after_fork ) { db.push_transaction(trx); // Now the proposal should have processed and been removed from the database - BOOST_REQUIRE_EQUAL(db.find(pid), nullptr); + BOOST_REQUIRE(db.find(pid) == nullptr); } catch (fc::exception& e) { edump((e.to_detail_string())); throw;