From e6246bf9a0938c298b118f5371b000b5999859f5 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Tue, 16 Jun 2015 14:43:52 -0400 Subject: [PATCH] Implement node_property_object --- .../chain/include/graphene/chain/database.hpp | 4 +- .../graphene/chain/node_property_object.hpp | 41 +++++++++++++++++++ .../chain/transaction_evaluation_state.hpp | 5 +-- libraries/chain/proposal_evaluator.cpp | 15 ++++--- .../chain/transaction_evaluation_state.cpp | 4 +- 5 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 libraries/chain/include/graphene/chain/node_property_object.hpp diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index b1b170af..20b9f726 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -215,6 +216,7 @@ namespace graphene { namespace chain { const asset_object& get_core_asset()const; const global_property_object& get_global_properties()const; const dynamic_global_property_object& get_dynamic_global_properties()const; + const node_property_object& get_node_properties()const; const fee_schedule_type& current_fee_schedule()const; time_point_sec head_block_time()const; @@ -353,7 +355,7 @@ namespace graphene { namespace chain { ///Steps involved in applying a new block ///@{ - const witness_object& validate_block_header( uint32_t skip, const signed_block& next_block )const; + const witness_object& validate_block_header( const signed_block& next_block )const; void create_block_summary(const signed_block& next_block); //////////////////// db_update.cpp //////////////////// diff --git a/libraries/chain/include/graphene/chain/node_property_object.hpp b/libraries/chain/include/graphene/chain/node_property_object.hpp new file mode 100644 index 00000000..b06099ef --- /dev/null +++ b/libraries/chain/include/graphene/chain/node_property_object.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, Cryptonomex, Inc. + * All rights reserved. + * + * This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and + * the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification, + * are permitted until September 8, 2015, provided that the following conditions are met: + * + * 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#include + +namespace graphene { namespace chain { + + /** + * @brief Contains per-node database configuration. + * + * Transactions are evaluated differently based on per-node state. + * Settings here may change based on whether the node is syncing or up-to-date. + * Or whether the node is a witness node. Or if we're processing a + * transaction in a witness-signed block vs. a fresh transaction + * from the p2p network. Or configuration-specified tradeoffs of + * performance/hardfork resilience vs. paranoia. + */ + class node_property_object + { + public: + node_property_object() : skip_flags(0) {} + ~node_property_object(){} + + bool skip_authority_check; + }; +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp b/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp index 20faadf5..e520e4c8 100644 --- a/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp +++ b/libraries/chain/include/graphene/chain/transaction_evaluation_state.hpp @@ -33,8 +33,8 @@ namespace graphene { namespace chain { class transaction_evaluation_state { public: - transaction_evaluation_state( database* db = nullptr, bool skip_authority_check = false ) - :_db(db),_skip_authority_check(skip_authority_check){} + transaction_evaluation_state( database* db = nullptr ) + :_db(db){} bool check_authority( const account_object&, authority::classification auth_class = authority::active, int depth = 0 ); @@ -55,7 +55,6 @@ namespace graphene { namespace chain { const signed_transaction* _trx = nullptr; database* _db = nullptr; - bool _skip_authority_check = false; bool _is_proposed_trx = false; }; } } // namespace graphene::chain diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp index f365263f..cbf1613b 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -93,13 +93,16 @@ void_result proposal_update_evaluator::do_evaluate(const proposal_update_operati FC_ASSERT( _proposal->available_owner_approvals.find(id) != _proposal->available_owner_approvals.end(), "", ("id", id)("available", _proposal->available_owner_approvals) ); } - for( key_id_type id : o.key_approvals_to_add ) + if( (d.get_node_properties().skip_flags & database::skip_authority_check) == 0 ) { - FC_ASSERT( trx_state->signed_by(id) || trx_state->_skip_authority_check ); - } - for( key_id_type id : o.key_approvals_to_remove ) - { - FC_ASSERT( trx_state->signed_by(id) || trx_state->_skip_authority_check ); + for( key_id_type id : o.key_approvals_to_add ) + { + FC_ASSERT( trx_state->signed_by(id) ); + } + for( key_id_type id : o.key_approvals_to_remove ) + { + FC_ASSERT( trx_state->signed_by(id) ); + } } return void_result(); diff --git a/libraries/chain/transaction_evaluation_state.cpp b/libraries/chain/transaction_evaluation_state.cpp index e1271384..35d3973f 100644 --- a/libraries/chain/transaction_evaluation_state.cpp +++ b/libraries/chain/transaction_evaluation_state.cpp @@ -25,7 +25,9 @@ namespace graphene { namespace chain { bool transaction_evaluation_state::check_authority( const account_object& account, authority::classification auth_class, int depth ) { - if( _skip_authority_check || approved_by.find(make_pair(account.id, auth_class)) != approved_by.end() ) + if( (!_is_proposed_trx) && (_db->get_node_properties().skip_flags & database::skip_authority_check) ) + return true; + if( approved_by.find(make_pair(account.id, auth_class)) != approved_by.end() ) return true; FC_ASSERT( account.id.instance() != 0 || _is_proposed_trx );