Skip to content

Commit

Permalink
Merge pull request #121 from chfast/version
Browse files Browse the repository at this point in the history
Library version / algorithms revisions
  • Loading branch information
chfast authored Feb 19, 2019
2 parents 13c97f8 + 1d5ca88 commit d8d9c03
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 3 deletions.
1 change: 1 addition & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ values =
rel

[bumpversion:file:CMakeLists.txt]
[bumpversion:file:include/ethash/version.h]

8 changes: 6 additions & 2 deletions cmake/cable/CableCompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro(cable_configure_compiler)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.

cmake_parse_arguments(cable "NO_CONVERSION_WARNINGS;NO_STACK_PROTECTION" "" "" ${ARGN})
cmake_parse_arguments(cable "NO_CONVERSION_WARNINGS;NO_STACK_PROTECTION;NO_PEDANTIC" "" "" ${ARGN})

if(cable_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "cable_configure_compiler: Unknown options: ${cable_UNPARSED_ARGUMENTS}")
Expand All @@ -52,8 +52,12 @@ macro(cable_configure_compiler)

if(CABLE_COMPILER_GNULIKE)

if(NOT cable_NO_PEDANTIC)
add_compile_options(-pedantic)
endif()

# Enable basing warnings set and treat them as errors.
add_compile_options(-pedantic -Werror -Wall -Wextra)
add_compile_options(-Werror -Wall -Wextra)

if(NOT cable_NO_CONVERSION_WARNINGS)
# Enable conversion warnings if not explicitly disabled.
Expand Down
2 changes: 1 addition & 1 deletion cmake/cable/bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# This is internal variable automatically updated with external tools.
# Use CABLE_VERSION variable if you need this information.
set(version 0.2.14)
set(version 0.2.16)

# For convenience, add the project CMake module dir to module path.
set(module_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
Expand Down
9 changes: 9 additions & 0 deletions cmake/cable/toolchains/cxx14-pic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Cable: CMake Bootstrap Library.
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
7 changes: 7 additions & 0 deletions cmake/cable/toolchains/cxx14.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Cable: CMake Bootstrap Library.
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)
9 changes: 9 additions & 0 deletions cmake/cable/toolchains/cxx17-pic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Cable: CMake Bootstrap Library.
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
7 changes: 7 additions & 0 deletions cmake/cable/toolchains/cxx17.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Cable: CMake Bootstrap Library.
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)
6 changes: 6 additions & 0 deletions include/ethash/ethash.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
extern "C" {
#endif

/**
* The Ethash algorithm revision implemented as specified in the Ethash spec
* https://github.com/ethereum/wiki/wiki/Ethash.
*/
#define ETHASH_REVISION "23"

#define ETHASH_EPOCH_LENGTH 30000
#define ETHASH_LIGHT_CACHE_ITEM_SIZE 64
#define ETHASH_FULL_DATASET_ITEM_SIZE 128
Expand Down
2 changes: 2 additions & 0 deletions include/ethash/ethash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace ethash
{
constexpr auto revision = ETHASH_REVISION;

static constexpr int epoch_length = ETHASH_EPOCH_LENGTH;
static constexpr int light_cache_item_size = ETHASH_LIGHT_CACHE_ITEM_SIZE;
static constexpr int full_dataset_item_size = ETHASH_FULL_DATASET_ITEM_SIZE;
Expand Down
5 changes: 5 additions & 0 deletions include/ethash/progpow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ namespace progpow
{
using namespace ethash; // Include ethash namespace.


/// The ProgPoW algorithm revision implemented as specified in the spec
/// https://github.com/ifdefelse/ProgPOW#change-history.
constexpr auto revision = "0.9.2";

constexpr int period_length = 50;
constexpr uint32_t num_regs = 32;
constexpr size_t num_lanes = 16;
Expand Down
18 changes: 18 additions & 0 deletions include/ethash/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
* Copyright 2019 Pawel Bylica.
* Licensed under the Apache License, Version 2.0.
*/

#pragma once

/** The ethash library version. */
#define ETHASH_VERSION "0.4.2"

#ifdef __cplusplus
namespace ethash
{
/// The ethash library version.
constexpr auto version = ETHASH_VERSION;

} // namespace ethash
#endif
3 changes: 3 additions & 0 deletions test/integration/cmake-config/cmake_config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
// Licensed under the Apache License, Version 2.0. See the LICENSE file.

#include <ethash/ethash.hpp>
#include <ethash/version.h>

int main()
{
static_assert(sizeof(ethash::version) >= 6, "incorrect ethash::version");

uint8_t seed_bytes[32] = {0};
ethash::hash256 seed = ethash::hash256_from_bytes(seed_bytes);
return ethash::find_epoch_number(seed);
Expand Down
3 changes: 3 additions & 0 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ add_executable(
test_managed.cpp
test_primes.cpp
test_progpow.cpp
test_version.cpp
)

set_source_files_properties(test_version.cpp PROPERTIES COMPILE_DEFINITIONS TEST_PROJECT_VERSION="${PROJECT_VERSION}")

target_link_libraries(ethash-test PRIVATE ethash GTest::gtest GTest::main)
target_include_directories(ethash-test PRIVATE ${ETHASH_PRIVATE_INCLUDE_DIR})
set_target_properties(ethash-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)
7 changes: 7 additions & 0 deletions test/unittests/test_ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ hash512 copy(const hash512& h) noexcept
}
}

TEST(ethash, revision)
{
static_assert(ethash::revision[0] == '2', "");
static_assert(ethash::revision[1] == '3', "");
EXPECT_EQ(ethash::revision, "23");
EXPECT_EQ(ethash::revision, (std::string{"23"}));
}

TEST(hash, hash256_from_bytes)
{
Expand Down
10 changes: 10 additions & 0 deletions test/unittests/test_progpow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
#include <gtest/gtest.h>
#include <array>

TEST(progpow, revision)
{
static_assert(progpow::revision[0] == '0', "");
static_assert(progpow::revision[1] == '.', "");
static_assert(progpow::revision[2] == '9', "");
static_assert(progpow::revision[3] == '.', "");
static_assert(progpow::revision[4] == '2', "");
EXPECT_EQ(progpow::revision, "0.9.2");
EXPECT_EQ(progpow::revision, (std::string{"0.9.2"}));
}

TEST(progpow, l1_cache)
{
Expand Down
15 changes: 15 additions & 0 deletions test/unittests/test_version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2019 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include <ethash/version.h>

#include <gtest/gtest.h>

TEST(libethash, version)
{
static_assert(ethash::version[0] != 0, "incorrect ethash::version");

EXPECT_EQ(ETHASH_VERSION, TEST_PROJECT_VERSION);
EXPECT_EQ(ethash::version, TEST_PROJECT_VERSION);
}

0 comments on commit d8d9c03

Please sign in to comment.