diff --git a/.travis.yml b/.travis.yml index 77e0407a33..52397688bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,10 @@ script: - ccache -s - programs/build_helpers/buildstep Prepare 1 "sed -i '/tests/d' libraries/fc/CMakeLists.txt" - programs/build_helpers/buildstep cmake 5 "cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage -DBoost_USE_STATIC_LIBS=OFF -DCMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON ." - - programs/build_helpers/buildstep make.cli_wallet 2200 "programs/build_helpers/make_with_sonar bw-output -j 2 cli_wallet witness_node js_operation_serializer get_dev_key network_mapper" + - programs/build_helpers/buildstep make.fc 200 "make -j 2 fc" + - programs/build_helpers/buildstep make.custom_auths 1000 "make -j 1 graphene_protocol_custom_auths" + - programs/build_helpers/buildstep make.protocol 700 "make -j 2 graphene_protocol" + - programs/build_helpers/buildstep make.cli_wallet 800 "programs/build_helpers/make_with_sonar bw-output -j 2 cli_wallet witness_node js_operation_serializer get_dev_key network_mapper" - programs/build_helpers/buildstep make.chain_test 1000 "make -j 2 chain_test" - programs/build_helpers/buildstep make.cli_test 200 "make -j 2 cli_test" - programs/build_helpers/buildstep make.perf_test 120 "make -j 2 performance_test" diff --git a/libraries/chain/custom_authority_evaluator.cpp b/libraries/chain/custom_authority_evaluator.cpp index 9901d7f688..783abf7c88 100644 --- a/libraries/chain/custom_authority_evaluator.cpp +++ b/libraries/chain/custom_authority_evaluator.cpp @@ -45,7 +45,7 @@ void_result custom_authority_create_evaluator::do_evaluate(const custom_authorit FC_ASSERT((op.valid_to - now).to_seconds() <= config->max_custom_authority_lifetime_seconds, "Custom authority lifetime exceeds maximum limit"); - FC_ASSERT(op.operation_type.value <= config->max_operation_tag, + FC_ASSERT(op.operation_type.value <= (size_t)config->max_operation_tag, "Cannot create custom authority for operation type which is not yet active"); for (const auto& account_weight_pair : op.auth.account_auths) diff --git a/libraries/protocol/CMakeLists.txt b/libraries/protocol/CMakeLists.txt index 3785a8d992..aab50360ee 100644 --- a/libraries/protocol/CMakeLists.txt +++ b/libraries/protocol/CMakeLists.txt @@ -17,14 +17,6 @@ list(APPEND SOURCES account.cpp authority.cpp special_authority.cpp custom_authority.cpp - custom_authorities/restriction_predicate.cpp - custom_authorities/list_1.cpp - custom_authorities/list_2.cpp - custom_authorities/list_3.cpp - custom_authorities/list_4.cpp - custom_authorities/list_5.cpp - custom_authorities/list_6.cpp - custom_authorities/list_7.cpp committee_member.cpp custom.cpp market.cpp @@ -38,8 +30,28 @@ list(APPEND SOURCES account.cpp htlc.cpp) +list(APPEND CUSTOM_AUTHS_FILES + custom_authorities/restriction_predicate.cpp + custom_authorities/list_1.cpp + custom_authorities/list_2.cpp + custom_authorities/list_3.cpp + custom_authorities/list_4.cpp + custom_authorities/list_5.cpp + custom_authorities/list_6.cpp + custom_authorities/list_7.cpp + custom_authorities/list_8.cpp + custom_authorities/list_9.cpp) + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${CUSTOM_AUTHS_FILES} PROPERTIES COMPILE_FLAGS -Wno-sign-compare) +endif() + +add_library( graphene_protocol_custom_auths ${CUSTOM_AUTHS_FILES} ) +target_link_libraries( graphene_protocol_custom_auths fc ) +target_include_directories( graphene_protocol_custom_auths PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + add_library( graphene_protocol ${SOURCES} ${HEADERS} ) -target_link_libraries( graphene_protocol fc ) +target_link_libraries( graphene_protocol fc graphene_protocol_custom_auths ) target_include_directories( graphene_protocol PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) install( TARGETS diff --git a/libraries/protocol/custom_authorities/list_1.cpp b/libraries/protocol/custom_authorities/list_1.cpp index 2093dafdeb..ba01e0ac44 100644 --- a/libraries/protocol/custom_authorities/list_1.cpp +++ b/libraries/protocol/custom_authorities/list_1.cpp @@ -25,7 +25,6 @@ #include "restriction_predicate.hxx" namespace graphene { namespace protocol { - using result_type = object_restriction_predicate; result_type get_restriction_predicate_list_1(size_t idx, vector rs) { diff --git a/libraries/protocol/custom_authorities/list_8.cpp b/libraries/protocol/custom_authorities/list_8.cpp new file mode 100644 index 0000000000..2244f00133 --- /dev/null +++ b/libraries/protocol/custom_authorities/list_8.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "restriction_predicate.hxx" + +namespace graphene { namespace protocol { + +using result_type = object_restriction_predicate; + +result_type get_restriction_predicate_list_8(size_t idx, vector rs) { + return typelist::runtime::dispatch(operation_list_8::list(), idx, [&rs] (auto t) -> result_type { + using Op = typename decltype(t)::type; + return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { + FC_ASSERT(op.which() == operation::tag::value, + "Supplied operation is incorrect type for restriction predicate"); + return p(op.get()); + }; + }); +} +} } diff --git a/libraries/protocol/custom_authorities/list_9.cpp b/libraries/protocol/custom_authorities/list_9.cpp new file mode 100644 index 0000000000..cbc504e47e --- /dev/null +++ b/libraries/protocol/custom_authorities/list_9.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "restriction_predicate.hxx" + +namespace graphene { namespace protocol { + +using result_type = object_restriction_predicate; + +result_type get_restriction_predicate_list_9(size_t idx, vector rs) { + return typelist::runtime::dispatch(operation_list_9::list(), idx, [&rs] (auto t) -> result_type { + using Op = typename decltype(t)::type; + return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { + FC_ASSERT(op.which() == operation::tag::value, + "Supplied operation is incorrect type for restriction predicate"); + return p(op.get()); + }; + }); +} +} } diff --git a/libraries/protocol/custom_authorities/restriction_predicate.cpp b/libraries/protocol/custom_authorities/restriction_predicate.cpp index 2465422188..5837365723 100644 --- a/libraries/protocol/custom_authorities/restriction_predicate.cpp +++ b/libraries/protocol/custom_authorities/restriction_predicate.cpp @@ -45,12 +45,17 @@ restriction_predicate_function get_restriction_predicate(vector rs, return get_restriction_predicate_list_6(typelist::index_of(), std::move(rs)); if (typelist::contains()) return get_restriction_predicate_list_7(typelist::index_of(), std::move(rs)); + if (typelist::contains()) + return get_restriction_predicate_list_8(typelist::index_of(), std::move(rs)); + if (typelist::contains()) + return get_restriction_predicate_list_9(typelist::index_of(), std::move(rs)); // Compile time check that we'll never get to the exception below static_assert(typelist::contains, Op>(), ""); + operation_list_7::list, operation_list_8::list, + operation_list_9::list>, Op>(), ""); FC_THROW_EXCEPTION(fc::assert_exception, "LOGIC ERROR: Operation type not handled by custom authorities implementation. " "Please report this error."); diff --git a/libraries/protocol/custom_authorities/restriction_predicate.hxx b/libraries/protocol/custom_authorities/restriction_predicate.hxx index d5a4a6f709..7a45cc6178 100644 --- a/libraries/protocol/custom_authorities/restriction_predicate.hxx +++ b/libraries/protocol/custom_authorities/restriction_predicate.hxx @@ -102,10 +102,12 @@ using object_restriction_predicate = std::function; // predicate which returns true if any branch of the OR passes // - create_predicate_function() -- switches on restriction type to determine which predicate template to use // going forward -// - restriction_argument_visitor -- Determines what type the restriction argument is and creates a -// predicate functor for that type +// - make_predicate -- Determines what type the restriction argument is and creates +// a predicate functor for that type // - attribute_assertion -- If the restriction is an attribute assertion, instead of using the // restriction_argument_visitor, we recurse into restrictions_to_predicate with the current Field as the Object +// - embed_argument() -- Embeds the argument into the predicate if it is a valid type +// for the predicate, and throws otherwise. // - predicate_xyz -- These are functors implementing the various predicate function types ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -306,26 +308,6 @@ struct predicate_has_none, Argument, void> : predicat }; ////////////////////////////////////////////// END PREDICATE FUNCTORS ////////////////////////////////////////////// -// Template to visit the restriction argument, resolving its type, and create the appropriate predicate functor, or -// throw if the types are not compatible for the predicate assertion -template class Predicate, typename Field> -struct restriction_argument_visitor { - using result_type = object_restriction_predicate; - - template::template can_evaluate_helper::value>> - result_type make_predicate(const Argument& a, short) { - return Predicate(a); - } - template - result_type make_predicate(const Argument&, long) { - FC_THROW_EXCEPTION(fc::assert_exception, "Invalid argument types for predicate: ${Field}, ${Argument}", - ("Field", fc::get_typename::name())("Argument", fc::get_typename::name())); - } - template - result_type operator()(const Argument& a) { return make_predicate(a, short()); } -}; - // Forward declaration of restrictions_to_predicate, because attribute assertions and logical ORs recurse into it template object_restriction_predicate restrictions_to_predicate(vector, bool); @@ -353,21 +335,23 @@ struct attribute_assertion> { } }; +// Embed the argument into the predicate functor template> -object_restriction_predicate mkpred(P p, A a, short) { +object_restriction_predicate embed_argument(P p, A a, short) { return std::bind(p, std::placeholders::_1, std::move(a)); } template -object_restriction_predicate mkpred(P, A, long) { +object_restriction_predicate embed_argument(P, A, long) { FC_THROW_EXCEPTION(fc::assert_exception, "Invalid types for predicated"); } +// Resolve the argument type and make a predicate for it template class Predicate, typename Field, typename ArgVariant> object_restriction_predicate make_predicate(ArgVariant arg) { return typelist::runtime::dispatch(typename ArgVariant::list(), arg.which(), [&arg](auto t) mutable -> object_restriction_predicate { using Arg = typename decltype(t)::type; - return mkpred(Predicate(), std::move(arg.template get()), short()); + return embed_argument(Predicate(), std::move(arg.template get()), short()); }); } @@ -477,13 +461,19 @@ object_restriction_predicate restrictions_to_predicate(vector>; -using operation_list_2 = static_variant>; -using operation_list_3 = static_variant>; -using operation_list_4 = static_variant>; -using operation_list_5 = static_variant>; -using operation_list_6 = static_variant>; -using operation_list_7 = static_variant>; +// Process account create, update, and global parameters update operations separately, as they are the largest +using operation_list = typelist::remove_element, account_update_operation>, + committee_member_update_global_parameters_operation>; +using operation_list_1 = static_variant>; +using operation_list_2 = static_variant>; +using operation_list_3 = static_variant>; +using operation_list_4 = static_variant>; +using operation_list_5 = static_variant>; +using operation_list_6 = static_variant>; +using operation_list_7 = static_variant>; +using operation_list_8 = static_variant; +using operation_list_9 = static_variant; object_restriction_predicate get_restriction_predicate_list_1(size_t idx, vector rs); object_restriction_predicate get_restriction_predicate_list_2(size_t idx, vector rs); @@ -492,5 +482,7 @@ object_restriction_predicate get_restriction_predicate_list_4(size_t object_restriction_predicate get_restriction_predicate_list_5(size_t idx, vector rs); object_restriction_predicate get_restriction_predicate_list_6(size_t idx, vector rs); object_restriction_predicate get_restriction_predicate_list_7(size_t idx, vector rs); +object_restriction_predicate get_restriction_predicate_list_8(size_t idx, vector rs); +object_restriction_predicate get_restriction_predicate_list_9(size_t idx, vector rs); } } // namespace graphene::protocol