Skip to content

Commit

Permalink
Fixing some bad tests for the voting median test, need to look as thi…
Browse files Browse the repository at this point in the history
…s is copying the struct, maybe there is a better way to get a reference instead
  • Loading branch information
Super-Genius committed Sep 28, 2023
1 parent a46a571 commit d5dfe0d
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 61 deletions.
23 changes: 8 additions & 15 deletions build/CommonBuildParameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ include_directories(${GTest_INCLUDE_DIR})

# --------------------------------------------------------
# Set config of protobuf project
set(Protobuf_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/lib/cmake/protobuf")
set(grpc_INCLUDE_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/include")
set(Protobuf_INCLUDE_DIR "${grpc_INCLUDE_DIR}/google/protobuf")
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
set(Protobuf_DIR "${iOS_Protobuf_DIR}")
set(Protobuf_INCLUDE_DIR "${iOS_Protobuf_INCLUDE_DIR}")
set(Protobuf_LIBRARIES "${iOS_Protobuf_LIBRARIES}")
if (NOT DEFINED Protobuf_DIR)
set(Protobuf_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/lib/cmake/protobuf")
endif()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
# TODO: Check grpc install on Windows
set(Protobuf_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/build/third_party/protobuf/cmake")
set(Protobuf_INCLUDE_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/build/third_party/protobuf/include/google/protobuf")
if (NOT DEFINED grpc_INCLUDE_DIR)
set(grpc_INCLUDE_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/include")
endif()
if (NOT DEFINED Protobuf_INCLUDE_DIR)
set(Protobuf_INCLUDE_DIR "${grpc_INCLUDE_DIR}/google/protobuf")
endif()

find_package(Protobuf CONFIG REQUIRED )
Expand Down Expand Up @@ -145,10 +141,7 @@ set(boost_thread_DIR "${Boost_LIB_DIR}/cmake/boost_thread-${BOOST_VERSION}")
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_USE_STATIC_RUNTIME ON)
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
option(Boost_USE_STATIC_RUNTIME "Use static runtimes" ON)

option (SGNS_STACKTRACE_BACKTRACE "Use BOOST_STACKTRACE_USE_BACKTRACE in stacktraces, for POSIX" OFF)
if (SGNS_STACKTRACE_BACKTRACE)
Expand Down
31 changes: 0 additions & 31 deletions build/CommonCompilerOptions.CMake
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,6 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")

if (CMAKE_BUILD_TYPE EQUAL Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MTd")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MTd")
set(MSVC_RUNTIME_LIBRARY_OPTION "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif (CMAKE_BUILD_TYPE EQUAL Debug)

if (CMAKE_BUILD_TYPE EQUAL Release)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
set(MSVC_RUNTIME_LIBRARY_OPTION "MultiThreaded$<$<CONFIG:Realease>:Release>")
endif (CMAKE_BUILD_TYPE EQUAL Release)

print("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif()

if (NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
# https://cgold.readthedocs.io/en/latest/tutorials/toolchain/globals/cxx-standard.html#summary
Expand Down
4 changes: 3 additions & 1 deletion build/CompilationFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
add_flag(-Wduplicated-cond) # (only in GCC >= 6.0) warn if if / else chain has duplicated conditions
add_flag(-Wduplicated-branches) # (only in GCC >= 7.0) warn if if / else branches have duplicated code
add_flag(-Wnull-dereference) # (only in GCC >= 6.0) warn if a null dereference is detected
add_flag(-Wdouble-promotion) # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
add_flag(-Wsign-compare)
add_flag(-Wtype-limits) # size_t - size_t >= 0 -> always true
add_flag(-Wnon-virtual-dtor) # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors

# disable those flags
add_flag(-Wno-unused-command-line-argument) # clang: warning: argument unused during compilation: '--coverage' [-Wunused-command-line-argument]
add_flag(-Wno-unused-variable) # prints too many useless warnings
add_flag(-Wno-double-promotion) # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
add_flag(-Wno-unused-parameter) # prints too many useless warnings
add_flag(-Wno-unused-function) # prints too many useless warnings
add_flag(-Wno-format-nonliteral) # prints way too many warnings from spdlog
add_flag(-Wno-gnu-zero-variadic-macro-arguments) # https://stackoverflow.com/questions/21266380/is-the-gnu-zero-variadic-macro-arguments-safe-to-ignore

Expand Down
34 changes: 34 additions & 0 deletions build/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ endif()
# Project
project(SuperGenius C CXX)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")

if (CMAKE_BUILD_TYPE EQUAL Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MTd")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MTd")
set(MSVC_RUNTIME_LIBRARY_OPTION "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif (CMAKE_BUILD_TYPE EQUAL Debug)

if (CMAKE_BUILD_TYPE EQUAL Release)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
set(MSVC_RUNTIME_LIBRARY_OPTION "MultiThreaded$<$<CONFIG:Realease>:Release>")
endif (CMAKE_BUILD_TYPE EQUAL Release)

print("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()

# TODO: Check grpc install on Windows
set(Protobuf_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/build/third_party/protobuf/cmake")
set(Protobuf_INCLUDE_DIR "${_THIRDPARTY_BUILD_DIR}/grpc/build/third_party/protobuf/include/google/protobuf")

# --------------------------------------------------------
# build common libraries by platforms
include(../CommonCompilerOptions.CMake)
Expand Down
5 changes: 5 additions & 0 deletions build/iOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ project(SuperGenius C CXX)
# Set cross compiling settings
set(CMAKE_SYSTEM_NAME "iOS")

set(Protobuf_DIR "${iOS_Protobuf_DIR}")
set(Protobuf_INCLUDE_DIR "${iOS_Protobuf_INCLUDE_DIR}")
set(Protobuf_LIBRARIES "${iOS_Protobuf_LIBRARIES}")
#set(Boost_USE_STATIC_RUNTIME OFF)

# --------------------------------------------------------
# include common compiler options
include(../CommonCompilerOptions.CMake)
Expand Down
6 changes: 3 additions & 3 deletions src/crdt/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ set(PROTOS
bcast.proto
)

set(PROTO_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)
set(PROTO_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto_buf)
file(MAKE_DIRECTORY ${PROTO_SRC_DIR})
include_directories(${PROTO_SRC_DIR})

set(Protobuf_USE_STATIC_LIBS ON)
protobuf_generate_cpp(DELTA_PROTO_SRCS DELTA_PROTO_HDRS ${PROTO_SRC_DIR} PROTO_PATH delta.proto)
protobuf_generate_cpp(DELTA_PROTO_SRCS DELTA_PROTO_HDRS ${CMAKE_CURRENT_LIST_DIR} PROTO_PATH delta.proto)

protobuf_generate_cpp(BCAST_PROTO_SRCS BCAST_PROTO_HDRS ${PROTO_SRC_DIR} PROTO_PATH bcast.proto)
protobuf_generate_cpp(BCAST_PROTO_SRCS BCAST_PROTO_HDRS ${CMAKE_CURRENT_LIST_DIR} PROTO_PATH bcast.proto)
2 changes: 1 addition & 1 deletion src/processing/processing_subtask_queue_accessor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SubTaskQueueAccessorImpl : public SubTaskQueueAccessor,

/** SubTaskQueueAccessor overrides
*/
void ConnectToSubTaskQueue(std::function<void()> onSubTaskQueueConnectedEventSink);
void ConnectToSubTaskQueue(std::function<void()> onSubTaskQueueConnectedEventSink) override;
void AssignSubTasks(std::list<SGProcessing::SubTask>& subTasks) override;
void GrabSubTask(SubTaskGrabbedCallback onSubTaskGrabbedCallback) override;
void CompleteSubTask(const std::string& subTaskId, const SGProcessing::SubTaskResult& subTaskResult) override;
Expand Down
12 changes: 6 additions & 6 deletions src/verification/finality/impl/vote_tracker_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ namespace sgns::verification::finality {
return prevotes;
}

VotingMessage& VoteTrackerImpl::getMedianMessage(const BlockHash& block_hash)
VotingMessage VoteTrackerImpl::getMedianMessage(const BlockHash& block_hash)
const {
std::map<Timestamp, VotingMessage, VoteOrderComparator> tmp_votes;
for (const auto &item : ordered_votes_) {
std::vector<VotingMessage> tmp_votes;
for (const auto &item : ordered_votes_) {
if(block_hash == item.second.block_hash()) {
tmp_votes.insert(item);
tmp_votes.push_back(item.second);
}
}
size_t size = tmp_votes.size();
size_t median_index = size % 2 == 0 ? (size/2) - 1 : size/2;
auto median_it = std::next(tmp_votes.begin(), median_index);
return median_it->second;
assert((median_index >= 0) && (median_index < size));
return tmp_votes[median_index];
}

size_t VoteTrackerImpl::getTotalWeight() const {
Expand Down
2 changes: 1 addition & 1 deletion src/verification/finality/impl/vote_tracker_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace sgns::verification::finality {

size_t getTotalWeight() const override;

VotingMessage& getMedianMessage(const BlockHash& block_hash) const;
VotingMessage getMedianMessage(const BlockHash& block_hash) const override;
// Test
std::map<Timestamp, VotingMessage, VoteOrderComparator> getOrderedVotes() const {
return ordered_votes_;
Expand Down
2 changes: 1 addition & 1 deletion src/verification/finality/vote_tracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace sgns::verification::finality {
/**
* @return the median voting message
*/
virtual VotingMessage& getMedianMessage(const BlockHash& block_hash) const = 0;
virtual VotingMessage getMedianMessage(const BlockHash& block_hash) const = 0;
};

} // namespace sgns::verification::finality
Expand Down
4 changes: 2 additions & 2 deletions test/src/processing/processing_engine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ namespace
std::bind(&SubTaskQueueAccessorMock::OnTimerEvent, this, std::placeholders::_1));
}

void ConnectToSubTaskQueue(std::function<void()> onSubTaskQueueConnectedEventSink)
void ConnectToSubTaskQueue(std::function<void()> onSubTaskQueueConnectedEventSink) override
{
m_onSubTaskQueueConnectedEventSink = onSubTaskQueueConnectedEventSink;
}

void AssignSubTasks(std::list<SGProcessing::SubTask>& subTasks)
void AssignSubTasks(std::list<SGProcessing::SubTask>& subTasks) override
{
m_subTasks.swap(subTasks);
if (m_onSubTaskQueueConnectedEventSink)
Expand Down

0 comments on commit d5dfe0d

Please sign in to comment.