Skip to content

Commit

Permalink
Merge branch 'develop' into block_pipeline
Browse files Browse the repository at this point in the history
# Conflicts:
#	nano/secure/ledger.cpp
#	nano/secure/ledger.hpp
  • Loading branch information
clemahieu committed Jan 27, 2023
2 parents 6f4ba33 + 0d30fbe commit 1f608a3
Show file tree
Hide file tree
Showing 39 changed files with 1,022 additions and 963 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

windows_test:
name: Windows Unit Tests [TEST_USE_ROCKSDB=${{ matrix.TEST_USE_ROCKSDB }}]
timeout-minutes: 90
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
Expand Down
34 changes: 30 additions & 4 deletions ci/actions/dev-build-tag-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ function output_variable {
set -o nounset
set -o xtrace

# The reference branch is 'develop', that is the current release being developed. Here it is extracting the
# major and minor numbers from the CMakeLists.txt file.
current_version_major=$(grep -P "(set)(.)*(CPACK_PACKAGE_VERSION_MAJOR)" "${source_dir}/CMakeLists.txt" | grep -oP "([0-9]+)")
current_version_minor=$(grep -P "(set)(.)*(CPACK_PACKAGE_VERSION_MINOR)" "${source_dir}/CMakeLists.txt" | grep -oP "([0-9]+)")
current_version_pre_release=$(grep -P "(set)(.)*(CPACK_PACKAGE_VERSION_PRE_RELEASE)" "${source_dir}/CMakeLists.txt" | grep -oP "([0-9]+)")

version_tags=$(git tag | sort -V -r | grep -E "^(V([0-9]+).([0-9]+)(RC[0-9]+)?)$")
# Get the list of version tags that can be either official releases or release candidates. The list comes
# ordered by version, in reverse order.
version_tags=$(git tag | sort -V -r | grep -E "^(V([0-9]+)\.([0-9]+)(RC[0-9]+)?)$")

# Get the first tag of the list, that means, the latest version.
last_tag=$(get_first_item "$version_tags")
tag_version_major=$(echo "$last_tag" | grep -oP "\V([0-9]+)\." | grep -oP "[0-9]+")
if [[ ${tag_version_major} -ge ${current_version_major} ]]; then
Expand All @@ -128,21 +134,38 @@ last_tag=""
version_tags=""
previous_release_major=0
previous_release_minor=0
# If option -r is set, then the script will handle tag generation as for the release branch, it'd do 'develop' branch
# otherwise.
if [[ $previous_release_gen == false ]]; then
version_tags=$(git tag | sort -V -r | grep -E "^(V(${current_version_major}).(${current_version_minor})(DB[0-9]+))$" || true)
# List of all beta-build (DB) tags in reverse version order.
version_tags=$(git tag | sort -V -r | grep -E "^(V(${current_version_major})\.(${current_version_minor})(DB[0-9]+))$" || true)
last_tag=$(get_first_item "$version_tags")
else
previous_release_major=$(( current_version_major - 1 ))
version_tags=$(git tag | sort -V -r | grep -E "^(V(${previous_release_major}).([0-9]+)(DB[0-9]+)?)$" || true)
# List of official release tags in reverse order.
version_tags=$(git tag | sort -V -r | grep -E "^(V(${previous_release_major})\.([0-9]+))$" || true)
if [[ -z "$version_tags" ]]; then
# Previous release minor is 0 if no official release is found in the branch.
previous_release_minor=0
else
# Previous release minor version is increased by 1 because next beta-build should go on unreleased minor versions.
last_minor_release=$(get_first_item "$version_tags")
last_minor=$(echo "$last_minor_release" | grep -oP "\.([0-9]+)" | grep -oP "[0-9]+")
previous_release_minor=$(( last_minor + 1 ))
fi
# List of tags in reverse version order that may or many not include beta-build (DB) tags.
version_tags=$(git tag | sort -V -r | grep -E "^(V(${previous_release_major})\.(${previous_release_minor})(DB[0-9]+)?)$" || true)
last_tag=$(get_first_item "$version_tags")
previous_release_minor=$(echo "$last_tag" | grep -oP "\.([0-9]+)" | grep -oP "[0-9]+")
# The reference release branch in Git repository should follow the pattern 'releases/vXY'.
release_branch="releases/v${previous_release_major}"
output_variable release_branch
fi
popd

build_tag=""
if [[ -z "$last_tag" ]]; then
# If the last tag was not found previously, it means there was no previous beta-build for this major and minor
# numbers, then the build number is 1.
build_number=1
echo "info: no tag found, build_number=${build_number}"
if [[ $previous_release_gen == false ]]; then
Expand All @@ -156,6 +179,8 @@ if [[ -z "$last_tag" ]]; then
fi

pushd "$source_dir"
# This code block looks for the branch head in order to know if there is already a tag for it. There is no need
# to generate a new tag if the beta-build has already been created.
develop_head=""
if [[ $previous_release_gen == false ]]; then
develop_head=$(git rev-parse "${git_upstream}/develop")
Expand All @@ -170,6 +195,7 @@ if [[ "$develop_head" == "$tag_head" ]]; then
exit 2
fi

# Prepares the build number to be used.
latest_build_number=$(echo "$last_tag" | grep -oP "(DB[0-9]+)" | grep -oP "[0-9]+")
build_number=$(( latest_build_number + 1 ))
if [[ $previous_release_gen == false ]]; then
Expand Down
4 changes: 2 additions & 2 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

build_dir=${1-${PWD}}
if [[ ${TEST_USE_ROCKSDB-0} == 1 ]]; then
TIMEOUT_DEFAULT=1800
TIMEOUT_DEFAULT=2400
else
TIMEOUT_DEFAULT=900
TIMEOUT_DEFAULT=1200
fi

BUSYBOX_BASH=${BUSYBOX_BASH-0}
Expand Down
99 changes: 6 additions & 93 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/election.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/test_common/chains.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand Down Expand Up @@ -1409,94 +1410,6 @@ TEST (active_transactions, fifo)
ASSERT_TIMELY (1s, node.active.election (receive2->qualified_root ()) != nullptr);
}

namespace
{
/*
* Sends `amount` raw from genesis chain into a new account and makes it a representative
*/
nano::keypair setup_rep (nano::test::system & system, nano::node & node, nano::uint128_t const amount)
{
auto latest = node.latest (nano::dev::genesis_key.pub);
auto balance = node.balance (nano::dev::genesis_key.pub);

nano::keypair key;
nano::block_builder builder;

auto send = builder
.send ()
.previous (latest)
.destination (key.pub)
.balance (balance - amount)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (latest))
.build_shared ();

auto open = builder
.open ()
.source (send->hash ())
.representative (key.pub)
.account (key.pub)
.sign (key.prv, key.pub)
.work (*system.work.generate (key.pub))
.build_shared ();

EXPECT_TRUE (nano::test::process (node, { send, open }));
EXPECT_TIMELY (5s, nano::test::confirm (node, { send, open }));
EXPECT_TIMELY (5s, nano::test::confirmed (node, { send, open }));

return key;
}

/*
* Creates `count` 1 raw sends from genesis to unique accounts and corresponding open blocks.
* The genesis chain is then confirmed, but leaves open blocks unconfirmed.
*/
std::vector<std::shared_ptr<nano::block>> setup_independent_blocks (nano::test::system & system, nano::node & node, int count)
{
std::vector<std::shared_ptr<nano::block>> blocks;

auto latest = node.latest (nano::dev::genesis_key.pub);
auto balance = node.balance (nano::dev::genesis_key.pub);

for (int n = 0; n < count; ++n)
{
nano::keypair key;
nano::block_builder builder;

balance -= 1;
auto send = builder
.send ()
.previous (latest)
.destination (key.pub)
.balance (balance)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (latest))
.build_shared ();
latest = send->hash ();

auto open = builder
.open ()
.source (send->hash ())
.representative (key.pub)
.account (key.pub)
.sign (key.prv, key.pub)
.work (*system.work.generate (key.pub))
.build_shared ();

EXPECT_TRUE (nano::test::process (node, { send, open }));
EXPECT_TIMELY (5s, nano::test::exists (node, { send, open })); // Ensure blocks are in the ledger

blocks.push_back (open);
}

// Confirm whole genesis chain at once
EXPECT_TIMELY (5s, nano::test::confirm (node, { latest }));
EXPECT_TIMELY (5s, nano::test::confirmed (node, { latest }));

return blocks;
}
}

/*
* Ensures we limit the number of vote hinted elections in AEC
*/
Expand All @@ -1513,10 +1426,10 @@ TEST (active_transactions, limit_vote_hinted_elections)
// Setup representatives
// Enough weight to trigger election hinting but not enough to confirm block on its own
const auto amount = ((node.online_reps.trended () / 100) * node.config.election_hint_weight_percent) + 1000 * nano::Gxrb_ratio;
nano::keypair rep1 = setup_rep (system, node, amount / 2);
nano::keypair rep2 = setup_rep (system, node, amount / 2);
nano::keypair rep1 = nano::test::setup_rep (system, node, amount / 2);
nano::keypair rep2 = nano::test::setup_rep (system, node, amount / 2);

auto blocks = setup_independent_blocks (system, node, 2);
auto blocks = nano::test::setup_independent_blocks (system, node, 2);
auto open0 = blocks[0];
auto open1 = blocks[1];

Expand Down Expand Up @@ -1575,7 +1488,7 @@ TEST (active_transactions, allow_limited_overflow)
config.active_elections_hinted_limit_percentage = 20; // Should give us a limit of 4 hinted elections
auto & node = *system.add_node (config);

auto blocks = setup_independent_blocks (system, node, aec_limit * 4);
auto blocks = nano::test::setup_independent_blocks (system, node, aec_limit * 4);

// Split blocks in two halves
std::vector<std::shared_ptr<nano::block>> blocks1 (blocks.begin (), blocks.begin () + blocks.size () / 2);
Expand Down Expand Up @@ -1624,7 +1537,7 @@ TEST (active_transactions, allow_limited_overflow_adapt)
config.active_elections_hinted_limit_percentage = 20; // Should give us a limit of 4 hinted elections
auto & node = *system.add_node (config);

auto blocks = setup_independent_blocks (system, node, aec_limit * 4);
auto blocks = nano::test::setup_independent_blocks (system, node, aec_limit * 4);

// Split blocks in two halves
std::vector<std::shared_ptr<nano::block>> blocks1 (blocks.begin (), blocks.begin () + blocks.size () / 2);
Expand Down
63 changes: 3 additions & 60 deletions nano/core_test/backlog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <nano/node/active_transactions.hpp>
#include <nano/test_common/chains.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand All @@ -8,72 +9,14 @@

using namespace std::chrono_literals;

namespace
{
using block_list_t = std::vector<std::shared_ptr<nano::block>>;

/*
* Creates `count` 1 raw sends from genesis to unique accounts and corresponding open blocks.
* The genesis chain is then confirmed, but leaves open blocks unconfirmed
* The list of unconfirmed open blocks is returned.
*/
block_list_t setup_independent_blocks (nano::test::system & system, nano::node & node, int count)
{
std::vector<std::shared_ptr<nano::block>> blocks;

auto latest = node.latest (nano::dev::genesis_key.pub);
auto balance = node.balance (nano::dev::genesis_key.pub);

for (int n = 0; n < count; ++n)
{
nano::keypair key;
nano::block_builder builder;

balance -= 1;
auto send = builder
.state ()
.account (nano::dev::genesis_key.pub)
.previous (latest)
.representative (nano::dev::genesis_key.pub)
.balance (balance)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (latest))
.build_shared ();
latest = send->hash ();

auto open = builder
.state ()
.account (key.pub)
.previous (0)
.representative (key.pub)
.balance (1)
.link (send->hash ())
.sign (key.prv, key.pub)
.work (*system.work.generate (key.pub))
.build_shared ();

EXPECT_TRUE (nano::test::process (node, { send, open }));
EXPECT_TIMELY (5s, nano::test::exists (node, { send, open })); // Ensure blocks are in the ledger

blocks.push_back (open);
}

// Confirm whole genesis chain at once
EXPECT_TIMELY (5s, nano::test::confirm (node, { latest }));
EXPECT_TIMELY (5s, nano::test::confirmed (node, { latest }));

return blocks;
}
}

/*
* Ensures all not confirmed accounts get activated by backlog scan periodically
*/
TEST (backlog, population)
{
nano::mutex mutex;
std::unordered_set<nano::account> activated;

nano::test::system system{};
auto & node = *system.add_node ();

Expand All @@ -83,7 +26,7 @@ TEST (backlog, population)
activated.insert (account);
});

auto blocks = setup_independent_blocks (system, node, 256);
auto blocks = nano::test::setup_independent_blocks (system, node, 256);

// Checks if `activated` set contains all accounts we previously set up
auto all_activated = [&] () {
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,8 +1677,8 @@ namespace lmdb
nano::ledger ledger (store, stats, nano::dev::constants);
auto transaction (store.tx_begin_write ());
store.initialize (transaction, ledger.cache, nano::dev::constants);
nano::account_info account_info;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis->account (), account_info));
auto account_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (account_info);
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (),
confirmation_height_info));
Expand Down
Loading

0 comments on commit 1f608a3

Please sign in to comment.