Skip to content

Commit

Permalink
Merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptocode committed Feb 27, 2020
2 parents 27956cc + bac78d0 commit 268a5ae
Show file tree
Hide file tree
Showing 140 changed files with 3,874 additions and 2,952 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ set (NANO_FUZZER_TEST OFF CACHE BOOL "")
option (NANO_STACKTRACE_BACKTRACE "Use BOOST_STACKTRACE_USE_BACKTRACE in stacktraces, for POSIX" OFF)
if (NANO_STACKTRACE_BACKTRACE)
add_definitions(-DNANO_STACKTRACE_BACKTRACE=1)
if (BACKTRACE_INCLUDE)
add_definitions(-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=${BACKTRACE_INCLUDE})
endif()
endif ()

if (${NANO_TIMED_LOCKS} GREATER 0)
Expand Down Expand Up @@ -167,7 +170,11 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
#set(CMAKE_C_EXTENSIONS OFF)

set(CMAKE_CXX_STANDARD 14)
set(NANO_SUPPORTED_CPP_STANDARD "17" CACHE STRING "Supported C++ standard (14 or 17)")
if (CI_BUILD OR CI_TEST)
set(NANO_SUPPORTED_CPP_STANDARD "14")
endif()
set(CMAKE_CXX_STANDARD ${NANO_SUPPORTED_CPP_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
3 changes: 1 addition & 2 deletions ci/actions/windows/build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Stop immediately if any error happens
$ErrorActionPreference = "Stop"
$ErrorActionPreference = "Continue"

if (${env:artifact} -eq 1) {
if ( ${env:BETA} -eq 1 ) {
Expand Down
3 changes: 1 addition & 2 deletions ci/actions/windows/deploy.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Stop immediately if any error happens
$ErrorActionPreference = "Stop"
$ErrorActionPreference = "Continue"

if ( ${env:BETA} -eq 1 ) {
$network_cfg="beta"
Expand Down
2 changes: 2 additions & 0 deletions ci/actions/windows/disable_windows_defender.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$ErrorActionPreference = "Continue"

Set-MpPreference -DisableArchiveScanning $true
Set-MpPreference -DisableRealtimeMonitoring $true
Set-MpPreference -DisableBehaviorMonitoring $true
2 changes: 2 additions & 0 deletions ci/actions/windows/install_deps.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$ErrorActionPreference = "Continue"

function Get-RedirectedUri {
<#
.SYNOPSIS
Expand Down
2 changes: 2 additions & 0 deletions ci/actions/windows/signing.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$ErrorActionPreference = "Continue"

if (Test-Path env:CSC_LINK) {
$path = Join-Path -Path "$env:TMP" -ChildPath csc.p12
[IO.File]::WriteAllBytes($path, [Convert]::FromBase64String($env:CSC_LINK))
Expand Down
18 changes: 16 additions & 2 deletions ci/build-travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ OS=`uname`

# This is to prevent out of scope access in async_write from asio which is not picked up by static analysers
if [[ $(grep -rl --exclude="*asio.hpp" "asio::async_write" ./nano) ]]; then
echo "using boost::asio::async_write directly is not permitted (except in nano/lib/asio.hpp). Use nano::async_write instead"
echo "Using boost::asio::async_write directly is not permitted (except in nano/lib/asio.hpp). Use nano::async_write instead"
exit 1
fi

# prevent unsolicited use of std::lock_guard & std::unique_lock outside of allowed areas
if [[ $(grep -rl --exclude={"*random_pool.cpp","*random_pool.hpp","*random_pool_shuffle.hpp","*locks.hpp","*locks.cpp"} "std::unique_lock\|std::lock_guard\|std::condition_variable" ./nano) ]]; then
echo "using std::unique_lock, std::lock_guard or std::condition_variable is not permitted (except in nano/lib/locks.hpp and non-nano dependent libraries). Use the nano::* versions instead"
echo "Using std::unique_lock, std::lock_guard or std::condition_variable is not permitted (except in nano/lib/locks.hpp and non-nano dependent libraries). Use the nano::* versions instead"
exit 1
fi

if [[ $(grep -rlP "^\s*assert \(" ./nano) ]]; then
echo "Using assert is not permitted. Use debug_assert instead."
exit 1
fi

# prevent unsolicited use of std::lock_guard & std::unique_lock outside of allowed areas
mkdir build
pushd build

Expand All @@ -44,8 +50,15 @@ ulimit -S -n 8192
if [[ "$OS" == 'Linux' ]]; then
ROCKSDB="-DROCKSDB_LIBRARIES=/tmp/rocksdb/lib/librocksdb.a \
-DROCKSDB_INCLUDE_DIRS=/tmp/rocksdb/include"
if clang --version; then
BACKTRACE="-DNANO_STACKTRACE_BACKTRACE=ON \
-DBACKTRACE_INCLUDE=</tmp/backtrace.h>"
else
BACKTRACE="-DNANO_STACKTRACE_BACKTRACE=ON"
fi
else
ROCKSDB=""
BACKTRACE=""
fi

cmake \
Expand All @@ -61,6 +74,7 @@ cmake \
-DBOOST_ROOT=/tmp/boost/ \
-DQt5_DIR=${qt_dir} \
-DCI_TEST="1" \
${BACKTRACE} \
${SANITIZERS} \
..

Expand Down
9 changes: 7 additions & 2 deletions docker/ci/Dockerfile-clang
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100
RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100
ENV BOOST_ROOT=/tmp/boost

ADD util/build_prep/fetch_boost.sh fetch_boost.sh
ADD util/build_prep/bootstrap_boost.sh bootstrap_boost.sh
RUN ./bootstrap_boost.sh -m -c -B 1.70

RUN ./fetch_boost.sh
# workaround to get a path that can be easily passed into cmake for
# BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE
# see https://www.boost.org/doc/libs/1_70_0/doc/html/stacktrace/configuration_and_build.html#stacktrace.configuration_and_build.f3

RUN ln -s /usr/lib/gcc/x86_64-linux-gnu/5/include/backtrace.h /tmp/backtrace.h
80 changes: 4 additions & 76 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ TEST (active_transactions, keep_local)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (0, node.active.dropped_elections_cache_size ());
while (!node.active.empty ())
{
nano::lock_guard<std::mutex> active_guard (node.active.mutex);
Expand All @@ -276,7 +275,6 @@ TEST (active_transactions, keep_local)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (1, node.active.dropped_elections_cache_size ());
}

TEST (active_transactions, prioritize_chains)
Expand All @@ -299,10 +297,8 @@ TEST (active_transactions, prioritize_chains)
auto send5 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 20 * nano::xrb_ratio, key2.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ())));
auto send6 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send5->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 30 * nano::xrb_ratio, key3.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send5->hash ())));
auto open2 (std::make_shared<nano::state_block> (key2.pub, 0, key2.pub, 10 * nano::xrb_ratio, send5->hash (), key2.prv, key2.pub, *system.work.generate (key2.pub, nano::difficulty::from_multiplier (50., node1.network_params.network.publish_threshold))));
uint64_t difficulty1 (0);
nano::work_validate (*open2, &difficulty1);
uint64_t difficulty2 (0);
nano::work_validate (*send6, &difficulty2);
auto difficulty1 (open2->difficulty ());
auto difficulty2 (send6->difficulty ());

node1.process_active (send1);
node1.process_active (open1);
Expand Down Expand Up @@ -519,11 +515,9 @@ TEST (active_transactions, update_difficulty)
nano::keypair key1;
// Generate blocks & start elections
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - 100, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
uint64_t difficulty1 (0);
nano::work_validate (*send1, &difficulty1);
auto difficulty1 (send1->difficulty ());
auto send2 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 200, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ())));
uint64_t difficulty2 (0);
nano::work_validate (*send2, &difficulty2);
auto difficulty2 (send2->difficulty ());
node1.process_active (send1);
node1.process_active (send2);
node1.block_processor.flush ();
Expand Down Expand Up @@ -571,72 +565,6 @@ TEST (active_transactions, update_difficulty)
}
}

TEST (active_transactions, restart_dropped)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.enable_voting = false;
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto & node = *system.add_node (node_config);
nano::genesis genesis;
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::xrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
// Process only in ledger and emulate dropping the election
ASSERT_EQ (nano::process_result::progress, node.process (*send1).code);
{
nano::lock_guard<std::mutex> guard (node.active.mutex);
node.active.add_dropped_elections_cache (send1->qualified_root ());
}
uint64_t difficulty1 (0);
nano::work_validate (*send1, &difficulty1);
// Generate higher difficulty work
auto work2 (*system.work.generate (send1->root (), difficulty1));
uint64_t difficulty2 (0);
nano::work_validate (send1->root (), work2, &difficulty2);
ASSERT_GT (difficulty2, difficulty1);
// Process the same block with updated work
auto send2 (std::make_shared<nano::state_block> (*send1));
send2->block_work_set (work2);
node.process_active (send2);
// Wait until the block is in elections
system.deadline_set (5s);
bool done{ false };
while (!done)
{
{
nano::lock_guard<std::mutex> guard (node.active.mutex);
auto existing (node.active.roots.find (send2->qualified_root ()));
done = existing != node.active.roots.end ();
if (done)
{
ASSERT_EQ (difficulty2, existing->difficulty);
}
}
ASSERT_NO_ERROR (system.poll ());
}
std::shared_ptr<nano::block> block;
while (block == nullptr)
{
ASSERT_NO_ERROR (system.poll ());
block = node.store.block_get (node.store.tx_begin_read (), send1->hash ());
}
ASSERT_EQ (work2, block->block_work ());
// Drop election
node.active.erase (*send2);
// Try to restart election with the lower difficulty block, should not work since the block as lower work
node.process_active (send1);
system.deadline_set (5s);
while (node.block_processor.size () > 0)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_TRUE (node.active.empty ());
// Verify the block was not updated in the ledger
{
auto block (node.store.block_get (node.store.tx_begin_read (), send1->hash ()));
ASSERT_EQ (work2, block->block_work ());
}
}

TEST (active_transactions, vote_replays)
{
nano::system system;
Expand Down
15 changes: 15 additions & 0 deletions nano/core_test/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ TEST (block, publish_req_serialization)
ASSERT_EQ (*req.block, *req2.block);
}

TEST (block, difficulty)
{
nano::send_block block (0, 1, 2, nano::keypair ().prv, 4, 5);
ASSERT_EQ (block.difficulty (), nano::work_difficulty (block.work_version (), block.root (), block.block_work ()));
}

TEST (state_block, serialization)
{
nano::keypair key1;
Expand Down Expand Up @@ -399,6 +405,15 @@ TEST (state_block, hashing)
ASSERT_EQ (hash, block.hash ());
}

TEST (blocks, work_version)
{
ASSERT_EQ (nano::work_version::work_1, nano::send_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::receive_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::change_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::open_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::state_block ().work_version ());
}

TEST (block_uniquer, null)
{
nano::block_uniquer uniquer;
Expand Down
19 changes: 7 additions & 12 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ TEST (block_store, large_iteration)
for (auto i (store->latest_begin (transaction, 0)), n (store->latest_end ()); i != n; ++i)
{
nano::account current (i->first);
assert (current.number () > previous.number ());
ASSERT_GT (current.number (), previous.number ());
accounts2.insert (current);
previous = current;
}
Expand Down Expand Up @@ -874,8 +874,7 @@ TEST (mdb_block_store, upgrade_v2_v3)
auto rep_block = ledger.representative (transaction, ledger.latest (transaction, nano::test_genesis_key.pub));
nano::account_info_v5 info_old (info.head, rep_block, info.open_block, info.balance, info.modified);
auto status (mdb_put (store.env.tx (transaction), store.accounts_v0, nano::mdb_val (nano::test_genesis_key.pub), nano::mdb_val (sizeof (info_old), &info_old), 0));
(void)status;
assert (status == 0);
ASSERT_EQ (status, 0);
store.confirmation_height_del (transaction, nano::genesis_account);
}
nano::logger_mt logger;
Expand Down Expand Up @@ -2321,7 +2320,7 @@ void write_sideband_v15 (nano::mdb_store & store_a, nano::transaction & transact
auto block = store_a.block_get (transaction_a, block_a.hash (), &sideband);
ASSERT_NE (block, nullptr);

assert (sideband.details.epoch <= nano::epoch::max);
ASSERT_LE (sideband.details.epoch, nano::epoch::max);
// Simulated by writing 0 on every of the most significant bits, leaving out epoch only, as if pre-upgrade
nano::block_sideband sideband_v15 (sideband.type, sideband.account, sideband.successor, sideband.balance, sideband.timestamp, sideband.height, sideband.details.epoch, false, false, false);
std::vector<uint8_t> data;
Expand All @@ -2342,8 +2341,7 @@ void modify_account_info_to_v13 (nano::mdb_store & store, nano::transaction cons
ASSERT_FALSE (store.account_get (transaction, account, info));
nano::account_info_v13 account_info_v13 (info.head, rep_block, info.open_block, info.balance, info.modified, info.block_count, info.epoch ());
auto status (mdb_put (store.env.tx (transaction), (info.epoch () == nano::epoch::epoch_0) ? store.accounts_v0 : store.accounts_v1, nano::mdb_val (account), nano::mdb_val (account_info_v13), 0));
(void)status;
assert (status == 0);
ASSERT_EQ (status, 0);
}

void modify_account_info_to_v14 (nano::mdb_store & store, nano::transaction const & transaction, nano::account const & account, uint64_t confirmation_height, nano::block_hash const & rep_block)
Expand All @@ -2352,15 +2350,13 @@ void modify_account_info_to_v14 (nano::mdb_store & store, nano::transaction cons
ASSERT_FALSE (store.account_get (transaction, account, info));
nano::account_info_v14 account_info_v14 (info.head, rep_block, info.open_block, info.balance, info.modified, info.block_count, confirmation_height, info.epoch ());
auto status (mdb_put (store.env.tx (transaction), info.epoch () == nano::epoch::epoch_0 ? store.accounts_v0 : store.accounts_v1, nano::mdb_val (account), nano::mdb_val (account_info_v14), 0));
(void)status;
assert (status == 0);
ASSERT_EQ (status, 0);
}

void modify_confirmation_height_to_v15 (nano::mdb_store & store, nano::transaction const & transaction, nano::account const & account, uint64_t confirmation_height)
{
auto status (mdb_put (store.env.tx (transaction), store.confirmation_height, nano::mdb_val (account), nano::mdb_val (confirmation_height), 0));
(void)status;
assert (status == 0);
ASSERT_EQ (status, 0);
}

void modify_genesis_account_info_to_v5 (nano::mdb_store & store, nano::transaction const & transaction)
Expand All @@ -2371,7 +2367,6 @@ void modify_genesis_account_info_to_v5 (nano::mdb_store & store, nano::transacti
visitor.compute (info.head);
nano::account_info_v5 info_old (info.head, visitor.result, info.open_block, info.balance, info.modified);
auto status (mdb_put (store.env.tx (transaction), store.accounts_v0, nano::mdb_val (nano::test_genesis_key.pub), nano::mdb_val (sizeof (info_old), &info_old), 0));
(void)status;
assert (status == 0);
ASSERT_EQ (status, 0);
}
}
Loading

0 comments on commit 268a5ae

Please sign in to comment.