Skip to content

Commit

Permalink
BSIP 40: Cleanup, disable sign-compare warnings on g++
Browse files Browse the repository at this point in the history
Set travis to build single-threaded and disable signed-unsigned
comparison warnings on g++. If anyone has a real solution to
signed comparisons, I'd love to hear it, but until then, the
warnings are actually so awful that travis breaks over them.
  • Loading branch information
nathanielhourt committed Aug 5, 2019
1 parent b600cbc commit a442c84
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/custom_authority_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 21 additions & 9 deletions libraries/protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion libraries/protocol/custom_authorities/list_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "restriction_predicate.hxx"

namespace graphene { namespace protocol {

using result_type = object_restriction_predicate<operation>;

result_type get_restriction_predicate_list_1(size_t idx, vector<restriction> rs) {
Expand Down
41 changes: 41 additions & 0 deletions libraries/protocol/custom_authorities/list_8.cpp
Original file line number Diff line number Diff line change
@@ -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<operation>;

result_type get_restriction_predicate_list_8(size_t idx, vector<restriction> 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<Op>(std::move(rs), true)] (const operation& op) {
FC_ASSERT(op.which() == operation::tag<Op>::value,
"Supplied operation is incorrect type for restriction predicate");
return p(op.get<Op>());
};
});
}
} }
41 changes: 41 additions & 0 deletions libraries/protocol/custom_authorities/list_9.cpp
Original file line number Diff line number Diff line change
@@ -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<operation>;

result_type get_restriction_predicate_list_9(size_t idx, vector<restriction> 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<Op>(std::move(rs), true)] (const operation& op) {
FC_ASSERT(op.which() == operation::tag<Op>::value,
"Supplied operation is incorrect type for restriction predicate");
return p(op.get<Op>());
};
});
}
} }
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ restriction_predicate_function get_restriction_predicate(vector<restriction> rs,
return get_restriction_predicate_list_6(typelist::index_of<operation_list_6::list, Op>(), std::move(rs));
if (typelist::contains<operation_list_7::list, Op>())
return get_restriction_predicate_list_7(typelist::index_of<operation_list_7::list, Op>(), std::move(rs));
if (typelist::contains<operation_list_8::list, Op>())
return get_restriction_predicate_list_8(typelist::index_of<operation_list_8::list, Op>(), std::move(rs));
if (typelist::contains<operation_list_9::list, Op>())
return get_restriction_predicate_list_9(typelist::index_of<operation_list_9::list, Op>(), std::move(rs));

// Compile time check that we'll never get to the exception below
static_assert(typelist::contains<typelist::concat<operation_list_1::list, operation_list_2::list,
operation_list_3::list, operation_list_4::list,
operation_list_5::list, operation_list_6::list,
operation_list_7::list>, 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.");
Expand Down
56 changes: 24 additions & 32 deletions libraries/protocol/custom_authorities/restriction_predicate.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ using object_restriction_predicate = std::function<bool(const Field&)>;
// predicate which returns true if any branch of the OR passes
// - create_predicate_function<Field>() -- switches on restriction type to determine which predicate template to use
// going forward
// - restriction_argument_visitor<Field> -- Determines what type the restriction argument is and creates a
// predicate functor for that type
// - make_predicate<Predicate, Field, ArgVariant> -- Determines what type the restriction argument is and creates
// a predicate functor for that type
// - attribute_assertion<Field> -- 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<Field, Predicate, Argument>() -- Embeds the argument into the predicate if it is a valid type
// for the predicate, and throws otherwise.
// - predicate_xyz<Argument> -- These are functors implementing the various predicate function types
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -306,26 +308,6 @@ struct predicate_has_none<fc::optional<OptionalType>, 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<template<typename> class Predicate, typename Field>
struct restriction_argument_visitor {
using result_type = object_restriction_predicate<Field>;

template<typename Argument,
typename = std::enable_if_t<Predicate<Argument>::template can_evaluate_helper<Field>::value>>
result_type make_predicate(const Argument& a, short) {
return Predicate<Argument>(a);
}
template<typename Argument>
result_type make_predicate(const Argument&, long) {
FC_THROW_EXCEPTION(fc::assert_exception, "Invalid argument types for predicate: ${Field}, ${Argument}",
("Field", fc::get_typename<Field>::name())("Argument", fc::get_typename<Argument>::name()));
}
template<typename Argument>
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<typename Field> object_restriction_predicate<Field> restrictions_to_predicate(vector<restriction>, bool);

Expand Down Expand Up @@ -353,21 +335,23 @@ struct attribute_assertion<extension<Extension>> {
}
};

// Embed the argument into the predicate functor
template<typename F, typename P, typename A, typename = std::enable_if_t<P::valid>>
object_restriction_predicate<F> mkpred(P p, A a, short) {
object_restriction_predicate<F> embed_argument(P p, A a, short) {
return std::bind(p, std::placeholders::_1, std::move(a));
}
template<typename F, typename P, typename A>
object_restriction_predicate<F> mkpred(P, A, long) {
object_restriction_predicate<F> 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<template<typename...> class Predicate, typename Field, typename ArgVariant>
object_restriction_predicate<Field> make_predicate(ArgVariant arg) {
return typelist::runtime::dispatch(typename ArgVariant::list(), arg.which(),
[&arg](auto t) mutable -> object_restriction_predicate<Field> {
using Arg = typename decltype(t)::type;
return mkpred<Field>(Predicate<Field, Arg>(), std::move(arg.template get<Arg>()), short());
return embed_argument<Field>(Predicate<Field, Arg>(), std::move(arg.template get<Arg>()), short());
});
}

Expand Down Expand Up @@ -477,13 +461,19 @@ object_restriction_predicate<Object> restrictions_to_predicate(vector<restrictio
}

// To make the build gentler on RAM, break the operation list into several pieces to build over several files
using operation_list_1 = static_variant<typelist::slice<operation::list, 0, 5>>;
using operation_list_2 = static_variant<typelist::slice<operation::list, 5, 10>>;
using operation_list_3 = static_variant<typelist::slice<operation::list, 10, 20>>;
using operation_list_4 = static_variant<typelist::slice<operation::list, 20, 30>>;
using operation_list_5 = static_variant<typelist::slice<operation::list, 30, 40>>;
using operation_list_6 = static_variant<typelist::slice<operation::list, 40, 50>>;
using operation_list_7 = static_variant<typelist::slice<operation::list, 50>>;
// Process account create, update, and global parameters update operations separately, as they are the largest
using operation_list = typelist::remove_element<typelist::remove_element<typelist::remove_element<operation::list,
account_create_operation>, account_update_operation>,
committee_member_update_global_parameters_operation>;
using operation_list_1 = static_variant<typelist::slice<operation_list, 0, 5>>;
using operation_list_2 = static_variant<typelist::slice<operation_list, 5, 10>>;
using operation_list_3 = static_variant<typelist::slice<operation_list, 10, 20>>;
using operation_list_4 = static_variant<typelist::slice<operation_list, 20, 30>>;
using operation_list_5 = static_variant<typelist::slice<operation_list, 30, 40>>;
using operation_list_6 = static_variant<typelist::slice<operation_list, 40, 50>>;
using operation_list_7 = static_variant<typelist::slice<operation_list, 50>>;
using operation_list_8 = static_variant<account_create_operation, account_update_operation>;
using operation_list_9 = static_variant<committee_member_update_global_parameters_operation>;

object_restriction_predicate<operation> get_restriction_predicate_list_1(size_t idx, vector<restriction> rs);
object_restriction_predicate<operation> get_restriction_predicate_list_2(size_t idx, vector<restriction> rs);
Expand All @@ -492,5 +482,7 @@ object_restriction_predicate<operation> get_restriction_predicate_list_4(size_t
object_restriction_predicate<operation> get_restriction_predicate_list_5(size_t idx, vector<restriction> rs);
object_restriction_predicate<operation> get_restriction_predicate_list_6(size_t idx, vector<restriction> rs);
object_restriction_predicate<operation> get_restriction_predicate_list_7(size_t idx, vector<restriction> rs);
object_restriction_predicate<operation> get_restriction_predicate_list_8(size_t idx, vector<restriction> rs);
object_restriction_predicate<operation> get_restriction_predicate_list_9(size_t idx, vector<restriction> rs);

} } // namespace graphene::protocol

0 comments on commit a442c84

Please sign in to comment.