Skip to content

Commit

Permalink
Merge pull request nanocurrency#1 from bbedward/master
Browse files Browse the repository at this point in the history
Merge in nano node v12 changes
  • Loading branch information
BananoCoin authored Apr 20, 2018
2 parents 954126a + 8d34221 commit 4537cdc
Show file tree
Hide file tree
Showing 34 changed files with 1,069 additions and 593 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required (VERSION 2.8.11)
project (rai)

set (CPACK_PACKAGE_VERSION_MAJOR "11")
set (CPACK_PACKAGE_VERSION_MINOR "2")
set (CPACK_PACKAGE_VERSION_MAJOR "12")
set (CPACK_PACKAGE_VERSION_MINOR "0")
set (CPACK_PACKAGE_VERSION_PATCH "0")
if (DEFINED GIT_COMMIT)
set (CPACK_PACKAGE_VERSION_PATCH "GIT-${GIT_COMMIT}")
Expand Down
6 changes: 2 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ clone_script:
- cmd: "git clone -q --branch=%APPVEYOR_REPO_BRANCH% https://github.com/%APPVEYOR_REPO_NAME%.git %APPVEYOR_BUILD_FOLDER% \ncd %APPVEYOR_BUILD_FOLDER%\ngit checkout -q %APPVEYOR_REPO_COMMIT%\ngit submodule update --init --recursive"
install:
- cmd: >-
SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT:~0,7%
copy /Y FindBoost.cmake "C:/Program Files (x86)/CMake/share/cmake-3.10/Modules/FindBoost.cmake"
SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT:~0,3%
cmake -DBANANO_GUI=ON -DQt5_DIR=C:\Qt\5.9.4\msvc2015_64\lib\cmake\Qt5 -DBANANO_SIMD_OPTIMIZATIONS=TRUE -DBOOST_INCLUDEDIR=C:/Libraries/boost_1_66_0 -DBOOST_LIBRARYDIR=C:/Libraries/boost_1_66_0/lib64-msvc-14.0 -G "Visual Studio 14 2015 Win64" -DIPHLPAPI_LIBRARY="C:/Program Files (x86)/Windows Kits/10/Lib/10.0.14393.0/um/x64/iphlpapi.lib" -DWINSOCK2_LIBRARY="C:/Program Files (x86)/Windows Kits/10/Lib/10.0.14393.0/um/x64/WS2_32.lib" -DGIT_COMMIT=%GIT_COMMIT%
Expand Down Expand Up @@ -43,4 +41,4 @@ artifacts:
- path: nano.zip
name: nano_release
- path: Banano_Installer-*.exe
name: Banano_installer
name: Banano_installer
159 changes: 0 additions & 159 deletions banano/bananode/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,106 +7,6 @@
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>

class xorshift128
{
public:
uint64_t s[2];

uint64_t next (void)
{
uint64_t s1 = s[0];
const uint64_t s0 = s[1];
s[0] = s0;
s1 ^= s1 << 23; // a
return (s[1] = (s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26))) + s0; // b, c
}
};

class xorshift1024
{
public:
uint64_t s[16];
int p;

uint64_t next (void)
{
uint64_t s0 = s[p];
uint64_t s1 = s[p = (p + 1) & 15];
s1 ^= s1 << 31; // a
s1 ^= s1 >> 11; // b
s0 ^= s0 >> 30; // c
return (s[p] = s0 ^ s1) * 1181783497276652981LL;
}
};

void fill_128_reference (void * data)
{
xorshift128 rng;
rng.s[0] = 1;
rng.s[1] = 0;
for (auto i (reinterpret_cast<uint64_t *> (data)), n (reinterpret_cast<uint64_t *> (data) + 1024 * 1024); i != n; ++i)
{
*i = rng.next ();
}
}

#if 0
void fill_128_sse (void * data)
{
xorshift128 rng;
rng.s [0] = 1;
rng.s [1] = 0;
for (auto i (reinterpret_cast <__m128i *> (data)), n (reinterpret_cast <__m128i *> (data) + 512 * 1024); i != n; ++i)
{
auto v0 (rng.next ());
auto v1 (rng.next ());
_mm_store_si128 (i, _mm_set_epi64x (v1, v0));
}
}
#endif // 0

void fill_1024_reference (void * data)
{
xorshift1024 rng;
rng.p = 0;
rng.s[0] = 1;
for (auto i (0u); i < 16; ++i)
{
rng.s[i] = 0;
}
for (auto i (reinterpret_cast<uint64_t *> (data)), n (reinterpret_cast<uint64_t *> (data) + 1024 * 1024); i != n; ++i)
{
*i = rng.next ();
}
}

#if 0
void fill_1024_sse (void * data)
{
xorshift1024 rng;
rng.p = 0;
rng.s [0] = 1;
for (auto i (0u); i < 16; ++i)
{
rng.s [i] = 0;
}
for (auto i (reinterpret_cast <__m128i *> (data)), n (reinterpret_cast <__m128i *> (data) + 512 * 1024); i != n; ++i)
{
auto v0 (rng.next ());
auto v1 (rng.next ());
_mm_store_si128 (i, _mm_set_epi64x (v1, v0));
}
}

void fill_zero (void * data)
{
for (auto i (reinterpret_cast <__m128i *> (data)), n (reinterpret_cast <__m128i *> (data) + 512 * 1024); i != n; ++i)
{
_mm_store_si128 (i, _mm_setzero_si128 ());
}
}
#endif // 0

int main (int argc, char * const * argv)
{
boost::program_options::options_description description ("Command line options");
Expand All @@ -128,7 +28,6 @@ int main (int argc, char * const * argv)
("debug_profile_kdf", "Profile kdf function")
("debug_verify_profile", "Profile signature verification")
("debug_profile_sign", "Profile signature generation")
("debug_xorshift_profile", "Profile xorshift algorithms")
("platform", boost::program_options::value<std::string> (), "Defines the <platform> for OpenCL commands")
("device", boost::program_options::value<std::string> (), "Defines <device> for OpenCL command")
("threads", boost::program_options::value<std::string> (), "Defines <threads> count for OpenCL command");
Expand Down Expand Up @@ -222,7 +121,6 @@ int main (int argc, char * const * argv)
std::map<rai::account, rai::uint128_t> calculated;
for (auto i (node.node->store.latest_begin (transaction)), n (node.node->store.latest_end ()); i != n; ++i)
{
rai::account account (i->first.uint256 ());
rai::account_info info (i->second);
rai::block_hash rep_block (node.node->ledger.representative_calculated (transaction, info.head));
std::unique_ptr<rai::block> block (node.node->store.block_get (transaction, rep_block));
Expand Down Expand Up @@ -419,63 +317,6 @@ int main (int argc, char * const * argv)
{
std::cout << "Version " << BANANO_VERSION_MAJOR << "." << BANANO_VERSION_MINOR << std::endl;
}
#if 0
else if (vm.count ("debug_xorshift_profile"))
{
auto unaligned (new uint8_t [64 * 1024 * 1024 + 16]);
auto aligned (reinterpret_cast <void *> (reinterpret_cast <uintptr_t> (unaligned) & ~uintptr_t (0xfu)));
{
memset (aligned, 0x0, 64 * 1024 * 1024);
auto begin (std::chrono::high_resolution_clock::now ());
for (auto i (0u); i < 1000; ++i)
{
fill_zero (aligned);
}
auto end (std::chrono::high_resolution_clock::now ());
std::cerr << "Memset " << std::chrono::duration_cast <std::chrono::microseconds> (end - begin).count () << std::endl;
}
{
memset (aligned, 0x0, 64 * 1024 * 1024);
auto begin (std::chrono::high_resolution_clock::now ());
for (auto i (0u); i < 1000; ++i)
{
fill_128_reference (aligned);
}
auto end (std::chrono::high_resolution_clock::now ());
std::cerr << "Ref fill 128 " << std::chrono::duration_cast <std::chrono::microseconds> (end - begin).count () << std::endl;
}
{
memset (aligned, 0x0, 64 * 1024 * 1024);
auto begin (std::chrono::high_resolution_clock::now ());
for (auto i (0u); i < 1000; ++i)
{
fill_1024_reference (aligned);
}
auto end (std::chrono::high_resolution_clock::now ());
std::cerr << "Ref fill 1024 " << std::chrono::duration_cast <std::chrono::microseconds> (end - begin).count () << std::endl;
}
{
memset (aligned, 0x0, 64 * 1024 * 1024);
auto begin (std::chrono::high_resolution_clock::now ());
for (auto i (0u); i < 1000; ++i)
{
fill_128_sse (aligned);
}
auto end (std::chrono::high_resolution_clock::now ());
std::cerr << "SSE fill 128 " << std::chrono::duration_cast <std::chrono::microseconds> (end - begin).count () << std::endl;
}
{
memset (aligned, 0x0, 64 * 1024 * 1024);
auto begin (std::chrono::high_resolution_clock::now ());
for (auto i (0u); i < 1000; ++i)
{
fill_1024_sse (aligned);
}
auto end (std::chrono::high_resolution_clock::now ());
std::cerr << "SSE fill 1024 " << std::chrono::duration_cast <std::chrono::microseconds> (end - begin).count () << std::endl;
}
}
#endif // 0
else
{
std::cout << description << std::endl;
Expand Down
1 change: 0 additions & 1 deletion banano/blockstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ void rai::block_store::upgrade_v4_to_v5 (MDB_txn * transaction_a)
version_put (transaction_a, 5);
for (auto i (latest_begin (transaction_a)), n (latest_end ()); i != n; ++i)
{
rai::account account (i->first.uint256 ());
rai::account_info_v5 info (i->second);
rai::block_hash successor (0);
auto block (block_get (transaction_a, info.head));
Expand Down
59 changes: 38 additions & 21 deletions banano/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ rai::tally_result rai::votes::vote (std::shared_ptr<rai::vote> vote_a)
return result;
}

bool rai::votes::uncontested ()
{
bool result (true);
if (!rep_votes.empty ())
{
auto block (rep_votes.begin ()->second);
for (auto i (rep_votes.begin ()), n (rep_votes.end ()); result && i != n; ++i)
{
result = *i->second == *block;
}
}
return result;
}

// Create a new random keypair
rai::keypair::keypair ()
{
Expand Down Expand Up @@ -421,22 +435,24 @@ void rai::amount_visitor::send_block (rai::send_block const & block_a)
balance_visitor prev (transaction, store);
prev.compute (block_a.hashables.previous);
result = prev.result - block_a.hashables.balance.number ();
current = 0;
}

void rai::amount_visitor::receive_block (rai::receive_block const & block_a)
{
from_send (block_a.hashables.source);
current = block_a.hashables.source;
}

void rai::amount_visitor::open_block (rai::open_block const & block_a)
{
if (block_a.hashables.source != rai::genesis_account)
{
from_send (block_a.hashables.source);
current = block_a.hashables.source;
}
else
{
result = rai::genesis_amount;
current = 0;
}
}

Expand All @@ -446,37 +462,38 @@ void rai::amount_visitor::state_block (rai::state_block const & block_a)
prev.compute (block_a.hashables.previous);
result = block_a.hashables.balance.number ();
result = result < prev.result ? prev.result - result : result - prev.result;
current = 0;
}

void rai::amount_visitor::change_block (rai::change_block const & block_a)
{
result = 0;
}

void rai::amount_visitor::from_send (rai::block_hash const & hash_a)
{
auto source_block (store.block_get (transaction, hash_a));
assert (source_block != nullptr);
source_block->visit (*this);
current = 0;
}

void rai::amount_visitor::compute (rai::block_hash const & block_hash)
{
auto block (store.block_get (transaction, block_hash));
if (block != nullptr)
{
block->visit (*this);
}
else
current = block_hash;
while (!current.is_zero ())
{
if (block_hash == rai::genesis_account)
auto block (store.block_get (transaction, current));
if (block != nullptr)
{
result = std::numeric_limits<rai::uint128_t>::max ();
block->visit (*this);
}
else
{
assert (false);
result = 0;
if (block_hash == rai::genesis_account)
{
result = std::numeric_limits<rai::uint128_t>::max ();
current = 0;
}
else
{
assert (false);
result = 0;
current = 0;
}
}
}
}
Expand All @@ -497,8 +514,6 @@ void rai::balance_visitor::send_block (rai::send_block const & block_a)

void rai::balance_visitor::receive_block (rai::receive_block const & block_a)
{
amount_visitor source (transaction, store);
source.compute (block_a.hashables.source);
rai::block_info block_info;
if (!store.block_info_get (transaction, block_a.hash (), block_info))
{
Expand All @@ -507,6 +522,8 @@ void rai::balance_visitor::receive_block (rai::receive_block const & block_a)
}
else
{
amount_visitor source (transaction, store);
source.compute (block_a.hashables.source);
result += source.result;
current = block_a.hashables.previous;
}
Expand Down
5 changes: 5 additions & 0 deletions banano/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct hash<rai::uint256_union>
}
namespace rai
{
const uint8_t protocol_version = 0x08;
const uint8_t protocol_version_min = 0x07;

class block_store;
/**
* Determine the balance as of this block
Expand Down Expand Up @@ -61,6 +64,7 @@ class amount_visitor : public rai::block_visitor
void from_send (rai::block_hash const &);
MDB_txn * transaction;
rai::block_store & store;
rai::block_hash current;
rai::uint128_t result;
};

Expand Down Expand Up @@ -248,6 +252,7 @@ class votes
public:
votes (std::shared_ptr<rai::block>);
rai::tally_result vote (std::shared_ptr<rai::vote>);
bool uncontested ();
// Root block of fork
rai::block_hash id;
// All votes received by account
Expand Down
12 changes: 12 additions & 0 deletions banano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@ TEST (conflicts, add_two)
}
ASSERT_EQ (2, node1.active.roots.size ());
}

TEST (votes, contested)
{
rai::genesis genesis;
auto block1 (std::make_shared<rai::state_block> (rai::test_genesis_key.pub, genesis.hash (), rai::test_genesis_key.pub, rai::genesis_amount - rai::kBAN_ratio, rai::test_genesis_key.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
auto block2 (std::make_shared<rai::state_block> (rai::test_genesis_key.pub, genesis.hash (), rai::test_genesis_key.pub, rai::genesis_amount - 2 * rai::kBAN_ratio, rai::test_genesis_key.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
ASSERT_FALSE (*block1 == *block2);
rai::votes votes (block1);
ASSERT_TRUE (votes.uncontested ());
votes.rep_votes[rai::test_genesis_key.pub] = block2;
ASSERT_FALSE (votes.uncontested ());
}
Loading

0 comments on commit 4537cdc

Please sign in to comment.