Merge pull request #408 from lukealonso/tabs

Spaces -> tabs.
This commit is contained in:
androm3da 2018-01-05 19:50:56 -06:00 committed by GitHub
commit daa6e153d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 4449 additions and 4449 deletions

View file

@ -25,13 +25,13 @@ if (WIN32)
set (BLAKE2_IMPLEMENTATION "blake2/blake2b.c")
else (WIN32)
set (PLATFORM_COMPILE_FLAGS "-DBOOST_SPIRIT_THREADSAFE -Werror=switch -fPIC")
if (RAIBLOCKS_ASAN)
set (PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -fsanitize=address,undefined -DED25519_NO_INLINE_ASM")
elseif (RAIBLOCKS_ASAN_INT)
set (PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -fsanitize=address,undefined,integer -DED25519_NO_INLINE_ASM")
elseif (RAIBLOCKS_TSAN)
set (PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -fsanitize=thread -DED25519_NO_INLINE_ASM")
endif()
if (RAIBLOCKS_ASAN)
set (PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -fsanitize=address,undefined -DED25519_NO_INLINE_ASM")
elseif (RAIBLOCKS_ASAN_INT)
set (PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -fsanitize=address,undefined,integer -DED25519_NO_INLINE_ASM")
elseif (RAIBLOCKS_TSAN)
set (PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -fsanitize=thread -DED25519_NO_INLINE_ASM")
endif()
IF (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86(_64)?)$")
if (RAIBLOCKS_SIMD_OPTIMIZATIONS)
@ -78,13 +78,13 @@ elseif (WIN32)
set (PLATFORM_LINK_FLAGS "")
else ()
set (PLATFORM_LINK_FLAGS "-static-libgcc -static-libstdc++")
if (RAIBLOCKS_ASAN)
set (PLATFORM_LINK_FLAGS "${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined")
elseif (RAIBLOCKS_ASAN_INT)
set (PLATFORM_LINK_FLAGS "${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined,integer")
elseif (RAIBLOCKS_TSAN)
set (PLATFORM_LINK_FLAGS "${PLATFORM_LINK_FLAGS} -fsanitize=thread")
endif()
if (RAIBLOCKS_ASAN)
set (PLATFORM_LINK_FLAGS "${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined")
elseif (RAIBLOCKS_ASAN_INT)
set (PLATFORM_LINK_FLAGS "${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined,integer")
elseif (RAIBLOCKS_TSAN)
set (PLATFORM_LINK_FLAGS "${PLATFORM_LINK_FLAGS} -fsanitize=thread")
endif()
endif (APPLE)
if (RAIBLOCKS_GUI)
@ -303,7 +303,7 @@ endif (RAIBLOCKS_TEST)
if (RAIBLOCKS_GUI)
qt5_add_resources(RES resources.qrc)
qt5_add_resources(RES resources.qrc)
add_library (qt

View file

@ -12,316 +12,316 @@
TEST (ed25519, signing)
{
rai::uint256_union prv (0);
rai::uint256_union pub;
ed25519_publickey (prv.bytes.data (), pub.bytes.data ());
rai::uint256_union message (0);
rai::uint512_union signature;
ed25519_sign (message.bytes.data (), sizeof (message.bytes), prv.bytes.data (), pub.bytes.data (), signature.bytes.data ());
auto valid1 (ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), pub.bytes.data (), signature.bytes.data ()));
ASSERT_EQ (0, valid1);
signature.bytes [32] ^= 0x1;
auto valid2 (ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), pub.bytes.data (), signature.bytes.data ()));
ASSERT_NE (0, valid2);
rai::uint256_union prv (0);
rai::uint256_union pub;
ed25519_publickey (prv.bytes.data (), pub.bytes.data ());
rai::uint256_union message (0);
rai::uint512_union signature;
ed25519_sign (message.bytes.data (), sizeof (message.bytes), prv.bytes.data (), pub.bytes.data (), signature.bytes.data ());
auto valid1 (ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), pub.bytes.data (), signature.bytes.data ()));
ASSERT_EQ (0, valid1);
signature.bytes [32] ^= 0x1;
auto valid2 (ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), pub.bytes.data (), signature.bytes.data ()));
ASSERT_NE (0, valid2);
}
TEST (transaction_block, empty)
{
rai::keypair key1;
rai::send_block block (0, 1, 13, key1.prv, key1.pub, 2);
rai::uint256_union hash (block.hash ());
ASSERT_FALSE (rai::validate_message (key1.pub, hash, block.signature));
block.signature.bytes [32] ^= 0x1;
ASSERT_TRUE (rai::validate_message (key1.pub, hash, block.signature));
rai::keypair key1;
rai::send_block block (0, 1, 13, key1.prv, key1.pub, 2);
rai::uint256_union hash (block.hash ());
ASSERT_FALSE (rai::validate_message (key1.pub, hash, block.signature));
block.signature.bytes [32] ^= 0x1;
ASSERT_TRUE (rai::validate_message (key1.pub, hash, block.signature));
}
TEST (block, send_serialize)
{
rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
auto data (bytes.data ());
auto size (bytes.size ());
ASSERT_NE (nullptr, data);
ASSERT_NE (0, size);
rai::bufferstream stream2 (data, size);
rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
auto data (bytes.data ());
auto size (bytes.size ());
ASSERT_NE (nullptr, data);
ASSERT_NE (0, size);
rai::bufferstream stream2 (data, size);
bool error;
rai::send_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
rai::send_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
}
TEST (block, send_serialize_json)
{
rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
bool error;
rai::send_block block2 (error, tree1);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
rai::send_block block2 (error, tree1);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
}
TEST (block, receive_serialize)
{
rai::receive_block block1 (0, 1, rai::keypair ().prv, 3, 4);
rai::keypair key1;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
rai::bufferstream stream2 (bytes.data (), bytes.size ());
rai::receive_block block1 (0, 1, rai::keypair ().prv, 3, 4);
rai::keypair key1;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
rai::bufferstream stream2 (bytes.data (), bytes.size ());
bool error;
rai::receive_block block2 (error, stream2);
rai::receive_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
ASSERT_EQ (block1, block2);
}
TEST (block, receive_serialize_json)
{
rai::receive_block block1 (0, 1, rai::keypair ().prv, 3, 4);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
rai::receive_block block1 (0, 1, rai::keypair ().prv, 3, 4);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
bool error;
rai::receive_block block2 (error, tree1);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
rai::receive_block block2 (error, tree1);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
}
TEST (block, open_serialize_json)
{
rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
bool error;
rai::open_block block2 (error, tree1);
rai::open_block block2 (error, tree1);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
ASSERT_EQ (block1, block2);
}
TEST (block, change_serialize_json)
{
rai::change_block block1 (0, 1, rai::keypair ().prv, 3, 4);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
bool error;
rai::change_block block2 (error, tree1);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
rai::change_block block1 (0, 1, rai::keypair ().prv, 3, 4);
std::string string1;
block1.serialize_json (string1);
ASSERT_NE (0, string1.size ());
boost::property_tree::ptree tree1;
std::stringstream istream (string1);
boost::property_tree::read_json (istream, tree1);
bool error;
rai::change_block block2 (error, tree1);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
}
TEST (uint512_union, parse_zero)
{
rai::uint512_union input (rai::uint512_t (0));
std::string text;
input.encode_hex (text);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_TRUE (output.number ().is_zero ());
rai::uint512_union input (rai::uint512_t (0));
std::string text;
input.encode_hex (text);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_TRUE (output.number ().is_zero ());
}
TEST (uint512_union, parse_zero_short)
{
std::string text ("0");
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_TRUE (output.number ().is_zero ());
std::string text ("0");
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_TRUE (output.number ().is_zero ());
}
TEST (uint512_union, parse_one)
{
rai::uint512_union input (rai::uint512_t (1));
std::string text;
input.encode_hex (text);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (1, output.number ());
rai::uint512_union input (rai::uint512_t (1));
std::string text;
input.encode_hex (text);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (1, output.number ());
}
TEST (uint512_union, parse_error_symbol)
{
rai::uint512_union input (rai::uint512_t (1000));
std::string text;
input.encode_hex (text);
text [5] = '!';
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
rai::uint512_union input (rai::uint512_t (1000));
std::string text;
input.encode_hex (text);
text [5] = '!';
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
}
TEST (uint512_union, max)
{
rai::uint512_union input (std::numeric_limits <rai::uint512_t>::max ());
std::string text;
input.encode_hex (text);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (rai::uint512_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ());
rai::uint512_union input (std::numeric_limits <rai::uint512_t>::max ());
std::string text;
input.encode_hex (text);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (rai::uint512_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ());
}
TEST (uint512_union, parse_error_overflow)
{
rai::uint512_union input (std::numeric_limits <rai::uint512_t>::max ());
std::string text;
input.encode_hex (text);
text.push_back (0);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
rai::uint512_union input (std::numeric_limits <rai::uint512_t>::max ());
std::string text;
input.encode_hex (text);
text.push_back (0);
rai::uint512_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
}
TEST (send_block, deserialize)
{
rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5);
rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5);
ASSERT_EQ (block1.hash (), block1.hash ());
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
ASSERT_EQ (rai::send_block::size, bytes.size ());
rai::bufferstream stream2 (bytes.data (), bytes.size ());
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
ASSERT_EQ (rai::send_block::size, bytes.size ());
rai::bufferstream stream2 (bytes.data (), bytes.size ());
bool error;
rai::send_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
rai::send_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
}
TEST (receive_block, deserialize)
{
rai::receive_block block1 (0, 1, rai::keypair ().prv, 3, 4);
rai::receive_block block1 (0, 1, rai::keypair ().prv, 3, 4);
ASSERT_EQ (block1.hash (), block1.hash ());
block1.hashables.previous = 2;
block1.hashables.source = 4;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
ASSERT_EQ (rai::receive_block::size, bytes.size ());
rai::bufferstream stream2 (bytes.data (), bytes.size ());
block1.hashables.previous = 2;
block1.hashables.source = 4;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
ASSERT_EQ (rai::receive_block::size, bytes.size ());
rai::bufferstream stream2 (bytes.data (), bytes.size ());
bool error;
rai::receive_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
rai::receive_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
}
TEST (open_block, deserialize)
{
rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0);
ASSERT_EQ (block1.hash (), block1.hash ());
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
block1.serialize (stream);
}
ASSERT_EQ (rai::open_block::size, bytes.size ());
rai::bufferstream stream (bytes.data (), bytes.size ());
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
block1.serialize (stream);
}
ASSERT_EQ (rai::open_block::size, bytes.size ());
rai::bufferstream stream (bytes.data (), bytes.size ());
bool error;
rai::open_block block2 (error, stream);
rai::open_block block2 (error, stream);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
ASSERT_EQ (block1, block2);
}
TEST (change_block, deserialize)
{
rai::change_block block1 (1, 2, rai::keypair ().prv, 4, 5);
rai::change_block block1 (1, 2, rai::keypair ().prv, 4, 5);
ASSERT_EQ (block1.hash (), block1.hash ());
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
ASSERT_EQ (rai::change_block::size, bytes.size ());
auto data (bytes.data ());
auto size (bytes.size ());
ASSERT_NE (nullptr, data);
ASSERT_NE (0, size);
rai::bufferstream stream2 (data, size);
bool error;
rai::change_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
block1.serialize (stream1);
}
ASSERT_EQ (rai::change_block::size, bytes.size ());
auto data (bytes.data ());
auto size (bytes.size ());
ASSERT_NE (nullptr, data);
ASSERT_NE (0, size);
rai::bufferstream stream2 (data, size);
bool error;
rai::change_block block2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (block1, block2);
}
TEST (frontier_req, serialization)
{
rai::frontier_req request1;
request1.start = 1;
request1.age = 2;
request1.count = 3;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
request1.serialize (stream);
}
rai::bufferstream buffer (bytes.data (), bytes.size ());
rai::frontier_req request2;
ASSERT_FALSE (request2.deserialize (buffer));
ASSERT_EQ (request1, request2);
rai::frontier_req request1;
request1.start = 1;
request1.age = 2;
request1.count = 3;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
request1.serialize (stream);
}
rai::bufferstream buffer (bytes.data (), bytes.size ());
rai::frontier_req request2;
ASSERT_FALSE (request2.deserialize (buffer));
ASSERT_EQ (request1, request2);
}
TEST (block, publish_req_serialization)
{
rai::keypair key1;
rai::keypair key2;
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3)));
rai::publish req (std::move (block));
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
req.serialize (stream);
}
rai::publish req2;
rai::bufferstream stream2 (bytes.data (), bytes.size ());
auto error (req2.deserialize (stream2));
ASSERT_FALSE (error);
ASSERT_EQ (req, req2);
ASSERT_EQ (*req.block, *req2.block);
rai::keypair key1;
rai::keypair key2;
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3)));
rai::publish req (std::move (block));
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
req.serialize (stream);
}
rai::publish req2;
rai::bufferstream stream2 (bytes.data (), bytes.size ());
auto error (req2.deserialize (stream2));
ASSERT_FALSE (error);
ASSERT_EQ (req, req2);
ASSERT_EQ (*req.block, *req2.block);
}
TEST (block, confirm_req_serialization)
{
rai::keypair key1;
rai::keypair key2;
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3)));
rai::confirm_req req (std::move (block));
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
req.serialize (stream);
}
rai::confirm_req req2;
rai::bufferstream stream2 (bytes.data (), bytes.size ());
auto error (req2.deserialize (stream2));
ASSERT_FALSE (error);
ASSERT_EQ (req, req2);
ASSERT_EQ (*req.block, *req2.block);
rai::keypair key1;
rai::keypair key2;
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3)));
rai::confirm_req req (std::move (block));
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
req.serialize (stream);
}
rai::confirm_req req2;
rai::bufferstream stream2 (bytes.data (), bytes.size ());
auto error (req2.deserialize (stream2));
ASSERT_FALSE (error);
ASSERT_EQ (req, req2);
ASSERT_EQ (*req.block, *req2.block);
}

View file

@ -6,29 +6,29 @@
TEST (block_store, construction)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
auto now (store.now ());
ASSERT_GT (now, 1408074640);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
auto now (store.now ());
ASSERT_GT (now, 1408074640);
}
TEST (block_store, add_item)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::open_block block (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::open_block block (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
rai::transaction transaction (store.environment, nullptr, true);
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
ASSERT_FALSE (store.block_exists (transaction, hash1));
store.block_put (transaction, hash1, block);
auto latest2 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest2);
ASSERT_EQ (block, *latest2);
ASSERT_TRUE (store.block_exists (transaction, hash1));
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
ASSERT_FALSE (store.block_exists (transaction, hash1));
store.block_put (transaction, hash1, block);
auto latest2 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest2);
ASSERT_EQ (block, *latest2);
ASSERT_TRUE (store.block_exists (transaction, hash1));
ASSERT_FALSE (store.block_exists (transaction, hash1.number () - 1));
store.block_del (transaction, hash1);
auto latest3 (store.block_get (transaction, hash1));
@ -37,124 +37,124 @@ TEST (block_store, add_item)
TEST (block_store, add_nonempty_block)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::open_block block (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
block.signature = rai::sign_message (key1.prv, key1.pub, hash1);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::open_block block (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
block.signature = rai::sign_message (key1.prv, key1.pub, hash1);
rai::transaction transaction (store.environment, nullptr, true);
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
store.block_put (transaction, hash1, block);
auto latest2 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest2);
ASSERT_EQ (block, *latest2);
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
store.block_put (transaction, hash1, block);
auto latest2 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest2);
ASSERT_EQ (block, *latest2);
}
TEST (block_store, add_two_items)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::open_block block (0, 1, 1, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
block.signature = rai::sign_message (key1.prv, key1.pub, hash1);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::open_block block (0, 1, 1, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
block.signature = rai::sign_message (key1.prv, key1.pub, hash1);
rai::transaction transaction (store.environment, nullptr, true);
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
rai::open_block block2 (0, 1, 3, rai::keypair ().prv, 0, 0);
block2.hashables.account = 3;
rai::uint256_union hash2 (block2.hash ());
block2.signature = rai::sign_message (key1.prv, key1.pub, hash2);
auto latest2 (store.block_get (transaction, hash2));
ASSERT_EQ (nullptr, latest2);
store.block_put (transaction, hash1, block);
store.block_put (transaction, hash2, block2);
auto latest3 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest3);
ASSERT_EQ (block, *latest3);
auto latest4 (store.block_get (transaction, hash2));
ASSERT_NE (nullptr, latest4);
ASSERT_EQ (block2, *latest4);
ASSERT_FALSE (*latest3 == *latest4);
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
rai::open_block block2 (0, 1, 3, rai::keypair ().prv, 0, 0);
block2.hashables.account = 3;
rai::uint256_union hash2 (block2.hash ());
block2.signature = rai::sign_message (key1.prv, key1.pub, hash2);
auto latest2 (store.block_get (transaction, hash2));
ASSERT_EQ (nullptr, latest2);
store.block_put (transaction, hash1, block);
store.block_put (transaction, hash2, block2);
auto latest3 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest3);
ASSERT_EQ (block, *latest3);
auto latest4 (store.block_get (transaction, hash2));
ASSERT_NE (nullptr, latest4);
ASSERT_EQ (block2, *latest4);
ASSERT_FALSE (*latest3 == *latest4);
}
TEST (block_store, add_receive)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::keypair key2;
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::keypair key2;
rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::transaction transaction (store.environment, nullptr, true);
store.block_put (transaction, block1.hash (), block1);
rai::receive_block block (block1.hash (), 1, rai::keypair ().prv, 2, 3);
rai::block_hash hash1 (block.hash ());
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
store.block_put (transaction, hash1, block);
auto latest2 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest2);
ASSERT_EQ (block, *latest2);
rai::receive_block block (block1.hash (), 1, rai::keypair ().prv, 2, 3);
rai::block_hash hash1 (block.hash ());
auto latest1 (store.block_get (transaction, hash1));
ASSERT_EQ (nullptr, latest1);
store.block_put (transaction, hash1, block);
auto latest2 (store.block_get (transaction, hash1));
ASSERT_NE (nullptr, latest2);
ASSERT_EQ (block, *latest2);
}
TEST (block_store, add_pending)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::pending_key key2 (0, 0);
rai::pending_info pending1;
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::pending_key key2 (0, 0);
rai::pending_info pending1;
rai::transaction transaction (store.environment, nullptr, true);
ASSERT_TRUE (store.pending_get (transaction, key2, pending1));
store.pending_put (transaction, key2, pending1);
rai::pending_info pending2;
ASSERT_FALSE (store.pending_get (transaction, key2, pending2));
ASSERT_EQ (pending1, pending2);
store.pending_del (transaction, key2);
ASSERT_TRUE (store.pending_get (transaction, key2, pending2));
ASSERT_TRUE (store.pending_get (transaction, key2, pending1));
store.pending_put (transaction, key2, pending1);
rai::pending_info pending2;
ASSERT_FALSE (store.pending_get (transaction, key2, pending2));
ASSERT_EQ (pending1, pending2);
store.pending_del (transaction, key2);
ASSERT_TRUE (store.pending_get (transaction, key2, pending2));
}
TEST (block_store, pending_iterator)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::transaction transaction (store.environment, nullptr, true);
ASSERT_EQ (store.pending_end (), store.pending_begin (transaction));
store.pending_put (transaction, rai::pending_key (1, 2), {2, 3});
auto current (store.pending_begin (transaction));
ASSERT_NE (store.pending_end (), current);
ASSERT_EQ (store.pending_end (), store.pending_begin (transaction));
store.pending_put (transaction, rai::pending_key (1, 2), {2, 3});
auto current (store.pending_begin (transaction));
ASSERT_NE (store.pending_end (), current);
rai::pending_key key1 (current->first);
ASSERT_EQ (rai::account (1), key1.account);
ASSERT_EQ (rai::block_hash (2), key1.hash);
ASSERT_EQ (rai::account (1), key1.account);
ASSERT_EQ (rai::block_hash (2), key1.hash);
rai::pending_info pending (current->second);
ASSERT_EQ (rai::account (2), pending.source);
ASSERT_EQ (rai::amount (3), pending.amount);
ASSERT_EQ (rai::account (2), pending.source);
ASSERT_EQ (rai::amount (3), pending.amount);
}
TEST (block_store, genesis)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::genesis genesis;
auto hash (genesis.hash ());
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::genesis genesis;
auto hash (genesis.hash ());
rai::transaction transaction (store.environment, nullptr, true);
genesis.initialize (transaction, store);
rai::account_info info;
ASSERT_FALSE (store.account_get (transaction, rai::genesis_account, info));
genesis.initialize (transaction, store);
rai::account_info info;
ASSERT_FALSE (store.account_get (transaction, rai::genesis_account, info));
ASSERT_EQ (hash, info.head);
auto block1 (store.block_get (transaction, info.head));
ASSERT_NE (nullptr, block1);
auto receive1 (dynamic_cast <rai::open_block *> (block1.get ()));
ASSERT_NE (nullptr, receive1);
ASSERT_LE (info.modified, store.now ());
auto block1 (store.block_get (transaction, info.head));
ASSERT_NE (nullptr, block1);
auto receive1 (dynamic_cast <rai::open_block *> (block1.get ()));
ASSERT_NE (nullptr, receive1);
ASSERT_LE (info.modified, store.now ());
auto test_pub_text (rai::test_genesis_key.pub.to_string ());
auto test_pub_account (rai::test_genesis_key.pub.to_account ());
auto test_prv_text (rai::test_genesis_key.prv.data.to_string ());
@ -163,102 +163,102 @@ TEST (block_store, genesis)
TEST (representation, changes)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::transaction transaction (store.environment, nullptr, true);
ASSERT_EQ (0, store.representation_get (transaction, key1.pub));
store.representation_put (transaction, key1.pub, 1);
ASSERT_EQ (1, store.representation_get (transaction, key1.pub));
store.representation_put (transaction, key1.pub, 2);
ASSERT_EQ (2, store.representation_get (transaction, key1.pub));
ASSERT_EQ (0, store.representation_get (transaction, key1.pub));
store.representation_put (transaction, key1.pub, 1);
ASSERT_EQ (1, store.representation_get (transaction, key1.pub));
store.representation_put (transaction, key1.pub, 2);
ASSERT_EQ (2, store.representation_get (transaction, key1.pub));
}
TEST (bootstrap, simple)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
auto block1 (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
auto block1 (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
rai::transaction transaction (store.environment, nullptr, true);
auto block2 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_TRUE (block2.empty ());
store.unchecked_put (transaction, block1->previous (), block1);
auto block3 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_FALSE (block3.empty ());
ASSERT_EQ (*block1, *block3 [0]);
store.unchecked_del (transaction, block1->previous (), *block1);
auto block4 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_TRUE (block4.empty ());
auto block2 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_TRUE (block2.empty ());
store.unchecked_put (transaction, block1->previous (), block1);
auto block3 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_FALSE (block3.empty ());
ASSERT_EQ (*block1, *block3 [0]);
store.unchecked_del (transaction, block1->previous (), *block1);
auto block4 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_TRUE (block4.empty ());
}
TEST (unchecked, multiple)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
auto block1 (std::make_shared <rai::send_block> (4, 1, 2, rai::keypair ().prv, 4, 5));
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
auto block1 (std::make_shared <rai::send_block> (4, 1, 2, rai::keypair ().prv, 4, 5));
rai::transaction transaction (store.environment, nullptr, true);
auto block2 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_TRUE (block2.empty ());
store.unchecked_put (transaction, block1->previous (), block1);
store.unchecked_put (transaction, block1->source (), block1);
auto block3 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_FALSE (block3.empty ());
auto block2 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_TRUE (block2.empty ());
store.unchecked_put (transaction, block1->previous (), block1);
store.unchecked_put (transaction, block1->source (), block1);
auto block3 (store.unchecked_get (transaction, block1->previous ()));
ASSERT_FALSE (block3.empty ());
auto block4 (store.unchecked_get (transaction, block1->source ()));
ASSERT_FALSE (block4.empty ());
ASSERT_FALSE (block4.empty ());
}
TEST (checksum, simple)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::block_hash hash0 (0);
rai::transaction transaction (store.environment, nullptr, true);
ASSERT_TRUE (store.checksum_get (transaction, 0x100, 0x10, hash0));
rai::block_hash hash1 (0);
store.checksum_put (transaction, 0x100, 0x10, hash1);
rai::block_hash hash2;
ASSERT_FALSE (store.checksum_get (transaction, 0x100, 0x10, hash2));
ASSERT_EQ (hash1, hash2);
store.checksum_del (transaction, 0x100, 0x10);
rai::block_hash hash3;
ASSERT_TRUE (store.checksum_get (transaction, 0x100, 0x10, hash3));
ASSERT_TRUE (store.checksum_get (transaction, 0x100, 0x10, hash0));
rai::block_hash hash1 (0);
store.checksum_put (transaction, 0x100, 0x10, hash1);
rai::block_hash hash2;
ASSERT_FALSE (store.checksum_get (transaction, 0x100, 0x10, hash2));
ASSERT_EQ (hash1, hash2);
store.checksum_del (transaction, 0x100, 0x10);
rai::block_hash hash3;
ASSERT_TRUE (store.checksum_get (transaction, 0x100, 0x10, hash3));
}
TEST (block_store, empty_accounts)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::transaction transaction (store.environment, nullptr, false);
auto begin (store.latest_begin (transaction));
auto end (store.latest_end ());
ASSERT_EQ (end, begin);
auto begin (store.latest_begin (transaction));
auto end (store.latest_end ());
ASSERT_EQ (end, begin);
}
TEST (block_store, one_block)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::transaction transaction (store.environment, nullptr, true);
store.block_put (transaction, block1.hash (), block1);
store.block_put (transaction, block1.hash (), block1);
ASSERT_TRUE (store.block_exists (transaction, block1.hash ()));
}
TEST (block_store, empty_bootstrap)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::transaction transaction (store.environment, nullptr, false);
auto begin (store.unchecked_begin (transaction));
auto end (store.unchecked_end ());
ASSERT_EQ (end, begin);
auto begin (store.unchecked_begin (transaction));
auto end (store.unchecked_end ());
ASSERT_EQ (end, begin);
}
TEST (block_store, one_bootstrap)
@ -283,9 +283,9 @@ TEST (block_store, one_bootstrap)
TEST (block_store, unchecked_begin_search)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key0;
rai::send_block block1 (0, 1, 2, key0.prv, key0.pub, 3);
rai::send_block block2 (5, 6, 7, key0.prv, key0.pub, 8);
@ -532,8 +532,8 @@ TEST (block_store, large_iteration)
TEST (block_store, frontier)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::transaction transaction (store.environment, nullptr, true);
rai::block_hash hash (100);
@ -547,8 +547,8 @@ TEST (block_store, frontier)
TEST (block_store, block_replace)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::send_block send1 (0, 0, 0, rai::keypair ().prv, 0, 1);
rai::send_block send2 (0, 0, 0, rai::keypair ().prv, 0, 2);
@ -562,20 +562,20 @@ TEST (block_store, block_replace)
TEST (block_store, block_count)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
ASSERT_EQ (0, store.block_count (rai::transaction (store.environment, nullptr, false)).sum ());
rai::open_block block (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
store.block_put (rai::transaction (store.environment, nullptr, true), hash1, block);
rai::open_block block (0, 1, 0, rai::keypair ().prv, 0, 0);
rai::uint256_union hash1 (block.hash ());
store.block_put (rai::transaction (store.environment, nullptr, true), hash1, block);
ASSERT_EQ (1, store.block_count (rai::transaction (store.environment, nullptr, false)).sum ());
}
TEST (block_store, frontier_count)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
ASSERT_EQ (0, store.frontier_count (rai::transaction (store.environment, nullptr, false)));
rai::block_hash hash (100);
@ -586,8 +586,8 @@ TEST (block_store, frontier_count)
TEST (block_store, sequence_increment)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
rai::keypair key2;
@ -728,12 +728,12 @@ TEST (block_store, upgrade_v4_v5)
TEST (block_store, block_random)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::genesis genesis;
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::genesis genesis;
rai::transaction transaction (store.environment, nullptr, true);
genesis.initialize (transaction, store);
genesis.initialize (transaction, store);
auto block (store.block_random (transaction));
ASSERT_NE (nullptr, block);
ASSERT_EQ (*block, *genesis.open);
@ -741,9 +741,9 @@ TEST (block_store, block_random)
TEST (vote, validate)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::keypair key1;
auto send1 (std::make_shared <rai::send_block> (0, key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
auto vote1 (std::make_shared <rai::vote> (key1.pub, key1.prv, 2, send1));

View file

@ -3,75 +3,75 @@
TEST (conflicts, start_stop)
{
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
rai::genesis genesis;
rai::keypair key1;
auto send1 (std::make_shared <rai::send_block> (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
rai::genesis genesis;
rai::keypair key1;
auto send1 (std::make_shared <rai::send_block> (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
ASSERT_EQ (rai::process_result::progress, node1.process (*send1).code);
ASSERT_EQ (0, node1.active.roots.size ());
ASSERT_EQ (0, node1.active.roots.size ());
auto node_l (system.nodes [0]);
{
rai::transaction transaction (node1.store.environment, nullptr, true);
node1.active.start (transaction, send1);
}
ASSERT_EQ (1, node1.active.roots.size ());
auto root1 (send1->root ());
auto existing1 (node1.active.roots.find (root1));
ASSERT_NE (node1.active.roots.end (), existing1);
auto votes1 (existing1->election);
ASSERT_NE (nullptr, votes1);
ASSERT_EQ (1, votes1->votes.rep_votes.size ());
ASSERT_EQ (1, node1.active.roots.size ());
auto root1 (send1->root ());
auto existing1 (node1.active.roots.find (root1));
ASSERT_NE (node1.active.roots.end (), existing1);
auto votes1 (existing1->election);
ASSERT_NE (nullptr, votes1);
ASSERT_EQ (1, votes1->votes.rep_votes.size ());
}
TEST (conflicts, add_existing)
{
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
rai::genesis genesis;
rai::keypair key1;
auto send1 (std::make_shared <rai::send_block> (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
rai::genesis genesis;
rai::keypair key1;
auto send1 (std::make_shared <rai::send_block> (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
ASSERT_EQ (rai::process_result::progress, node1.process (*send1).code);
auto node_l (system.nodes [0]);
{
rai::transaction transaction (node1.store.environment, nullptr, true);
node1.active.start (transaction, send1);
}
rai::keypair key2;
auto send2 (std::make_shared <rai::send_block> (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
rai::keypair key2;
auto send2 (std::make_shared <rai::send_block> (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
{
rai::transaction transaction (node1.store.environment, nullptr, true);
node1.active.start (transaction, send2);
}
ASSERT_EQ (1, node1.active.roots.size ());
ASSERT_EQ (1, node1.active.roots.size ());
auto vote1 (std::make_shared <rai::vote> (key2.pub, key2.prv, 0, send2));
node1.active.vote (vote1);
ASSERT_EQ (1, node1.active.roots.size ());
auto votes1 (node1.active.roots.find (send2->root ())->election);
ASSERT_NE (nullptr, votes1);
ASSERT_EQ (2, votes1->votes.rep_votes.size ());
ASSERT_NE (votes1->votes.rep_votes.end (), votes1->votes.rep_votes.find (key2.pub));
node1.active.vote (vote1);
ASSERT_EQ (1, node1.active.roots.size ());
auto votes1 (node1.active.roots.find (send2->root ())->election);
ASSERT_NE (nullptr, votes1);
ASSERT_EQ (2, votes1->votes.rep_votes.size ());
ASSERT_NE (votes1->votes.rep_votes.end (), votes1->votes.rep_votes.find (key2.pub));
}
TEST (conflicts, add_two)
{
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
rai::genesis genesis;
rai::keypair key1;
auto send1 (std::make_shared <rai::send_block> (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
rai::genesis genesis;
rai::keypair key1;
auto send1 (std::make_shared <rai::send_block> (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
ASSERT_EQ (rai::process_result::progress, node1.process (*send1).code);
auto node_l (system.nodes [0]);
{
rai::transaction transaction (node1.store.environment, nullptr, true);
node1.active.start (transaction, send1);
}
rai::keypair key2;
auto send2 (std::make_shared <rai::send_block> (send1->hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
rai::keypair key2;
auto send2 (std::make_shared <rai::send_block> (send1->hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
ASSERT_EQ (rai::process_result::progress, node1.process (*send2).code);
{
rai::transaction transaction (node1.store.environment, nullptr, true);
node1.active.start (transaction, send2);
}
ASSERT_EQ (2, node1.active.roots.size ());
ASSERT_EQ (2, node1.active.roots.size ());
}

View file

@ -2,5 +2,5 @@
TEST (daemon, fork)
{
}

View file

@ -2,7 +2,7 @@
TEST (basic, basic)
{
ASSERT_TRUE (true);
ASSERT_TRUE (true);
}
TEST (asan, DISABLED_memory)

View file

@ -3,49 +3,49 @@
TEST (gap_cache, add_new)
{
rai::system system (24000, 1);
rai::gap_cache cache (*system.nodes [0]);
auto block1 (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
rai::system system (24000, 1);
rai::gap_cache cache (*system.nodes [0]);
auto block1 (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
cache.add (transaction, block1);
cache.add (transaction, block1);
}
TEST (gap_cache, add_existing)
{
rai::system system (24000, 1);
rai::gap_cache cache (*system.nodes [0]);
auto block1 (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
cache.add (transaction, block1);
auto existing1 (cache.blocks.get <1> ().find (block1->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing1);
auto arrival (existing1->arrival);
while (arrival == std::chrono::system_clock::now ());
cache.add (transaction, block1);
ASSERT_EQ (1, cache.blocks.size ());
auto existing2 (cache.blocks.get <1> ().find (block1->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing2);
ASSERT_GT (existing2->arrival, arrival);
rai::system system (24000, 1);
rai::gap_cache cache (*system.nodes [0]);
auto block1 (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
cache.add (transaction, block1);
auto existing1 (cache.blocks.get <1> ().find (block1->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing1);
auto arrival (existing1->arrival);
while (arrival == std::chrono::system_clock::now ());
cache.add (transaction, block1);
ASSERT_EQ (1, cache.blocks.size ());
auto existing2 (cache.blocks.get <1> ().find (block1->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing2);
ASSERT_GT (existing2->arrival, arrival);
}
TEST (gap_cache, comparison)
{
rai::system system (24000, 1);
rai::gap_cache cache (*system.nodes [0]);
auto block1 (std::make_shared <rai::send_block> (1, 0, 2, rai::keypair ().prv, 4, 5));
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
cache.add (transaction, block1);
auto existing1 (cache.blocks.get <1> ().find (block1->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing1);
auto arrival (existing1->arrival);
while (std::chrono::system_clock::now () == arrival);
auto block3 (std::make_shared <rai::send_block> (0, 42, 1, rai::keypair ().prv, 3, 4));
cache.add (transaction, block3);
ASSERT_EQ (2, cache.blocks.size ());
auto existing2 (cache.blocks.get <1> ().find (block3->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing2);
ASSERT_GT (existing2->arrival, arrival);
ASSERT_EQ (arrival, cache.blocks.get <1> ().begin ()->arrival);
rai::system system (24000, 1);
rai::gap_cache cache (*system.nodes [0]);
auto block1 (std::make_shared <rai::send_block> (1, 0, 2, rai::keypair ().prv, 4, 5));
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
cache.add (transaction, block1);
auto existing1 (cache.blocks.get <1> ().find (block1->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing1);
auto arrival (existing1->arrival);
while (std::chrono::system_clock::now () == arrival);
auto block3 (std::make_shared <rai::send_block> (0, 42, 1, rai::keypair ().prv, 3, 4));
cache.add (transaction, block3);
ASSERT_EQ (2, cache.blocks.size ());
auto existing2 (cache.blocks.get <1> ().find (block3->hash ()));
ASSERT_NE (cache.blocks.get <1> ().end (), existing2);
ASSERT_GT (existing2->arrival, arrival);
ASSERT_EQ (arrival, cache.blocks.get <1> ().begin ()->arrival);
}
TEST (gap_cache, gap_bootstrap)

View file

@ -528,37 +528,37 @@ TEST (ledger, DISABLED_checksum_range)
TEST (system, generate_send_existing)
{
rai::system system (24000, 1);
rai::system system (24000, 1);
rai::thread_runner runner (system.service, system.nodes [0]->config.io_threads);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::account_info info1;
rai::account_info info1;
{
rai::transaction transaction (system.wallet (0)->store.environment, nullptr, false);
ASSERT_FALSE (system.nodes [0]->store.account_get (transaction, rai::test_genesis_key.pub, info1));
}
std::vector <rai::account> accounts;
accounts.push_back (rai::test_genesis_key.pub);
system.generate_send_existing (*system.nodes [0], accounts);
rai::account_info info2;
system.generate_send_existing (*system.nodes [0], accounts);
rai::account_info info2;
{
rai::transaction transaction (system.wallet (0)->store.environment, nullptr, false);
ASSERT_FALSE (system.nodes [0]->store.account_get (transaction, rai::test_genesis_key.pub, info2));
}
ASSERT_NE (info1.head, info2.head);
auto iterations1 (0);
while (system.nodes [0]->balance (rai::test_genesis_key.pub) == rai::genesis_amount)
{
ASSERT_NE (info1.head, info2.head);
auto iterations1 (0);
while (system.nodes [0]->balance (rai::test_genesis_key.pub) == rai::genesis_amount)
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 20);
}
auto iterations2 (0);
while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount)
{
++iterations1;
ASSERT_LT (iterations1, 20);
}
auto iterations2 (0);
while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount)
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 20);
}
++iterations2;
ASSERT_LT (iterations2, 20);
}
system.stop ();
runner.join ();
}

View file

@ -4,88 +4,88 @@
TEST (message, keepalive_serialization)
{
rai::keepalive request1;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
request1.serialize (stream);
}
rai::keepalive request2;
rai::bufferstream buffer (bytes.data (), bytes.size ());
ASSERT_FALSE (request2.deserialize (buffer));
ASSERT_EQ (request1, request2);
rai::keepalive request1;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
request1.serialize (stream);
}
rai::keepalive request2;
rai::bufferstream buffer (bytes.data (), bytes.size ());
ASSERT_FALSE (request2.deserialize (buffer));
ASSERT_EQ (request1, request2);
}
TEST (message, keepalive_deserialize)
{
rai::keepalive message1;
message1.peers [0] = rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message1.serialize (stream);
}
uint8_t version_max;
uint8_t version_using;
uint8_t version_min;
rai::keepalive message1;
message1.peers [0] = rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message1.serialize (stream);
}
uint8_t version_max;
uint8_t version_using;
uint8_t version_min;
rai::message_type type;
std::bitset <16> extensions;
rai::bufferstream header_stream (bytes.data (), bytes.size ());
ASSERT_FALSE (rai::message::read_header (header_stream, version_max, version_using, version_min, type, extensions));
ASSERT_EQ (rai::message_type::keepalive, type);
rai::keepalive message2;
rai::bufferstream stream (bytes.data (), bytes.size ());
ASSERT_FALSE (message2.deserialize (stream));
ASSERT_EQ (message1.peers, message2.peers);
rai::bufferstream header_stream (bytes.data (), bytes.size ());
ASSERT_FALSE (rai::message::read_header (header_stream, version_max, version_using, version_min, type, extensions));
ASSERT_EQ (rai::message_type::keepalive, type);
rai::keepalive message2;
rai::bufferstream stream (bytes.data (), bytes.size ());
ASSERT_FALSE (message2.deserialize (stream));
ASSERT_EQ (message1.peers, message2.peers);
}
TEST (message, publish_serialization)
{
rai::publish publish (std::unique_ptr <rai::block> (new rai::send_block (0, 1, 2, rai::keypair ().prv, 4, 5)));
ASSERT_EQ (rai::block_type::send, publish.block_type ());
ASSERT_FALSE (publish.ipv4_only ());
publish.ipv4_only_set (true);
ASSERT_TRUE (publish.ipv4_only ());
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
publish.write_header (stream);
}
ASSERT_EQ (8, bytes.size ());
ASSERT_EQ (0x52, bytes [0]);
ASSERT_EQ (0x41, bytes [1]);
ASSERT_EQ (0x05, bytes [2]);
ASSERT_EQ (0x05, bytes [3]);
ASSERT_EQ (0x01, bytes [4]);
ASSERT_EQ (static_cast <uint8_t> (rai::message_type::publish), bytes [5]);
ASSERT_EQ (0x02, bytes [6]);
ASSERT_EQ (static_cast <uint8_t> (rai::block_type::send), bytes [7]);
rai::bufferstream stream (bytes.data (), bytes.size ());
uint8_t version_max;
uint8_t version_using;
uint8_t version_min;
rai::message_type type;
std::bitset <16> extensions;
ASSERT_FALSE (rai::message::read_header (stream, version_max, version_using, version_min, type, extensions));
ASSERT_EQ (0x01, version_min);
ASSERT_EQ (0x05, version_using);
ASSERT_EQ (0x05, version_max);
ASSERT_EQ (rai::message_type::publish, type);
rai::publish publish (std::unique_ptr <rai::block> (new rai::send_block (0, 1, 2, rai::keypair ().prv, 4, 5)));
ASSERT_EQ (rai::block_type::send, publish.block_type ());
ASSERT_FALSE (publish.ipv4_only ());
publish.ipv4_only_set (true);
ASSERT_TRUE (publish.ipv4_only ());
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
publish.write_header (stream);
}
ASSERT_EQ (8, bytes.size ());
ASSERT_EQ (0x52, bytes [0]);
ASSERT_EQ (0x41, bytes [1]);
ASSERT_EQ (0x05, bytes [2]);
ASSERT_EQ (0x05, bytes [3]);
ASSERT_EQ (0x01, bytes [4]);
ASSERT_EQ (static_cast <uint8_t> (rai::message_type::publish), bytes [5]);
ASSERT_EQ (0x02, bytes [6]);
ASSERT_EQ (static_cast <uint8_t> (rai::block_type::send), bytes [7]);
rai::bufferstream stream (bytes.data (), bytes.size ());
uint8_t version_max;
uint8_t version_using;
uint8_t version_min;
rai::message_type type;
std::bitset <16> extensions;
ASSERT_FALSE (rai::message::read_header (stream, version_max, version_using, version_min, type, extensions));
ASSERT_EQ (0x01, version_min);
ASSERT_EQ (0x05, version_using);
ASSERT_EQ (0x05, version_max);
ASSERT_EQ (rai::message_type::publish, type);
}
TEST (message, confirm_ack_serialization)
{
rai::keypair key1;
rai::keypair key1;
auto vote (std::make_shared <rai::vote> (key1.pub, key1.prv, 0, std::unique_ptr <rai::block> (new rai::send_block (0, 1, 2, key1.prv, 4, 5))));
rai::confirm_ack con1 (vote);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
con1.serialize (stream1);
}
rai::bufferstream stream2 (bytes.data (), bytes.size ());
rai::confirm_ack con1 (vote);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream1 (bytes);
con1.serialize (stream1);
}
rai::bufferstream stream2 (bytes.data (), bytes.size ());
bool error;
rai::confirm_ack con2 (error, stream2);
rai::confirm_ack con2 (error, stream2);
ASSERT_FALSE (error);
ASSERT_EQ (con1, con2);
ASSERT_EQ (con1, con2);
}

View file

@ -5,142 +5,142 @@ namespace {
class test_visitor : public rai::message_visitor
{
public:
test_visitor () :
keepalive_count (0),
publish_count (0),
confirm_req_count (0),
confirm_ack_count (0),
bulk_pull_count (0),
bulk_push_count (0),
frontier_req_count (0)
{
}
void keepalive (rai::keepalive const &)
{
++keepalive_count;
}
void publish (rai::publish const &)
{
++publish_count;
}
void confirm_req (rai::confirm_req const &)
{
++confirm_req_count;
}
void confirm_ack (rai::confirm_ack const &)
{
++confirm_ack_count;
}
void bulk_pull (rai::bulk_pull const &)
{
++bulk_pull_count;
}
void bulk_push (rai::bulk_push const &)
{
++bulk_push_count;
}
void frontier_req (rai::frontier_req const &)
{
++frontier_req_count;
}
uint64_t keepalive_count;
uint64_t publish_count;
uint64_t confirm_req_count;
uint64_t confirm_ack_count;
uint64_t bulk_pull_count;
uint64_t bulk_push_count;
uint64_t frontier_req_count;
test_visitor () :
keepalive_count (0),
publish_count (0),
confirm_req_count (0),
confirm_ack_count (0),
bulk_pull_count (0),
bulk_push_count (0),
frontier_req_count (0)
{
}
void keepalive (rai::keepalive const &)
{
++keepalive_count;
}
void publish (rai::publish const &)
{
++publish_count;
}
void confirm_req (rai::confirm_req const &)
{
++confirm_req_count;
}
void confirm_ack (rai::confirm_ack const &)
{
++confirm_ack_count;
}
void bulk_pull (rai::bulk_pull const &)
{
++bulk_pull_count;
}
void bulk_push (rai::bulk_push const &)
{
++bulk_push_count;
}
void frontier_req (rai::frontier_req const &)
{
++frontier_req_count;
}
uint64_t keepalive_count;
uint64_t publish_count;
uint64_t confirm_req_count;
uint64_t confirm_ack_count;
uint64_t bulk_pull_count;
uint64_t bulk_push_count;
uint64_t frontier_req_count;
};
}
TEST (message_parser, exact_confirm_ack_size)
{
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))));
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))));
auto vote (std::make_shared <rai::vote> (0, rai::keypair ().prv, 0, std::move (block)));
rai::confirm_ack message (vote);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.confirm_ack_count);
ASSERT_FALSE (parser.error);
parser.deserialize_confirm_ack (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_ack_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_confirm_ack (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_ack_count);
ASSERT_TRUE (parser.error);
rai::confirm_ack message (vote);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.confirm_ack_count);
ASSERT_FALSE (parser.error);
parser.deserialize_confirm_ack (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_ack_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_confirm_ack (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_ack_count);
ASSERT_TRUE (parser.error);
}
TEST (message_parser, exact_confirm_req_size)
{
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))));
rai::confirm_req message (std::move (block));
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.confirm_req_count);
ASSERT_FALSE (parser.error);
parser.deserialize_confirm_req (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_req_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_confirm_req (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_req_count);
ASSERT_TRUE (parser.error);
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))));
rai::confirm_req message (std::move (block));
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.confirm_req_count);
ASSERT_FALSE (parser.error);
parser.deserialize_confirm_req (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_req_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_confirm_req (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.confirm_req_count);
ASSERT_TRUE (parser.error);
}
TEST (message_parser, exact_publish_size)
{
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
auto block (std::unique_ptr <rai::send_block> (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))));
rai::publish message (std::move (block));
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.publish_count);
ASSERT_FALSE (parser.error);
parser.deserialize_publish (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.publish_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_publish (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.publish_count);
ASSERT_TRUE (parser.error);
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.publish_count);
ASSERT_FALSE (parser.error);
parser.deserialize_publish (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.publish_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_publish (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.publish_count);
ASSERT_TRUE (parser.error);
}
TEST (message_parser, exact_keepalive_size)
{
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
rai::keepalive message;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.keepalive_count);
ASSERT_FALSE (parser.error);
parser.deserialize_keepalive (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.keepalive_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_keepalive (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.keepalive_count);
ASSERT_TRUE (parser.error);
rai::system system (24000, 1);
test_visitor visitor;
rai::message_parser parser (visitor, system.work);
rai::keepalive message;
std::vector <uint8_t> bytes;
{
rai::vectorstream stream (bytes);
message.serialize (stream);
}
ASSERT_EQ (0, visitor.keepalive_count);
ASSERT_FALSE (parser.error);
parser.deserialize_keepalive (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.keepalive_count);
ASSERT_FALSE (parser.error);
bytes.push_back (0);
parser.deserialize_keepalive (bytes.data (), bytes.size ());
ASSERT_EQ (1, visitor.keepalive_count);
ASSERT_TRUE (parser.error);
}

File diff suppressed because it is too large Load diff

View file

@ -6,53 +6,53 @@
TEST (node, stop)
{
rai::system system (24000, 1);
ASSERT_NE (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.begin ());
system.nodes [0]->stop ();
system.service.run ();
ASSERT_TRUE (true);
rai::system system (24000, 1);
ASSERT_NE (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.begin ());
system.nodes [0]->stop ();
system.service.run ();
ASSERT_TRUE (true);
}
TEST (node, block_store_path_failure)
{
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::alarm alarm (*service);
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::alarm alarm (*service);
auto path (rai::unique_path ());
rai::logging logging;
logging.init (path);
rai::work_pool work (std::numeric_limits <unsigned>::max (), nullptr);
auto node (std::make_shared <rai::node> (init, *service, 0, path, alarm, logging, work));
auto node (std::make_shared <rai::node> (init, *service, 0, path, alarm, logging, work));
ASSERT_TRUE (node->wallets.items.empty ());
node->stop ();
node->stop ();
}
TEST (node, inactive_supply)
{
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::alarm alarm (*service);
auto path (rai::unique_path ());
rai::node_config config;
config.logging.init (path);
rai::work_pool work (std::numeric_limits <unsigned>::max (), nullptr);
config.inactive_supply = 10;
auto node (std::make_shared <rai::node> (init, *service, path, alarm, config, work));
auto node (std::make_shared <rai::node> (init, *service, path, alarm, config, work));
ASSERT_EQ (10, node->ledger.inactive_supply);
node->stop ();
}
TEST (node, password_fanout)
{
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::alarm alarm (*service);
auto path (rai::unique_path ());
rai::node_config config;
config.logging.init (path);
rai::work_pool work (std::numeric_limits <unsigned>::max (), nullptr);
config.password_fanout = 10;
auto node (std::make_shared <rai::node> (init, *service, path, alarm, config, work));
auto node (std::make_shared <rai::node> (init, *service, path, alarm, config, work));
auto wallet (node->wallets.create (100));
ASSERT_EQ (10, wallet->store.password.values.size ());
node->stop ();
@ -60,7 +60,7 @@ TEST (node, password_fanout)
TEST (node, balance)
{
rai::system system (24000, 1);
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max (), system.nodes [0]->ledger.account_balance (transaction, rai::test_genesis_key.pub));
@ -68,7 +68,7 @@ TEST (node, balance)
TEST (node, representative)
{
rai::system system (24000, 1);
rai::system system (24000, 1);
auto block1 (system.nodes [0]->representative (rai::test_genesis_key.pub));
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
@ -80,117 +80,117 @@ TEST (node, representative)
TEST (node, send_unkeyed)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (0)->store.password.value_set (rai::keypair ().prv);
ASSERT_EQ (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_EQ (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
}
TEST (node, send_self)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (0)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
auto iterations (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
auto iterations (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub));
}
TEST (node, send_single)
{
rai::system system (24000, 2);
rai::keypair key2;
rai::system system (24000, 2);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (1)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub));
ASSERT_TRUE (system.nodes [0]->balance (key2.pub).is_zero ());
auto iterations (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
}
TEST (node, send_single_observing_peer)
{
rai::system system (24000, 3);
rai::keypair key2;
rai::system system (24000, 3);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (1)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub));
ASSERT_TRUE (system.nodes [0]->balance (key2.pub).is_zero ());
auto iterations (0);
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr <rai::node> const & node_a) { return node_a->balance (key2.pub).is_zero (); }))
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr <rai::node> const & node_a) { return node_a->balance (key2.pub).is_zero (); }))
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
}
TEST (node, send_single_many_peers)
{
rai::system system (24000, 10);
rai::keypair key2;
rai::system system (24000, 10);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (1)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub));
ASSERT_TRUE (system.nodes [0]->balance (key2.pub).is_zero ());
auto iterations (0);
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr <rai::node> const & node_a) { return node_a->balance (key2.pub).is_zero(); }))
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 2000);
}
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr <rai::node> const & node_a) { return node_a->balance (key2.pub).is_zero(); }))
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 2000);
}
}
TEST (node, send_out_of_order)
{
rai::system system (24000, 2);
rai::keypair key2;
rai::genesis genesis;
rai::send_block send1 (genesis.hash (), key2.pub, std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()));
rai::send_block send2 (send1.hash (), key2.pub, std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number () * 2, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1.hash ()));
system.nodes [0]->process_active (std::unique_ptr <rai::block> (new rai::send_block (send2)));
system.nodes [0]->process_active (std::unique_ptr <rai::block> (new rai::send_block (send1)));
auto iterations (0);
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr <rai::node> const & node_a) {return node_a->balance (rai::test_genesis_key.pub) != rai::genesis_amount - system.nodes [0]->config.receive_minimum.number () * 2;}))
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
rai::system system (24000, 2);
rai::keypair key2;
rai::genesis genesis;
rai::send_block send1 (genesis.hash (), key2.pub, std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()));
rai::send_block send2 (send1.hash (), key2.pub, std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number () * 2, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1.hash ()));
system.nodes [0]->process_active (std::unique_ptr <rai::block> (new rai::send_block (send2)));
system.nodes [0]->process_active (std::unique_ptr <rai::block> (new rai::send_block (send1)));
auto iterations (0);
while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr <rai::node> const & node_a) {return node_a->balance (rai::test_genesis_key.pub) != rai::genesis_amount - system.nodes [0]->config.receive_minimum.number () * 2;}))
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
}
TEST (node, quick_confirm)
{
rai::system system (24000, 1);
rai::keypair key;
rai::system system (24000, 1);
rai::keypair key;
rai::block_hash previous (system.nodes [0]->latest (rai::test_genesis_key.pub));
system.wallet (0)->insert_adhoc (key.prv);
auto send (std::make_shared <rai::send_block> (previous, key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (previous)));
auto send (std::make_shared <rai::send_block> (previous, key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (previous)));
system.nodes [0]->process_active (send);
auto iterations (0);
while (system.nodes [0]->balance (key.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
auto iterations (0);
while (system.nodes [0]->balance (key.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
}
TEST (node, auto_bootstrap)
@ -213,9 +213,9 @@ TEST (node, auto_bootstrap)
node1->network.send_keepalive (system.nodes [0]->network.endpoint ());
node1->start ();
while (!node1->bootstrap_initiator.in_progress ())
{
system.poll ();
}
{
system.poll ();
}
auto iterations3 (0);
while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ())
{
@ -235,37 +235,37 @@ TEST (node, auto_bootstrap)
TEST (node, auto_bootstrap_reverse)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (0)->insert_adhoc (key2.prv);
rai::node_init init1;
auto node1 (std::make_shared <rai::node> (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work));
ASSERT_FALSE (init1.error ());
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.nodes [0]->network.send_keepalive (node1->network.endpoint ());
node1->start ();
auto iterations (0);
while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
node1->stop ();
rai::node_init init1;
auto node1 (std::make_shared <rai::node> (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work));
ASSERT_FALSE (init1.error ());
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.nodes [0]->network.send_keepalive (node1->network.endpoint ());
node1->start ();
auto iterations (0);
while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
node1->stop ();
}
TEST (node, receive_gap)
{
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
ASSERT_EQ (0, node1.gap_cache.blocks.size ());
auto block (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
rai::confirm_req message;
message.block = block;
node1.process_message (message, node1.network.endpoint ());
node1.block_processor.flush ();
ASSERT_EQ (1, node1.gap_cache.blocks.size ());
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
ASSERT_EQ (0, node1.gap_cache.blocks.size ());
auto block (std::make_shared <rai::send_block> (0, 1, 2, rai::keypair ().prv, 4, 5));
rai::confirm_req message;
message.block = block;
node1.process_message (message, node1.network.endpoint ());
node1.block_processor.flush ();
ASSERT_EQ (1, node1.gap_cache.blocks.size ());
}
TEST (node, merge_peers)
@ -280,125 +280,125 @@ TEST (node, merge_peers)
TEST (node, search_pending)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
auto node (system.nodes [0]);
ASSERT_FALSE (system.wallet (0)->search_pending ());
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
}
TEST (node, search_pending_same)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
auto node (system.nodes [0]);
ASSERT_FALSE (system.wallet (0)->search_pending ());
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub) != 2 * system.nodes [0]->config.receive_minimum.number ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub) != 2 * system.nodes [0]->config.receive_minimum.number ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
}
TEST (node, search_pending_multiple)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
rai::keypair key3;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (0)->insert_adhoc (key3.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key3.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key3.pub, system.nodes [0]->config.receive_minimum.number ()));
auto iterations1 (0);
while (system.nodes [0]->balance (key3.pub).is_zero ())
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
while (system.nodes [0]->balance (key3.pub).is_zero ())
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
auto node (system.nodes [0]);
ASSERT_FALSE (system.wallet (0)->search_pending ());
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub) != 2 * system.nodes [0]->config.receive_minimum.number ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub) != 2 * system.nodes [0]->config.receive_minimum.number ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
}
TEST (node, unlock_search)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
rai::uint128_t balance (system.nodes [0]->balance (rai::test_genesis_key.pub));
{
rai::transaction transaction (system.wallet (0)->store.environment, nullptr, true);
system.wallet (0)->store.rekey (transaction, "");
}
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
auto iterations1 (0);
while (system.nodes [0]->balance (rai::test_genesis_key.pub) == balance)
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
auto iterations1 (0);
while (system.nodes [0]->balance (rai::test_genesis_key.pub) == balance)
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
system.wallet (0)->insert_adhoc (key2.prv);
system.wallet (0)->store.password.value_set (rai::keypair ().prv);
auto node (system.nodes [0]);
ASSERT_FALSE (system.wallet (0)->enter_password (""));
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
auto iterations2 (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
}
TEST (node, connect_after_junk)
{
rai::system system (24000, 1);
rai::node_init init1;
auto node1 (std::make_shared <rai::node> (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work));
uint64_t junk (0);
node1->network.socket.async_send_to (boost::asio::buffer (&junk, sizeof (junk)), system.nodes [0]->network.endpoint (), [] (boost::system::error_code const &, size_t) {});
auto iterations1 (0);
while (system.nodes [0]->network.error_count == 0)
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
node1->start ();
node1->network.send_keepalive (system.nodes [0]->network.endpoint ());
auto iterations2 (0);
while (node1->peers.empty ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
node1->stop ();
rai::system system (24000, 1);
rai::node_init init1;
auto node1 (std::make_shared <rai::node> (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work));
uint64_t junk (0);
node1->network.socket.async_send_to (boost::asio::buffer (&junk, sizeof (junk)), system.nodes [0]->network.endpoint (), [] (boost::system::error_code const &, size_t) {});
auto iterations1 (0);
while (system.nodes [0]->network.error_count == 0)
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
node1->start ();
node1->network.send_keepalive (system.nodes [0]->network.endpoint ());
auto iterations2 (0);
while (node1->peers.empty ())
{
system.poll ();
++iterations2;
ASSERT_LT (iterations2, 200);
}
node1->stop ();
}
TEST (node, working)
@ -839,40 +839,40 @@ TEST (node, fork_flip)
TEST (node, fork_multi_flip)
{
rai::system system (24000, 2);
auto & node1 (*system.nodes [0]);
auto & node2 (*system.nodes [1]);
rai::system system (24000, 2);
auto & node1 (*system.nodes [0]);
auto & node2 (*system.nodes [1]);
ASSERT_EQ (1, node1.peers.size ());
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::keypair key1;
rai::keypair key1;
rai::genesis genesis;
std::unique_ptr <rai::send_block> send1 (new rai::send_block (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ())));
rai::publish publish1;
publish1.block = std::move (send1);
rai::keypair key2;
std::unique_ptr <rai::send_block> send2 (new rai::send_block (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ())));
rai::publish publish2;
publish2.block = std::move (send2);
std::unique_ptr <rai::send_block> send3 (new rai::send_block (publish2.block->hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (publish2.block->hash ())));
rai::publish publish3;
publish3.block = std::move (send3);
node1.process_message (publish1, node1.network.endpoint ());
std::unique_ptr <rai::send_block> send1 (new rai::send_block (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ())));
rai::publish publish1;
publish1.block = std::move (send1);
rai::keypair key2;
std::unique_ptr <rai::send_block> send2 (new rai::send_block (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ())));
rai::publish publish2;
publish2.block = std::move (send2);
std::unique_ptr <rai::send_block> send3 (new rai::send_block (publish2.block->hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (publish2.block->hash ())));
rai::publish publish3;
publish3.block = std::move (send3);
node1.process_message (publish1, node1.network.endpoint ());
node1.block_processor.flush ();
node2.process_message (publish2, node2.network.endpoint ());
node2.process_message (publish3, node2.network.endpoint ());
node2.process_message (publish3, node2.network.endpoint ());
node2.block_processor.flush ();
ASSERT_EQ (1, node1.active.roots.size ());
ASSERT_EQ (2, node2.active.roots.size ());
node1.process_message (publish2, node1.network.endpoint ());
node1.process_message (publish3, node1.network.endpoint ());
ASSERT_EQ (1, node1.active.roots.size ());
ASSERT_EQ (2, node2.active.roots.size ());
node1.process_message (publish2, node1.network.endpoint ());
node1.process_message (publish3, node1.network.endpoint ());
node1.block_processor.flush ();
node2.process_message (publish1, node2.network.endpoint ());
node2.block_processor.flush ();
auto conflict (node2.active.roots.find (genesis.hash ()));
ASSERT_NE (node2.active.roots.end (), conflict);
auto votes1 (conflict->election);
ASSERT_NE (nullptr, votes1);
ASSERT_EQ (1, votes1->votes.rep_votes.size ());
auto conflict (node2.active.roots.find (genesis.hash ()));
ASSERT_NE (node2.active.roots.end (), conflict);
auto votes1 (conflict->election);
ASSERT_NE (nullptr, votes1);
ASSERT_EQ (1, votes1->votes.rep_votes.size ());
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ()));
@ -882,21 +882,21 @@ TEST (node, fork_multi_flip)
ASSERT_TRUE (node2.store.block_exists (transaction, publish2.block->hash ()));
ASSERT_TRUE (node2.store.block_exists (transaction, publish3.block->hash ()));
}
auto iterations (0);
while (votes1->votes.rep_votes.size () == 1)
auto iterations (0);
while (votes1->votes.rep_votes.size () == 1)
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
++iterations;
ASSERT_LT (iterations, 200);
}
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
auto winner (node1.ledger.winner (transaction, votes1->votes));
ASSERT_EQ (*publish1.block, *winner.second);
ASSERT_EQ (rai::genesis_amount - 100, winner.first);
auto winner (node1.ledger.winner (transaction, votes1->votes));
ASSERT_EQ (*publish1.block, *winner.second);
ASSERT_EQ (rai::genesis_amount - 100, winner.first);
ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ()));
ASSERT_TRUE (node2.store.block_exists (transaction, publish1.block->hash ()));
ASSERT_FALSE (node2.store.block_exists (transaction, publish2.block->hash ()));
ASSERT_FALSE (node2.store.block_exists (transaction, publish3.block->hash ()));
ASSERT_FALSE (node2.store.block_exists (transaction, publish3.block->hash ()));
}
// Blocks that are no longer actively being voted on should be able to be evicted through bootstrapping.
@ -1028,8 +1028,8 @@ TEST (node, fork_open_flip)
TEST (node, coherent_observer)
{
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
rai::system system (24000, 1);
auto & node1 (*system.nodes [0]);
node1.observers.blocks.add ([&node1] (std::shared_ptr <rai::block> block_a, rai::account const & account_a, rai::amount const &)
{
rai::transaction transaction (node1.store.environment, nullptr, false);
@ -1042,10 +1042,10 @@ TEST (node, coherent_observer)
TEST (node, fork_no_vote_quorum)
{
rai::system system (24000, 3);
auto & node1 (*system.nodes [0]);
auto & node2 (*system.nodes [1]);
auto & node3 (*system.nodes [2]);
rai::system system (24000, 3);
auto & node1 (*system.nodes [0]);
auto & node2 (*system.nodes [1]);
auto & node3 (*system.nodes [2]);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
auto key4 (system.wallet (0)->deterministic_insert ());
system.wallet (0)->send_action (rai::test_genesis_key.pub, key4, rai::genesis_amount / 4);
@ -1090,7 +1090,7 @@ TEST (node, fork_no_vote_quorum)
TEST (node, broadcast_elected)
{
rai::system system (24000, 3);
rai::system system (24000, 3);
auto node0 (system.nodes [0]);
auto node1 (system.nodes [1]);
auto node2 (system.nodes [2]);
@ -1159,7 +1159,7 @@ TEST (node, broadcast_elected)
TEST (node, rep_self_vote)
{
rai::system system (24000, 1);
rai::system system (24000, 1);
auto node0 (system.nodes [0]);
rai::keypair rep_big;
{
@ -1192,8 +1192,8 @@ TEST (node, rep_self_vote)
// Bootstrapping shouldn't republish the blocks to the network.
TEST (node, bootstrap_no_publish)
{
rai::system system0 (24000, 1);
rai::system system1 (24001, 1);
rai::system system0 (24000, 1);
rai::system system1 (24001, 1);
auto node0 (system0.nodes [0]);
auto node1 (system1.nodes [0]);
rai::keypair key0;
@ -1207,7 +1207,7 @@ TEST (node, bootstrap_no_publish)
node1->bootstrap_initiator.bootstrap (node0->network.endpoint ());
ASSERT_TRUE (node1->active.roots.empty ());
auto iterations1 (0);
while (node1->block (send0.hash ()) == nullptr)
while (node1->block (send0.hash ()) == nullptr)
{
// Poll until the TCP connection is torn down and in_progress goes false
system0.poll ();
@ -1222,7 +1222,7 @@ TEST (node, bootstrap_no_publish)
// Bootstrapping a forked open block should succeed.
TEST (node, bootstrap_fork_open)
{
rai::system system0 (24000, 2);
rai::system system0 (24000, 2);
system0.wallet(0)->insert_adhoc (rai::test_genesis_key.prv);
auto node0 (system0.nodes [0]);
auto node1 (system0.nodes [1]);
@ -1259,7 +1259,7 @@ TEST (node, bootstrap_fork_open)
// Test that if we create a block that isn't confirmed, we sync.
TEST (node, unconfirmed_send)
{
rai::system system (24000, 2);
rai::system system (24000, 2);
auto & node0 (*system.nodes [0]);
auto & node1 (*system.nodes [1]);
auto wallet0 (system.wallet (0));
@ -1294,7 +1294,7 @@ TEST (node, unconfirmed_send)
// Test that nodes can track nodes that have rep weight for priority broadcasting
TEST (node, rep_list)
{
rai::system system (24000, 2);
rai::system system (24000, 2);
auto & node0 (*system.nodes [0]);
auto & node1 (*system.nodes [1]);
auto wallet0 (system.wallet (0));
@ -1329,7 +1329,7 @@ TEST (node, rep_list)
// Test that nodes can disable representative voting
TEST (node, no_voting)
{
rai::system system (24000, 2);
rai::system system (24000, 2);
auto & node0 (*system.nodes [0]);
auto & node1 (*system.nodes [1]);
auto wallet0 (system.wallet (0));
@ -1353,14 +1353,14 @@ TEST (node, no_voting)
TEST (node, start_observer)
{
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::alarm alarm (*service);
rai::node_init init;
auto service (boost::make_shared <boost::asio::io_service> ());
rai::alarm alarm (*service);
auto path (rai::unique_path ());
rai::logging logging;
logging.init (path);
rai::work_pool work (std::numeric_limits <unsigned>::max (), nullptr);
auto node (std::make_shared <rai::node> (init, *service, 0, path, alarm, logging, work));
auto node (std::make_shared <rai::node> (init, *service, 0, path, alarm, logging, work));
auto started (false);
node->observers.started.add([&started] ()
{
@ -1373,22 +1373,22 @@ TEST (node, start_observer)
TEST (node, send_callback)
{
rai::system system (24000, 1);
rai::keypair key2;
rai::system system (24000, 1);
rai::keypair key2;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (0)->insert_adhoc (key2.prv);
system.nodes [0]->config.callback_address = "localhost";
system.nodes [0]->config.callback_port = 8010;
system.nodes [0]->config.callback_target = "/";
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
auto iterations (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ()));
auto iterations (0);
while (system.nodes [0]->balance (key2.pub).is_zero ())
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
ASSERT_EQ (std::numeric_limits <rai::uint128_t>::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub));
}
// Check that votes get replayed back to nodes if they sent an old sequence number.

File diff suppressed because it is too large Load diff

View file

@ -7,71 +7,71 @@
TEST (uint128_union, decode_dec)
{
rai::uint128_union value;
std::string text ("16");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_EQ (16, value.bytes [15]);
rai::uint128_union value;
std::string text ("16");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_EQ (16, value.bytes [15]);
}
TEST (uint128_union, decode_dec_negative)
{
rai::uint128_union value;
std::string text ("-1");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
rai::uint128_union value;
std::string text ("-1");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
}
TEST (uint128_union, decode_dec_zero)
{
rai::uint128_union value;
std::string text ("0");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_TRUE (value.is_zero ());
rai::uint128_union value;
std::string text ("0");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_TRUE (value.is_zero ());
}
TEST (uint128_union, decode_dec_leading_zero)
{
rai::uint128_union value;
std::string text ("010");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
rai::uint128_union value;
std::string text ("010");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
}
struct test_punct : std::moneypunct<char> {
pattern do_pos_format () const { return { {value, none, none, none} }; }
int do_frac_digits () const { return 0; }
char_type do_decimal_point () const { return '+'; }
char_type do_thousands_sep () const { return '-'; }
string_type do_grouping () const { return "\3\4"; }
pattern do_pos_format () const { return { {value, none, none, none} }; }
int do_frac_digits () const { return 0; }
char_type do_decimal_point () const { return '+'; }
char_type do_thousands_sep () const { return '-'; }
string_type do_grouping () const { return "\3\4"; }
};
TEST (uint128_union, balance_format)
{
ASSERT_EQ ("0", rai::amount (rai::uint128_t ("0")).format_balance (rai::Mxrb_ratio, 0, false));
ASSERT_EQ ("0", rai::amount (rai::uint128_t ("0")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("340,282,366", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("340,282,366.920938463463374607431768211455", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).format_balance (rai::Mxrb_ratio, 64, true));
ASSERT_EQ ("340,282,366,920,938,463,463,374,607,431,768,211,455", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).format_balance (1, 4, true));
ASSERT_EQ ("340,282,366", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("340,282,366.920938463463374607431768211454", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 64, true));
ASSERT_EQ ("340282366920938463463374607431768211454", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (1, 4, false));
ASSERT_EQ ("170,141,183", rai::amount (rai::uint128_t ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("170,141,183.460469231731687303715884105726", rai::amount (rai::uint128_t ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 64, true));
ASSERT_EQ ("170141183460469231731687303715884105726", rai::amount (rai::uint128_t ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (1, 4, false));
ASSERT_EQ ("1", rai::amount (rai::uint128_t ("1000000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("1.2", rai::amount (rai::uint128_t ("1200000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("1.23", rai::amount (rai::uint128_t ("1230000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("1.2", rai::amount (rai::uint128_t ("1230000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 1, true));
ASSERT_EQ ("1", rai::amount (rai::uint128_t ("1230000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("< 0.01", rai::amount (rai::xrb_ratio * 10).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("< 0.1", rai::amount (rai::xrb_ratio * 10).format_balance (rai::Mxrb_ratio, 1, true));
ASSERT_EQ ("< 1", rai::amount (rai::xrb_ratio * 10).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("< 0.01", rai::amount (rai::xrb_ratio * 9999).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("0.01", rai::amount (rai::xrb_ratio * 10000).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("123456789", rai::amount (rai::Mxrb_ratio * 123456789).format_balance (rai::Mxrb_ratio, 2, false));
ASSERT_EQ ("123,456,789", rai::amount (rai::Mxrb_ratio * 123456789).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("123,456,789.12", rai::amount (rai::Mxrb_ratio * 123456789 + rai::kxrb_ratio * 123).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("12-3456-789+123", rai::amount (rai::Mxrb_ratio * 123456789 + rai::kxrb_ratio * 123).format_balance (rai::Mxrb_ratio, 4, true, std::locale (std::cout.getloc (), new test_punct)));
ASSERT_EQ ("0", rai::amount (rai::uint128_t ("0")).format_balance (rai::Mxrb_ratio, 0, false));
ASSERT_EQ ("0", rai::amount (rai::uint128_t ("0")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("340,282,366", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("340,282,366.920938463463374607431768211455", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).format_balance (rai::Mxrb_ratio, 64, true));
ASSERT_EQ ("340,282,366,920,938,463,463,374,607,431,768,211,455", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).format_balance (1, 4, true));
ASSERT_EQ ("340,282,366", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("340,282,366.920938463463374607431768211454", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 64, true));
ASSERT_EQ ("340282366920938463463374607431768211454", rai::amount (rai::uint128_t ("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (1, 4, false));
ASSERT_EQ ("170,141,183", rai::amount (rai::uint128_t ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("170,141,183.460469231731687303715884105726", rai::amount (rai::uint128_t ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (rai::Mxrb_ratio, 64, true));
ASSERT_EQ ("170141183460469231731687303715884105726", rai::amount (rai::uint128_t ("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE")).format_balance (1, 4, false));
ASSERT_EQ ("1", rai::amount (rai::uint128_t ("1000000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("1.2", rai::amount (rai::uint128_t ("1200000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("1.23", rai::amount (rai::uint128_t ("1230000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("1.2", rai::amount (rai::uint128_t ("1230000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 1, true));
ASSERT_EQ ("1", rai::amount (rai::uint128_t ("1230000000000000000000000000000")).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("< 0.01", rai::amount (rai::xrb_ratio * 10).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("< 0.1", rai::amount (rai::xrb_ratio * 10).format_balance (rai::Mxrb_ratio, 1, true));
ASSERT_EQ ("< 1", rai::amount (rai::xrb_ratio * 10).format_balance (rai::Mxrb_ratio, 0, true));
ASSERT_EQ ("< 0.01", rai::amount (rai::xrb_ratio * 9999).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("0.01", rai::amount (rai::xrb_ratio * 10000).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("123456789", rai::amount (rai::Mxrb_ratio * 123456789).format_balance (rai::Mxrb_ratio, 2, false));
ASSERT_EQ ("123,456,789", rai::amount (rai::Mxrb_ratio * 123456789).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("123,456,789.12", rai::amount (rai::Mxrb_ratio * 123456789 + rai::kxrb_ratio * 123).format_balance (rai::Mxrb_ratio, 2, true));
ASSERT_EQ ("12-3456-789+123", rai::amount (rai::Mxrb_ratio * 123456789 + rai::kxrb_ratio * 123).format_balance (rai::Mxrb_ratio, 4, true, std::locale (std::cout.getloc (), new test_punct)));
}
TEST (unions, identity)
@ -83,151 +83,151 @@ TEST (unions, identity)
TEST (uint256_union, key_encryption)
{
rai::keypair key1;
rai::raw_key secret_key;
secret_key.data.bytes.fill (0);
rai::uint256_union encrypted;
rai::keypair key1;
rai::raw_key secret_key;
secret_key.data.bytes.fill (0);
rai::uint256_union encrypted;
encrypted.encrypt (key1.prv, secret_key, key1.pub.owords [0]);
rai::raw_key key4;
rai::raw_key key4;
key4.decrypt (encrypted, secret_key, key1.pub.owords [0]);
ASSERT_EQ (key1.prv, key4);
rai::public_key pub;
ed25519_publickey (key4.data.bytes.data (), pub.bytes.data ());
ASSERT_EQ (key1.pub, pub);
ASSERT_EQ (key1.prv, key4);
rai::public_key pub;
ed25519_publickey (key4.data.bytes.data (), pub.bytes.data ());
ASSERT_EQ (key1.pub, pub);
}
TEST (uint256_union, encryption)
{
rai::raw_key key;
rai::raw_key key;
key.data.clear ();
rai::raw_key number1;
rai::raw_key number1;
number1.data = 1;
rai::uint256_union encrypted1;
rai::uint256_union encrypted1;
encrypted1.encrypt (number1, key, key.data.owords [0]);
rai::uint256_union encrypted2;
rai::uint256_union encrypted2;
encrypted2.encrypt (number1, key, key.data.owords [0]);
ASSERT_EQ (encrypted1, encrypted2);
rai::raw_key number2;
ASSERT_EQ (encrypted1, encrypted2);
rai::raw_key number2;
number2.decrypt (encrypted1, key, key.data.owords [0]);
ASSERT_EQ (number1, number2);
ASSERT_EQ (number1, number2);
}
TEST (uint256_union, decode_empty)
{
std::string text;
rai::uint256_union val;
ASSERT_TRUE (val.decode_hex (text));
std::string text;
rai::uint256_union val;
ASSERT_TRUE (val.decode_hex (text));
}
TEST (uint256_union, parse_zero)
{
rai::uint256_union input (rai::uint256_t (0));
std::string text;
input.encode_hex (text);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_TRUE (output.number ().is_zero ());
rai::uint256_union input (rai::uint256_t (0));
std::string text;
input.encode_hex (text);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_TRUE (output.number ().is_zero ());
}
TEST (uint256_union, parse_zero_short)
{
std::string text ("0");
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_TRUE (output.number ().is_zero ());
std::string text ("0");
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_TRUE (output.number ().is_zero ());
}
TEST (uint256_union, parse_one)
{
rai::uint256_union input (rai::uint256_t (1));
std::string text;
input.encode_hex (text);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (1, output.number ());
rai::uint256_union input (rai::uint256_t (1));
std::string text;
input.encode_hex (text);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (1, output.number ());
}
TEST (uint256_union, parse_error_symbol)
{
rai::uint256_union input (rai::uint256_t (1000));
std::string text;
input.encode_hex (text);
text [5] = '!';
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
rai::uint256_union input (rai::uint256_t (1000));
std::string text;
input.encode_hex (text);
text [5] = '!';
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
}
TEST (uint256_union, max_hex)
{
rai::uint256_union input (std::numeric_limits <rai::uint256_t>::max ());
std::string text;
input.encode_hex (text);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (rai::uint256_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ());
rai::uint256_union input (std::numeric_limits <rai::uint256_t>::max ());
std::string text;
input.encode_hex (text);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (rai::uint256_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ());
}
TEST (uint256_union, decode_dec)
{
rai::uint256_union value;
std::string text ("16");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_EQ (16, value.bytes [31]);
rai::uint256_union value;
std::string text ("16");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_EQ (16, value.bytes [31]);
}
TEST (uint256_union, max_dec)
{
rai::uint256_union input (std::numeric_limits <rai::uint256_t>::max ());
std::string text;
input.encode_dec (text);
rai::uint256_union output;
auto error (output.decode_dec (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (rai::uint256_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ());
rai::uint256_union input (std::numeric_limits <rai::uint256_t>::max ());
std::string text;
input.encode_dec (text);
rai::uint256_union output;
auto error (output.decode_dec (text));
ASSERT_FALSE (error);
ASSERT_EQ (input, output);
ASSERT_EQ (rai::uint256_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ());
}
TEST (uint256_union, decode_dec_negative)
{
rai::uint256_union value;
std::string text ("-1");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
rai::uint256_union value;
std::string text ("-1");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
}
TEST (uint256_union, decode_dec_zero)
{
rai::uint256_union value;
std::string text ("0");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_TRUE (value.is_zero ());
rai::uint256_union value;
std::string text ("0");
ASSERT_FALSE (value.decode_dec (text));
ASSERT_TRUE (value.is_zero ());
}
TEST (uint256_union, decode_dec_leading_zero)
{
rai::uint256_union value;
std::string text ("010");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
rai::uint256_union value;
std::string text ("010");
auto error (value.decode_dec (text));
ASSERT_TRUE (error);
}
TEST (uint256_union, parse_error_overflow)
{
rai::uint256_union input (std::numeric_limits <rai::uint256_t>::max ());
std::string text;
input.encode_hex (text);
text.push_back (0);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
rai::uint256_union input (std::numeric_limits <rai::uint256_t>::max ());
std::string text;
input.encode_hex (text);
text.push_back (0);
rai::uint256_union output;
auto error (output.decode_hex (text));
ASSERT_TRUE (error);
}
TEST (uint256_union, big_endian_union_constructor)
@ -292,10 +292,10 @@ TEST (uint256_union, decode_account_v1)
TEST (uint256_union, account_transcode)
{
rai::uint256_union value;
rai::uint256_union value;
auto text (rai::test_genesis_key.pub.to_account ());
ASSERT_FALSE (value.decode_account (text));
ASSERT_EQ (rai::test_genesis_key.pub, value);
ASSERT_FALSE (value.decode_account (text));
ASSERT_EQ (rai::test_genesis_key.pub, value);
ASSERT_EQ ('_', text [3]);
text [3] = '-';
rai::uint256_union value2;
@ -305,8 +305,8 @@ TEST (uint256_union, account_transcode)
TEST (uint256_union, account_encode_lex)
{
rai::uint256_union min ("0000000000000000000000000000000000000000000000000000000000000000");
rai::uint256_union max ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
rai::uint256_union min ("0000000000000000000000000000000000000000000000000000000000000000");
rai::uint256_union max ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
auto min_text (min.to_account ());
ASSERT_EQ (64, min_text.size ());
auto max_text (max.to_account ());

View file

@ -670,8 +670,8 @@ TEST (wallet, work_generate)
TEST (wallet, unsynced_work)
{
rai::system system (24000, 1);
auto wallet (system.wallet (0));
rai::system system (24000, 1);
auto wallet (system.wallet (0));
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
wallet->store.work_put (transaction, 0, 0);
auto work1 (wallet->work_fetch (transaction, 0, 1));
@ -680,8 +680,8 @@ TEST (wallet, unsynced_work)
TEST (wallet, insert_locked)
{
rai::system system (24000, 1);
auto wallet (system.wallet (0));
rai::system system (24000, 1);
auto wallet (system.wallet (0));
wallet->store.rekey (rai::transaction (wallet->store.environment, nullptr, true), "1");
ASSERT_EQ (true, wallet->valid_password ());
wallet->enter_password ("");
@ -691,8 +691,8 @@ TEST (wallet, insert_locked)
TEST (wallet, version_1_2_upgrade)
{
rai::system system (24000, 1);
auto wallet (system.wallet (0));
rai::system system (24000, 1);
auto wallet (system.wallet (0));
wallet->enter_initial_password ();
ASSERT_EQ (true, wallet->valid_password ());
rai::keypair key;
@ -741,12 +741,12 @@ TEST (wallet, version_1_2_upgrade)
TEST (wallet, deterministic_keys)
{
bool init;
bool init;
rai::mdb_env environment (init, rai::unique_path ());
ASSERT_FALSE (init);
rai::transaction transaction (environment, nullptr, true);
rai::kdf kdf;
rai::wallet_store wallet (init, kdf, transaction, rai::genesis_account, 1, "0");
rai::wallet_store wallet (init, kdf, transaction, rai::genesis_account, 1, "0");
rai::raw_key key1;
wallet.deterministic_key (key1, transaction, 0);
rai::raw_key key2;
@ -787,12 +787,12 @@ TEST (wallet, deterministic_keys)
TEST (wallet, reseed)
{
bool init;
bool init;
rai::mdb_env environment (init, rai::unique_path ());
ASSERT_FALSE (init);
rai::transaction transaction (environment, nullptr, true);
rai::kdf kdf;
rai::wallet_store wallet (init, kdf, transaction, rai::genesis_account, 1, "0");
rai::wallet_store wallet (init, kdf, transaction, rai::genesis_account, 1, "0");
rai::raw_key seed1;
seed1.data = 1;
rai::raw_key seed2;
@ -820,8 +820,8 @@ TEST (wallet, reseed)
TEST (wallet, insert_deterministic_locked)
{
rai::system system (24000, 1);
auto wallet (system.wallet (0));
rai::system system (24000, 1);
auto wallet (system.wallet (0));
wallet->store.rekey (rai::transaction (wallet->store.environment, nullptr, true), "1");
ASSERT_EQ (true, wallet->valid_password ());
wallet->enter_password ("");
@ -831,8 +831,8 @@ TEST (wallet, insert_deterministic_locked)
TEST (wallet, version_2_3_upgrade)
{
rai::system system (24000, 1);
auto wallet (system.wallet (0));
rai::system system (24000, 1);
auto wallet (system.wallet (0));
{
rai::transaction transaction (wallet->store.environment, nullptr, true);
wallet->store.rekey (transaction, "1");
@ -859,19 +859,19 @@ TEST (wallet, no_work)
{
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::keypair key2;
auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits <rai::uint128_t>::max (), false));
ASSERT_NE (nullptr, block);
ASSERT_EQ (0, block->block_work ());
rai::keypair key2;
auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits <rai::uint128_t>::max (), false));
ASSERT_NE (nullptr, block);
ASSERT_EQ (0, block->block_work ());
}
TEST (wallet, send_race)
{
rai::system system (24000, 1);
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::keypair key2;
system.nodes [0]->block_processor.stop ();
{
rai::keypair key2;
system.nodes [0]->block_processor.stop ();
{
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, rai::Gxrb_ratio));
ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, rai::Gxrb_ratio));
}

View file

@ -6,18 +6,18 @@
TEST (work, one)
{
rai::work_pool pool (std::numeric_limits <unsigned>::max (), nullptr);
rai::change_block block (1, 1, rai::keypair ().prv, 3, 4);
block.block_work_set (pool.generate (block.root ()));
ASSERT_FALSE (rai::work_validate (block));
rai::change_block block (1, 1, rai::keypair ().prv, 3, 4);
block.block_work_set (pool.generate (block.root ()));
ASSERT_FALSE (rai::work_validate (block));
}
TEST (work, validate)
{
rai::work_pool pool (std::numeric_limits <unsigned>::max (), nullptr);
rai::send_block send_block (1, 1, 2, rai::keypair ().prv, 4, 6);
ASSERT_TRUE (rai::work_validate (send_block));
send_block.block_work_set (pool.generate (send_block.root ()));
ASSERT_FALSE (rai::work_validate (send_block));
ASSERT_TRUE (rai::work_validate (send_block));
send_block.block_work_set (pool.generate (send_block.root ()));
ASSERT_FALSE (rai::work_validate (send_block));
}
TEST (work, cancel)

View file

@ -890,7 +890,7 @@ std::unique_ptr <rai::block> rai::deserialize_block (rai::stream & stream_a, rai
void rai::receive_block::visit (rai::block_visitor & visitor_a) const
{
visitor_a.receive_block (*this);
visitor_a.receive_block (*this);
}
bool rai::receive_block::operator == (rai::receive_block const & other_a) const
@ -1071,7 +1071,7 @@ void rai::receive_block::signature_set (rai::uint512_union const & signature_a)
rai::block_type rai::receive_block::type () const
{
return rai::block_type::receive;
return rai::block_type::receive;
}
rai::receive_hashables::receive_hashables (rai::block_hash const & previous_a, rai::block_hash const & source_a) :

View file

@ -186,7 +186,7 @@ void rai::uint256_union::encrypt (rai::raw_key const & cleartext, rai::raw_key c
bool rai::uint256_union::is_zero () const
{
return qwords [0] == 0 && qwords [1] == 0 && qwords [2] == 0 && qwords [3] == 0;
return qwords [0] == 0 && qwords [1] == 0 && qwords [2] == 0 && qwords [3] == 0;
}
std::string rai::uint256_union::to_string () const
@ -488,7 +488,7 @@ rai::uint128_union::uint128_union (rai::uint128_t const & value_a)
bool rai::uint128_union::operator == (rai::uint128_union const & other_a) const
{
return qwords [0] == other_a.qwords [0] && qwords [1] == other_a.qwords [1];
return qwords [0] == other_a.qwords [0] && qwords [1] == other_a.qwords [1];
}
bool rai::uint128_union::operator != (rai::uint128_union const & other_a) const

View file

@ -57,11 +57,11 @@ rai::work_pool::~work_pool ()
void rai::work_pool::loop (uint64_t thread)
{
// Quick RNG for work attempts.
xorshift1024star rng;
xorshift1024star rng;
rai::random_pool.GenerateBlock (reinterpret_cast <uint8_t *> (rng.s.data ()), rng.s.size () * sizeof (decltype (rng.s)::value_type));
uint64_t work;
uint64_t output;
blake2b_state hash;
blake2b_state hash;
blake2b_init (&hash, sizeof (output));
std::unique_lock <std::mutex> lock (mutex);
while (!done || !pending.empty())

View file

@ -190,10 +190,10 @@ void rai::bootstrap_client::stop_timeout ()
void rai::bootstrap_client::run ()
{
auto this_l (shared_from_this ());
auto this_l (shared_from_this ());
start_timeout ();
socket.async_connect (endpoint, [this_l] (boost::system::error_code const & ec)
{
socket.async_connect (endpoint, [this_l] (boost::system::error_code const & ec)
{
this_l->stop_timeout ();
if (!ec)
{
@ -216,7 +216,7 @@ void rai::bootstrap_client::run ()
}
}
}
});
});
}
void rai::frontier_req_client::run ()
@ -272,13 +272,13 @@ rai::frontier_req_client::~frontier_req_client ()
void rai::frontier_req_client::receive_frontier ()
{
auto this_l (shared_from_this ());
auto this_l (shared_from_this ());
connection->start_timeout ();
boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data (), sizeof (rai::uint256_union) + sizeof (rai::uint256_union)), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data (), sizeof (rai::uint256_union) + sizeof (rai::uint256_union)), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->connection->stop_timeout ();
this_l->received_frontier (ec, size_a);
});
this_l->received_frontier (ec, size_a);
});
}
void rai::frontier_req_client::request_account (rai::account const & account_a, rai::block_hash const & latest_a)
@ -640,7 +640,7 @@ rai::bulk_push_client::bulk_push_client (std::shared_ptr <rai::bootstrap_client>
connection (connection_a),
synchronization (*connection->node, [this] (MDB_txn * transaction_a, rai::block const & block_a)
{
push_block (block_a);
push_block (block_a);
return rai::sync_result::success;
})
{
@ -791,37 +791,37 @@ rai::bootstrap_attempt::~bootstrap_attempt ()
bool rai::bootstrap_attempt::request_frontier (std::unique_lock <std::mutex> & lock_a)
{
auto result (true);
auto connection_l (connection (lock_a));
if (connection_l)
{
std::future <bool> future;
{
auto client (std::make_shared <rai::frontier_req_client> (connection_l));
client->run ();
auto result (true);
auto connection_l (connection (lock_a));
if (connection_l)
{
std::future <bool> future;
{
auto client (std::make_shared <rai::frontier_req_client> (connection_l));
client->run ();
frontiers = client;
future = client->promise.get_future ();
}
lock_a.unlock ();
result = consume_future (future);
lock_a.lock ();
if (result)
{
pulls.clear ();
}
if (node->config.logging.network_logging ())
{
if (!result)
{
BOOST_LOG (node->log) << boost::str (boost::format ("Completed frontier request, %1% out of sync accounts according to %2%") % pulls.size () % connection_l->endpoint);
}
else
{
BOOST_LOG (node->log) << "frontier_req failed, reattempting";
}
}
}
return result;
future = client->promise.get_future ();
}
lock_a.unlock ();
result = consume_future (future);
lock_a.lock ();
if (result)
{
pulls.clear ();
}
if (node->config.logging.network_logging ())
{
if (!result)
{
BOOST_LOG (node->log) << boost::str (boost::format ("Completed frontier request, %1% out of sync accounts according to %2%") % pulls.size () % connection_l->endpoint);
}
else
{
BOOST_LOG (node->log) << "frontier_req failed, reattempting";
}
}
}
return result;
}
void rai::bootstrap_attempt::request_pull (std::unique_lock <std::mutex> & lock_a)
@ -843,30 +843,30 @@ void rai::bootstrap_attempt::request_pull (std::unique_lock <std::mutex> & lock_
bool rai::bootstrap_attempt::request_push (std::unique_lock <std::mutex> & lock_a)
{
auto result (true);
auto connection_l (connection (lock_a));
if (connection_l)
{
std::future <bool> future;
{
auto client (std::make_shared <rai::bulk_push_client> (connection_l));
client->start ();
auto result (true);
auto connection_l (connection (lock_a));
if (connection_l)
{
std::future <bool> future;
{
auto client (std::make_shared <rai::bulk_push_client> (connection_l));
client->start ();
push = client;
future = client->promise.get_future ();
}
lock_a.unlock ();
result = consume_future (future);
lock_a.lock ();
if (node->config.logging.network_logging ())
{
BOOST_LOG (node->log) << "Exiting bulk push client";
if (result)
{
BOOST_LOG (node->log) << "Bulk push client failed";
}
}
}
return result;
future = client->promise.get_future ();
}
lock_a.unlock ();
result = consume_future (future);
lock_a.lock ();
if (node->config.logging.network_logging ())
{
BOOST_LOG (node->log) << "Exiting bulk push client";
if (result)
{
BOOST_LOG (node->log) << "Bulk push client failed";
}
}
}
return result;
}
bool rai::bootstrap_attempt::still_pulling ()
@ -925,29 +925,29 @@ std::shared_ptr <rai::bootstrap_client> rai::bootstrap_attempt::connection (std:
{
while (!stopped && idle.empty ())
{
condition.wait (lock_a);
condition.wait (lock_a);
}
std::shared_ptr <rai::bootstrap_client> result;
if (!idle.empty ())
{
result = idle.back ();
idle.pop_back ();
}
std::shared_ptr <rai::bootstrap_client> result;
if (!idle.empty ())
{
result = idle.back ();
idle.pop_back ();
}
return result;
}
bool rai::bootstrap_attempt::consume_future (std::future <bool> & future_a)
{
bool result;
try
{
result = future_a.get ();
}
catch (std::future_error &)
{
result = true;
}
return result;
bool result;
try
{
result = future_a.get ();
}
catch (std::future_error &)
{
result = true;
}
return result;
}
void rai::bootstrap_attempt::populate_connections ()
@ -1224,11 +1224,11 @@ node (node_a)
void rai::bootstrap_server::receive ()
{
auto this_l (shared_from_this ());
boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data (), 8), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->receive_header_action (ec, size_a);
});
auto this_l (shared_from_this ());
boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data (), 8), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->receive_header_action (ec, size_a);
});
}
void rai::bootstrap_server::receive_header_action (boost::system::error_code const & ec, size_t size_a)
@ -1291,21 +1291,21 @@ void rai::bootstrap_server::receive_header_action (boost::system::error_code con
void rai::bootstrap_server::receive_bulk_pull_action (boost::system::error_code const & ec, size_t size_a)
{
if (!ec)
{
std::unique_ptr <rai::bulk_pull> request (new rai::bulk_pull);
rai::bufferstream stream (receive_buffer.data (), 8 + sizeof (rai::uint256_union) + sizeof (rai::uint256_union));
auto error (request->deserialize (stream));
if (!error)
{
if (node->config.logging.bulk_pull_logging ())
{
BOOST_LOG (node->log) << boost::str (boost::format ("Received bulk pull for %1% down to %2%") % request->start.to_string () % request->end.to_string ());
}
if (!ec)
{
std::unique_ptr <rai::bulk_pull> request (new rai::bulk_pull);
rai::bufferstream stream (receive_buffer.data (), 8 + sizeof (rai::uint256_union) + sizeof (rai::uint256_union));
auto error (request->deserialize (stream));
if (!error)
{
if (node->config.logging.bulk_pull_logging ())
{
BOOST_LOG (node->log) << boost::str (boost::format ("Received bulk pull for %1% down to %2%") % request->start.to_string () % request->end.to_string ());
}
add_request (std::unique_ptr <rai::message> (request.release ()));
receive ();
}
}
receive ();
}
}
}
void rai::bootstrap_server::receive_frontier_req_action (boost::system::error_code const & ec, size_t size_a)
@ -1325,19 +1325,19 @@ void rai::bootstrap_server::receive_frontier_req_action (boost::system::error_co
receive ();
}
}
else
{
if (node->config.logging.network_logging ())
{
BOOST_LOG (node->log) << boost::str (boost::format ("Error sending receiving frontier request %1%") % ec.message ());
}
}
else
{
if (node->config.logging.network_logging ())
{
BOOST_LOG (node->log) << boost::str (boost::format ("Error sending receiving frontier request %1%") % ec.message ());
}
}
}
void rai::bootstrap_server::add_request (std::unique_ptr <rai::message> message_a)
{
std::lock_guard <std::mutex> lock (mutex);
auto start (requests.empty ());
auto start (requests.empty ());
requests.push (std::move (message_a));
if (start)
{
@ -1556,8 +1556,8 @@ connection (connection_a)
void rai::bulk_push_server::receive ()
{
auto this_l (shared_from_this ());
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data (), 1), [this_l] (boost::system::error_code const & ec, size_t size_a)
auto this_l (shared_from_this ());
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data (), 1), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
if (!ec)
{
@ -1572,74 +1572,74 @@ void rai::bulk_push_server::receive ()
void rai::bulk_push_server::received_type ()
{
auto this_l (shared_from_this ());
rai::block_type type (static_cast <rai::block_type> (receive_buffer [0]));
switch (type)
{
case rai::block_type::send:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::send_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
auto this_l (shared_from_this ());
rai::block_type type (static_cast <rai::block_type> (receive_buffer [0]));
switch (type)
{
case rai::block_type::send:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::send_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->received_block (ec, size_a);
});
break;
}
case rai::block_type::receive:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::receive_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
break;
}
case rai::block_type::receive:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::receive_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->received_block (ec, size_a);
});
break;
}
case rai::block_type::open:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::open_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
break;
}
case rai::block_type::open:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::open_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->received_block (ec, size_a);
});
break;
}
case rai::block_type::change:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::change_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
break;
}
case rai::block_type::change:
{
boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::change_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->received_block (ec, size_a);
});
break;
}
case rai::block_type::not_a_block:
{
connection->finish_request ();
break;
}
default:
{
BOOST_LOG (connection->node->log) << "Unknown type received as block type";
break;
}
}
break;
}
case rai::block_type::not_a_block:
{
connection->finish_request ();
break;
}
default:
{
BOOST_LOG (connection->node->log) << "Unknown type received as block type";
break;
}
}
}
void rai::bulk_push_server::received_block (boost::system::error_code const & ec, size_t size_a)
{
if (!ec)
{
rai::bufferstream stream (receive_buffer.data (), 1 + size_a);
auto block (rai::deserialize_block (stream));
if (block != nullptr)
{
if (!ec)
{
rai::bufferstream stream (receive_buffer.data (), 1 + size_a);
auto block (rai::deserialize_block (stream));
if (block != nullptr)
{
if (!connection->node->bootstrap_initiator.in_progress ())
{
connection->node->process_active (std::move (block));
}
receive ();
}
else
{
BOOST_LOG (connection->node->log) << "Error deserializing block received from pull request";
}
}
receive ();
}
else
{
BOOST_LOG (connection->node->log) << "Error deserializing block received from pull request";
}
}
}
rai::frontier_req_server::frontier_req_server (std::shared_ptr <rai::bootstrap_server> const & connection_a, std::unique_ptr <rai::frontier_req> request_a) :
@ -1649,96 +1649,96 @@ info (0, 0, 0, 0, 0, 0),
request (std::move (request_a))
{
next ();
skip_old ();
skip_old ();
}
void rai::frontier_req_server::skip_old ()
{
if (request->age != std::numeric_limits<decltype (request->age)>::max ())
{
auto now (connection->node->store.now ());
while (!current.is_zero () && (now - info.modified) >= request->age)
{
next ();
}
}
if (request->age != std::numeric_limits<decltype (request->age)>::max ())
{
auto now (connection->node->store.now ());
while (!current.is_zero () && (now - info.modified) >= request->age)
{
next ();
}
}
}
void rai::frontier_req_server::send_next ()
{
if (!current.is_zero ())
{
{
send_buffer.clear ();
rai::vectorstream stream (send_buffer);
write (stream, current.bytes);
write (stream, info.head.bytes);
}
auto this_l (shared_from_this ());
if (connection->node->config.logging.bulk_pull_logging ())
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Sending frontier for %1% %2%") % current.to_account () % info.head.to_string ());
}
if (!current.is_zero ())
{
{
send_buffer.clear ();
rai::vectorstream stream (send_buffer);
write (stream, current.bytes);
write (stream, info.head.bytes);
}
auto this_l (shared_from_this ());
if (connection->node->config.logging.bulk_pull_logging ())
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Sending frontier for %1% %2%") % current.to_account () % info.head.to_string ());
}
next ();
async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->sent_action (ec, size_a);
});
}
else
{
send_finished ();
}
async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->sent_action (ec, size_a);
});
}
else
{
send_finished ();
}
}
void rai::frontier_req_server::send_finished ()
{
{
send_buffer.clear ();
rai::vectorstream stream (send_buffer);
rai::uint256_union zero (0);
write (stream, zero.bytes);
write (stream, zero.bytes);
}
auto this_l (shared_from_this ());
if (connection->node->config.logging.network_logging ())
{
BOOST_LOG (connection->node->log) << "Frontier sending finished";
}
async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->no_block_sent (ec, size_a);
});
{
send_buffer.clear ();
rai::vectorstream stream (send_buffer);
rai::uint256_union zero (0);
write (stream, zero.bytes);
write (stream, zero.bytes);
}
auto this_l (shared_from_this ());
if (connection->node->config.logging.network_logging ())
{
BOOST_LOG (connection->node->log) << "Frontier sending finished";
}
async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l] (boost::system::error_code const & ec, size_t size_a)
{
this_l->no_block_sent (ec, size_a);
});
}
void rai::frontier_req_server::no_block_sent (boost::system::error_code const & ec, size_t size_a)
{
if (!ec)
{
if (!ec)
{
connection->finish_request ();
}
else
{
if (connection->node->config.logging.network_logging ())
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Error sending frontier finish %1%") % ec.message ());
}
}
}
else
{
if (connection->node->config.logging.network_logging ())
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Error sending frontier finish %1%") % ec.message ());
}
}
}
void rai::frontier_req_server::sent_action (boost::system::error_code const & ec, size_t size_a)
{
if (!ec)
{
send_next ();
}
else
{
if (connection->node->config.logging.network_logging ())
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Error sending frontier pair %1%") % ec.message ());
}
}
if (!ec)
{
send_next ();
}
else
{
if (connection->node->config.logging.network_logging ())
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Error sending frontier pair %1%") % ec.message ());
}
}
}
void rai::frontier_req_server::next ()

View file

@ -24,27 +24,27 @@ enum class sync_result
class block_synchronization
{
public:
block_synchronization (boost::log::sources::logger_mt &);
~block_synchronization ();
// Return true if target already has block
virtual bool synchronized (MDB_txn *, rai::block_hash const &) = 0;
virtual std::unique_ptr <rai::block> retrieve (MDB_txn *, rai::block_hash const &) = 0;
virtual rai::sync_result target (MDB_txn *, rai::block const &) = 0;
// return true if all dependencies are synchronized
bool add_dependency (MDB_txn *, rai::block const &);
void fill_dependencies (MDB_txn *);
rai::sync_result synchronize_one (MDB_txn *);
rai::sync_result synchronize (MDB_txn *, rai::block_hash const &);
block_synchronization (boost::log::sources::logger_mt &);
~block_synchronization ();
// Return true if target already has block
virtual bool synchronized (MDB_txn *, rai::block_hash const &) = 0;
virtual std::unique_ptr <rai::block> retrieve (MDB_txn *, rai::block_hash const &) = 0;
virtual rai::sync_result target (MDB_txn *, rai::block const &) = 0;
// return true if all dependencies are synchronized
bool add_dependency (MDB_txn *, rai::block const &);
void fill_dependencies (MDB_txn *);
rai::sync_result synchronize_one (MDB_txn *);
rai::sync_result synchronize (MDB_txn *, rai::block_hash const &);
boost::log::sources::logger_mt & log;
std::deque <rai::block_hash> blocks;
};
class push_synchronization : public rai::block_synchronization
{
public:
push_synchronization (rai::node &, std::function <rai::sync_result (MDB_txn *, rai::block const &)> const &);
bool synchronized (MDB_txn *, rai::block_hash const &) override;
std::unique_ptr <rai::block> retrieve (MDB_txn *, rai::block_hash const &) override;
rai::sync_result target (MDB_txn *, rai::block const &) override;
push_synchronization (rai::node &, std::function <rai::sync_result (MDB_txn *, rai::block const &)> const &);
bool synchronized (MDB_txn *, rai::block_hash const &) override;
std::unique_ptr <rai::block> retrieve (MDB_txn *, rai::block_hash const &) override;
rai::sync_result target (MDB_txn *, rai::block const &) override;
std::function <rai::sync_result (MDB_txn *, rai::block const &)> target_m;
rai::node & node;
};
@ -68,11 +68,11 @@ public:
~bootstrap_attempt ();
void run ();
std::shared_ptr <rai::bootstrap_client> connection (std::unique_lock <std::mutex> &);
bool consume_future (std::future <bool> &);
bool consume_future (std::future <bool> &);
void populate_connections ();
bool request_frontier (std::unique_lock <std::mutex> &);
void request_pull (std::unique_lock <std::mutex> &);
bool request_push (std::unique_lock <std::mutex> &);
bool request_frontier (std::unique_lock <std::mutex> &);
void request_pull (std::unique_lock <std::mutex> &);
bool request_push (std::unique_lock <std::mutex> &);
void add_connection (rai::endpoint const &);
void pool_connection (std::shared_ptr <rai::bootstrap_client>);
void stop ();
@ -81,10 +81,10 @@ public:
std::deque <std::weak_ptr <rai::bootstrap_client>> clients;
std::weak_ptr <rai::frontier_req_client> frontiers;
std::weak_ptr <rai::bulk_push_client> push;
std::deque <rai::pull_info> pulls;
std::deque <rai::pull_info> pulls;
std::vector <std::shared_ptr <rai::bootstrap_client>> idle;
std::atomic <unsigned> connections;
std::atomic <unsigned> pulling;
std::atomic <unsigned> pulling;
std::shared_ptr <rai::node> node;
std::atomic <unsigned> account_count;
bool stopped;
@ -94,16 +94,16 @@ public:
class frontier_req_client : public std::enable_shared_from_this <rai::frontier_req_client>
{
public:
frontier_req_client (std::shared_ptr <rai::bootstrap_client>);
~frontier_req_client ();
frontier_req_client (std::shared_ptr <rai::bootstrap_client>);
~frontier_req_client ();
void run ();
void receive_frontier ();
void received_frontier (boost::system::error_code const &, size_t);
void request_account (rai::account const &, rai::block_hash const &);
void receive_frontier ();
void received_frontier (boost::system::error_code const &, size_t);
void request_account (rai::account const &, rai::block_hash const &);
void unsynced (MDB_txn *, rai::account const &, rai::block_hash const &);
void next (MDB_txn *);
void insert_pull (rai::pull_info const &);
std::shared_ptr <rai::bootstrap_client> connection;
std::shared_ptr <rai::bootstrap_client> connection;
rai::account current;
rai::account_info info;
unsigned count;
@ -130,29 +130,29 @@ class bootstrap_client : public std::enable_shared_from_this <bootstrap_client>
{
public:
bootstrap_client (std::shared_ptr <rai::node>, std::shared_ptr <rai::bootstrap_attempt>, rai::tcp_endpoint const &);
~bootstrap_client ();
void run ();
~bootstrap_client ();
void run ();
std::shared_ptr <rai::bootstrap_client> shared ();
void start_timeout ();
void stop_timeout ();
std::shared_ptr <rai::node> node;
std::shared_ptr <rai::node> node;
std::shared_ptr <rai::bootstrap_attempt> attempt;
boost::asio::ip::tcp::socket socket;
std::array <uint8_t, 200> receive_buffer;
boost::asio::ip::tcp::socket socket;
std::array <uint8_t, 200> receive_buffer;
rai::tcp_endpoint endpoint;
boost::asio::deadline_timer timeout;
};
class bulk_push_client : public std::enable_shared_from_this <rai::bulk_push_client>
{
public:
bulk_push_client (std::shared_ptr <rai::bootstrap_client> const &);
~bulk_push_client ();
void start ();
void push (MDB_txn *);
void push_block (rai::block const &);
void send_finished ();
std::shared_ptr <rai::bootstrap_client> connection;
rai::push_synchronization synchronization;
bulk_push_client (std::shared_ptr <rai::bootstrap_client> const &);
~bulk_push_client ();
void start ();
void push (MDB_txn *);
void push_block (rai::block const &);
void send_finished ();
std::shared_ptr <rai::bootstrap_client> connection;
rai::push_synchronization synchronization;
std::promise <bool> promise;
};
class bootstrap_initiator
@ -160,8 +160,8 @@ class bootstrap_initiator
public:
bootstrap_initiator (rai::node &);
~bootstrap_initiator ();
void bootstrap (rai::endpoint const &);
void bootstrap ();
void bootstrap (rai::endpoint const &);
void bootstrap ();
void notify_listeners (bool);
void add_observer (std::function <void (bool)> const &);
bool in_progress ();
@ -171,7 +171,7 @@ public:
std::unique_ptr <std::thread> attempt_thread;
bool stopped;
private:
void stop_attempt (std::unique_lock <std::mutex> &);
void stop_attempt (std::unique_lock <std::mutex> &);
std::mutex mutex;
std::condition_variable condition;
std::vector <std::function <void (bool)>> observers;
@ -180,83 +180,83 @@ class bootstrap_server;
class bootstrap_listener
{
public:
bootstrap_listener (boost::asio::io_service &, uint16_t, rai::node &);
void start ();
void stop ();
void accept_connection ();
void accept_action (boost::system::error_code const &, std::shared_ptr <boost::asio::ip::tcp::socket>);
std::mutex mutex;
std::unordered_map <rai::bootstrap_server *, std::weak_ptr <rai::bootstrap_server>> connections;
rai::tcp_endpoint endpoint ();
boost::asio::ip::tcp::acceptor acceptor;
rai::tcp_endpoint local;
boost::asio::io_service & service;
rai::node & node;
bool on;
bootstrap_listener (boost::asio::io_service &, uint16_t, rai::node &);
void start ();
void stop ();
void accept_connection ();
void accept_action (boost::system::error_code const &, std::shared_ptr <boost::asio::ip::tcp::socket>);
std::mutex mutex;
std::unordered_map <rai::bootstrap_server *, std::weak_ptr <rai::bootstrap_server>> connections;
rai::tcp_endpoint endpoint ();
boost::asio::ip::tcp::acceptor acceptor;
rai::tcp_endpoint local;
boost::asio::io_service & service;
rai::node & node;
bool on;
};
class message;
class bootstrap_server : public std::enable_shared_from_this <rai::bootstrap_server>
{
public:
bootstrap_server (std::shared_ptr <boost::asio::ip::tcp::socket>, std::shared_ptr <rai::node>);
~bootstrap_server ();
void receive ();
void receive_header_action (boost::system::error_code const &, size_t);
void receive_bulk_pull_action (boost::system::error_code const &, size_t);
void receive_frontier_req_action (boost::system::error_code const &, size_t);
void receive_bulk_push_action ();
void add_request (std::unique_ptr <rai::message>);
void finish_request ();
void run_next ();
std::array <uint8_t, 128> receive_buffer;
std::shared_ptr <boost::asio::ip::tcp::socket> socket;
std::shared_ptr <rai::node> node;
std::mutex mutex;
std::queue <std::unique_ptr <rai::message>> requests;
bootstrap_server (std::shared_ptr <boost::asio::ip::tcp::socket>, std::shared_ptr <rai::node>);
~bootstrap_server ();
void receive ();
void receive_header_action (boost::system::error_code const &, size_t);
void receive_bulk_pull_action (boost::system::error_code const &, size_t);
void receive_frontier_req_action (boost::system::error_code const &, size_t);
void receive_bulk_push_action ();
void add_request (std::unique_ptr <rai::message>);
void finish_request ();
void run_next ();
std::array <uint8_t, 128> receive_buffer;
std::shared_ptr <boost::asio::ip::tcp::socket> socket;
std::shared_ptr <rai::node> node;
std::mutex mutex;
std::queue <std::unique_ptr <rai::message>> requests;
};
class bulk_pull;
class bulk_pull_server : public std::enable_shared_from_this <rai::bulk_pull_server>
{
public:
bulk_pull_server (std::shared_ptr <rai::bootstrap_server> const &, std::unique_ptr <rai::bulk_pull>);
void set_current_end ();
std::unique_ptr <rai::block> get_next ();
void send_next ();
void sent_action (boost::system::error_code const &, size_t);
void send_finished ();
void no_block_sent (boost::system::error_code const &, size_t);
std::shared_ptr <rai::bootstrap_server> connection;
std::unique_ptr <rai::bulk_pull> request;
std::vector <uint8_t> send_buffer;
rai::block_hash current;
bulk_pull_server (std::shared_ptr <rai::bootstrap_server> const &, std::unique_ptr <rai::bulk_pull>);
void set_current_end ();
std::unique_ptr <rai::block> get_next ();
void send_next ();
void sent_action (boost::system::error_code const &, size_t);
void send_finished ();
void no_block_sent (boost::system::error_code const &, size_t);
std::shared_ptr <rai::bootstrap_server> connection;
std::unique_ptr <rai::bulk_pull> request;
std::vector <uint8_t> send_buffer;
rai::block_hash current;
};
class bulk_push_server : public std::enable_shared_from_this <rai::bulk_push_server>
{
public:
bulk_push_server (std::shared_ptr <rai::bootstrap_server> const &);
void receive ();
void receive_block ();
void received_type ();
void received_block (boost::system::error_code const &, size_t);
std::array <uint8_t, 256> receive_buffer;
std::shared_ptr <rai::bootstrap_server> connection;
bulk_push_server (std::shared_ptr <rai::bootstrap_server> const &);
void receive ();
void receive_block ();
void received_type ();
void received_block (boost::system::error_code const &, size_t);
std::array <uint8_t, 256> receive_buffer;
std::shared_ptr <rai::bootstrap_server> connection;
};
class frontier_req;
class frontier_req_server : public std::enable_shared_from_this <rai::frontier_req_server>
{
public:
frontier_req_server (std::shared_ptr <rai::bootstrap_server> const &, std::unique_ptr <rai::frontier_req>);
void skip_old ();
void send_next ();
void sent_action (boost::system::error_code const &, size_t);
void send_finished ();
void no_block_sent (boost::system::error_code const &, size_t);
frontier_req_server (std::shared_ptr <rai::bootstrap_server> const &, std::unique_ptr <rai::frontier_req>);
void skip_old ();
void send_next ();
void sent_action (boost::system::error_code const &, size_t);
void send_finished ();
void no_block_sent (boost::system::error_code const &, size_t);
void next ();
std::shared_ptr <rai::bootstrap_server> connection;
std::shared_ptr <rai::bootstrap_server> connection;
rai::account current;
rai::account_info info;
std::unique_ptr <rai::frontier_req> request;
std::vector <uint8_t> send_buffer;
size_t count;
std::unique_ptr <rai::frontier_req> request;
std::vector <uint8_t> send_buffer;
size_t count;
};
}

View file

@ -42,29 +42,29 @@ struct endpoint_hash
template <>
struct endpoint_hash <8>
{
size_t operator () (rai::endpoint const & endpoint_a) const
{
size_t operator () (rai::endpoint const & endpoint_a) const
{
return endpoint_hash_raw (endpoint_a);
}
}
};
template <>
struct endpoint_hash <4>
{
size_t operator () (rai::endpoint const & endpoint_a) const
{
size_t operator () (rai::endpoint const & endpoint_a) const
{
uint64_t big (endpoint_hash_raw (endpoint_a));
uint32_t result (static_cast <uint32_t> (big) ^ static_cast <uint32_t> (big >> 32));
return result;
}
}
};
template <>
struct hash <rai::endpoint>
{
size_t operator () (rai::endpoint const & endpoint_a) const
{
endpoint_hash <sizeof (size_t)> ehash;
return ehash (endpoint_a);
}
size_t operator () (rai::endpoint const & endpoint_a) const
{
endpoint_hash <sizeof (size_t)> ehash;
return ehash (endpoint_a);
}
};
}
namespace boost
@ -72,11 +72,11 @@ namespace boost
template <>
struct hash <rai::endpoint>
{
size_t operator () (rai::endpoint const & endpoint_a) const
{
std::hash <rai::endpoint> hash;
return hash (endpoint_a);
}
size_t operator () (rai::endpoint const & endpoint_a) const
{
std::hash <rai::endpoint> hash;
return hash (endpoint_a);
}
};
}
@ -84,140 +84,140 @@ namespace rai
{
enum class message_type : uint8_t
{
invalid,
not_a_type,
keepalive,
publish,
confirm_req,
confirm_ack,
bulk_pull,
bulk_push,
frontier_req
invalid,
not_a_type,
keepalive,
publish,
confirm_req,
confirm_ack,
bulk_pull,
bulk_push,
frontier_req
};
class message_visitor;
class message
{
public:
message (rai::message_type);
message (rai::message_type);
message (bool &, rai::stream &);
virtual ~message () = default;
void write_header (rai::stream &);
static bool read_header (rai::stream &, uint8_t &, uint8_t &, uint8_t &, rai::message_type &, std::bitset <16> &);
virtual void serialize (rai::stream &) = 0;
virtual bool deserialize (rai::stream &) = 0;
virtual void visit (rai::message_visitor &) const = 0;
rai::block_type block_type () const;
void block_type_set (rai::block_type);
bool ipv4_only ();
void ipv4_only_set (bool);
virtual ~message () = default;
void write_header (rai::stream &);
static bool read_header (rai::stream &, uint8_t &, uint8_t &, uint8_t &, rai::message_type &, std::bitset <16> &);
virtual void serialize (rai::stream &) = 0;
virtual bool deserialize (rai::stream &) = 0;
virtual void visit (rai::message_visitor &) const = 0;
rai::block_type block_type () const;
void block_type_set (rai::block_type);
bool ipv4_only ();
void ipv4_only_set (bool);
static std::array <uint8_t, 2> constexpr magic_number = rai::rai_network == rai::rai_networks::rai_test_network ? std::array <uint8_t, 2>({ 'R', 'A' }) : rai::rai_network == rai::rai_networks::rai_beta_network ? std::array <uint8_t, 2>({ 'R', 'B' }) : std::array <uint8_t, 2>({ 'R', 'C' });
uint8_t version_max;
uint8_t version_using;
uint8_t version_min;
rai::message_type type;
std::bitset <16> extensions;
static size_t constexpr ipv4_only_position = 1;
static size_t constexpr bootstrap_server_position = 2;
static std::bitset <16> constexpr block_type_mask = std::bitset <16> (0x0f00);
uint8_t version_max;
uint8_t version_using;
uint8_t version_min;
rai::message_type type;
std::bitset <16> extensions;
static size_t constexpr ipv4_only_position = 1;
static size_t constexpr bootstrap_server_position = 2;
static std::bitset <16> constexpr block_type_mask = std::bitset <16> (0x0f00);
};
class work_pool;
class message_parser
{
public:
message_parser (rai::message_visitor &, rai::work_pool &);
void deserialize_buffer (uint8_t const *, size_t);
void deserialize_keepalive (uint8_t const *, size_t);
void deserialize_publish (uint8_t const *, size_t);
void deserialize_confirm_req (uint8_t const *, size_t);
void deserialize_confirm_ack (uint8_t const *, size_t);
bool at_end (rai::bufferstream &);
rai::message_visitor & visitor;
message_parser (rai::message_visitor &, rai::work_pool &);
void deserialize_buffer (uint8_t const *, size_t);
void deserialize_keepalive (uint8_t const *, size_t);
void deserialize_publish (uint8_t const *, size_t);
void deserialize_confirm_req (uint8_t const *, size_t);
void deserialize_confirm_ack (uint8_t const *, size_t);
bool at_end (rai::bufferstream &);
rai::message_visitor & visitor;
rai::work_pool & pool;
bool error;
bool insufficient_work;
bool error;
bool insufficient_work;
};
class keepalive : public message
{
public:
keepalive ();
void visit (rai::message_visitor &) const override;
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
bool operator == (rai::keepalive const &) const;
std::array <rai::endpoint, 8> peers;
keepalive ();
void visit (rai::message_visitor &) const override;
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
bool operator == (rai::keepalive const &) const;
std::array <rai::endpoint, 8> peers;
};
class publish : public message
{
public:
publish ();
publish (std::shared_ptr <rai::block>);
void visit (rai::message_visitor &) const override;
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
bool operator == (rai::publish const &) const;
std::shared_ptr <rai::block> block;
publish ();
publish (std::shared_ptr <rai::block>);
void visit (rai::message_visitor &) const override;
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
bool operator == (rai::publish const &) const;
std::shared_ptr <rai::block> block;
};
class confirm_req : public message
{
public:
confirm_req ();
confirm_req (std::shared_ptr <rai::block>);
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
bool operator == (rai::confirm_req const &) const;
std::shared_ptr <rai::block> block;
confirm_req ();
confirm_req (std::shared_ptr <rai::block>);
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
bool operator == (rai::confirm_req const &) const;
std::shared_ptr <rai::block> block;
};
class confirm_ack : public message
{
public:
confirm_ack (bool &, rai::stream &);
confirm_ack (std::shared_ptr <rai::vote>);
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
bool operator == (rai::confirm_ack const &) const;
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
bool operator == (rai::confirm_ack const &) const;
std::shared_ptr <rai::vote> vote;
};
class frontier_req : public message
{
public:
frontier_req ();
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
bool operator == (rai::frontier_req const &) const;
rai::account start;
uint32_t age;
uint32_t count;
frontier_req ();
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
bool operator == (rai::frontier_req const &) const;
rai::account start;
uint32_t age;
uint32_t count;
};
class bulk_pull : public message
{
public:
bulk_pull ();
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
rai::uint256_union start;
rai::block_hash end;
bulk_pull ();
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
rai::uint256_union start;
rai::block_hash end;
};
class bulk_push : public message
{
public:
bulk_push ();
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
bulk_push ();
bool deserialize (rai::stream &) override;
void serialize (rai::stream &) override;
void visit (rai::message_visitor &) const override;
};
class message_visitor
{
public:
virtual void keepalive (rai::keepalive const &) = 0;
virtual void publish (rai::publish const &) = 0;
virtual void confirm_req (rai::confirm_req const &) = 0;
virtual void confirm_ack (rai::confirm_ack const &) = 0;
virtual void bulk_pull (rai::bulk_pull const &) = 0;
virtual void bulk_push (rai::bulk_push const &) = 0;
virtual void frontier_req (rai::frontier_req const &) = 0;
virtual void keepalive (rai::keepalive const &) = 0;
virtual void publish (rai::publish const &) = 0;
virtual void confirm_req (rai::confirm_req const &) = 0;
virtual void confirm_ack (rai::confirm_ack const &) = 0;
virtual void bulk_pull (rai::bulk_pull const &) = 0;
virtual void bulk_push (rai::bulk_push const &) = 0;
virtual void frontier_req (rai::frontier_req const &) = 0;
};
}

File diff suppressed because it is too large Load diff

View file

@ -42,7 +42,7 @@ class election : public std::enable_shared_from_this <rai::election>
std::function <void (std::shared_ptr <rai::block>)> confirmation_action;
void confirm_once (MDB_txn *);
public:
election (MDB_txn *, rai::node &, std::shared_ptr <rai::block>, std::function <void (std::shared_ptr <rai::block>)> const &);
election (MDB_txn *, rai::node &, std::shared_ptr <rai::block>, std::function <void (std::shared_ptr <rai::block>)> const &);
void vote (std::shared_ptr <rai::vote>);
// Check if we have vote quorum
bool have_quorum (MDB_txn *);
@ -54,13 +54,13 @@ public:
void confirm_if_quorum (MDB_txn *);
// Confirmation method 2, settling time
void confirm_cutoff (MDB_txn *);
rai::uint128_t quorum_threshold (MDB_txn *, rai::ledger &);
rai::uint128_t quorum_threshold (MDB_txn *, rai::ledger &);
rai::uint128_t minimum_threshold (MDB_txn *, rai::ledger &);
rai::votes votes;
rai::node & node;
std::chrono::system_clock::time_point last_vote;
rai::votes votes;
rai::node & node;
std::chrono::system_clock::time_point last_vote;
std::shared_ptr <rai::block> last_winner;
std::atomic_flag confirmed;
std::atomic_flag confirmed;
};
class conflict_info
{
@ -103,50 +103,50 @@ public:
class operation
{
public:
bool operator > (rai::operation const &) const;
std::chrono::system_clock::time_point wakeup;
std::function <void ()> function;
bool operator > (rai::operation const &) const;
std::chrono::system_clock::time_point wakeup;
std::function <void ()> function;
};
class alarm
{
public:
alarm (boost::asio::io_service &);
alarm (boost::asio::io_service &);
~alarm ();
void add (std::chrono::system_clock::time_point const &, std::function <void ()> const &);
void add (std::chrono::system_clock::time_point const &, std::function <void ()> const &);
void run ();
boost::asio::io_service & service;
std::mutex mutex;
std::condition_variable condition;
std::priority_queue <operation, std::vector <operation>, std::greater <operation>> operations;
std::mutex mutex;
std::condition_variable condition;
std::priority_queue <operation, std::vector <operation>, std::greater <operation>> operations;
std::thread thread;
};
class gap_information
{
public:
std::chrono::system_clock::time_point arrival;
rai::block_hash hash;
std::chrono::system_clock::time_point arrival;
rai::block_hash hash;
std::unique_ptr <rai::votes> votes;
};
class gap_cache
{
public:
gap_cache (rai::node &);
void add (MDB_txn *, std::shared_ptr <rai::block>);
void vote (std::shared_ptr <rai::vote>);
rai::uint128_t bootstrap_threshold (MDB_txn *);
gap_cache (rai::node &);
void add (MDB_txn *, std::shared_ptr <rai::block>);
void vote (std::shared_ptr <rai::vote>);
rai::uint128_t bootstrap_threshold (MDB_txn *);
void purge_old ();
boost::multi_index_container
<
rai::gap_information,
boost::multi_index::indexed_by
<
boost::multi_index::ordered_non_unique <boost::multi_index::member <gap_information, std::chrono::system_clock::time_point, &gap_information::arrival>>,
boost::multi_index::hashed_unique <boost::multi_index::member <gap_information, rai::block_hash, &gap_information::hash>>
>
> blocks;
size_t const max = 256;
std::mutex mutex;
rai::node & node;
boost::multi_index_container
<
rai::gap_information,
boost::multi_index::indexed_by
<
boost::multi_index::ordered_non_unique <boost::multi_index::member <gap_information, std::chrono::system_clock::time_point, &gap_information::arrival>>,
boost::multi_index::hashed_unique <boost::multi_index::member <gap_information, rai::block_hash, &gap_information::hash>>
>
> blocks;
size_t const max = 256;
std::mutex mutex;
rai::node & node;
};
class work_pool;
class peer_information
@ -174,7 +174,7 @@ class peer_container
public:
peer_container (rai::endpoint const &);
// We were contacted by endpoint, update peers
void contacted (rai::endpoint const &, unsigned);
void contacted (rai::endpoint const &, unsigned);
// Unassigned, reserved, self
bool not_a_peer (rai::endpoint const &);
// Returns true if peer was already known
@ -280,91 +280,91 @@ class message_statistics
{
public:
message_statistics ();
std::atomic <uint64_t> keepalive;
std::atomic <uint64_t> publish;
std::atomic <uint64_t> confirm_req;
std::atomic <uint64_t> confirm_ack;
std::atomic <uint64_t> keepalive;
std::atomic <uint64_t> publish;
std::atomic <uint64_t> confirm_req;
std::atomic <uint64_t> confirm_ack;
};
class block_arrival_info
{
public:
std::chrono::system_clock::time_point arrival;
rai::block_hash hash;
std::chrono::system_clock::time_point arrival;
rai::block_hash hash;
};
// This class tracks blocks that are probably live because they arrived in a UDP packet
// This gives a fairly reliable way to differentiate between blocks being inserted via bootstrap or new, live blocks.
class block_arrival
{
public:
void add (rai::block_hash const &);
bool recent (rai::block_hash const &);
boost::multi_index_container
<
rai::block_arrival_info,
boost::multi_index::indexed_by
<
boost::multi_index::ordered_non_unique <boost::multi_index::member <rai::block_arrival_info, std::chrono::system_clock::time_point, &rai::block_arrival_info::arrival>>,
boost::multi_index::hashed_unique <boost::multi_index::member <rai::block_arrival_info, rai::block_hash, &rai::block_arrival_info::hash>>
>
> arrival;
std::mutex mutex;
void add (rai::block_hash const &);
bool recent (rai::block_hash const &);
boost::multi_index_container
<
rai::block_arrival_info,
boost::multi_index::indexed_by
<
boost::multi_index::ordered_non_unique <boost::multi_index::member <rai::block_arrival_info, std::chrono::system_clock::time_point, &rai::block_arrival_info::arrival>>,
boost::multi_index::hashed_unique <boost::multi_index::member <rai::block_arrival_info, rai::block_hash, &rai::block_arrival_info::hash>>
>
> arrival;
std::mutex mutex;
};
class network
{
public:
network (rai::node &, uint16_t);
void receive ();
void stop ();
void receive_action (boost::system::error_code const &, size_t);
void rpc_action (boost::system::error_code const &, size_t);
network (rai::node &, uint16_t);
void receive ();
void stop ();
void receive_action (boost::system::error_code const &, size_t);
void rpc_action (boost::system::error_code const &, size_t);
void rebroadcast_reps (std::shared_ptr <rai::block>);
void republish_vote (std::chrono::system_clock::time_point const &, std::shared_ptr <rai::vote>);
void republish_block (MDB_txn *, std::shared_ptr <rai::block>);
void republish_block (MDB_txn *, std::shared_ptr <rai::block>);
void republish (rai::block_hash const &, std::shared_ptr <std::vector <uint8_t>>, rai::endpoint);
void publish_broadcast (std::vector <rai::peer_information> &, std::unique_ptr <rai::block>);
void publish_broadcast (std::vector <rai::peer_information> &, std::unique_ptr <rai::block>);
void confirm_send (rai::confirm_ack const &, std::shared_ptr <std::vector <uint8_t>>, rai::endpoint const &);
void merge_peers (std::array <rai::endpoint, 8> const &);
void send_keepalive (rai::endpoint const &);
void merge_peers (std::array <rai::endpoint, 8> const &);
void send_keepalive (rai::endpoint const &);
void broadcast_confirm_req (std::shared_ptr <rai::block>);
void send_confirm_req (rai::endpoint const &, std::shared_ptr <rai::block>);
void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function <void (boost::system::error_code const &, size_t)>);
rai::endpoint endpoint ();
rai::endpoint remote;
std::array <uint8_t, 512> buffer;
boost::asio::ip::udp::socket socket;
std::mutex socket_mutex;
boost::asio::ip::udp::resolver resolver;
rai::node & node;
uint64_t bad_sender_count;
bool on;
uint64_t insufficient_work_count;
uint64_t error_count;
void send_confirm_req (rai::endpoint const &, std::shared_ptr <rai::block>);
void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function <void (boost::system::error_code const &, size_t)>);
rai::endpoint endpoint ();
rai::endpoint remote;
std::array <uint8_t, 512> buffer;
boost::asio::ip::udp::socket socket;
std::mutex socket_mutex;
boost::asio::ip::udp::resolver resolver;
rai::node & node;
uint64_t bad_sender_count;
bool on;
uint64_t insufficient_work_count;
uint64_t error_count;
rai::message_statistics incoming;
rai::message_statistics outgoing;
static uint16_t const node_port = rai::rai_network == rai::rai_networks::rai_live_network ? 7075 : 54000;
static uint16_t const node_port = rai::rai_network == rai::rai_networks::rai_live_network ? 7075 : 54000;
};
class logging
{
public:
logging ();
void serialize_json (boost::property_tree::ptree &) const;
void serialize_json (boost::property_tree::ptree &) const;
bool deserialize_json (bool &, boost::property_tree::ptree &);
bool upgrade_json (unsigned, boost::property_tree::ptree &);
bool ledger_logging () const;
bool ledger_duplicate_logging () const;
bool ledger_logging () const;
bool ledger_duplicate_logging () const;
bool vote_logging () const;
bool network_logging () const;
bool network_message_logging () const;
bool network_publish_logging () const;
bool network_packet_logging () const;
bool network_keepalive_logging () const;
bool node_lifetime_tracing () const;
bool insufficient_work_logging () const;
bool log_rpc () const;
bool bulk_pull_logging () const;
bool network_logging () const;
bool network_message_logging () const;
bool network_publish_logging () const;
bool network_packet_logging () const;
bool network_keepalive_logging () const;
bool node_lifetime_tracing () const;
bool insufficient_work_logging () const;
bool log_rpc () const;
bool bulk_pull_logging () const;
bool callback_logging () const;
bool work_generation_time () const;
bool log_to_cerr () const;
bool work_generation_time () const;
bool log_to_cerr () const;
void init (boost::filesystem::path const &);
bool ledger_logging_value;
@ -382,22 +382,22 @@ public:
bool work_generation_time_value;
bool log_to_cerr_value;
uintmax_t max_size;
boost::log::sources::logger_mt log;
boost::log::sources::logger_mt log;
};
class node_init
{
public:
node_init ();
bool error ();
bool block_store_init;
bool wallet_init;
node_init ();
bool error ();
bool block_store_init;
bool wallet_init;
};
class node_config
{
public:
node_config ();
node_config (uint16_t, rai::logging const &);
void serialize_json (boost::property_tree::ptree &) const;
void serialize_json (boost::property_tree::ptree &) const;
bool deserialize_json (bool &, boost::property_tree::ptree &);
bool upgrade_json (unsigned, boost::property_tree::ptree &);
rai::account random_representative ();
@ -417,8 +417,8 @@ public:
std::string callback_address;
uint16_t callback_port;
std::string callback_target;
static std::chrono::seconds constexpr keepalive_period = std::chrono::seconds (60);
static std::chrono::seconds constexpr keepalive_cutoff = keepalive_period * 5;
static std::chrono::seconds constexpr keepalive_period = std::chrono::seconds (60);
static std::chrono::seconds constexpr keepalive_cutoff = keepalive_period * 5;
static std::chrono::minutes constexpr wallet_backup_interval = std::chrono::minutes (5);
};
class node_observers
@ -484,32 +484,32 @@ private:
class node : public std::enable_shared_from_this <rai::node>
{
public:
node (rai::node_init &, boost::asio::io_service &, uint16_t, boost::filesystem::path const &, rai::alarm &, rai::logging const &, rai::work_pool &);
node (rai::node_init &, boost::asio::io_service &, boost::filesystem::path const &, rai::alarm &, rai::node_config const &, rai::work_pool &);
~node ();
node (rai::node_init &, boost::asio::io_service &, uint16_t, boost::filesystem::path const &, rai::alarm &, rai::logging const &, rai::work_pool &);
node (rai::node_init &, boost::asio::io_service &, boost::filesystem::path const &, rai::alarm &, rai::node_config const &, rai::work_pool &);
~node ();
template <typename T>
void background (T action_a)
{
alarm.service.post (action_a);
}
void send_keepalive (rai::endpoint const &);
void send_keepalive (rai::endpoint const &);
void keepalive (std::string const &, uint16_t);
void start ();
void stop ();
std::shared_ptr <rai::node> shared ();
void start ();
void stop ();
std::shared_ptr <rai::node> shared ();
int store_version ();
void process_confirmed (std::shared_ptr <rai::block>);
void process_confirmed (std::shared_ptr <rai::block>);
void process_message (rai::message &, rai::endpoint const &);
void process_active (std::shared_ptr <rai::block>);
rai::process_return process (rai::block const &);
void keepalive_preconfigured (std::vector <std::string> const &);
void keepalive_preconfigured (std::vector <std::string> const &);
rai::block_hash latest (rai::account const &);
rai::uint128_t balance (rai::account const &);
std::unique_ptr <rai::block> block (rai::block_hash const &);
std::pair <rai::uint128_t, rai::uint128_t> balance_pending (rai::account const &);
rai::uint128_t weight (rai::account const &);
rai::account representative (rai::account const &);
void ongoing_keepalive ();
void ongoing_keepalive ();
void ongoing_rep_crawl ();
void ongoing_bootstrap ();
void ongoing_store_flush ();
@ -518,34 +518,34 @@ public:
void generate_work (rai::block &);
uint64_t generate_work (rai::uint256_union const &);
void generate_work (rai::uint256_union const &, std::function <void (uint64_t)>);
void add_initial_peers ();
boost::asio::io_service & service;
void add_initial_peers ();
boost::asio::io_service & service;
rai::node_config config;
rai::alarm & alarm;
rai::alarm & alarm;
rai::work_pool & work;
boost::log::sources::logger_mt log;
rai::block_store store;
rai::gap_cache gap_cache;
rai::ledger ledger;
rai::active_transactions active;
rai::wallets wallets;
rai::network network;
boost::log::sources::logger_mt log;
rai::block_store store;
rai::gap_cache gap_cache;
rai::ledger ledger;
rai::active_transactions active;
rai::wallets wallets;
rai::network network;
rai::bootstrap_initiator bootstrap_initiator;
rai::bootstrap_listener bootstrap;
rai::peer_container peers;
rai::bootstrap_listener bootstrap;
rai::peer_container peers;
boost::filesystem::path application_path;
rai::node_observers observers;
rai::port_mapping port_mapping;
rai::vote_processor vote_processor;
rai::rep_crawler rep_crawler;
unsigned warmed_up;
rai::block_processor block_processor;
rai::block_processor block_processor;
std::thread block_processor_thread;
rai::block_arrival block_arrival;
rai::block_arrival block_arrival;
static double constexpr price_max = 16.0;
static double constexpr free_cutoff = 1024.0;
static std::chrono::seconds constexpr period = std::chrono::seconds (60);
static std::chrono::seconds constexpr cutoff = period * 5;
static std::chrono::seconds constexpr period = std::chrono::seconds (60);
static std::chrono::seconds constexpr cutoff = period * 5;
static std::chrono::minutes constexpr backup_interval = std::chrono::minutes (5);
};
class thread_runner

View file

@ -213,10 +213,10 @@ static int blake2b_compress( blake2b_state *S, __private const uchar block[BLAKE
int i;
for( i = 0; i < 16; ++i )
m[i] = load64( block + i * sizeof( m[i] ) );
m[i] = load64( block + i * sizeof( m[i] ) );
for( i = 0; i < 8; ++i )
v[i] = S->h[i];
v[i] = S->h[i];
v[ 8] = blake2b_IV[0];
v[ 9] = blake2b_IV[1];
@ -228,25 +228,25 @@ static int blake2b_compress( blake2b_state *S, __private const uchar block[BLAKE
v[15] = S->f[1] ^ blake2b_IV[7];
#define G(r,i,a,b,c,d) \
do { \
a = a + b + m[blake2b_sigma[r][2*i+0]]; \
d = rotr64(d ^ a, 32); \
c = c + d; \
b = rotr64(b ^ c, 24); \
a = a + b + m[blake2b_sigma[r][2*i+1]]; \
d = rotr64(d ^ a, 16); \
c = c + d; \
b = rotr64(b ^ c, 63); \
a = a + b + m[blake2b_sigma[r][2*i+0]]; \
d = rotr64(d ^ a, 32); \
c = c + d; \
b = rotr64(b ^ c, 24); \
a = a + b + m[blake2b_sigma[r][2*i+1]]; \
d = rotr64(d ^ a, 16); \
c = c + d; \
b = rotr64(b ^ c, 63); \
} while(0)
#define ROUND(r) \
do { \
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
} while(0)
ROUND( 0 );
ROUND( 1 );
@ -262,7 +262,7 @@ static int blake2b_compress( blake2b_state *S, __private const uchar block[BLAKE
ROUND( 11 );
for( i = 0; i < 8; ++i )
S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
#undef G
#undef ROUND
@ -292,27 +292,27 @@ static int blake2b_update( blake2b_state *S, const uchar *in, ulong inlen )
{
while( inlen > 0 )
{
size_t left = S->buflen;
size_t fill = 2 * BLAKE2B_BLOCKBYTES - left;
size_t left = S->buflen;
size_t fill = 2 * BLAKE2B_BLOCKBYTES - left;
if( inlen > fill )
{
ucharcpy( S->buf + left, in, fill ); // Fill buffer
S->buflen += fill;
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
blake2b_compress( S, S->buf ); // Compress
ucharcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); // Shift buffer left
S->buflen -= BLAKE2B_BLOCKBYTES;
in += fill;
inlen -= fill;
}
else // inlen <= fill
{
ucharcpy( S->buf + left, in, inlen );
S->buflen += inlen; // Be lazy, do not compress
in += inlen;
inlen -= inlen;
}
if( inlen > fill )
{
ucharcpy( S->buf + left, in, fill ); // Fill buffer
S->buflen += fill;
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
blake2b_compress( S, S->buf ); // Compress
ucharcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); // Shift buffer left
S->buflen -= BLAKE2B_BLOCKBYTES;
in += fill;
inlen -= fill;
}
else // inlen <= fill
{
ucharcpy( S->buf + left, in, inlen );
S->buflen += inlen; // Be lazy, do not compress
in += inlen;
inlen -= inlen;
}
}
return 0;
@ -325,10 +325,10 @@ static int blake2b_final( blake2b_state *S, uchar *out, uchar outlen )
if( S->buflen > BLAKE2B_BLOCKBYTES )
{
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
blake2b_compress( S, S->buf );
S->buflen -= BLAKE2B_BLOCKBYTES;
ucharcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen );
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
blake2b_compress( S, S->buf );
S->buflen -= BLAKE2B_BLOCKBYTES;
ucharcpy( S->buf, S->buf + BLAKE2B_BLOCKBYTES, S->buflen );
}
//blake2b_increment_counter( S, S->buflen );
@ -343,7 +343,7 @@ static int blake2b_final( blake2b_state *S, uchar *out, uchar outlen )
blake2b_compress( S, S->buf );
for( int i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );
store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );
ucharcpy( out, buffer, outlen );
return 0;
@ -511,8 +511,8 @@ void rai::opencl_config::serialize_json (boost::property_tree::ptree & tree_a) c
bool rai::opencl_config::deserialize_json (boost::property_tree::ptree const & tree_a)
{
auto result (false);
try
{
try
{
auto platform_l (tree_a.get <std::string> ("platform"));
auto device_l (tree_a.get <std::string> ("device"));
auto threads_l (tree_a.get <std::string> ("threads"));
@ -526,11 +526,11 @@ bool rai::opencl_config::deserialize_json (boost::property_tree::ptree const & t
{
result = true;
}
}
catch (std::runtime_error const &)
{
result = true;
}
}
catch (std::runtime_error const &)
{
result = true;
}
return result;
}

View file

@ -39,7 +39,7 @@ class opencl_config
public:
opencl_config ();
opencl_config (unsigned, unsigned, unsigned);
void serialize_json (boost::property_tree::ptree &) const;
void serialize_json (boost::property_tree::ptree &) const;
bool deserialize_json (boost::property_tree::ptree const &);
unsigned platform;
unsigned device;

View file

@ -37,8 +37,8 @@ void rai::rpc_config::serialize_json (boost::property_tree::ptree & tree_a) cons
bool rai::rpc_config::deserialize_json (boost::property_tree::ptree const & tree_a)
{
auto result (false);
try
{
try
{
auto address_l (tree_a.get <std::string> ("address"));
auto port_l (tree_a.get <std::string> ("port"));
enable_control = tree_a.get <bool> ("enable_control");
@ -61,11 +61,11 @@ bool rai::rpc_config::deserialize_json (boost::property_tree::ptree const & tree
{
result = true;
}
}
catch (std::runtime_error const &)
{
result = true;
}
}
catch (std::runtime_error const &)
{
result = true;
}
return result;
}

View file

@ -21,7 +21,7 @@ class rpc_config
public:
rpc_config ();
rpc_config (bool);
void serialize_json (boost::property_tree::ptree &) const;
void serialize_json (boost::property_tree::ptree &) const;
bool deserialize_json (boost::property_tree::ptree const &);
boost::asio::ip::address_v6 address;
uint16_t port;
@ -44,17 +44,17 @@ class payment_observer;
class rpc
{
public:
rpc (boost::asio::io_service &, rai::node &, rai::rpc_config const &);
void start ();
void stop ();
rpc (boost::asio::io_service &, rai::node &, rai::rpc_config const &);
void start ();
void stop ();
void observer_action (rai::account const &);
boost::asio::ip::tcp::acceptor acceptor;
std::mutex mutex;
std::unordered_map <rai::account, std::shared_ptr <rai::payment_observer>> payment_observers;
rai::rpc_config config;
rai::node & node;
bool on;
static uint16_t const rpc_port = rai::rai_network == rai::rai_networks::rai_live_network ? 7076 : 55000;
rai::node & node;
bool on;
static uint16_t const rpc_port = rai::rai_network == rai::rai_networks::rai_live_network ? 7076 : 55000;
};
class rpc_connection : public std::enable_shared_from_this <rai::rpc_connection>
{

View file

@ -8,32 +8,32 @@ alarm (service),
work (1, nullptr)
{
logging.init (rai::unique_path ());
nodes.reserve (count_a);
for (size_t i (0); i < count_a; ++i)
{
rai::node_init init;
nodes.reserve (count_a);
for (size_t i (0); i < count_a; ++i)
{
rai::node_init init;
rai::node_config config (port_a + i, logging);
auto node (std::make_shared <rai::node> (init, service, rai::unique_path (), alarm, config, work));
assert (!init.error ());
node->start ();
auto node (std::make_shared <rai::node> (init, service, rai::unique_path (), alarm, config, work));
assert (!init.error ());
node->start ();
rai::uint256_union wallet;
rai::random_pool.GenerateBlock (wallet.bytes.data (), wallet.bytes.size ());
node->wallets.create (wallet);
nodes.push_back (node);
}
for (auto i (nodes.begin ()), j (nodes.begin () + 1), n (nodes.end ()); j != n; ++i, ++j)
{
auto starting1 ((*i)->peers.size ());
auto new1 (starting1);
auto starting2 ((*j)->peers.size ());
auto new2 (starting2);
(*j)->network.send_keepalive ((*i)->network.endpoint ());
do {
poll ();
new1 = (*i)->peers.size ();
new2 = (*j)->peers.size ();
} while (new1 == starting1 || new2 == starting2);
}
nodes.push_back (node);
}
for (auto i (nodes.begin ()), j (nodes.begin () + 1), n (nodes.end ()); j != n; ++i, ++j)
{
auto starting1 ((*i)->peers.size ());
auto new1 (starting1);
auto starting2 ((*j)->peers.size ());
auto new2 (starting2);
(*j)->network.send_keepalive ((*i)->network.endpoint ());
do {
poll ();
new1 = (*i)->peers.size ();
new2 = (*j)->peers.size ();
} while (new1 == starting1 || new2 == starting2);
}
auto iterations1 (0);
while (std::any_of (nodes.begin (), nodes.end (), [] (std::shared_ptr <rai::node> const & node_a) {return node_a->bootstrap_initiator.in_progress ();}))
{
@ -45,28 +45,28 @@ work (1, nullptr)
rai::system::~system ()
{
for (auto & i: nodes)
{
i->stop ();
}
for (auto & i: nodes)
{
i->stop ();
}
}
std::shared_ptr <rai::wallet> rai::system::wallet (size_t index_a)
{
assert (nodes.size () > index_a);
assert (nodes.size () > index_a);
auto size (nodes [index_a]->wallets.items.size ());
assert (size == 1);
return nodes [index_a]->wallets.items.begin ()->second;
assert (size == 1);
return nodes [index_a]->wallets.items.begin ()->second;
}
rai::account rai::system::account (MDB_txn * transaction_a, size_t index_a)
{
auto wallet_l (wallet (index_a));
auto keys (wallet_l->store.begin (transaction_a));
assert (keys != wallet_l->store.end ());
auto result (keys->first);
assert (++keys == wallet_l->store.end ());
return result.uint256 ();
auto wallet_l (wallet (index_a));
auto keys (wallet_l->store.begin (transaction_a));
assert (keys != wallet_l->store.end ());
auto result (keys->first);
assert (++keys == wallet_l->store.end ());
return result.uint256 ();
}
void rai::system::poll ()
@ -84,46 +84,46 @@ namespace
class traffic_generator : public std::enable_shared_from_this <traffic_generator>
{
public:
traffic_generator (uint32_t count_a, uint32_t wait_a, std::shared_ptr <rai::node> node_a, rai::system & system_a) :
count (count_a),
wait (wait_a),
node (node_a),
system (system_a)
{
}
void run ()
{
auto count_l (count - 1);
count = count_l - 1;
system.generate_activity (*node, accounts);
if (count_l > 0)
{
auto this_l (shared_from_this ());
node->alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (wait), [this_l] () {this_l->run ();});
}
}
traffic_generator (uint32_t count_a, uint32_t wait_a, std::shared_ptr <rai::node> node_a, rai::system & system_a) :
count (count_a),
wait (wait_a),
node (node_a),
system (system_a)
{
}
void run ()
{
auto count_l (count - 1);
count = count_l - 1;
system.generate_activity (*node, accounts);
if (count_l > 0)
{
auto this_l (shared_from_this ());
node->alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (wait), [this_l] () {this_l->run ();});
}
}
std::vector <rai::account> accounts;
uint32_t count;
uint32_t wait;
std::shared_ptr <rai::node> node;
rai::system & system;
uint32_t count;
uint32_t wait;
std::shared_ptr <rai::node> node;
rai::system & system;
};
}
void rai::system::generate_usage_traffic (uint32_t count_a, uint32_t wait_a)
{
for (size_t i (0), n (nodes.size ()); i != n; ++i)
{
generate_usage_traffic (count_a, wait_a, i);
}
for (size_t i (0), n (nodes.size ()); i != n; ++i)
{
generate_usage_traffic (count_a, wait_a, i);
}
}
void rai::system::generate_usage_traffic (uint32_t count_a, uint32_t wait_a, size_t index_a)
{
assert (nodes.size () > index_a);
assert (count_a > 0);
auto generate (std::make_shared <traffic_generator> (count_a, wait_a, nodes [index_a], *this));
generate->run ();
assert (nodes.size () > index_a);
assert (count_a > 0);
auto generate (std::make_shared <traffic_generator> (count_a, wait_a, nodes [index_a], *this));
generate->run ();
}
void rai::system::generate_rollback (rai::node & node_a, std::vector <rai::account> & accounts_a)
@ -185,7 +185,7 @@ void rai::system::generate_receive (rai::node & node_a)
void rai::system::generate_activity (rai::node & node_a, std::vector <rai::account> & accounts_a)
{
auto what (random_pool.GenerateByte ());
auto what (random_pool.GenerateByte ());
if (what < 0x10)
{
generate_rollback (node_a, accounts_a);
@ -202,14 +202,14 @@ void rai::system::generate_activity (rai::node & node_a, std::vector <rai::accou
{
generate_receive (node_a);
}
else if (what < 0xc0)
{
generate_send_existing (node_a, accounts_a);
}
else
{
generate_send_new (node_a, accounts_a);
}
else if (what < 0xc0)
{
generate_send_existing (node_a, accounts_a);
}
else
{
generate_send_new (node_a, accounts_a);
}
}
rai::account rai::system::get_random_account (std::vector <rai::account> & accounts_a)
@ -221,13 +221,13 @@ rai::account rai::system::get_random_account (std::vector <rai::account> & accou
rai::uint128_t rai::system::get_random_amount (MDB_txn * transaction_a, rai::node & node_a, rai::account const & account_a)
{
rai::uint128_t balance (node_a.ledger.account_balance (transaction_a, account_a));
std::string balance_text (balance.convert_to <std::string> ());
rai::uint128_union random_amount;
random_pool.GenerateBlock (random_amount.bytes.data (), sizeof (random_amount.bytes));
auto result (((rai::uint256_t {random_amount.number ()} * balance) / rai::uint256_t {std::numeric_limits <rai::uint128_t>::max ()}).convert_to <rai::uint128_t> ());
std::string text (result.convert_to <std::string> ());
return result;
rai::uint128_t balance (node_a.ledger.account_balance (transaction_a, account_a));
std::string balance_text (balance.convert_to <std::string> ());
rai::uint128_union random_amount;
random_pool.GenerateBlock (random_amount.bytes.data (), sizeof (random_amount.bytes));
auto result (((rai::uint256_t {random_amount.number ()} * balance) / rai::uint256_t {std::numeric_limits <rai::uint128_t>::max ()}).convert_to <rai::uint128_t> ());
std::string text (result.convert_to <std::string> ());
return result;
}
void rai::system::generate_send_existing (rai::node & node_a, std::vector <rai::account> & accounts_a)
@ -281,7 +281,7 @@ void rai::system::generate_change_unknown (rai::node & node_a, std::vector <rai:
void rai::system::generate_send_new (rai::node & node_a, std::vector <rai::account> & accounts_a)
{
assert (node_a.wallets.items.size () == 1);
assert (node_a.wallets.items.size () == 1);
rai::uint128_t amount;
rai::account source;
{
@ -301,20 +301,20 @@ void rai::system::generate_send_new (rai::node & node_a, std::vector <rai::accou
void rai::system::generate_mass_activity (uint32_t count_a, rai::node & node_a)
{
std::vector <rai::account> accounts;
wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
accounts.push_back (rai::test_genesis_key.pub);
auto previous (std::chrono::system_clock::now ());
for (uint32_t i (0); i < count_a; ++i)
{
if ((i & 0xfff) == 0)
{
auto now (std::chrono::system_clock::now ());
auto us (std::chrono::duration_cast <std::chrono::microseconds> (now - previous).count ());
std::cerr << boost::str (boost::format ("Mass activity iteration %1% us %2% us/t %3%\n") % i % us % (us / 256));
previous = now;
}
generate_activity (node_a, accounts);
}
auto previous (std::chrono::system_clock::now ());
for (uint32_t i (0); i < count_a; ++i)
{
if ((i & 0xfff) == 0)
{
auto now (std::chrono::system_clock::now ());
auto us (std::chrono::duration_cast <std::chrono::microseconds> (now - previous).count ());
std::cerr << boost::str (boost::format ("Mass activity iteration %1% us %2% us/t %3%\n") % i % us % (us / 256));
previous = now;
}
generate_activity (node_a, accounts);
}
}
void rai::system::stop ()

View file

@ -7,27 +7,27 @@ namespace rai
class system
{
public:
system (uint16_t, size_t);
~system ();
void generate_activity (rai::node &, std::vector <rai::account> &);
void generate_mass_activity (uint32_t, rai::node &);
void generate_usage_traffic (uint32_t, uint32_t, size_t);
void generate_usage_traffic (uint32_t, uint32_t);
system (uint16_t, size_t);
~system ();
void generate_activity (rai::node &, std::vector <rai::account> &);
void generate_mass_activity (uint32_t, rai::node &);
void generate_usage_traffic (uint32_t, uint32_t, size_t);
void generate_usage_traffic (uint32_t, uint32_t);
rai::account get_random_account (std::vector <rai::account> &);
rai::uint128_t get_random_amount (MDB_txn *, rai::node &, rai::account const &);
rai::uint128_t get_random_amount (MDB_txn *, rai::node &, rai::account const &);
void generate_rollback (rai::node &, std::vector <rai::account> &);
void generate_change_known (rai::node &, std::vector <rai::account> &);
void generate_change_unknown (rai::node &, std::vector <rai::account> &);
void generate_receive (rai::node &);
void generate_send_new (rai::node &, std::vector <rai::account> &);
void generate_send_existing (rai::node &, std::vector <rai::account> &);
std::shared_ptr <rai::wallet> wallet (size_t);
rai::account account (MDB_txn *, size_t);
void generate_send_new (rai::node &, std::vector <rai::account> &);
void generate_send_existing (rai::node &, std::vector <rai::account> &);
std::shared_ptr <rai::wallet> wallet (size_t);
rai::account account (MDB_txn *, size_t);
void poll ();
void stop ();
boost::asio::io_service service;
rai::alarm alarm;
std::vector <std::shared_ptr <rai::node>> nodes;
boost::asio::io_service service;
rai::alarm alarm;
std::vector <std::shared_ptr <rai::node>> nodes;
rai::logging logging;
rai::work_pool work;
};

View file

@ -35,7 +35,7 @@ bool fetch_object (T & object, std::iostream & stream_a)
assert (stream_a.tellg () == std::streampos (0) || stream_a.tellg () == std::streampos (-1));
assert (stream_a.tellp () == std::streampos (0) || stream_a.tellp () == std::streampos (-1));
bool error (false);
boost::property_tree::ptree tree;
boost::property_tree::ptree tree;
try
{
boost::property_tree::read_json (stream_a, tree);

View file

@ -16,21 +16,21 @@
rai::uint256_union rai::wallet_store::check (MDB_txn * transaction_a)
{
rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::check_special));
return value.key;
return value.key;
}
rai::uint256_union rai::wallet_store::salt (MDB_txn * transaction_a)
{
rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::salt_special));
return value.key;
return value.key;
}
void rai::wallet_store::wallet_key (rai::raw_key & prv_a, MDB_txn * transaction_a)
{
rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::wallet_key_special));
rai::raw_key password_l;
rai::raw_key password_l;
password.value (password_l);
prv_a.decrypt (value.key, password_l, salt (transaction_a).owords [0]);
prv_a.decrypt (value.key, password_l, salt (transaction_a).owords [0]);
}
void rai::wallet_store::seed (rai::raw_key & prv_a, MDB_txn * transaction_a)
@ -56,8 +56,8 @@ rai::public_key rai::wallet_store::deterministic_insert (MDB_txn * transaction_a
auto index (deterministic_index_get (transaction_a));
rai::raw_key prv;
deterministic_key (prv, transaction_a, index);
rai::public_key result;
ed25519_publickey (prv.data.bytes.data (), result.bytes.data ());
rai::public_key result;
ed25519_publickey (prv.data.bytes.data (), result.bytes.data ());
while (exists (transaction_a, result))
{
++index;
@ -120,20 +120,20 @@ void rai::wallet_store::deterministic_clear (MDB_txn * transaction_a)
bool rai::wallet_store::valid_password (MDB_txn * transaction_a)
{
rai::raw_key zero;
zero.data.clear ();
rai::raw_key wallet_key_l;
rai::raw_key zero;
zero.data.clear ();
rai::raw_key wallet_key_l;
wallet_key (wallet_key_l, transaction_a);
rai::uint256_union check_l;
rai::uint256_union check_l;
check_l.encrypt (zero, wallet_key_l, salt (transaction_a).owords [0]);
return check (transaction_a) == check_l;
return check (transaction_a) == check_l;
}
bool rai::wallet_store::attempt_password (MDB_txn * transaction_a, std::string const & password_a)
{
rai::raw_key password_l;
derive_key (password_l, transaction_a, password_a);
password.value_set (password_l);
password.value_set (password_l);
auto result (!valid_password (transaction_a));
if (!result)
{
@ -151,25 +151,25 @@ bool rai::wallet_store::attempt_password (MDB_txn * transaction_a, std::string c
bool rai::wallet_store::rekey (MDB_txn * transaction_a, std::string const & password_a)
{
bool result (false);
bool result (false);
if (valid_password (transaction_a))
{
rai::raw_key password_new;
{
rai::raw_key password_new;
derive_key (password_new, transaction_a, password_a);
rai::raw_key wallet_key_l;
rai::raw_key wallet_key_l;
wallet_key (wallet_key_l, transaction_a);
rai::raw_key password_l;
rai::raw_key password_l;
password.value (password_l);
password.value_set (password_new);
rai::uint256_union encrypted;
rai::uint256_union encrypted;
encrypted.encrypt (wallet_key_l, password_new, salt (transaction_a).owords [0]);
entry_put_raw (transaction_a, rai::wallet_store::wallet_key_special, rai::wallet_value (encrypted, 0));
}
else
{
result = true;
}
return result;
}
else
{
result = true;
}
return result;
}
void rai::wallet_store::derive_key (rai::raw_key & prv_a, MDB_txn * transaction_a, std::string const & password_a)
@ -180,15 +180,15 @@ void rai::wallet_store::derive_key (rai::raw_key & prv_a, MDB_txn * transaction_
rai::fan::fan (rai::uint256_union const & key, size_t count_a)
{
std::unique_ptr <rai::uint256_union> first (new rai::uint256_union (key));
for (auto i (1); i < count_a; ++i)
{
std::unique_ptr <rai::uint256_union> entry (new rai::uint256_union);
random_pool.GenerateBlock (entry->bytes.data (), entry->bytes.size ());
*first ^= *entry;
values.push_back (std::move (entry));
}
values.push_back (std::move (first));
std::unique_ptr <rai::uint256_union> first (new rai::uint256_union (key));
for (auto i (1); i < count_a; ++i)
{
std::unique_ptr <rai::uint256_union> entry (new rai::uint256_union);
random_pool.GenerateBlock (entry->bytes.data (), entry->bytes.size ());
*first ^= *entry;
values.push_back (std::move (entry));
}
values.push_back (std::move (first));
}
void rai::fan::value (rai::raw_key & prv_a)
@ -200,20 +200,20 @@ void rai::fan::value (rai::raw_key & prv_a)
void rai::fan::value_get (rai::raw_key & prv_a)
{
assert (!mutex.try_lock ());
prv_a.data.clear ();
for (auto & i: values)
{
prv_a.data ^= *i;
}
prv_a.data.clear ();
for (auto & i: values)
{
prv_a.data ^= *i;
}
}
void rai::fan::value_set (rai::raw_key const & value_a)
{
std::lock_guard <std::mutex> lock (mutex);
rai::raw_key value_l;
rai::raw_key value_l;
value_get (value_l);
*(values [0]) ^= value_l.data;
*(values [0]) ^= value_a.data;
*(values [0]) ^= value_l.data;
*(values [0]) ^= value_a.data;
}
rai::wallet_value::wallet_value (rai::mdb_val const & val_a)
@ -371,7 +371,7 @@ void rai::wallet_store::initialize (MDB_txn * transaction_a, bool & init_a, std:
bool rai::wallet_store::is_representative (MDB_txn * transaction_a)
{
return exists (transaction_a, representative (transaction_a));
return exists (transaction_a, representative (transaction_a));
}
void rai::wallet_store::representative_set (MDB_txn * transaction_a, rai::account const & representative_a)
@ -382,7 +382,7 @@ void rai::wallet_store::representative_set (MDB_txn * transaction_a, rai::accoun
rai::account rai::wallet_store::representative (MDB_txn * transaction_a)
{
rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::representative_special));
return value.key;
return value.key;
}
rai::public_key rai::wallet_store::insert_adhoc (MDB_txn * transaction_a, rai::raw_key const & prv)
@ -452,7 +452,7 @@ rai::key_type rai::wallet_store::key_type (rai::wallet_value const & value_a)
bool rai::wallet_store::fetch (MDB_txn * transaction_a, rai::public_key const & pub, rai::raw_key & prv)
{
auto result (false);
auto result (false);
if (valid_password (transaction_a))
{
rai::wallet_value value (entry_get_raw (transaction_a, pub));
@ -501,7 +501,7 @@ bool rai::wallet_store::fetch (MDB_txn * transaction_a, rai::public_key const &
result = true;
}
}
return result;
return result;
}
bool rai::wallet_store::exists (MDB_txn * transaction_a, rai::public_key const & pub)
@ -819,7 +819,7 @@ bool check_ownership (rai::wallets & wallets_a, rai::account const & account_a)
std::shared_ptr <rai::block> rai::wallet::receive_action (rai::send_block const & send_a, rai::account const & representative_a, rai::uint128_union const & amount_a, bool generate_work_a)
{
auto hash (send_a.hash ());
auto hash (send_a.hash ());
std::shared_ptr <rai::block> block;
if (node.config.receive_minimum.number () <= amount_a.number ())
{
@ -872,7 +872,7 @@ std::shared_ptr <rai::block> rai::wallet::receive_action (rai::send_block const
});
}
}
return block;
return block;
}
std::shared_ptr <rai::block> rai::wallet::change_action (rai::account const & source_a, rai::account const & representative_a, bool generate_work_a)
@ -1028,28 +1028,28 @@ void rai::wallet::send_async (rai::account const & source_a, rai::account const
// Update work for account if latest root is root_a
void rai::wallet::work_update (MDB_txn * transaction_a, rai::account const & account_a, rai::block_hash const & root_a, uint64_t work_a)
{
assert (!rai::work_validate (root_a, work_a));
assert (store.exists (transaction_a, account_a));
auto latest (node.ledger.latest_root (transaction_a, account_a));
if (latest == root_a)
{
store.work_put (transaction_a, account_a, work_a);
}
else
{
BOOST_LOG (node.log) << "Cached work no longer valid, discarding";
}
assert (!rai::work_validate (root_a, work_a));
assert (store.exists (transaction_a, account_a));
auto latest (node.ledger.latest_root (transaction_a, account_a));
if (latest == root_a)
{
store.work_put (transaction_a, account_a, work_a);
}
else
{
BOOST_LOG (node.log) << "Cached work no longer valid, discarding";
}
}
// Fetch work for root_a, use cached value if possible
uint64_t rai::wallet::work_fetch (MDB_txn * transaction_a, rai::account const & account_a, rai::block_hash const & root_a)
{
uint64_t result;
auto error (store.work_get (transaction_a, account_a, result));
if (error)
uint64_t result;
auto error (store.work_get (transaction_a, account_a, result));
if (error)
{
result = node.generate_work (root_a);
}
result = node.generate_work (root_a);
}
else
{
if (rai::work_validate (root_a, result))
@ -1058,7 +1058,7 @@ uint64_t rai::wallet::work_fetch (MDB_txn * transaction_a, rai::account const &
result = node.generate_work (root_a);
}
}
return result;
return result;
}
void rai::wallet::work_ensure (MDB_txn * transaction_a, rai::account const & account_a)
@ -1207,7 +1207,7 @@ void rai::wallet::init_free_accounts (MDB_txn * transaction_a)
void rai::wallet::work_generate (rai::account const & account_a, rai::block_hash const & root_a)
{
auto begin (std::chrono::system_clock::now ());
auto work (node.generate_work (root_a));
auto work (node.generate_work (root_a));
if (node.config.logging.work_generation_time ())
{
BOOST_LOG (node.log) << "Work generation complete: " << (std::chrono::duration_cast <std::chrono::microseconds> (std::chrono::system_clock::now () - begin).count ()) << " us";
@ -1256,34 +1256,34 @@ node (node_a)
std::shared_ptr <rai::wallet> rai::wallets::open (rai::uint256_union const & id_a)
{
std::shared_ptr <rai::wallet> result;
auto existing (items.find (id_a));
if (existing != items.end ())
{
result = existing->second;
}
return result;
std::shared_ptr <rai::wallet> result;
auto existing (items.find (id_a));
if (existing != items.end ())
{
result = existing->second;
}
return result;
}
std::shared_ptr <rai::wallet> rai::wallets::create (rai::uint256_union const & id_a)
{
assert (items.find (id_a) == items.end ());
std::shared_ptr <rai::wallet> result;
bool error;
assert (items.find (id_a) == items.end ());
std::shared_ptr <rai::wallet> result;
bool error;
{
rai::transaction transaction (node.store.environment, nullptr, true);
result = std::make_shared <rai::wallet> (error, transaction, node, id_a.to_string ());
items [id_a] = result;
result = result;
items [id_a] = result;
result = result;
}
if (!error)
{
if (!error)
{
node.background ([result] ()
{
result->enter_initial_password ();
});
}
return result;
}
return result;
}
bool rai::wallets::search_pending (rai::uint256_union const & wallet_a)

View file

@ -132,13 +132,13 @@ wallet (wallet_a)
{
separator->setFrameShape (QFrame::HLine);
separator->setFrameShadow (QFrame::Sunken);
model->setHorizontalHeaderItem (0, new QStandardItem ("Balance"));
model->setHorizontalHeaderItem (1, new QStandardItem ("Account"));
view->setEditTriggers (QAbstractItemView::NoEditTriggers);
view->setModel (model);
view->verticalHeader ()->hide ();
view->setContextMenuPolicy (Qt::ContextMenuPolicy::CustomContextMenu);
view->horizontalHeader()->setStretchLastSection(true);
model->setHorizontalHeaderItem (0, new QStandardItem ("Balance"));
model->setHorizontalHeaderItem (1, new QStandardItem ("Account"));
view->setEditTriggers (QAbstractItemView::NoEditTriggers);
view->setModel (model);
view->verticalHeader ()->hide ();
view->setContextMenuPolicy (Qt::ContextMenuPolicy::CustomContextMenu);
view->horizontalHeader()->setStretchLastSection(true);
layout->addWidget (wallet_balance_label);
layout->addWidget (view);
layout->addWidget (use_account);
@ -148,8 +148,8 @@ wallet (wallet_a)
layout->addWidget (separator);
layout->addWidget (account_key_line);
layout->addWidget (account_key_button);
layout->addWidget (back);
window->setLayout (layout);
layout->addWidget (back);
window->setLayout (layout);
QObject::connect (use_account, &QPushButton::released, [this] ()
{
auto selection (view->selectionModel ()->selection ().indexes ());
@ -179,8 +179,8 @@ wallet (wallet_a)
show_line_error (*account_key_line);
}
});
QObject::connect (back, &QPushButton::clicked, [this] ()
{
QObject::connect (back, &QPushButton::clicked, [this] ()
{
this->wallet.pop_main_stack ();
});
QObject::connect (create_account, &QPushButton::released, [this] ()
@ -487,11 +487,11 @@ wallet (wallet_a)
tx_layout->addWidget (tx_count);
tx_layout->setContentsMargins (0, 0, 0, 0);
tx_window->setLayout (tx_layout);*/
model->setHorizontalHeaderItem (0, new QStandardItem ("Type"));
model->setHorizontalHeaderItem (1, new QStandardItem ("Account"));
model->setHorizontalHeaderItem (2, new QStandardItem ("Amount"));
model->setHorizontalHeaderItem (3, new QStandardItem ("Hash"));
view->setModel (model);
model->setHorizontalHeaderItem (0, new QStandardItem ("Type"));
model->setHorizontalHeaderItem (1, new QStandardItem ("Account"));
model->setHorizontalHeaderItem (2, new QStandardItem ("Amount"));
model->setHorizontalHeaderItem (3, new QStandardItem ("Hash"));
view->setModel (model);
view->setEditTriggers (QAbstractItemView::NoEditTriggers);
view->verticalHeader ()->hide ();
view->horizontalHeader()->setStretchLastSection(true);
@ -727,7 +727,7 @@ wallet (wallet_a)
rai_qt::status::status (rai_qt::wallet & wallet_a) :
wallet (wallet_a)
{
wallet.status->setToolTip ("Wallet status, block count (blocks downloaded)");
wallet.status->setToolTip ("Wallet status, block count (blocks downloaded)");
active.insert (rai_qt::status_types::nominal);
set_text ();
}
@ -793,12 +793,12 @@ std::string rai_qt::status::text ()
break;
}
result += ", Block: ";
if (unchecked != 0 && wallet.wallet_m->node.bootstrap_initiator.in_progress ())
{
count_string += " (" + std::to_string (unchecked) + ")";
}
result += count_string.c_str ();
result += ", Block: ";
if (unchecked != 0 && wallet.wallet_m->node.bootstrap_initiator.in_progress ())
{
count_string += " (" + std::to_string (unchecked) + ")";
}
result += count_string.c_str ();
return result;
}
@ -924,29 +924,29 @@ active_status (*this)
void rai_qt::wallet::start ()
{
std::weak_ptr <rai_qt::wallet> this_w (shared_from_this ());
QObject::connect (settings_button, &QPushButton::released, [this_w] ()
{
QObject::connect (settings_button, &QPushButton::released, [this_w] ()
{
if (auto this_l = this_w.lock ())
{
this_l->settings.activate ();
}
});
QObject::connect (accounts_button, &QPushButton::released, [this_w] ()
{
});
QObject::connect (accounts_button, &QPushButton::released, [this_w] ()
{
if (auto this_l = this_w.lock ())
{
this_l->push_main_stack (this_l->accounts.window);
}
});
QObject::connect (show_advanced, &QPushButton::released, [this_w] ()
{
});
QObject::connect (show_advanced, &QPushButton::released, [this_w] ()
{
if (auto this_l = this_w.lock ())
{
this_l->push_main_stack (this_l->advanced.window);
}
});
QObject::connect (send_blocks_send, &QPushButton::released, [this_w] ()
{
});
QObject::connect (send_blocks_send, &QPushButton::released, [this_w] ()
{
if (auto this_l = this_w.lock ())
{
show_line_ok (*this_l->send_count);
@ -1076,23 +1076,23 @@ void rai_qt::wallet::start ()
});
}
}
});
QObject::connect (send_blocks_back, &QPushButton::released, [this_w] ()
{
});
QObject::connect (send_blocks_back, &QPushButton::released, [this_w] ()
{
if (auto this_l = this_w.lock ())
{
this_l->pop_main_stack ();
}
});
QObject::connect (send_blocks, &QPushButton::released, [this_w] ()
{
});
QObject::connect (send_blocks, &QPushButton::released, [this_w] ()
{
if (auto this_l = this_w.lock ())
{
this_l->push_main_stack (this_l->send_blocks_window);
}
});
});
node.observers.blocks.add ([this_w] (std::shared_ptr <rai::block>, rai::account const & account_a, rai::amount const &)
{
{
if (auto this_l = this_w.lock ())
{
this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, account_a] ()
@ -1111,7 +1111,7 @@ void rai_qt::wallet::start ()
}
}));
}
});
});
node.observers.wallet.add ([this_w] (rai::account const & account_a, bool active_a)
{
if (auto this_l = this_w.lock ())
@ -1274,13 +1274,13 @@ std::string rai_qt::wallet::format_balance (rai::uint128_t const & balance) cons
void rai_qt::wallet::push_main_stack (QWidget * widget_a)
{
main_stack->addWidget (widget_a);
main_stack->setCurrentIndex (main_stack->count () - 1);
main_stack->addWidget (widget_a);
main_stack->setCurrentIndex (main_stack->count () - 1);
}
void rai_qt::wallet::pop_main_stack ()
{
main_stack->removeWidget (main_stack->currentWidget ());
main_stack->removeWidget (main_stack->currentWidget ());
}
rai_qt::settings::settings (rai_qt::wallet & wallet_a) :
@ -1301,19 +1301,19 @@ back (new QPushButton ("Back")),
wallet (wallet_a)
{
password->setPlaceholderText("Password");
password->setEchoMode (QLineEdit::EchoMode::Password);
layout->addWidget (password);
layout->addWidget(lock_toggle);
password->setEchoMode (QLineEdit::EchoMode::Password);
layout->addWidget (password);
layout->addWidget(lock_toggle);
sep1->setFrameShape (QFrame::HLine);
sep1->setFrameShadow (QFrame::Sunken);
layout->addWidget (sep1);
new_password->setEchoMode (QLineEdit::EchoMode::Password);
new_password->setEchoMode (QLineEdit::EchoMode::Password);
new_password->setPlaceholderText ("New password");
layout->addWidget (new_password);
retype_password->setEchoMode (QLineEdit::EchoMode::Password);
layout->addWidget (new_password);
retype_password->setEchoMode (QLineEdit::EchoMode::Password);
retype_password->setPlaceholderText ("Retype password");
layout->addWidget (retype_password);
layout->addWidget (change);
layout->addWidget (retype_password);
layout->addWidget (change);
sep2->setFrameShape (QFrame::HLine);
sep2->setFrameShadow (QFrame::Sunken);
layout->addWidget (sep2);
@ -1323,9 +1323,9 @@ wallet (wallet_a)
new_representative->setPlaceholderText (rai::zero_key.pub.to_account ().c_str ());
layout->addWidget (new_representative);
layout->addWidget (change_rep);
layout->addStretch ();
layout->addWidget (back);
window->setLayout (layout);
layout->addStretch ();
layout->addWidget (back);
window->setLayout (layout);
QObject::connect (change, &QPushButton::released, [this] ()
{
rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true);
@ -1562,106 +1562,106 @@ peers_refresh (new QPushButton ("Refresh")),
peers_back (new QPushButton ("Back")),
wallet (wallet_a)
{
ratio_group->addButton (mrai);
ratio_group->addButton (krai);
ratio_group->addButton (rai);
ratio_group->setId (mrai, 0);
ratio_group->setId (krai, 1);
ratio_group->setId (rai, 2);
ratio_group->addButton (mrai);
ratio_group->addButton (krai);
ratio_group->addButton (rai);
ratio_group->setId (mrai, 0);
ratio_group->setId (krai, 1);
ratio_group->setId (rai, 2);
scale_layout->addWidget(scale_label);
scale_layout->addWidget(mrai);
scale_layout->addWidget(krai);
scale_layout->addWidget(rai);
scale_window->setLayout(scale_layout);
ledger_model->setHorizontalHeaderItem (0, new QStandardItem ("Account"));
ledger_model->setHorizontalHeaderItem (1, new QStandardItem ("Balance"));
ledger_model->setHorizontalHeaderItem (2, new QStandardItem ("Block"));
ledger_view->setModel (ledger_model);
ledger_view->setEditTriggers (QAbstractItemView::NoEditTriggers);
ledger_view->verticalHeader ()->hide ();
ledger_view->horizontalHeader()->setStretchLastSection(true);
ledger_layout->addWidget (ledger_view);
ledger_layout->addWidget (ledger_refresh);
ledger_layout->addWidget (ledger_back);
ledger_layout->setContentsMargins (0, 0, 0, 0);
ledger_window->setLayout (ledger_layout);
peers_model->setHorizontalHeaderItem (0, new QStandardItem ("IPv6 address:port"));
peers_model->setHorizontalHeaderItem (1, new QStandardItem ("Net version"));
peers_view->setEditTriggers (QAbstractItemView::NoEditTriggers);
peers_view->verticalHeader ()->hide ();
peers_view->setModel (peers_model);
ledger_model->setHorizontalHeaderItem (0, new QStandardItem ("Account"));
ledger_model->setHorizontalHeaderItem (1, new QStandardItem ("Balance"));
ledger_model->setHorizontalHeaderItem (2, new QStandardItem ("Block"));
ledger_view->setModel (ledger_model);
ledger_view->setEditTriggers (QAbstractItemView::NoEditTriggers);
ledger_view->verticalHeader ()->hide ();
ledger_view->horizontalHeader()->setStretchLastSection(true);
ledger_layout->addWidget (ledger_view);
ledger_layout->addWidget (ledger_refresh);
ledger_layout->addWidget (ledger_back);
ledger_layout->setContentsMargins (0, 0, 0, 0);
ledger_window->setLayout (ledger_layout);
peers_model->setHorizontalHeaderItem (0, new QStandardItem ("IPv6 address:port"));
peers_model->setHorizontalHeaderItem (1, new QStandardItem ("Net version"));
peers_view->setEditTriggers (QAbstractItemView::NoEditTriggers);
peers_view->verticalHeader ()->hide ();
peers_view->setModel (peers_model);
peers_view->setColumnWidth(0, 220);
peers_view->setSortingEnabled(true);
peers_view->horizontalHeader()->setStretchLastSection(true);
peers_layout->addWidget (peers_view);
peers_layout->addWidget (peers_view);
peers_layout->addWidget (bootstrap_label);
peers_layout->addWidget (bootstrap_line);
peers_layout->addWidget (peers_bootstrap);
peers_layout->addWidget (peers_refresh);
peers_layout->addWidget (peers_back);
peers_layout->setContentsMargins (0, 0, 0, 0);
peers_window->setLayout (peers_layout);
peers_layout->addWidget (peers_refresh);
peers_layout->addWidget (peers_back);
peers_layout->setContentsMargins (0, 0, 0, 0);
peers_window->setLayout (peers_layout);
layout->addWidget (show_ledger);
layout->addWidget (show_peers);
layout->addWidget (search_for_receivables);
layout->addWidget (show_ledger);
layout->addWidget (show_peers);
layout->addWidget (search_for_receivables);
layout->addWidget (bootstrap);
layout->addWidget (wallet_refresh);
layout->addWidget (create_block);
layout->addWidget (enter_block);
layout->addWidget (wallet_refresh);
layout->addWidget (create_block);
layout->addWidget (enter_block);
layout->addWidget (block_viewer);
layout->addWidget (account_viewer);
layout->addWidget (scale_window);
layout->addStretch ();
layout->addWidget (back);
window->setLayout (layout);
layout->addStretch ();
layout->addWidget (back);
window->setLayout (layout);
QObject::connect (mrai, &QRadioButton::toggled, [this] ()
{
if (mrai->isChecked ())
{
QObject::connect (mrai, &QRadioButton::toggled, [this] ()
{
if (mrai->isChecked ())
{
this->wallet.change_rendering_ratio (rai::Mxrb_ratio);
}
});
QObject::connect (krai, &QRadioButton::toggled, [this] ()
{
if (krai->isChecked ())
{
}
});
QObject::connect (krai, &QRadioButton::toggled, [this] ()
{
if (krai->isChecked ())
{
this->wallet.change_rendering_ratio (rai::kxrb_ratio);
}
});
QObject::connect (rai, &QRadioButton::toggled, [this] ()
{
if (rai->isChecked ())
{
}
});
QObject::connect (rai, &QRadioButton::toggled, [this] ()
{
if (rai->isChecked ())
{
this->wallet.change_rendering_ratio (rai::xrb_ratio);
}
});
}
});
mrai->click ();
QObject::connect (wallet_refresh, &QPushButton::released, [this] ()
{
QObject::connect (wallet_refresh, &QPushButton::released, [this] ()
{
this->wallet.accounts.refresh ();
this->wallet.accounts.refresh_wallet_balance ();
});
QObject::connect (show_peers, &QPushButton::released, [this] ()
{
});
QObject::connect (show_peers, &QPushButton::released, [this] ()
{
refresh_peers ();
this->wallet.push_main_stack (peers_window);
});
QObject::connect (show_ledger, &QPushButton::released, [this] ()
{
});
QObject::connect (show_ledger, &QPushButton::released, [this] ()
{
this->wallet.push_main_stack (ledger_window);
});
QObject::connect (back, &QPushButton::released, [this] ()
{
});
QObject::connect (back, &QPushButton::released, [this] ()
{
this->wallet.pop_main_stack ();
});
QObject::connect (peers_back, &QPushButton::released, [this] ()
{
});
QObject::connect (peers_back, &QPushButton::released, [this] ()
{
this->wallet.pop_main_stack ();
});
});
QObject::connect (peers_bootstrap, &QPushButton::released, [this] ()
{
rai::endpoint endpoint;
@ -1765,42 +1765,42 @@ process (new QPushButton ("Process")),
back (new QPushButton ("Back")),
wallet (wallet_a)
{
layout->addWidget (block);
layout->addWidget (status);
layout->addWidget (process);
layout->addWidget (back);
window->setLayout (layout);
QObject::connect (process, &QPushButton::released, [this] ()
{
auto string (block->toPlainText ().toStdString ());
try
{
boost::property_tree::ptree tree;
std::stringstream istream (string);
boost::property_tree::read_json (istream, tree);
auto block_l (rai::deserialize_block_json (tree));
if (block_l != nullptr)
{
layout->addWidget (block);
layout->addWidget (status);
layout->addWidget (process);
layout->addWidget (back);
window->setLayout (layout);
QObject::connect (process, &QPushButton::released, [this] ()
{
auto string (block->toPlainText ().toStdString ());
try
{
boost::property_tree::ptree tree;
std::stringstream istream (string);
boost::property_tree::read_json (istream, tree);
auto block_l (rai::deserialize_block_json (tree));
if (block_l != nullptr)
{
show_label_ok (*status);
this->status->setText ("");
this->wallet.node.process_active (std::move (block_l));
}
else
{
}
else
{
show_label_error (*status);
this->status->setText ("Unable to parse block");
}
}
catch (std::runtime_error const &)
{
}
}
catch (std::runtime_error const &)
{
show_label_error (*status);
this->status->setText ("Unable to parse block");
}
});
QObject::connect (back, &QPushButton::released, [this] ()
{
}
});
QObject::connect (back, &QPushButton::released, [this] ()
{
this->wallet.pop_main_stack ();
});
});
}
rai_qt::block_creation::block_creation (rai_qt::wallet & wallet_a) :
@ -1828,210 +1828,210 @@ create (new QPushButton ("Create")),
back (new QPushButton ("Back")),
wallet (wallet_a)
{
group->addButton (send);
group->addButton (receive);
group->addButton (change);
group->addButton (open);
group->setId (send, 0);
group->setId (receive, 1);
group->setId (change, 2);
group->setId (open, 3);
button_layout->addWidget (send);
button_layout->addWidget (receive);
button_layout->addWidget (open);
button_layout->addWidget (change);
layout->addLayout (button_layout);
layout->addWidget (account_label);
layout->addWidget (account);
layout->addWidget (source_label);
layout->addWidget (source);
layout->addWidget (amount_label);
layout->addWidget (amount);
layout->addWidget (destination_label);
layout->addWidget (destination);
layout->addWidget (representative_label);
layout->addWidget (representative);
layout->addWidget (block);
layout->addWidget (status);
layout->addWidget (create);
layout->addWidget (back);
window->setLayout (layout);
QObject::connect (send, &QRadioButton::toggled, [this] ()
{
if (send->isChecked ())
{
deactivate_all ();
activate_send ();
}
});
QObject::connect (receive, &QRadioButton::toggled, [this] ()
{
if (receive->isChecked ())
{
deactivate_all ();
activate_receive ();
}
});
QObject::connect (open, &QRadioButton::toggled, [this] ()
{
if (open->isChecked ())
{
deactivate_all ();
activate_open ();
}
});
QObject::connect (change, &QRadioButton::toggled, [this] ()
{
if (change->isChecked ())
{
deactivate_all ();
activate_change ();
}
});
QObject::connect (create, &QPushButton::released, [this] ()
{
switch (group->checkedId ())
{
case 0:
create_send ();
break;
case 1:
create_receive ();
break;
case 2:
create_change ();
break;
case 3:
create_open ();
break;
default:
assert (false);
break;
}
});
QObject::connect (back, &QPushButton::released, [this] ()
{
group->addButton (send);
group->addButton (receive);
group->addButton (change);
group->addButton (open);
group->setId (send, 0);
group->setId (receive, 1);
group->setId (change, 2);
group->setId (open, 3);
button_layout->addWidget (send);
button_layout->addWidget (receive);
button_layout->addWidget (open);
button_layout->addWidget (change);
layout->addLayout (button_layout);
layout->addWidget (account_label);
layout->addWidget (account);
layout->addWidget (source_label);
layout->addWidget (source);
layout->addWidget (amount_label);
layout->addWidget (amount);
layout->addWidget (destination_label);
layout->addWidget (destination);
layout->addWidget (representative_label);
layout->addWidget (representative);
layout->addWidget (block);
layout->addWidget (status);
layout->addWidget (create);
layout->addWidget (back);
window->setLayout (layout);
QObject::connect (send, &QRadioButton::toggled, [this] ()
{
if (send->isChecked ())
{
deactivate_all ();
activate_send ();
}
});
QObject::connect (receive, &QRadioButton::toggled, [this] ()
{
if (receive->isChecked ())
{
deactivate_all ();
activate_receive ();
}
});
QObject::connect (open, &QRadioButton::toggled, [this] ()
{
if (open->isChecked ())
{
deactivate_all ();
activate_open ();
}
});
QObject::connect (change, &QRadioButton::toggled, [this] ()
{
if (change->isChecked ())
{
deactivate_all ();
activate_change ();
}
});
QObject::connect (create, &QPushButton::released, [this] ()
{
switch (group->checkedId ())
{
case 0:
create_send ();
break;
case 1:
create_receive ();
break;
case 2:
create_change ();
break;
case 3:
create_open ();
break;
default:
assert (false);
break;
}
});
QObject::connect (back, &QPushButton::released, [this] ()
{
this->wallet.pop_main_stack ();
});
send->click ();
});
send->click ();
}
void rai_qt::block_creation::deactivate_all ()
{
account_label->hide ();
account->hide ();
source_label->hide ();
source->hide ();
amount_label->hide ();
amount->hide ();
destination_label->hide ();
destination->hide ();
representative_label->hide ();
representative->hide ();
account_label->hide ();
account->hide ();
source_label->hide ();
source->hide ();
amount_label->hide ();
amount->hide ();
destination_label->hide ();
destination->hide ();
representative_label->hide ();
representative->hide ();
}
void rai_qt::block_creation::activate_send ()
{
account_label->show ();
account->show ();
amount_label->show ();
amount->show ();
destination_label->show ();
destination->show ();
account_label->show ();
account->show ();
amount_label->show ();
amount->show ();
destination_label->show ();
destination->show ();
}
void rai_qt::block_creation::activate_receive ()
{
source_label->show ();
source->show ();
source_label->show ();
source->show ();
}
void rai_qt::block_creation::activate_open ()
{
source_label->show ();
source->show ();
representative_label->show ();
representative->show ();
source_label->show ();
source->show ();
representative_label->show ();
representative->show ();
}
void rai_qt::block_creation::activate_change ()
{
account_label->show ();
account->show ();
representative_label->show ();
representative->show ();
account_label->show ();
account->show ();
representative_label->show ();
representative->show ();
}
void rai_qt::block_creation::create_send ()
{
rai::account account_l;
auto error (account_l.decode_account (account->text ().toStdString ()));
if (!error)
{
rai::amount amount_l;
error = amount_l.decode_dec (amount->text ().toStdString ());
if (!error)
{
rai::account destination_l;
error = destination_l.decode_account (destination->text ().toStdString ());
if (!error)
{
rai::account account_l;
auto error (account_l.decode_account (account->text ().toStdString ()));
if (!error)
{
rai::amount amount_l;
error = amount_l.decode_dec (amount->text ().toStdString ());
if (!error)
{
rai::account destination_l;
error = destination_l.decode_account (destination->text ().toStdString ());
if (!error)
{
rai::transaction transaction (wallet.node.store.environment, nullptr, false);
rai::raw_key key;
if (!wallet.wallet_m->store.fetch (transaction, account_l, key))
{
auto balance (wallet.node.ledger.account_balance (transaction, account_l));
if (amount_l.number () <= balance)
{
rai::account_info info;
auto error (wallet.node.store.account_get (transaction, account_l, info));
assert (!error);
rai::send_block send (info.head, destination_l, balance - amount_l.number (), key, account_l, wallet.wallet_m->work_fetch (transaction, account_l, info.head));
std::string block_l;
send.serialize_json (block_l);
block->setPlainText (QString (block_l.c_str ()));
rai::raw_key key;
if (!wallet.wallet_m->store.fetch (transaction, account_l, key))
{
auto balance (wallet.node.ledger.account_balance (transaction, account_l));
if (amount_l.number () <= balance)
{
rai::account_info info;
auto error (wallet.node.store.account_get (transaction, account_l, info));
assert (!error);
rai::send_block send (info.head, destination_l, balance - amount_l.number (), key, account_l, wallet.wallet_m->work_fetch (transaction, account_l, info.head));
std::string block_l;
send.serialize_json (block_l);
block->setPlainText (QString (block_l.c_str ()));
show_label_ok (*status);
status->setText ("Created block");
}
else
{
status->setText ("Created block");
}
else
{
show_label_error (*status);
status->setText ("Insufficient balance");
}
}
else
{
status->setText ("Insufficient balance");
}
}
else
{
show_label_error (*status);
status->setText ("Account is not in wallet");
}
}
else
{
status->setText ("Account is not in wallet");
}
}
else
{
show_label_error (*status);
status->setText ("Unable to decode destination");
}
}
else
{
status->setText ("Unable to decode destination");
}
}
else
{
show_label_error (*status);
status->setText ("Unable to decode amount");
}
}
else
{
status->setText ("Unable to decode amount");
}
}
else
{
show_label_error (*status);
status->setText ("Unable to decode account");
}
status->setText ("Unable to decode account");
}
}
void rai_qt::block_creation::create_receive ()
{
rai::block_hash source_l;
auto error (source_l.decode_hex (source->text ().toStdString ()));
if (!error)
{
rai::block_hash source_l;
auto error (source_l.decode_hex (source->text ().toStdString ()));
if (!error)
{
rai::transaction transaction (wallet.node.store.environment, nullptr, false);
auto block_l (wallet.node.store.block_get (transaction, source_l));
if (block_l != nullptr)
@ -2087,75 +2087,75 @@ void rai_qt::block_creation::create_receive ()
show_label_error (*status);
status->setText("Source block not found");
}
}
else
{
}
else
{
show_label_error (*status);
status->setText ("Unable to decode source");
}
status->setText ("Unable to decode source");
}
}
void rai_qt::block_creation::create_change ()
{
rai::account account_l;
auto error (account_l.decode_account (account->text ().toStdString ()));
if (!error)
{
rai::account representative_l;
error = representative_l.decode_account (representative->text ().toStdString ());
if (!error)
{
rai::account account_l;
auto error (account_l.decode_account (account->text ().toStdString ()));
if (!error)
{
rai::account representative_l;
error = representative_l.decode_account (representative->text ().toStdString ());
if (!error)
{
rai::transaction transaction (wallet.node.store.environment, nullptr, false);
rai::account_info info;
auto error (wallet.node.store.account_get (transaction, account_l, info));
if (!error)
{
rai::raw_key key;
auto error (wallet.wallet_m->store.fetch (transaction, account_l, key));
if (!error)
{
rai::change_block change (info.head, representative_l, key, account_l, wallet.wallet_m->work_fetch (transaction, account_l, info.head));
std::string block_l;
change.serialize_json (block_l);
block->setPlainText (QString (block_l.c_str ()));
rai::account_info info;
auto error (wallet.node.store.account_get (transaction, account_l, info));
if (!error)
{
rai::raw_key key;
auto error (wallet.wallet_m->store.fetch (transaction, account_l, key));
if (!error)
{
rai::change_block change (info.head, representative_l, key, account_l, wallet.wallet_m->work_fetch (transaction, account_l, info.head));
std::string block_l;
change.serialize_json (block_l);
block->setPlainText (QString (block_l.c_str ()));
show_label_ok (*status);
status->setText ("Created block");
}
else
{
status->setText ("Created block");
}
else
{
show_label_error (*status);
status->setText ("Account is not in wallet");
}
}
else
{
status->setText ("Account is not in wallet");
}
}
else
{
show_label_error (*status);
status->setText ("Account not yet open");
}
}
else
{
status->setText ("Account not yet open");
}
}
else
{
show_label_error (*status);
status->setText ("Unable to decode representative");
}
}
else
{
status->setText ("Unable to decode representative");
}
}
else
{
show_label_error (*status);
status->setText ("Unable to decode account");
}
status->setText ("Unable to decode account");
}
}
void rai_qt::block_creation::create_open ()
{
rai::block_hash source_l;
auto error (source_l.decode_hex (source->text ().toStdString ()));
if (!error)
{
rai::account representative_l;
error = representative_l.decode_account (representative->text ().toStdString ());
if (!error)
{
rai::block_hash source_l;
auto error (source_l.decode_hex (source->text ().toStdString ()));
if (!error)
{
rai::account representative_l;
error = representative_l.decode_account (representative->text ().toStdString ());
if (!error)
{
rai::transaction transaction (wallet.node.store.environment, nullptr, false);
auto block_l (wallet.node.store.block_get (transaction, source_l));
if (block_l != nullptr)
@ -2211,16 +2211,16 @@ void rai_qt::block_creation::create_open ()
show_label_error (*status);
status->setText("Source block not found");
}
}
else
{
}
else
{
show_label_error (*status);
status->setText ("Unable to decode representative");
}
}
else
{
status->setText ("Unable to decode representative");
}
}
else
{
show_label_error (*status);
status->setText ("Unable to decode source");
}
status->setText ("Unable to decode source");
}
}

View file

@ -10,7 +10,7 @@
#include <QtWidgets>
namespace rai_qt {
class wallet;
class wallet;
class eventloop_processor : public QObject
{
public:
@ -22,32 +22,32 @@ namespace rai_qt {
eventloop_event (std::function <void ()> const &);
std::function <void ()> action;
};
class settings
{
public:
settings (rai_qt::wallet &);
class settings
{
public:
settings (rai_qt::wallet &);
void refresh_representative ();
void activate ();
void update_locked (bool, bool);
QWidget * window;
QVBoxLayout * layout;
QLineEdit * password;
void activate ();
void update_locked (bool, bool);
QWidget * window;
QVBoxLayout * layout;
QLineEdit * password;
QPushButton * lock_toggle;
QFrame * sep1;
QLineEdit * new_password;
QLineEdit * retype_password;
QPushButton * change;
QLineEdit * new_password;
QLineEdit * retype_password;
QPushButton * change;
QFrame * sep2;
QLabel * representative;
QLabel * current_representative;
QLineEdit * new_representative;
QPushButton * change_rep;
QPushButton * back;
rai_qt::wallet & wallet;
};
class advanced_actions
{
public:
QPushButton * back;
rai_qt::wallet & wallet;
};
class advanced_actions
{
public:
advanced_actions (rai_qt::wallet &);
QWidget * window;
QVBoxLayout * layout;
@ -87,82 +87,82 @@ namespace rai_qt {
QPushButton * peers_back;
rai_qt::wallet & wallet;
private:
void refresh_ledger ();
void refresh_peers ();
};
class block_entry
{
public:
block_entry (rai_qt::wallet &);
QWidget * window;
QVBoxLayout * layout;
QPlainTextEdit * block;
QLabel * status;
QPushButton * process;
QPushButton * back;
rai_qt::wallet & wallet;
};
class block_creation
{
public:
block_creation (rai_qt::wallet &);
void deactivate_all ();
void activate_send ();
void activate_receive ();
void activate_change ();
void activate_open ();
void create_send ();
void create_receive ();
void create_change ();
void create_open ();
QWidget * window;
QVBoxLayout * layout;
QButtonGroup * group;
QHBoxLayout * button_layout;
QRadioButton * send;
QRadioButton * receive;
QRadioButton * change;
QRadioButton * open;
QLabel * account_label;
QLineEdit * account;
QLabel * source_label;
QLineEdit * source;
QLabel * amount_label;
QLineEdit * amount;
QLabel * destination_label;
QLineEdit * destination;
QLabel * representative_label;
QLineEdit * representative;
QPlainTextEdit * block;
QLabel * status;
QPushButton * create;
QPushButton * back;
rai_qt::wallet & wallet;
};
class self_pane
{
public:
self_pane (rai_qt::wallet &, rai::account const &);
private:
void refresh_ledger ();
void refresh_peers ();
};
class block_entry
{
public:
block_entry (rai_qt::wallet &);
QWidget * window;
QVBoxLayout * layout;
QPlainTextEdit * block;
QLabel * status;
QPushButton * process;
QPushButton * back;
rai_qt::wallet & wallet;
};
class block_creation
{
public:
block_creation (rai_qt::wallet &);
void deactivate_all ();
void activate_send ();
void activate_receive ();
void activate_change ();
void activate_open ();
void create_send ();
void create_receive ();
void create_change ();
void create_open ();
QWidget * window;
QVBoxLayout * layout;
QButtonGroup * group;
QHBoxLayout * button_layout;
QRadioButton * send;
QRadioButton * receive;
QRadioButton * change;
QRadioButton * open;
QLabel * account_label;
QLineEdit * account;
QLabel * source_label;
QLineEdit * source;
QLabel * amount_label;
QLineEdit * amount;
QLabel * destination_label;
QLineEdit * destination;
QLabel * representative_label;
QLineEdit * representative;
QPlainTextEdit * block;
QLabel * status;
QPushButton * create;
QPushButton * back;
rai_qt::wallet & wallet;
};
class self_pane
{
public:
self_pane (rai_qt::wallet &, rai::account const &);
void refresh_balance ();
QWidget * window;
QVBoxLayout * layout;
QWidget * window;
QVBoxLayout * layout;
QHBoxLayout * self_layout;
QWidget * self_window;
QLabel * your_account_label;
QLabel * your_account_label;
QLabel * version;
QWidget * account_window;
QHBoxLayout * account_layout;
QLineEdit * account_text;
QLineEdit * account_text;
QPushButton * copy_button;
QWidget * balance_window;
QHBoxLayout * balance_layout;
QLabel * balance_label;
rai_qt::wallet & wallet;
};
class accounts
{
public:
QLabel * balance_label;
rai_qt::wallet & wallet;
};
class accounts
{
public:
accounts (rai_qt::wallet &);
void refresh ();
void refresh_wallet_balance ();
@ -180,7 +180,7 @@ namespace rai_qt {
QPushButton * account_key_button;
QPushButton * back;
rai_qt::wallet & wallet;
};
};
class import
{
public:
@ -228,7 +228,7 @@ namespace rai_qt {
QLabel * hash_label;
QLineEdit * hash;
QLabel * block_label;
QPlainTextEdit * block;
QPlainTextEdit * block;
QLabel * successor_label;
QLineEdit * successor;
QPushButton * retrieve;

View file

@ -5,38 +5,38 @@
int main (int argc, char ** argv)
{
QApplication application (argc, argv);
QApplication application (argc, argv);
rai_qt::eventloop_processor processor;
static int count (16);
rai::system system (24000, count);
std::unique_ptr <QTabWidget> client_tabs (new QTabWidget);
std::vector <std::unique_ptr <rai_qt::wallet>> guis;
for (auto i (0); i < count; ++i)
{
rai::uint256_union wallet_id;
rai::random_pool.GenerateBlock (wallet_id.bytes.data (), wallet_id.bytes.size ());
auto wallet (system.nodes [i]->wallets.create (wallet_id));
rai::keypair key;
wallet->insert_adhoc (key.prv);
guis.push_back (std::unique_ptr <rai_qt::wallet> (new rai_qt::wallet (application, processor, *system.nodes [i], wallet, key.pub)));
client_tabs->addTab (guis.back ()->client_window, boost::str (boost::format ("Wallet %1%") % i).c_str ());
}
client_tabs->show ();
static int count (16);
rai::system system (24000, count);
std::unique_ptr <QTabWidget> client_tabs (new QTabWidget);
std::vector <std::unique_ptr <rai_qt::wallet>> guis;
for (auto i (0); i < count; ++i)
{
rai::uint256_union wallet_id;
rai::random_pool.GenerateBlock (wallet_id.bytes.data (), wallet_id.bytes.size ());
auto wallet (system.nodes [i]->wallets.create (wallet_id));
rai::keypair key;
wallet->insert_adhoc (key.prv);
guis.push_back (std::unique_ptr <rai_qt::wallet> (new rai_qt::wallet (application, processor, *system.nodes [i], wallet, key.pub)));
client_tabs->addTab (guis.back ()->client_window, boost::str (boost::format ("Wallet %1%") % i).c_str ());
}
client_tabs->show ();
rai::thread_runner runner (system.service, system.nodes [0]->config.io_threads);
QObject::connect (&application, &QApplication::aboutToQuit, [&] ()
{
QObject::connect (&application, &QApplication::aboutToQuit, [&] ()
{
system.stop ();
});
int result;
try
{
result = application.exec ();
}
catch (...)
{
result = -1;
assert (false);
}
});
int result;
try
{
result = application.exec ();
}
catch (...)
{
result = -1;
assert (false);
}
runner.join ();
return result;
return result;
}

View file

@ -6,7 +6,7 @@ QApplication * test_application = nullptr;
int main (int argc, char **argv)
{
QApplication application (argc, argv);
QApplication application (argc, argv);
test_application = &application;
testing::InitGoogleTest (&argc, argv);
return RUN_ALL_TESTS ();

View file

@ -12,24 +12,24 @@ extern QApplication * test_application;
TEST (wallet, construction)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ()));
auto key (wallet_l->deterministic_insert ());
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key));
wallet->start ();
ASSERT_EQ (key.to_account_split (), wallet->self.account_text->text ().toStdString ());
ASSERT_EQ (1, wallet->accounts.model->rowCount ());
auto item1 (wallet->accounts.model->item (0, 1));
ASSERT_EQ (key.to_account (), item1->text ().toStdString ());
ASSERT_EQ (key.to_account_split (), wallet->self.account_text->text ().toStdString ());
ASSERT_EQ (1, wallet->accounts.model->rowCount ());
auto item1 (wallet->accounts.model->item (0, 1));
ASSERT_EQ (key.to_account (), item1->text ().toStdString ());
}
TEST (wallet, status)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ()));
rai::keypair key;
rai::keypair key;
wallet_l->insert_adhoc (key.prv);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key.pub));
wallet->start ();
@ -54,24 +54,24 @@ TEST (wallet, status)
TEST (wallet, startup_balance)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ()));
rai::keypair key;
rai::keypair key;
wallet_l->insert_adhoc (key.prv);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key.pub));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key.pub));
wallet->start ();
ASSERT_EQ ("Balance (XRB): 0", wallet->self.balance_label->text().toStdString ());
}
TEST (wallet, select_account)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ()));
rai::public_key key1 (wallet_l->deterministic_insert ());
rai::public_key key2 (wallet_l->deterministic_insert ());
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key1));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key1));
wallet->start ();
ASSERT_EQ (key1, wallet->account);
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
@ -87,48 +87,48 @@ TEST (wallet, select_account)
TEST (wallet, main)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ()));
rai::keypair key;
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ()));
rai::keypair key;
wallet_l->insert_adhoc (key.prv);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key.pub));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key.pub));
wallet->start ();
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->send_blocks, Qt::LeftButton);
ASSERT_EQ (wallet->send_blocks_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->send_blocks_back, Qt::LeftButton);
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
ASSERT_EQ (wallet->settings.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->settings.back, Qt::LeftButton);
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.show_ledger, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.ledger_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.ledger_back, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.show_peers, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.peers_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.peers_back, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.back, Qt::LeftButton);
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->send_blocks, Qt::LeftButton);
ASSERT_EQ (wallet->send_blocks_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->send_blocks_back, Qt::LeftButton);
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
ASSERT_EQ (wallet->settings.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->settings.back, Qt::LeftButton);
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.show_ledger, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.ledger_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.ledger_back, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.show_peers, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.peers_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.peers_back, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->advanced.back, Qt::LeftButton);
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
}
TEST (wallet, password_change)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai::account account;
system.wallet (0)->insert_adhoc (rai::keypair ().prv);
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
account = system.account (transaction, 0);
}
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
rai::raw_key password1;
@ -137,9 +137,9 @@ TEST (wallet, password_change)
system.wallet (0)->store.password.value (password2);
ASSERT_NE (password1, password2);
}
QTest::keyClicks (wallet->settings.new_password, "1");
QTest::keyClicks (wallet->settings.retype_password, "1");
QTest::mouseClick (wallet->settings.change, Qt::LeftButton);
QTest::keyClicks (wallet->settings.new_password, "1");
QTest::keyClicks (wallet->settings.retype_password, "1");
QTest::mouseClick (wallet->settings.change, Qt::LeftButton);
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
rai::raw_key password1;
@ -148,23 +148,23 @@ TEST (wallet, password_change)
system.wallet (0)->store.password.value (password2);
ASSERT_EQ (password1, password2);
}
ASSERT_EQ ("", wallet->settings.new_password->text ());
ASSERT_EQ ("", wallet->settings.retype_password->text ());
ASSERT_EQ ("", wallet->settings.new_password->text ());
ASSERT_EQ ("", wallet->settings.retype_password->text ());
}
TEST (client, password_nochange)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai::account account;
system.wallet (0)->insert_adhoc (rai::keypair ().prv);
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
account = system.account (transaction, 0);
}
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
auto iterations (0);
rai::raw_key password;
password.data.clear ();
@ -183,9 +183,9 @@ TEST (client, password_nochange)
system.wallet (0)->store.password.value (password2);
ASSERT_EQ (password1, password2);
}
QTest::keyClicks (wallet->settings.new_password, "1");
QTest::keyClicks (wallet->settings.retype_password, "2");
QTest::mouseClick (wallet->settings.change, Qt::LeftButton);
QTest::keyClicks (wallet->settings.new_password, "1");
QTest::keyClicks (wallet->settings.retype_password, "2");
QTest::mouseClick (wallet->settings.change, Qt::LeftButton);
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
rai::raw_key password1;
@ -194,68 +194,68 @@ TEST (client, password_nochange)
system.wallet (0)->store.password.value (password2);
ASSERT_EQ (password1, password2);
}
ASSERT_EQ ("1", wallet->settings.new_password->text ());
ASSERT_EQ ("", wallet->settings.retype_password->text ());
ASSERT_EQ ("1", wallet->settings.new_password->text ());
ASSERT_EQ ("", wallet->settings.retype_password->text ());
}
TEST (wallet, enter_password)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
rai::account account;
system.wallet (0)->insert_adhoc (rai::keypair ().prv);
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
account = system.account (transaction, 0);
}
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.password));
ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.lock_toggle));
ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.back));
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.password));
ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.lock_toggle));
ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.back));
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
test_application->processEvents();
ASSERT_EQ ("Status: Wallet password empty", wallet->status->text ().toStdString ());
ASSERT_EQ ("Status: Wallet password empty", wallet->status->text ().toStdString ());
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
ASSERT_FALSE (system.wallet (0)->store.rekey (transaction, "abc"));
}
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
QTest::mouseClick (wallet->settings.lock_toggle, Qt::LeftButton);
QTest::mouseClick (wallet->settings_button, Qt::LeftButton);
QTest::mouseClick (wallet->settings.lock_toggle, Qt::LeftButton);
test_application->processEvents();
ASSERT_EQ ("Status: Wallet locked", wallet->status->text ().toStdString ());
wallet->settings.new_password->setText ("");
QTest::keyClicks (wallet->settings.password, "abc");
QTest::mouseClick (wallet->settings.lock_toggle, Qt::LeftButton);
ASSERT_EQ ("Status: Wallet locked", wallet->status->text ().toStdString ());
wallet->settings.new_password->setText ("");
QTest::keyClicks (wallet->settings.password, "abc");
QTest::mouseClick (wallet->settings.lock_toggle, Qt::LeftButton);
test_application->processEvents();
ASSERT_EQ ("Status: Running", wallet->status->text ().toStdString ());
ASSERT_EQ ("", wallet->settings.password->text ());
ASSERT_EQ ("Status: Running", wallet->status->text ().toStdString ());
ASSERT_EQ ("", wallet->settings.password->text ());
}
TEST (wallet, send)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::public_key key1 (system.wallet (1)->insert_adhoc (rai::keypair ().prv));
auto account (rai::test_genesis_key.pub);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
QTest::mouseClick (wallet->send_blocks, Qt::LeftButton);
QTest::keyClicks (wallet->send_account, key1.to_account ().c_str ());
QTest::keyClicks (wallet->send_count, "2");
QTest::mouseClick (wallet->send_blocks_send, Qt::LeftButton);
QTest::mouseClick (wallet->send_blocks, Qt::LeftButton);
QTest::keyClicks (wallet->send_account, key1.to_account ().c_str ());
QTest::keyClicks (wallet->send_count, "2");
QTest::mouseClick (wallet->send_blocks_send, Qt::LeftButton);
auto iterations1 (0);
while (wallet->node.balance (key1).is_zero ())
{
system.poll ();
while (wallet->node.balance (key1).is_zero ())
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
}
rai::uint128_t amount (wallet->node.balance (key1));
ASSERT_EQ (2 * wallet->rendering_ratio, amount);
ASSERT_EQ (2 * wallet->rendering_ratio, amount);
QTest::mouseClick (wallet->send_blocks_back, Qt::LeftButton);
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
QTest::mouseClick (wallet->advanced.show_ledger, Qt::LeftButton);
QTest::mouseClick (wallet->advanced.ledger_refresh, Qt::LeftButton);
ASSERT_EQ (2, wallet->advanced.ledger_model->rowCount ());
@ -266,32 +266,32 @@ TEST (wallet, send)
TEST (wallet, send_locked)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::keypair key1;
system.wallet (0)->enter_password ("0");
auto account (rai::test_genesis_key.pub);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
QTest::mouseClick (wallet->send_blocks, Qt::LeftButton);
QTest::keyClicks (wallet->send_account, key1.pub.to_account ().c_str ());
QTest::keyClicks (wallet->send_count, "2");
QTest::mouseClick (wallet->send_blocks_send, Qt::LeftButton);
QTest::mouseClick (wallet->send_blocks, Qt::LeftButton);
QTest::keyClicks (wallet->send_account, key1.pub.to_account ().c_str ());
QTest::keyClicks (wallet->send_count, "2");
QTest::mouseClick (wallet->send_blocks_send, Qt::LeftButton);
auto iterations1 (0);
while (!wallet->send_blocks_send->isEnabled ())
{
while (!wallet->send_blocks_send->isEnabled ())
{
test_application->processEvents ();
system.poll ();
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
}
}
}
TEST (wallet, process_block)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai::account account;
rai::block_hash latest (system.nodes [0]->latest (rai::genesis_account));
system.wallet (0)->insert_adhoc (rai::keypair ().prv);
@ -299,39 +299,39 @@ TEST (wallet, process_block)
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
account = system.account (transaction, 0);
}
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
ASSERT_EQ ("Process", wallet->block_entry.process->text ());
ASSERT_EQ ("Back", wallet->block_entry.back->text ());
rai::keypair key1;
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
QTest::mouseClick (wallet->advanced.enter_block, Qt::LeftButton);
ASSERT_EQ (wallet->block_entry.window, wallet->main_stack->currentWidget ());
rai::send_block send (latest, key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest));
std::string previous;
send.hashables.previous.encode_hex (previous);
std::string balance;
send.hashables.balance.encode_hex (balance);
std::string signature;
send.signature.encode_hex (signature);
auto block_json (boost::str (boost::format ("{\"type\": \"send\", \"previous\": \"%1%\", \"balance\": \"%2%\", \"destination\": \"%3%\", \"work\": \"%4%\", \"signature\": \"%5%\"}") % previous % balance % send.hashables.destination.to_account () % rai::to_string_hex (send.work) % signature));
QTest::keyClicks (wallet->block_entry.block, block_json.c_str ());
QTest::mouseClick (wallet->block_entry.process, Qt::LeftButton);
ASSERT_EQ (send.hash (), system.nodes [0]->latest (rai::genesis_account));
QTest::mouseClick(wallet->block_entry.back, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
ASSERT_EQ ("Process", wallet->block_entry.process->text ());
ASSERT_EQ ("Back", wallet->block_entry.back->text ());
rai::keypair key1;
ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ());
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
QTest::mouseClick (wallet->advanced.enter_block, Qt::LeftButton);
ASSERT_EQ (wallet->block_entry.window, wallet->main_stack->currentWidget ());
rai::send_block send (latest, key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest));
std::string previous;
send.hashables.previous.encode_hex (previous);
std::string balance;
send.hashables.balance.encode_hex (balance);
std::string signature;
send.signature.encode_hex (signature);
auto block_json (boost::str (boost::format ("{\"type\": \"send\", \"previous\": \"%1%\", \"balance\": \"%2%\", \"destination\": \"%3%\", \"work\": \"%4%\", \"signature\": \"%5%\"}") % previous % balance % send.hashables.destination.to_account () % rai::to_string_hex (send.work) % signature));
QTest::keyClicks (wallet->block_entry.block, block_json.c_str ());
QTest::mouseClick (wallet->block_entry.process, Qt::LeftButton);
ASSERT_EQ (send.hash (), system.nodes [0]->latest (rai::genesis_account));
QTest::mouseClick(wallet->block_entry.back, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
}
TEST (wallet, create_send)
{
rai_qt::eventloop_processor processor;
rai_qt::eventloop_processor processor;
rai::keypair key;
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system.wallet (0)->insert_adhoc (key.prv);
auto account (rai::test_genesis_key.pub);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
wallet->client_window->show ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
@ -355,7 +355,7 @@ TEST (wallet, create_send)
TEST (wallet, create_open_receive)
{
rai_qt::eventloop_processor processor;
rai_qt::eventloop_processor processor;
rai::keypair key;
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
@ -366,7 +366,7 @@ TEST (wallet, create_open_receive)
ASSERT_NE (latest1, latest2);
system.wallet (0)->insert_adhoc (key.prv);
auto account (rai::test_genesis_key.pub);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
wallet->client_window->show ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
@ -404,12 +404,12 @@ TEST (wallet, create_open_receive)
TEST (wallet, create_change)
{
rai_qt::eventloop_processor processor;
rai_qt::eventloop_processor processor;
rai::keypair key;
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
auto account (rai::test_genesis_key.pub);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
wallet->client_window->show ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
@ -433,9 +433,9 @@ TEST (wallet, create_change)
TEST (history, short_text)
{
bool init;
rai_qt::eventloop_processor processor;
rai_qt::eventloop_processor processor;
rai::keypair key;
rai::system system (24000, 1);
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (key.prv);
rai::account account;
{
@ -465,18 +465,18 @@ TEST (history, short_text)
TEST (wallet, startup_work)
{
rai_qt::eventloop_processor processor;
rai_qt::eventloop_processor processor;
rai::keypair key;
rai::system system (24000, 1);
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (key.prv);
rai::account account;
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
account = system.account (transaction, 0);
}
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
uint64_t work1;
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
@ -484,33 +484,33 @@ TEST (wallet, startup_work)
}
QTest::mouseClick (wallet->accounts_button, Qt::LeftButton);
QTest::keyClicks (wallet->accounts.account_key_line, "34F0A37AAD20F4A260F0A5B3CB3D7FB50673212263E58A380BC10474BB039CE4");
QTest::mouseClick (wallet->accounts.account_key_button, Qt::LeftButton);
auto iterations1 (0);
QTest::mouseClick (wallet->accounts.account_key_button, Qt::LeftButton);
auto iterations1 (0);
auto again (true);
while (again)
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
while (again)
{
system.poll ();
++iterations1;
ASSERT_LT (iterations1, 200);
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
again = wallet->wallet_m->store.work_get (transaction, rai::test_genesis_key.pub, work1);
}
}
}
TEST (wallet, block_viewer)
{
rai_qt::eventloop_processor processor;
rai_qt::eventloop_processor processor;
rai::keypair key;
rai::system system (24000, 1);
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (key.prv);
rai::account account;
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
account = system.account (transaction, 0);
}
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_NE (-1, wallet->advanced.layout->indexOf (wallet->advanced.block_viewer));
QTest::mouseClick (wallet->advanced.block_viewer, Qt::LeftButton);
ASSERT_EQ (wallet->block_viewer.window, wallet->main_stack->currentWidget ());
@ -524,8 +524,8 @@ TEST (wallet, block_viewer)
TEST (wallet, import)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
std::string json;
rai::keypair key1;
rai::keypair key2;
@ -541,7 +541,7 @@ TEST (wallet, import)
stream.open (path.string ().c_str ());
stream << json;
}
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [1], system.wallet (1), key2.pub));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [1], system.wallet (1), key2.pub));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
@ -558,8 +558,8 @@ TEST (wallet, import)
TEST (wallet, republish)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
rai_qt::eventloop_processor processor;
rai::system system (24000, 2);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::keypair key;
rai::block_hash hash;
@ -570,7 +570,7 @@ TEST (wallet, republish)
ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (transaction, block).code);
}
auto account (rai::test_genesis_key.pub);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), account));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
@ -590,11 +590,11 @@ TEST (wallet, republish)
TEST (wallet, ignore_empty_adhoc)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai::keypair key1;
system.wallet (0)->insert_adhoc (key1.prv);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1.pub));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1.pub));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
@ -615,14 +615,14 @@ TEST (wallet, ignore_empty_adhoc)
TEST (wallet, change_seed)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto key1 (system.wallet (0)->deterministic_insert ());
auto key3 (system.wallet (0)->deterministic_insert ());
rai::raw_key seed3;
system.wallet (0)->store.seed (seed3, rai::transaction (system.wallet (0)->store.environment, nullptr, false));
auto wallet_key (key1);
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), wallet_key));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), wallet_key));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
@ -661,10 +661,10 @@ TEST (wallet, change_seed)
TEST (wallet, seed_work_generation)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto key1 (system.wallet (0)->deterministic_insert ());
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
@ -693,10 +693,10 @@ TEST (wallet, seed_work_generation)
TEST (wallet, backup_seed)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto key1 (system.wallet (0)->deterministic_insert ());
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
@ -710,11 +710,11 @@ TEST (wallet, backup_seed)
TEST (wallet, import_locked)
{
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
rai_qt::eventloop_processor processor;
rai::system system (24000, 1);
auto key1 (system.wallet (0)->deterministic_insert ());
system.wallet (0)->store.rekey (rai::transaction (system.wallet (0)->store.environment, nullptr, true), "1");
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], system.wallet (0), key1));
wallet->start ();
QTest::mouseClick (wallet->show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ());
@ -738,11 +738,11 @@ TEST (wallet, import_locked)
TEST (wallet, synchronizing)
{
rai_qt::eventloop_processor processor;
rai::system system0 (24000, 1);
rai::system system1 (24001, 1);
rai_qt::eventloop_processor processor;
rai::system system0 (24000, 1);
rai::system system1 (24001, 1);
auto key1 (system0.wallet (0)->deterministic_insert ());
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system0.nodes [0], system0.wallet (0), key1));
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system0.nodes [0], system0.wallet (0), key1));
wallet->start ();
{
rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true);

View file

@ -29,7 +29,7 @@ void rai_daemon::daemon_config::serialize_json (boost::property_tree::ptree & tr
bool rai_daemon::daemon_config::deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a)
{
auto error (false);
auto error (false);
try
{
if (!tree_a.empty ())
@ -97,10 +97,10 @@ bool rai_daemon::daemon_config::upgrade_json (unsigned version_a, boost::propert
void rai_daemon::daemon::run (boost::filesystem::path const & data_path)
{
boost::filesystem::create_directories (data_path);
rai_daemon::daemon_config config (data_path);
auto config_path ((data_path / "config.json"));
std::fstream config_file;
std::unique_ptr <rai::thread_runner> runner;
rai_daemon::daemon_config config (data_path);
auto config_path ((data_path / "config.json"));
std::fstream config_file;
std::unique_ptr <rai::thread_runner> runner;
auto error (rai::fetch_object (config, config_path, config_file));
if (!error)
{

View file

@ -3,22 +3,22 @@
namespace rai_daemon
{
class daemon
{
public:
void run (boost::filesystem::path const &);
};
class daemon_config
{
public:
daemon_config (boost::filesystem::path const &);
bool deserialize_json (bool &, boost::property_tree::ptree &);
void serialize_json (boost::property_tree::ptree &);
class daemon
{
public:
void run (boost::filesystem::path const &);
};
class daemon_config
{
public:
daemon_config (boost::filesystem::path const &);
bool deserialize_json (bool &, boost::property_tree::ptree &);
void serialize_json (boost::property_tree::ptree &);
bool upgrade_json (unsigned, boost::property_tree::ptree &);
bool rpc_enable;
rai::rpc_config rpc;
rai::node_config node;
bool opencl_enable;
rai::opencl_config opencl;
};
};
}

View file

@ -10,98 +10,98 @@
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
}
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;
}
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 ();
}
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));
}
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 ();
}
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));
}
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 ());
}
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

View file

@ -200,13 +200,13 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost
application.processEvents();
qt_wallet_config config (data_path);
auto config_path ((data_path / "config.json"));
int result (0);
int result (0);
std::fstream config_file;
auto error (rai::fetch_object (config, config_path, config_file));
config_file.close ();
if (!error)
{
boost::asio::io_service service;
{
boost::asio::io_service service;
config.node.logging.init (data_path);
std::shared_ptr <rai::node> node;
std::shared_ptr <rai_qt::wallet> gui;

File diff suppressed because it is too large Load diff

View file

@ -5,16 +5,16 @@
TEST (system, generate_mass_activity)
{
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
size_t count (20);
system.generate_mass_activity (count, *system.nodes [0]);
size_t accounts (0);
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
size_t count (20);
system.generate_mass_activity (count, *system.nodes [0]);
size_t accounts (0);
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
for (auto i (system.nodes [0]->store.latest_begin (transaction)), n (system.nodes [0]->store.latest_end ()); i != n; ++i)
{
++accounts;
}
for (auto i (system.nodes [0]->store.latest_begin (transaction)), n (system.nodes [0]->store.latest_end ()); i != n; ++i)
{
++accounts;
}
}
TEST (system, generate_mass_activity_long)
@ -383,7 +383,7 @@ TEST (peer_container, random_set)
TEST (store, unchecked_load)
{
rai::system system (24000, 1);
rai::system system (24000, 1);
auto & node (*system.nodes [0]);
auto block (std::make_shared <rai::send_block> (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
for (auto i (0); i < 1000000; ++i)
@ -397,7 +397,7 @@ TEST (store, unchecked_load)
TEST (store, vote_load)
{
rai::system system (24000, 1);
rai::system system (24000, 1);
auto & node (*system.nodes [0]);
auto block (std::make_shared <rai::send_block> (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
for (auto i (0); i < 1000000; ++i)

View file

@ -25,28 +25,28 @@ modified (modified_a)
void rai::account_info_v1::serialize (rai::stream & stream_a) const
{
write (stream_a, head.bytes);
write (stream_a, rep_block.bytes);
write (stream_a, balance.bytes);
write (stream_a, modified);
write (stream_a, head.bytes);
write (stream_a, rep_block.bytes);
write (stream_a, balance.bytes);
write (stream_a, modified);
}
bool rai::account_info_v1::deserialize (rai::stream & stream_a)
{
auto result (read (stream_a, head.bytes));
if (!result)
{
result = read (stream_a, rep_block.bytes);
if (!result)
{
auto result (read (stream_a, head.bytes));
if (!result)
{
result = read (stream_a, rep_block.bytes);
if (!result)
{
result = read (stream_a, balance.bytes);
if (!result)
{
result = read (stream_a, modified);
}
}
}
return result;
}
}
return result;
}
rai::mdb_val rai::account_info_v1::val () const
@ -77,28 +77,28 @@ destination (destination_a)
void rai::pending_info_v3::serialize (rai::stream & stream_a) const
{
rai::write (stream_a, source.bytes);
rai::write (stream_a, amount.bytes);
rai::write (stream_a, destination.bytes);
rai::write (stream_a, source.bytes);
rai::write (stream_a, amount.bytes);
rai::write (stream_a, destination.bytes);
}
bool rai::pending_info_v3::deserialize (rai::stream & stream_a)
{
auto result (rai::read (stream_a, source.bytes));
if (!result)
{
result = rai::read (stream_a, amount.bytes);
if (!result)
{
result = rai::read (stream_a, destination.bytes);
}
}
return result;
auto result (rai::read (stream_a, source.bytes));
if (!result)
{
result = rai::read (stream_a, amount.bytes);
if (!result)
{
result = rai::read (stream_a, destination.bytes);
}
}
return result;
}
bool rai::pending_info_v3::operator == (rai::pending_info_v3 const & other_a) const
{
return source == other_a.source && amount == other_a.amount && destination == other_a.destination;
return source == other_a.source && amount == other_a.amount && destination == other_a.destination;
}
rai::mdb_val rai::pending_info_v3::val () const
@ -133,21 +133,21 @@ modified (modified_a)
void rai::account_info_v5::serialize (rai::stream & stream_a) const
{
write (stream_a, head.bytes);
write (stream_a, rep_block.bytes);
write (stream_a, head.bytes);
write (stream_a, rep_block.bytes);
write (stream_a, open_block.bytes);
write (stream_a, balance.bytes);
write (stream_a, modified);
write (stream_a, balance.bytes);
write (stream_a, modified);
}
bool rai::account_info_v5::deserialize (rai::stream & stream_a)
{
auto result (read (stream_a, head.bytes));
if (!result)
{
result = read (stream_a, rep_block.bytes);
if (!result)
{
auto result (read (stream_a, head.bytes));
if (!result)
{
result = read (stream_a, rep_block.bytes);
if (!result)
{
result = read (stream_a, open_block.bytes);
if (!result)
{
@ -157,9 +157,9 @@ bool rai::account_info_v5::deserialize (rai::stream & stream_a)
result = read (stream_a, modified);
}
}
}
}
return result;
}
}
return result;
}
rai::mdb_val rai::account_info_v5::val () const