From d3c6cbf4de72a8d8003ffdb178e6ec3206062058 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Wed, 17 Feb 2016 09:17:00 -0500 Subject: [PATCH 1/5] Compile fixes for win32 and out-of-source builds --- libraries/chain/CMakeLists.txt | 2 +- libraries/chain/db_block.cpp | 1 + libraries/chain/include/graphene/chain/database.hpp | 3 ++- libraries/chain/include/graphene/chain/evaluator.hpp | 1 + libraries/chain/protocol/fee_schedule.cpp | 1 + programs/build_helpers/cat-parts.cpp | 1 + tests/tests/fee_tests.cpp | 1 + 7 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index c38bd80b76..9cc4285dd8 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -1,6 +1,6 @@ add_custom_target( build_hardfork_hpp - COMMAND cat-parts hardfork.d "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" ) + COMMAND cat-parts "${CMAKE_CURRENT_SOURCE_DIR}/hardfork.d" "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" ) set_source_files_properties( "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" PROPERTIES GENERATED TRUE ) add_dependencies( build_hardfork_hpp cat-parts ) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index d7c1e214be..e141cd08bb 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 1f563995b3..199acb3976 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -22,7 +22,6 @@ * THE SOFTWARE. */ #pragma once -#include #include #include #include @@ -45,6 +44,8 @@ namespace graphene { namespace chain { using graphene::db::abstract_object; using graphene::db::object; + class op_evaluator; + class transaction_evaluation_state; struct budget_record; diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index 64205b8034..f0369533d4 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace graphene { namespace chain { diff --git a/libraries/chain/protocol/fee_schedule.cpp b/libraries/chain/protocol/fee_schedule.cpp index 993df085df..334f33f1df 100644 --- a/libraries/chain/protocol/fee_schedule.cpp +++ b/libraries/chain/protocol/fee_schedule.cpp @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include #include #include diff --git a/programs/build_helpers/cat-parts.cpp b/programs/build_helpers/cat-parts.cpp index 0f06d2dc25..13e692fea9 100644 --- a/programs/build_helpers/cat-parts.cpp +++ b/programs/build_helpers/cat-parts.cpp @@ -62,6 +62,7 @@ int main( int argc, char** argv, char** envp ) } { + boost::filesystem::create_directories(opath.parent_path()); boost::filesystem::ofstream ofs(opath); ofs.write( new_data.c_str(), new_data.length() ); } diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index e6fd674811..984c6fcec7 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include From 53699a9d27f52c855cc6b47295abd4181fd8bb2a Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 22 Feb 2016 10:55:22 -0500 Subject: [PATCH 2/5] ext.hpp: Accept null and empty array for extensions #593 --- libraries/chain/include/graphene/chain/protocol/ext.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/chain/include/graphene/chain/protocol/ext.hpp b/libraries/chain/include/graphene/chain/protocol/ext.hpp index fda4feee35..366dcd63d4 100644 --- a/libraries/chain/include/graphene/chain/protocol/ext.hpp +++ b/libraries/chain/include/graphene/chain/protocol/ext.hpp @@ -168,6 +168,14 @@ struct graphene_extension_from_variant_visitor template< typename T > void from_variant( const fc::variant& var, graphene::chain::extension& value ) { + if( var.is_null() ) + return; + if( var.is_array() ) + { + FC_ASSERT( var.size() == 0 ); + return; + } + graphene_extension_from_variant_visitor vtor( var.get_object(), value.value ); fc::reflector::visit( vtor ); FC_ASSERT( vtor.count_left == 0 ); // unrecognized extension throws here From 567a40170e17d0d3a776e3bf313e1d4721146de6 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Mon, 22 Feb 2016 19:34:16 -0500 Subject: [PATCH 3/5] Fix gcc/clang builds broken by d3c6cbf4de72a8d8003ffdb178e6ec3206062058 (breaking circular dependency) --- libraries/chain/evaluator.cpp | 10 ++++++++++ .../chain/include/graphene/chain/database.hpp | 1 + .../chain/include/graphene/chain/evaluator.hpp | 14 ++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index b27d39608d..a4127c25b6 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -118,4 +118,14 @@ database& generic_evaluator::db()const { return trx_state->db(); } _fba.accumulated_fba_fees += core_fee_paid; } ); } + + share_type generic_evaluator::calculate_fee_for_operation(const operation& op) const + { + return db().current_fee_schedule().calculate_fee( op ).amount; + } + void generic_evaluator::db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account) + { + db().adjust_balance(fee_payer, fee_from_account); + } + } } diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 199acb3976..b73b8931b0 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index f0369533d4..af90517eca 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -25,7 +25,6 @@ #include #include #include -#include namespace graphene { namespace chain { @@ -103,6 +102,12 @@ namespace graphene { namespace chain { */ void pay_fba_fee( uint64_t fba_id ); + // the next two functions are helpers that allow template functions declared in this + // header to call db() without including database.hpp, which would + // cause a circular dependency + share_type calculate_fee_for_operation(const operation& op) const; + void db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account); + asset fee_from_account; share_type core_fee_paid; const account_object* fee_paying_account = nullptr; @@ -144,10 +149,11 @@ namespace graphene { namespace chain { prepare_fee(op.fee_payer(), op.fee); if( !trx_state->skip_fee_schedule_check ) { - GRAPHENE_ASSERT( core_fee_paid >= db().current_fee_schedule().calculate_fee( op ).amount, + share_type required_fee = calculate_fee_for_operation(op); + GRAPHENE_ASSERT( core_fee_paid >= required_fee, insufficient_fee, "Insufficient Fee Paid", - ("core_fee_paid",core_fee_paid)("required",db().current_fee_schedule().calculate_fee( op ).amount) ); + ("core_fee_paid",core_fee_paid)("required", required_fee) ); } return eval->do_evaluate(op); @@ -163,7 +169,7 @@ namespace graphene { namespace chain { auto result = eval->do_apply(op); - db().adjust_balance(op.fee_payer(), -fee_from_account); + db_adjust_balance(op.fee_payer(), -fee_from_account); return result; } From 0159297fa8f785a190e5f6401f4f92571a171a89 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 19 Feb 2016 15:12:53 -0500 Subject: [PATCH 4/5] fix linking errors on OS X --- libraries/chain/protocol/fee_schedule.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/chain/protocol/fee_schedule.cpp b/libraries/chain/protocol/fee_schedule.cpp index 334f33f1df..ab8f6532f8 100644 --- a/libraries/chain/protocol/fee_schedule.cpp +++ b/libraries/chain/protocol/fee_schedule.cpp @@ -41,6 +41,8 @@ namespace graphene { namespace chain { typedef fc::smart_ref smart_fee_schedule; + static smart_fee_schedule tmp; + fee_schedule::fee_schedule() { } From e3478d233847056943da6f84f18adcf18c42e64d Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Tue, 23 Feb 2016 12:00:40 -0500 Subject: [PATCH 5/5] Default initialize output in extension's from_variant and stream extraction #594 --- libraries/chain/include/graphene/chain/protocol/ext.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/chain/include/graphene/chain/protocol/ext.hpp b/libraries/chain/include/graphene/chain/protocol/ext.hpp index 366dcd63d4..7e8636f57b 100644 --- a/libraries/chain/include/graphene/chain/protocol/ext.hpp +++ b/libraries/chain/include/graphene/chain/protocol/ext.hpp @@ -130,6 +130,7 @@ struct graphene_extension_unpack_visitor template< typename Stream, typename T > void operator>>( Stream& s, graphene::chain::extension& value ) { + value = graphene::chain::extension(); graphene_extension_unpack_visitor vtor( s, value.value ); fc::reflector::visit( vtor ); FC_ASSERT( vtor.count_left == 0 ); // unrecognized extension throws here @@ -168,6 +169,7 @@ struct graphene_extension_from_variant_visitor template< typename T > void from_variant( const fc::variant& var, graphene::chain::extension& value ) { + value = graphene::chain::extension(); if( var.is_null() ) return; if( var.is_array() )