Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ if(ENABLE_COVERAGE_TESTING)
set(CMAKE_CXX_FLAGS "--coverage ${CMAKE_CXX_FLAGS}")
endif()

# Static libraries do not link, so a library's objects need not wait for its dependency
# libraries to finish compiling, only for their generated sources. Without this the Makefile
# generator builds target-by-target: nothing in graphene_chain starts until fc/protocol are
# archived, and no plugin starts until database.cpp (the longest TU) finishes on one core.
# Cold `make -j8 vizd cli_wallet` on an 8-core laptop: 805 s -> 305 s wall, ~2.4 -> ~4.8 cores busy.
set(CMAKE_OPTIMIZE_DEPENDENCIES ON)

add_subdirectory(thirdparty)
add_subdirectory(libraries)
add_subdirectory(plugins)
Expand Down
9 changes: 4 additions & 5 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ set_source_files_properties("${hardfork_hpp_out}" PROPERTIES GENERATED TRUE)
# Include the binary include dir
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")

# Variable used below in add_library
set(hardfork_hpp_file "${hardfork_hpp_out}")

## SORT .cpp by most likely to change / break compile

add_library(graphene_chain ${VIZ_LIBRARY_TYPE}
Expand Down Expand Up @@ -104,10 +101,12 @@ add_library(graphene_chain ${VIZ_LIBRARY_TYPE}
include/graphene/chain/paid_subscription_objects.hpp
include/graphene/chain/pm_objects.hpp

${hardfork_hpp_file}
)

add_dependencies(graphene_chain graphene_protocol graphene_utilities build_hardfork_hpp)
# Only the generated header is a real build-order dependency. Library-to-library order comes
# from target_link_libraries; an explicit add_dependencies here would defeat
# CMAKE_OPTIMIZE_DEPENDENCIES and make every chain TU wait for protocol to finish archiving.
add_dependencies(graphene_chain build_hardfork_hpp)
target_link_libraries(graphene_chain graphene_protocol graphene_utilities fc chainbase appbase ${PATCH_MERGE_LIB})
target_include_directories(graphene_chain PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../")

Expand Down
1 change: 1 addition & 0 deletions tests/consensus_sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ set(SCENARIO_SOURCES
scenarios/test_routable_endpoint.cpp
scenarios/test_p2p_slot_scale.cpp
scenarios/test_db_invariants.cpp
scenarios/test_operation_variant.cpp
)

# These scenarios require an actual HF14 activation and never soft-skip.
Expand Down
59 changes: 59 additions & 0 deletions tests/consensus_sim/scenarios/test_operation_variant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Contract of the `operation` static_variant: every alternative round-trips through the raw
// and JSON serializers under its own tag, tags are what the type list says they are, and an
// out-of-range tag is rejected instead of dispatching into garbage. The variant index is the
// consensus op-id, so this pins the dispatch machinery itself, not any one operation.

#include <boost/test/unit_test.hpp>

#include <graphene/protocol/operations.hpp>
#include <fc/io/raw.hpp>

using namespace graphene::protocol;

BOOST_AUTO_TEST_SUITE(operation_variant)

BOOST_AUTO_TEST_CASE(every_alternative_round_trips_under_its_tag) {
for (int i = 0; i < operation::count(); ++i) {
operation op;
op.set_which(i);
BOOST_REQUIRE_EQUAL(op.which(), i);

auto bytes = fc::raw::pack(op);
BOOST_CHECK_EQUAL(fc::raw::unpack<operation>(bytes).which(), i);

fc::variant v;
fc::to_variant(op, v);
operation from_json;
fc::from_variant(v, from_json);
BOOST_CHECK_EQUAL(from_json.which(), i);

operation copied(op);
operation moved(std::move(copied));
BOOST_CHECK_EQUAL(moved.which(), i);
operation assigned;
assigned = op;
BOOST_CHECK_EQUAL(assigned.which(), i);
}
}

BOOST_AUTO_TEST_CASE(tags_follow_the_type_list) {
BOOST_CHECK_EQUAL(int(operation::tag<vote_operation>::value), 0);
BOOST_CHECK_EQUAL(int(operation::tag<transfer_operation>::value), 2);
BOOST_CHECK_EQUAL(int(operation::tag<validator_equivocation_operation>::value), operation::count() - 1);

operation op = transfer_operation();
BOOST_CHECK_EQUAL(op.which(), int(operation::tag<transfer_operation>::value));
op.get<transfer_operation>().memo = "x";
BOOST_CHECK_EQUAL(op.get<transfer_operation>().memo, "x");
BOOST_CHECK_THROW(op.get<vote_operation>(), fc::assert_exception);
}

BOOST_AUTO_TEST_CASE(out_of_range_tag_is_rejected) {
operation op;
BOOST_CHECK_THROW(op.set_which(operation::count()), fc::exception);

auto bytes = fc::raw::pack(fc::unsigned_int(operation::count() + 7));
BOOST_CHECK_THROW(fc::raw::unpack<operation>(bytes), fc::exception);
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion thirdparty/fc
Submodule fc updated 1 files
+65 −43 include/fc/static_variant.hpp
Loading