diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d64a189..60e41ed6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/rai/core_test/block.cpp b/rai/core_test/block.cpp index c32ca44a..faa9e63d 100644 --- a/rai/core_test/block.cpp +++ b/rai/core_test/block.cpp @@ -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 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 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 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 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 ::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 ::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 ::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 ::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 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 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 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 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 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 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 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 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 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 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 (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); - rai::publish req (std::move (block)); - std::vector 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 (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); + rai::publish req (std::move (block)); + std::vector 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 (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); - rai::confirm_req req (std::move (block)); - std::vector 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 (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); + rai::confirm_req req (std::move (block)); + std::vector 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); } diff --git a/rai/core_test/block_store.cpp b/rai/core_test/block_store.cpp index ddc8ba25..04cd84b3 100644 --- a/rai/core_test/block_store.cpp +++ b/rai/core_test/block_store.cpp @@ -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 (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 (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 (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 (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 (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 (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 (0, key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); auto vote1 (std::make_shared (key1.pub, key1.prv, 2, send1)); diff --git a/rai/core_test/conflicts.cpp b/rai/core_test/conflicts.cpp index d05f98d6..67e3a37a 100644 --- a/rai/core_test/conflicts.cpp +++ b/rai/core_test/conflicts.cpp @@ -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 (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 (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 (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 (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 (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + rai::keypair key2; + auto send2 (std::make_shared (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 (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 (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 (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 (send1->hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + rai::keypair key2; + auto send2 (std::make_shared (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 ()); } diff --git a/rai/core_test/daemon.cpp b/rai/core_test/daemon.cpp index 0b7433a3..ba615ca5 100644 --- a/rai/core_test/daemon.cpp +++ b/rai/core_test/daemon.cpp @@ -2,5 +2,5 @@ TEST (daemon, fork) { - + } \ No newline at end of file diff --git a/rai/core_test/entry.cpp b/rai/core_test/entry.cpp index fbd9512f..3767764a 100644 --- a/rai/core_test/entry.cpp +++ b/rai/core_test/entry.cpp @@ -2,7 +2,7 @@ TEST (basic, basic) { - ASSERT_TRUE (true); + ASSERT_TRUE (true); } TEST (asan, DISABLED_memory) diff --git a/rai/core_test/gap_cache.cpp b/rai/core_test/gap_cache.cpp index ab78c7a4..ebe5b3d4 100644 --- a/rai/core_test/gap_cache.cpp +++ b/rai/core_test/gap_cache.cpp @@ -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 (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 (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 (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 (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 (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 (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 (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 (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) diff --git a/rai/core_test/ledger.cpp b/rai/core_test/ledger.cpp index bcbbb8e1..f25062c3 100644 --- a/rai/core_test/ledger.cpp +++ b/rai/core_test/ledger.cpp @@ -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 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 (); } diff --git a/rai/core_test/message.cpp b/rai/core_test/message.cpp index 4514c717..59b46775 100644 --- a/rai/core_test/message.cpp +++ b/rai/core_test/message.cpp @@ -4,88 +4,88 @@ TEST (message, keepalive_serialization) { - rai::keepalive request1; - std::vector 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 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 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 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 (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 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 (rai::message_type::publish), bytes [5]); - ASSERT_EQ (0x02, bytes [6]); - ASSERT_EQ (static_cast (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 (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 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 (rai::message_type::publish), bytes [5]); + ASSERT_EQ (0x02, bytes [6]); + ASSERT_EQ (static_cast (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 (key1.pub, key1.prv, 0, std::unique_ptr (new rai::send_block (0, 1, 2, key1.prv, 4, 5)))); - rai::confirm_ack con1 (vote); - std::vector bytes; - { - rai::vectorstream stream1 (bytes); - con1.serialize (stream1); - } - rai::bufferstream stream2 (bytes.data (), bytes.size ()); + rai::confirm_ack con1 (vote); + std::vector 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); } diff --git a/rai/core_test/message_parser.cpp b/rai/core_test/message_parser.cpp index cba7f766..98eb538d 100644 --- a/rai/core_test/message_parser.cpp +++ b/rai/core_test/message_parser.cpp @@ -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 (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 (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); auto vote (std::make_shared (0, rai::keypair ().prv, 0, std::move (block))); - rai::confirm_ack message (vote); - std::vector 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 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 (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); - rai::confirm_req message (std::move (block)); - std::vector 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 (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); + rai::confirm_req message (std::move (block)); + std::vector 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 (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); rai::publish message (std::move (block)); - std::vector 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 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 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 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); } diff --git a/rai/core_test/network.cpp b/rai/core_test/network.cpp index c8db0a70..e34d5158 100644 --- a/rai/core_test/network.cpp +++ b/rai/core_test/network.cpp @@ -4,57 +4,57 @@ TEST (network, tcp_connection) { - boost::asio::io_service service; - boost::asio::ip::tcp::acceptor acceptor (service); - boost::asio::ip::tcp::endpoint endpoint (boost::asio::ip::address_v4::any (), 24000); - acceptor.open (endpoint.protocol ()); - acceptor.set_option (boost::asio::ip::tcp::acceptor::reuse_address (true)); - acceptor.bind (endpoint); - acceptor.listen (); - boost::asio::ip::tcp::socket incoming (service); - auto done1 (false); - std::string message1; - acceptor.async_accept (incoming, - [&done1, &message1] (boost::system::error_code const & ec_a) - { - if (ec_a) - { - message1 = ec_a.message (); - std::cerr << message1; - } - done1 = true;} - ); - boost::asio::ip::tcp::socket connector (service); - auto done2 (false); - std::string message2; - connector.async_connect (boost::asio::ip::tcp::endpoint (boost::asio::ip::address_v4::loopback (), 24000), - [&done2, &message2] (boost::system::error_code const & ec_a) - { - if (ec_a) - { - message2 = ec_a.message (); - std::cerr << message2; - } - done2 = true; - }); - while (!done1 || !done2) - { - service.poll (); - } - ASSERT_EQ (0, message1.size ()); - ASSERT_EQ (0, message2.size ()); + boost::asio::io_service service; + boost::asio::ip::tcp::acceptor acceptor (service); + boost::asio::ip::tcp::endpoint endpoint (boost::asio::ip::address_v4::any (), 24000); + acceptor.open (endpoint.protocol ()); + acceptor.set_option (boost::asio::ip::tcp::acceptor::reuse_address (true)); + acceptor.bind (endpoint); + acceptor.listen (); + boost::asio::ip::tcp::socket incoming (service); + auto done1 (false); + std::string message1; + acceptor.async_accept (incoming, + [&done1, &message1] (boost::system::error_code const & ec_a) + { + if (ec_a) + { + message1 = ec_a.message (); + std::cerr << message1; + } + done1 = true;} + ); + boost::asio::ip::tcp::socket connector (service); + auto done2 (false); + std::string message2; + connector.async_connect (boost::asio::ip::tcp::endpoint (boost::asio::ip::address_v4::loopback (), 24000), + [&done2, &message2] (boost::system::error_code const & ec_a) + { + if (ec_a) + { + message2 = ec_a.message (); + std::cerr << message2; + } + done2 = true; + }); + while (!done1 || !done2) + { + service.poll (); + } + ASSERT_EQ (0, message1.size ()); + ASSERT_EQ (0, message2.size ()); } TEST (network, construction) { - rai::system system (24000, 1); - ASSERT_EQ (1, system.nodes.size ()); - ASSERT_EQ (24000, system.nodes [0]->network.socket.local_endpoint ().port ()); + rai::system system (24000, 1); + ASSERT_EQ (1, system.nodes.size ()); + ASSERT_EQ (24000, system.nodes [0]->network.socket.local_endpoint ().port ()); } TEST (network, self_discard) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.nodes [0]->network.remote = system.nodes [0]->network.endpoint (); ASSERT_EQ (0, system.nodes [0]->network.bad_sender_count); system.nodes [0]->network.receive_action (boost::system::error_code {}, 0); @@ -63,91 +63,91 @@ TEST (network, self_discard) TEST (network, send_keepalive) { - rai::system system (24000, 1); - auto list1 (system.nodes [0]->peers.list ()); - ASSERT_EQ (0, list1.size ()); - rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - node1->start (); - system.nodes [0]->network.send_keepalive (node1->network.endpoint ()); - auto initial (system.nodes [0]->network.incoming.keepalive.load ()); - ASSERT_EQ (0, system.nodes [0]->peers.list ().size ()); - ASSERT_EQ (0, node1->peers.list ().size ()); - auto iterations (0); - while (system.nodes [0]->network.incoming.keepalive == initial) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } - auto peers1 (system.nodes [0]->peers.list ()); - auto peers2 (node1->peers.list ()); - ASSERT_EQ (1, peers1.size ()); - ASSERT_EQ (1, peers2.size ()); - ASSERT_NE (peers1.end (), std::find_if (peers1.begin (), peers1.end (), [&node1] (rai::endpoint const & information_a) {return information_a == node1->network.endpoint ();})); - ASSERT_NE (peers2.end (), std::find_if (peers2.begin (), peers2.end (), [&system] (rai::endpoint const & information_a) {return information_a == system.nodes [0]->network.endpoint ();})); - node1->stop (); + rai::system system (24000, 1); + auto list1 (system.nodes [0]->peers.list ()); + ASSERT_EQ (0, list1.size ()); + rai::node_init init1; + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + node1->start (); + system.nodes [0]->network.send_keepalive (node1->network.endpoint ()); + auto initial (system.nodes [0]->network.incoming.keepalive.load ()); + ASSERT_EQ (0, system.nodes [0]->peers.list ().size ()); + ASSERT_EQ (0, node1->peers.list ().size ()); + auto iterations (0); + while (system.nodes [0]->network.incoming.keepalive == initial) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } + auto peers1 (system.nodes [0]->peers.list ()); + auto peers2 (node1->peers.list ()); + ASSERT_EQ (1, peers1.size ()); + ASSERT_EQ (1, peers2.size ()); + ASSERT_NE (peers1.end (), std::find_if (peers1.begin (), peers1.end (), [&node1] (rai::endpoint const & information_a) {return information_a == node1->network.endpoint ();})); + ASSERT_NE (peers2.end (), std::find_if (peers2.begin (), peers2.end (), [&system] (rai::endpoint const & information_a) {return information_a == system.nodes [0]->network.endpoint ();})); + node1->stop (); } TEST (network, keepalive_ipv4) { - rai::system system (24000, 1); - auto list1 (system.nodes [0]->peers.list ()); - ASSERT_EQ (0, list1.size ()); - rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - node1->start (); - node1->send_keepalive (rai::endpoint (boost::asio::ip::address_v4::loopback (), 24000)); - auto initial (system.nodes [0]->network.incoming.keepalive.load ()); - auto iterations (0); - while (system.nodes [0]->network.incoming.keepalive == initial) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } - node1->stop (); + rai::system system (24000, 1); + auto list1 (system.nodes [0]->peers.list ()); + ASSERT_EQ (0, list1.size ()); + rai::node_init init1; + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + node1->start (); + node1->send_keepalive (rai::endpoint (boost::asio::ip::address_v4::loopback (), 24000)); + auto initial (system.nodes [0]->network.incoming.keepalive.load ()); + auto iterations (0); + while (system.nodes [0]->network.incoming.keepalive == initial) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } + node1->stop (); } TEST (network, multi_keepalive) { - rai::system system (24000, 1); - auto list1 (system.nodes [0]->peers.list ()); - ASSERT_EQ (0, list1.size ()); - rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - ASSERT_FALSE (init1.error ()); - node1->start (); - ASSERT_EQ (0, node1->peers.size ()); - node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); - ASSERT_EQ (0, node1->peers.size ()); - ASSERT_EQ (0, system.nodes [0]->peers.size ()); - auto iterations1 (0); - while (system.nodes [0]->peers.size () != 1) - { - system.poll (); - ++iterations1; - ASSERT_LT (iterations1, 200); - } - rai::node_init init2; - auto node2 (std::make_shared (init2, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); - ASSERT_FALSE (init2.error ()); - node2->start (); - node2->network.send_keepalive (system.nodes [0]->network.endpoint ()); - auto iterations2 (0); - while (node1->peers.size () != 2 || system.nodes [0]->peers.size () != 2 || node2->peers.size () != 2) - { - system.poll (); - ++iterations2; - ASSERT_LT (iterations2, 200); - } - node1->stop (); - node2->stop (); + rai::system system (24000, 1); + auto list1 (system.nodes [0]->peers.list ()); + ASSERT_EQ (0, list1.size ()); + rai::node_init init1; + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + ASSERT_FALSE (init1.error ()); + node1->start (); + ASSERT_EQ (0, node1->peers.size ()); + node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); + ASSERT_EQ (0, node1->peers.size ()); + ASSERT_EQ (0, system.nodes [0]->peers.size ()); + auto iterations1 (0); + while (system.nodes [0]->peers.size () != 1) + { + system.poll (); + ++iterations1; + ASSERT_LT (iterations1, 200); + } + rai::node_init init2; + auto node2 (std::make_shared (init2, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); + ASSERT_FALSE (init2.error ()); + node2->start (); + node2->network.send_keepalive (system.nodes [0]->network.endpoint ()); + auto iterations2 (0); + while (node1->peers.size () != 2 || system.nodes [0]->peers.size () != 2 || node2->peers.size () != 2) + { + system.poll (); + ++iterations2; + ASSERT_LT (iterations2, 200); + } + node1->stop (); + node2->stop (); } TEST (network, send_discarded_publish) { - rai::system system (24000, 2); + rai::system system (24000, 2); auto block (std::make_shared (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))); rai::genesis genesis; { @@ -156,134 +156,134 @@ TEST (network, send_discarded_publish) ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); } - auto iterations (0); - while (system.nodes [1]->network.incoming.publish == 0) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); + auto iterations (0); + while (system.nodes [1]->network.incoming.publish == 0) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); } rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); - ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); } TEST (network, send_invalid_publish) { rai::system system (24000, 2); rai::genesis genesis; - auto block (std::make_shared (1, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (1))); + auto block (std::make_shared (1, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (1))); { rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); system.nodes [0]->network.republish_block (transaction, block); ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); } - auto iterations (0); - while (system.nodes [1]->network.incoming.publish == 0) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); + auto iterations (0); + while (system.nodes [1]->network.incoming.publish == 0) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); } rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); - ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); } TEST (network, send_valid_confirm_ack) { - 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); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); - rai::send_block block2 (latest1, key2.pub, 50, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1)); - rai::block_hash latest2 (system.nodes [1]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::send_block block2 (latest1, key2.pub, 50, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1)); + rai::block_hash latest2 (system.nodes [1]->latest (rai::test_genesis_key.pub)); system.nodes [0]->process_active (std::unique_ptr (new rai::send_block (block2))); - auto iterations (0); + auto iterations (0); // Keep polling until latest block changes - while (system.nodes [1]->latest (rai::test_genesis_key.pub) == latest2) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } + while (system.nodes [1]->latest (rai::test_genesis_key.pub) == latest2) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } // Make sure the balance has decreased after procssing the block. - ASSERT_EQ (50, system.nodes [1]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (50, system.nodes [1]->balance (rai::test_genesis_key.pub)); } TEST (network, send_valid_publish) { - rai::system system (24000, 2); + rai::system system (24000, 2); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::keypair key2; + rai::keypair key2; system.wallet (1)->insert_adhoc (key2.prv); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); - rai::send_block block2 (latest1, key2.pub, 50, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1)); - auto hash2 (block2.hash ()); - rai::block_hash latest2 (system.nodes [1]->latest (rai::test_genesis_key.pub)); - system.nodes [1]->process_active (std::unique_ptr (new rai::send_block (block2))); - auto iterations (0); - while (system.nodes [0]->network.incoming.publish == 0) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } - rai::block_hash latest3 (system.nodes [1]->latest (rai::test_genesis_key.pub)); - ASSERT_NE (latest2, latest3); - ASSERT_EQ (hash2, latest3); - ASSERT_EQ (50, system.nodes [1]->balance (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::send_block block2 (latest1, key2.pub, 50, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1)); + auto hash2 (block2.hash ()); + rai::block_hash latest2 (system.nodes [1]->latest (rai::test_genesis_key.pub)); + system.nodes [1]->process_active (std::unique_ptr (new rai::send_block (block2))); + auto iterations (0); + while (system.nodes [0]->network.incoming.publish == 0) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } + rai::block_hash latest3 (system.nodes [1]->latest (rai::test_genesis_key.pub)); + ASSERT_NE (latest2, latest3); + ASSERT_EQ (hash2, latest3); + ASSERT_EQ (50, system.nodes [1]->balance (rai::test_genesis_key.pub)); } TEST (network, send_insufficient_work) { - rai::system system (24000, 2); - std::unique_ptr block (new rai::send_block (0, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); - rai::publish publish (std::move (block)); - std::shared_ptr > bytes (new std::vector ); - { - rai::vectorstream stream (*bytes); - publish.serialize (stream); - } - auto node1 (system.nodes [1]->shared ()); - system.nodes [0]->network.send_buffer (bytes->data (), bytes->size (), system.nodes [1]->network.endpoint (), [bytes, node1] (boost::system::error_code const & ec, size_t size) {}); - ASSERT_EQ (0, system.nodes [0]->network.insufficient_work_count); - auto iterations (0); - while (system.nodes [1]->network.insufficient_work_count == 0) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } - ASSERT_EQ (1, system.nodes [1]->network.insufficient_work_count); + rai::system system (24000, 2); + std::unique_ptr block (new rai::send_block (0, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + rai::publish publish (std::move (block)); + std::shared_ptr > bytes (new std::vector ); + { + rai::vectorstream stream (*bytes); + publish.serialize (stream); + } + auto node1 (system.nodes [1]->shared ()); + system.nodes [0]->network.send_buffer (bytes->data (), bytes->size (), system.nodes [1]->network.endpoint (), [bytes, node1] (boost::system::error_code const & ec, size_t size) {}); + ASSERT_EQ (0, system.nodes [0]->network.insufficient_work_count); + auto iterations (0); + while (system.nodes [1]->network.insufficient_work_count == 0) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } + ASSERT_EQ (1, system.nodes [1]->network.insufficient_work_count); } TEST (receivable_processor, confirm_insufficient_pos) { - rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); - rai::genesis genesis; - auto block1 (std::make_shared (genesis.hash (), 0, 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; + auto block1 (std::make_shared (genesis.hash (), 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*block1).code); auto node_l (system.nodes [0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, block1); } - rai::keypair key1; + rai::keypair key1; auto vote (std::make_shared (key1.pub, key1.prv, 0, block1)); - rai::confirm_ack con1 (vote); + rai::confirm_ack con1 (vote); node1.process_message (con1, node1.network.endpoint ()); } TEST (receivable_processor, confirm_sufficient_pos) { - rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); - rai::genesis genesis; - auto block1 (std::make_shared (genesis.hash (), 0, 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; + auto block1 (std::make_shared (genesis.hash (), 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*block1).code); auto node_l (system.nodes [0]); { @@ -291,38 +291,38 @@ TEST (receivable_processor, confirm_sufficient_pos) node1.active.start (transaction, block1); } auto vote (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 0, block1)); - rai::confirm_ack con1 (vote); + rai::confirm_ack con1 (vote); node1.process_message (con1, node1.network.endpoint ()); } TEST (receivable_processor, send_with_receive) { - auto amount (std::numeric_limits ::max ()); - rai::system system (24000, 2); - rai::keypair key2; + auto amount (std::numeric_limits ::max ()); + rai::system system (24000, 2); + rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); system.wallet (1)->insert_adhoc (key2.prv); - auto block1 (std::make_shared (latest1, key2.pub, amount - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1))); + auto block1 (std::make_shared (latest1, key2.pub, amount - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1))); ASSERT_EQ (amount, system.nodes [0]->balance (rai::test_genesis_key.pub)); ASSERT_EQ (0, system.nodes [0]->balance (key2.pub)); ASSERT_EQ (amount, system.nodes [1]->balance (rai::test_genesis_key.pub)); ASSERT_EQ (0, system.nodes [1]->balance (key2.pub)); - system.nodes [0]->process_active (block1); - system.nodes [0]->block_processor.flush (); - system.nodes [1]->process_active (block1); - system.nodes [1]->block_processor.flush (); + system.nodes [0]->process_active (block1); + system.nodes [0]->block_processor.flush (); + system.nodes [1]->process_active (block1); + system.nodes [1]->block_processor.flush (); ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); ASSERT_EQ (0, system.nodes [0]->balance (key2.pub)); ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [1]->balance (rai::test_genesis_key.pub)); ASSERT_EQ (0, system.nodes [1]->balance (key2.pub)); - auto iterations (0); - while (system.nodes [0]->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } + auto iterations (0); + while (system.nodes [0]->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); ASSERT_EQ (system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (key2.pub)); ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [1]->balance (rai::test_genesis_key.pub)); @@ -331,175 +331,175 @@ TEST (receivable_processor, send_with_receive) TEST (network, receive_weight_change) { - rai::system system (24000, 2); + rai::system system (24000, 2); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::keypair key2; + rai::keypair key2; system.wallet (1)->insert_adhoc (key2.prv); { rai::transaction transaction (system.nodes [1]->store.environment, nullptr, true); system.wallet (1)->store.representative_set (transaction, key2.pub); } - 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 ())); auto iterations (0); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr const & node_a) { return node_a->weight (key2.pub) != system.nodes [0]->config.receive_minimum.number (); })) - { - system.poll (); + while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr const & node_a) { return node_a->weight (key2.pub) != system.nodes [0]->config.receive_minimum.number (); })) + { + system.poll (); ++iterations; ASSERT_LT (iterations, 200); - } + } } TEST (parse_endpoint, valid) { - std::string string ("::1:24000"); - rai::endpoint endpoint; - ASSERT_FALSE (rai::parse_endpoint (string, endpoint)); - ASSERT_EQ (boost::asio::ip::address_v6::loopback (), endpoint.address ()); - ASSERT_EQ (24000, endpoint.port ()); + std::string string ("::1:24000"); + rai::endpoint endpoint; + ASSERT_FALSE (rai::parse_endpoint (string, endpoint)); + ASSERT_EQ (boost::asio::ip::address_v6::loopback (), endpoint.address ()); + ASSERT_EQ (24000, endpoint.port ()); } TEST (parse_endpoint, invalid_port) { - std::string string ("::1:24a00"); - rai::endpoint endpoint; - ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); + std::string string ("::1:24a00"); + rai::endpoint endpoint; + ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); } TEST (parse_endpoint, invalid_address) { - std::string string ("::q:24000"); - rai::endpoint endpoint; - ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); + std::string string ("::q:24000"); + rai::endpoint endpoint; + ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); } TEST (parse_endpoint, no_address) { - std::string string (":24000"); - rai::endpoint endpoint; - ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); + std::string string (":24000"); + rai::endpoint endpoint; + ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); } TEST (parse_endpoint, no_port) { - std::string string ("::1:"); - rai::endpoint endpoint; - ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); + std::string string ("::1:"); + rai::endpoint endpoint; + ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); } TEST (parse_endpoint, no_colon) { - std::string string ("::1"); - rai::endpoint endpoint; - ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); + std::string string ("::1"); + rai::endpoint endpoint; + ASSERT_TRUE (rai::parse_endpoint (string, endpoint)); } // If the account doesn't exist, current == end so there's no iteration TEST (bulk_pull, no_address) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull); - req->start = 1; - req->end = 2; - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (request->current, request->request->end); - ASSERT_TRUE (request->current.is_zero ()); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::bulk_pull); + req->start = 1; + req->end = 2; + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (request->current, request->request->end); + ASSERT_TRUE (request->current.is_zero ()); } TEST (bulk_pull, genesis_to_end) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull {}); - req->start = rai::test_genesis_key.pub; - req->end.clear (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (system.nodes [0]->latest (rai::test_genesis_key.pub), request->current); - ASSERT_EQ (request->request->end, request->request->end); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::bulk_pull {}); + req->start = rai::test_genesis_key.pub; + req->end.clear (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (system.nodes [0]->latest (rai::test_genesis_key.pub), request->current); + ASSERT_EQ (request->request->end, request->request->end); } // If we can't find the end block, send everything TEST (bulk_pull, no_end) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull {}); - req->start = rai::test_genesis_key.pub; - req->end = 1; - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (system.nodes [0]->latest (rai::test_genesis_key.pub), request->current); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::bulk_pull {}); + req->start = rai::test_genesis_key.pub; + req->end = 1; + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (system.nodes [0]->latest (rai::test_genesis_key.pub), request->current); ASSERT_TRUE (request->request->end.is_zero ()); } TEST (bulk_pull, end_not_owned) { - 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, 100)); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, 100)); rai::block_hash latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); - rai::open_block open (0, 1, 2, rai::keypair ().prv, 4, 5); - open.hashables.account = key2.pub; - open.hashables.representative = key2.pub; - open.hashables.source = latest; - open.signature = rai::sign_message (key2.prv, key2.pub, open.hash ()); + rai::open_block open (0, 1, 2, rai::keypair ().prv, 4, 5); + open.hashables.account = key2.pub; + open.hashables.representative = key2.pub; + open.hashables.source = latest; + open.signature = rai::sign_message (key2.prv, key2.pub, open.hash ()); ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); - auto connection (std::make_shared (nullptr, system.nodes [0])); - rai::genesis genesis; - std::unique_ptr req (new rai::bulk_pull {}); - req->start = key2.pub; - req->end = genesis.hash (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (request->current, request->request->end); + auto connection (std::make_shared (nullptr, system.nodes [0])); + rai::genesis genesis; + std::unique_ptr req (new rai::bulk_pull {}); + req->start = key2.pub; + req->end = genesis.hash (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (request->current, request->request->end); } TEST (bulk_pull, none) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - rai::genesis genesis; - std::unique_ptr req (new rai::bulk_pull {}); - req->start = genesis.hash (); - req->end = genesis.hash (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - auto block (request->get_next ()); - ASSERT_EQ (nullptr, block); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + rai::genesis genesis; + std::unique_ptr req (new rai::bulk_pull {}); + req->start = genesis.hash (); + req->end = genesis.hash (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + auto block (request->get_next ()); + ASSERT_EQ (nullptr, block); } TEST (bulk_pull, get_next_on_open) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull {}); - req->start = rai::test_genesis_key.pub; - req->end.clear (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - auto block (request->get_next ()); - ASSERT_NE (nullptr, block); - ASSERT_TRUE (block->previous ().is_zero ()); - ASSERT_FALSE (connection->requests.empty ()); - ASSERT_EQ (request->current, request->request->end); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::bulk_pull {}); + req->start = rai::test_genesis_key.pub; + req->end.clear (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + auto block (request->get_next ()); + ASSERT_NE (nullptr, block); + ASSERT_TRUE (block->previous ().is_zero ()); + ASSERT_FALSE (connection->requests.empty ()); + ASSERT_EQ (request->current, request->request->end); } TEST (bootstrap_processor, DISABLED_process_none) { - rai::system system (24000, 1); - rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - ASSERT_FALSE (init1.error ()); - auto done (false); + rai::system system (24000, 1); + rai::node_init init1; + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + ASSERT_FALSE (init1.error ()); + auto done (false); node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); - while (!done) - { - system.service.run_one (); - } - node1->stop (); + while (!done) + { + system.service.run_one (); + } + node1->stop (); } // Bootstrap can pull one basic block @@ -523,7 +523,7 @@ TEST (bootstrap_processor, process_one) ASSERT_LT (iterations, 200); } ASSERT_EQ (0, node1->active.roots.size ()); - node1->stop (); + node1->stop (); } TEST (bootstrap_processor, process_two) @@ -603,7 +603,7 @@ TEST (bootstrap_processor, pull_diamond) auto iterations (0); while (node1->balance (rai::test_genesis_key.pub) != 100) { - system.poll (); + system.poll (); ++iterations; ASSERT_LT (iterations, 200); } @@ -633,7 +633,7 @@ TEST (bootstrap_processor, push_diamond) auto iterations (0); while (system.nodes [0]->balance (rai::test_genesis_key.pub) != 100) { - system.poll (); + system.poll (); ++iterations; ASSERT_LT (iterations, 200); } @@ -643,235 +643,235 @@ TEST (bootstrap_processor, push_diamond) TEST (bootstrap_processor, push_one) { - rai::system system (24000, 1); - rai::node_init init1; - rai::keypair key1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - auto wallet (node1->wallets.create (rai::uint256_union ())); - ASSERT_NE (nullptr, wallet); + rai::system system (24000, 1); + rai::node_init init1; + rai::keypair key1; + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto wallet (node1->wallets.create (rai::uint256_union ())); + ASSERT_NE (nullptr, wallet); wallet->insert_adhoc (rai::test_genesis_key.prv); - rai::uint128_t balance1 (node1->balance (rai::test_genesis_key.pub)); - ASSERT_NE (nullptr, wallet->send_action (rai::test_genesis_key.pub, key1.pub, 100)); + rai::uint128_t balance1 (node1->balance (rai::test_genesis_key.pub)); + ASSERT_NE (nullptr, wallet->send_action (rai::test_genesis_key.pub, key1.pub, 100)); ASSERT_NE (balance1, node1->balance (rai::test_genesis_key.pub)); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); - auto iterations (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) == balance1) - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } - node1->stop (); + node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + auto iterations (0); + while (system.nodes [0]->balance (rai::test_genesis_key.pub) == balance1) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } + node1->stop (); } TEST (frontier_req_response, DISABLED_destruction) { - { - std::shared_ptr hold; // Destructing tcp acceptor on non-existent io_service - { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); - req->start.clear (); - req->age = std::numeric_limits age)>::max (); - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - hold = std::make_shared (connection, std::move (req)); - } - } - ASSERT_TRUE (true); + { + std::shared_ptr hold; // Destructing tcp acceptor on non-existent io_service + { + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::frontier_req); + req->start.clear (); + req->age = std::numeric_limits age)>::max (); + req->count = std::numeric_limits count)>::max (); + connection->requests.push (std::unique_ptr {}); + hold = std::make_shared (connection, std::move (req)); + } + } + ASSERT_TRUE (true); } TEST (frontier_req, begin) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); - req->start.clear (); - req->age = std::numeric_limits age)>::max (); - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (rai::test_genesis_key.pub, request->current); - rai::genesis genesis; - ASSERT_EQ (genesis.hash (), request->info.head); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::frontier_req); + req->start.clear (); + req->age = std::numeric_limits age)>::max (); + req->count = std::numeric_limits count)>::max (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (rai::test_genesis_key.pub, request->current); + rai::genesis genesis; + ASSERT_EQ (genesis.hash (), request->info.head); } TEST (frontier_req, end) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); - req->start = rai::test_genesis_key.pub.number () + 1; - req->age = std::numeric_limits age)>::max (); - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_TRUE (request->current.is_zero ()); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::frontier_req); + req->start = rai::test_genesis_key.pub.number () + 1; + req->age = std::numeric_limits age)>::max (); + req->count = std::numeric_limits count)>::max (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_TRUE (request->current.is_zero ()); } TEST (frontier_req, time_bound) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); - req->start.clear (); - req->age = 0; - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_TRUE (request->current.is_zero ()); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::frontier_req); + req->start.clear (); + req->age = 0; + req->count = std::numeric_limits count)>::max (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_TRUE (request->current.is_zero ()); } TEST (frontier_req, time_cutoff) { - rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); - req->start.clear (); - req->age = 10; - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (rai::test_genesis_key.pub, request->current); - rai::genesis genesis; - ASSERT_EQ (genesis.hash (), request->info.head); + rai::system system (24000, 1); + auto connection (std::make_shared (nullptr, system.nodes [0])); + std::unique_ptr req (new rai::frontier_req); + req->start.clear (); + req->age = 10; + req->count = std::numeric_limits count)>::max (); + connection->requests.push (std::unique_ptr {}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (rai::test_genesis_key.pub, request->current); + rai::genesis genesis; + ASSERT_EQ (genesis.hash (), request->info.head); } TEST (bulk, genesis) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - ASSERT_FALSE (init1.error ()); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::node_init init1; + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + ASSERT_FALSE (init1.error ()); + rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); rai::block_hash latest2 (node1->latest (rai::test_genesis_key.pub)); - ASSERT_EQ (latest1, latest2); - rai::keypair key2; - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, 100)); - rai::block_hash latest3 (system.nodes [0]->latest (rai::test_genesis_key.pub)); - ASSERT_NE (latest1, latest3); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); - auto iterations (0); - while (node1->latest (rai::test_genesis_key.pub) != system.nodes [0]->latest (rai::test_genesis_key.pub)) - { + ASSERT_EQ (latest1, latest2); + rai::keypair key2; + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, 100)); + rai::block_hash latest3 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + ASSERT_NE (latest1, latest3); + node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + auto iterations (0); + while (node1->latest (rai::test_genesis_key.pub) != system.nodes [0]->latest (rai::test_genesis_key.pub)) + { system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } - ASSERT_EQ (node1->latest (rai::test_genesis_key.pub), system.nodes [0]->latest (rai::test_genesis_key.pub)); - node1->stop (); + ++iterations; + ASSERT_LT (iterations, 200); + } + ASSERT_EQ (node1->latest (rai::test_genesis_key.pub), system.nodes [0]->latest (rai::test_genesis_key.pub)); + node1->stop (); } TEST (bulk, offline_send) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - ASSERT_FALSE (init1.error ()); - node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); - node1->start (); - auto iterations (0); - do - { - system.poll (); - ++iterations; - ASSERT_LT (iterations, 200); - } while (system.nodes [0]->peers.empty () || node1->peers.empty ()); - rai::keypair key2; + rai::node_init init1; + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + ASSERT_FALSE (init1.error ()); + node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); + node1->start (); + auto iterations (0); + do + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } while (system.nodes [0]->peers.empty () || node1->peers.empty ()); + rai::keypair key2; auto wallet (node1->wallets.create (rai::uint256_union ())); wallet->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_NE (std::numeric_limits ::max (), system.nodes [0]->balance (rai::test_genesis_key.pub)); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); - auto iterations2 (0); - while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) - { - system.poll (); - ++iterations2; - ASSERT_LT (iterations2, 200); - } + node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + auto iterations2 (0); + while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) + { + system.poll (); + ++iterations2; + ASSERT_LT (iterations2, 200); + } node1->stop (); } TEST (network, ipv6) { - boost::asio::ip::address_v6 address (boost::asio::ip::address_v6::from_string ("::ffff:127.0.0.1")); - ASSERT_TRUE (address.is_v4_mapped ()); - rai::endpoint endpoint1 (address, 16384); - std::vector bytes1; - { - rai::vectorstream stream (bytes1); - rai::write (stream, address.to_bytes ()); - } - ASSERT_EQ (16, bytes1.size ()); - for (auto i (bytes1.begin ()), n (bytes1.begin () + 10); i != n; ++i) - { - ASSERT_EQ (0, *i); - } - ASSERT_EQ (0xff, bytes1 [10]); - ASSERT_EQ (0xff, bytes1 [11]); - std::array bytes2; - rai::bufferstream stream (bytes1.data (), bytes1.size ()); - rai::read (stream, bytes2); - rai::endpoint endpoint2 (boost::asio::ip::address_v6 (bytes2), 16384); - ASSERT_EQ (endpoint1, endpoint2); + boost::asio::ip::address_v6 address (boost::asio::ip::address_v6::from_string ("::ffff:127.0.0.1")); + ASSERT_TRUE (address.is_v4_mapped ()); + rai::endpoint endpoint1 (address, 16384); + std::vector bytes1; + { + rai::vectorstream stream (bytes1); + rai::write (stream, address.to_bytes ()); + } + ASSERT_EQ (16, bytes1.size ()); + for (auto i (bytes1.begin ()), n (bytes1.begin () + 10); i != n; ++i) + { + ASSERT_EQ (0, *i); + } + ASSERT_EQ (0xff, bytes1 [10]); + ASSERT_EQ (0xff, bytes1 [11]); + std::array bytes2; + rai::bufferstream stream (bytes1.data (), bytes1.size ()); + rai::read (stream, bytes2); + rai::endpoint endpoint2 (boost::asio::ip::address_v6 (bytes2), 16384); + ASSERT_EQ (endpoint1, endpoint2); } TEST (network, ipv6_from_ipv4) { - rai::endpoint endpoint1 (boost::asio::ip::address_v4::loopback(), 16000); - ASSERT_TRUE (endpoint1.address ().is_v4 ()); - rai::endpoint endpoint2 (boost::asio::ip::address_v6::v4_mapped (endpoint1.address ().to_v4 ()), 16000); - ASSERT_TRUE (endpoint2.address ().is_v6 ()); + rai::endpoint endpoint1 (boost::asio::ip::address_v4::loopback(), 16000); + ASSERT_TRUE (endpoint1.address ().is_v4 ()); + rai::endpoint endpoint2 (boost::asio::ip::address_v6::v4_mapped (endpoint1.address ().to_v4 ()), 16000); + ASSERT_TRUE (endpoint2.address ().is_v6 ()); } TEST (network, ipv6_bind_send_ipv4) { - boost::asio::io_service service; - rai::endpoint endpoint1 (boost::asio::ip::address_v6::any (), 24000); - rai::endpoint endpoint2 (boost::asio::ip::address_v4::any (), 24001); - std::array bytes1; - auto finish1 (false); - rai::endpoint endpoint3; - boost::asio::ip::udp::socket socket1 (service, endpoint1); - socket1.async_receive_from (boost::asio::buffer (bytes1.data (), bytes1.size ()), endpoint3, [&finish1] (boost::system::error_code const & error, size_t size_a) - { - ASSERT_FALSE (error); - ASSERT_EQ (16, size_a); - finish1 = true; - }); - boost::asio::ip::udp::socket socket2 (service, endpoint2); - rai::endpoint endpoint5 (boost::asio::ip::address_v4::loopback (), 24000); - rai::endpoint endpoint6 (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4::loopback ()), 24001); - socket2.async_send_to (boost::asio::buffer (std::array {}, 16), endpoint5, [] (boost::system::error_code const & error, size_t size_a) - { - ASSERT_FALSE (error); - ASSERT_EQ (16, size_a); - }); - auto iterations (0); - while (!finish1) - { - service.poll (); + boost::asio::io_service service; + rai::endpoint endpoint1 (boost::asio::ip::address_v6::any (), 24000); + rai::endpoint endpoint2 (boost::asio::ip::address_v4::any (), 24001); + std::array bytes1; + auto finish1 (false); + rai::endpoint endpoint3; + boost::asio::ip::udp::socket socket1 (service, endpoint1); + socket1.async_receive_from (boost::asio::buffer (bytes1.data (), bytes1.size ()), endpoint3, [&finish1] (boost::system::error_code const & error, size_t size_a) + { + ASSERT_FALSE (error); + ASSERT_EQ (16, size_a); + finish1 = true; + }); + boost::asio::ip::udp::socket socket2 (service, endpoint2); + rai::endpoint endpoint5 (boost::asio::ip::address_v4::loopback (), 24000); + rai::endpoint endpoint6 (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4::loopback ()), 24001); + socket2.async_send_to (boost::asio::buffer (std::array {}, 16), endpoint5, [] (boost::system::error_code const & error, size_t size_a) + { + ASSERT_FALSE (error); + ASSERT_EQ (16, size_a); + }); + auto iterations (0); + while (!finish1) + { + service.poll (); ++iterations; ASSERT_LT (iterations, 200); - } - ASSERT_EQ (endpoint6, endpoint3); - std::array bytes2; - auto finish2 (false); - rai::endpoint endpoint4; - socket2.async_receive_from (boost::asio::buffer (bytes2.data (), bytes2.size ()), endpoint4, [&finish2] (boost::system::error_code const & error, size_t size_a) - { - ASSERT_FALSE (!error); - ASSERT_EQ (16, size_a); - }); - socket1.async_send_to (boost::asio::buffer (std::array {}, 16), endpoint6, [] (boost::system::error_code const & error, size_t size_a) - { - ASSERT_FALSE (error); - ASSERT_EQ (16, size_a); - }); + } + ASSERT_EQ (endpoint6, endpoint3); + std::array bytes2; + auto finish2 (false); + rai::endpoint endpoint4; + socket2.async_receive_from (boost::asio::buffer (bytes2.data (), bytes2.size ()), endpoint4, [&finish2] (boost::system::error_code const & error, size_t size_a) + { + ASSERT_FALSE (!error); + ASSERT_EQ (16, size_a); + }); + socket1.async_send_to (boost::asio::buffer (std::array {}, 16), endpoint6, [] (boost::system::error_code const & error, size_t size_a) + { + ASSERT_FALSE (error); + ASSERT_EQ (16, size_a); + }); } TEST (network, endpoint_bad_fd) diff --git a/rai/core_test/node.cpp b/rai/core_test/node.cpp index a2ee3930..7e9eee88 100644 --- a/rai/core_test/node.cpp +++ b/rai/core_test/node.cpp @@ -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 ()); - rai::alarm alarm (*service); + rai::node_init init; + auto service (boost::make_shared ()); + rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::logging logging; logging.init (path); rai::work_pool work (std::numeric_limits ::max (), nullptr); - auto node (std::make_shared (init, *service, 0, path, alarm, logging, work)); + auto node (std::make_shared (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 ()); + rai::node_init init; + auto service (boost::make_shared ()); rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::node_config config; config.logging.init (path); rai::work_pool work (std::numeric_limits ::max (), nullptr); config.inactive_supply = 10; - auto node (std::make_shared (init, *service, path, alarm, config, work)); + auto node (std::make_shared (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 ()); + rai::node_init init; + auto service (boost::make_shared ()); rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::node_config config; config.logging.init (path); rai::work_pool work (std::numeric_limits ::max (), nullptr); config.password_fanout = 10; - auto node (std::make_shared (init, *service, path, alarm, config, work)); + auto node (std::make_shared (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 ::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 ::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 ::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 ::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 ::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 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 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 ::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 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 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 ::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 ::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 (new rai::send_block (send2))); - system.nodes [0]->process_active (std::unique_ptr (new rai::send_block (send1))); - auto iterations (0); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr 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 ::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 ::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 (new rai::send_block (send2))); + system.nodes [0]->process_active (std::unique_ptr (new rai::send_block (send1))); + auto iterations (0); + while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr 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 (previous, key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (previous))); + auto send (std::make_shared (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 (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 (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 (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 (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 (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 (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 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 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 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 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 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 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 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 ()); - rai::alarm alarm (*service); + rai::node_init init; + auto service (boost::make_shared ()); + rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::logging logging; logging.init (path); rai::work_pool work (std::numeric_limits ::max (), nullptr); - auto node (std::make_shared (init, *service, 0, path, alarm, logging, work)); + auto node (std::make_shared (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 ::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 ::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. diff --git a/rai/core_test/rpc.cpp b/rai/core_test/rpc.cpp index 1c9bc6c7..f4c121ca 100644 --- a/rai/core_test/rpc.cpp +++ b/rai/core_test/rpc.cpp @@ -78,12 +78,12 @@ public: TEST (rpc, account_balance) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "account_balance"); - request.put ("account", rai::test_genesis_key.pub.to_account ()); + boost::property_tree::ptree request; + request.put ("action", "account_balance"); + request.put ("account", rai::test_genesis_key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) { @@ -98,12 +98,12 @@ TEST (rpc, account_balance) TEST (rpc, account_block_count) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "account_block_count"); - request.put ("account", rai::test_genesis_key.pub.to_account ()); + boost::property_tree::ptree request; + request.put ("action", "account_block_count"); + request.put ("account", rai::test_genesis_key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) { @@ -136,124 +136,124 @@ TEST (rpc, account_create) TEST (rpc, account_weight) { - rai::keypair key; - rai::system system (24000, 1); - rai::block_hash latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::keypair key; + rai::system system (24000, 1); + rai::block_hash latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); auto & node1 (*system.nodes [0]); - rai::change_block block (latest, key.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); + rai::change_block block (latest, key.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); ASSERT_EQ (rai::process_result::progress, node1.process (block).code); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "account_weight"); - request.put ("account", key.pub.to_account ()); + boost::property_tree::ptree request; + request.put ("action", "account_weight"); + request.put ("account", key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } ASSERT_EQ (200, response.status); - std::string balance_text (response.json.get ("weight")); - ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); + std::string balance_text (response.json.get ("weight")); + ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); } TEST (rpc, wallet_contains) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "wallet_contains"); - request.put ("account", rai::test_genesis_key.pub.to_account ()); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "wallet_contains"); + request.put ("account", rai::test_genesis_key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("exists")); - ASSERT_EQ ("1", exists_text); + ASSERT_EQ (200, response.status); + std::string exists_text (response.json.get ("exists")); + ASSERT_EQ ("1", exists_text); } TEST (rpc, wallet_doesnt_contain) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "wallet_contains"); - request.put ("account", rai::test_genesis_key.pub.to_account ()); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "wallet_contains"); + request.put ("account", rai::test_genesis_key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("exists")); - ASSERT_EQ ("0", exists_text); + ASSERT_EQ (200, response.status); + std::string exists_text (response.json.get ("exists")); + ASSERT_EQ ("0", exists_text); } TEST (rpc, validate_account_number) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - boost::property_tree::ptree request; - request.put ("action", "validate_account_number"); - request.put ("account", rai::test_genesis_key.pub.to_account ()); + boost::property_tree::ptree request; + request.put ("action", "validate_account_number"); + request.put ("account", rai::test_genesis_key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - std::string exists_text (response.json.get ("valid")); - ASSERT_EQ ("1", exists_text); + std::string exists_text (response.json.get ("valid")); + ASSERT_EQ ("1", exists_text); } TEST (rpc, validate_account_invalid) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - std::string account; - rai::test_genesis_key.pub.encode_account (account); - account [0] ^= 0x1; + std::string account; + rai::test_genesis_key.pub.encode_account (account); + account [0] ^= 0x1; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - boost::property_tree::ptree request; - request.put ("action", "validate_account_number"); - request.put ("account", account); + boost::property_tree::ptree request; + request.put ("action", "validate_account_number"); + request.put ("account", account); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("valid")); - ASSERT_EQ ("0", exists_text); + ASSERT_EQ (200, response.status); + std::string exists_text (response.json.get ("valid")); + ASSERT_EQ ("0", exists_text); } TEST (rpc, send) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "send"); + system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "send"); request.put ("source", rai::test_genesis_key.pub.to_account ()); - request.put ("destination", rai::test_genesis_key.pub.to_account ()); - request.put ("amount", "100"); + request.put ("destination", rai::test_genesis_key.pub.to_account ()); + request.put ("amount", "100"); std::thread thread2 ([&system] () { auto iterations (0); @@ -269,8 +269,8 @@ TEST (rpc, send) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string block_text (response.json.get ("block")); + ASSERT_EQ (200, response.status); + std::string block_text (response.json.get ("block")); rai::block_hash block; ASSERT_FALSE (block.decode_hex (block_text)); ASSERT_TRUE (system.nodes [0]->ledger.block_exists (block)); @@ -279,17 +279,17 @@ TEST (rpc, send) TEST (rpc, send_fail) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "send"); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "send"); request.put ("source", rai::test_genesis_key.pub.to_account ()); - request.put ("destination", rai::test_genesis_key.pub.to_account ()); - request.put ("amount", "100"); + request.put ("destination", rai::test_genesis_key.pub.to_account ()); + request.put ("amount", "100"); std::atomic done (false); std::thread thread2 ([&system, &done] () { @@ -307,8 +307,8 @@ TEST (rpc, send_fail) system.poll (); } done = true; - ASSERT_EQ (200, response.status); - std::string block_text (response.json.get ("block")); + ASSERT_EQ (200, response.status); + std::string block_text (response.json.get ("block")); rai::block_hash block; ASSERT_FALSE (block.decode_hex (block_text)); ASSERT_TRUE (block.is_zero ()); @@ -317,11 +317,11 @@ TEST (rpc, send_fail) TEST (rpc, stop) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "stop"); + boost::property_tree::ptree request; + request.put ("action", "stop"); test_response response (request, rpc, system.service); while (response.status == 0) { @@ -332,78 +332,78 @@ TEST (rpc, stop) TEST (rpc, wallet_add) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - rai::keypair key1; - std::string key_text; - key1.prv.data.encode_hex (key_text); + rai::keypair key1; + std::string key_text; + key1.prv.data.encode_hex (key_text); system.wallet (0)->insert_adhoc (key1.prv); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "wallet_add"); - request.put ("key", key_text); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "wallet_add"); + request.put ("key", key_text); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("account")); - ASSERT_EQ (account_text1, key1.pub.to_account ()); + ASSERT_EQ (200, response.status); + std::string account_text1 (response.json.get ("account")); + ASSERT_EQ (account_text1, key1.pub.to_account ()); } TEST (rpc, wallet_password_valid) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "password_valid"); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "password_valid"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("valid")); - ASSERT_EQ (account_text1, "1"); + ASSERT_EQ (200, response.status); + std::string account_text1 (response.json.get ("valid")); + ASSERT_EQ (account_text1, "1"); } TEST (rpc, wallet_password_change) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "password_change"); - request.put ("password", "test"); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "password_change"); + request.put ("password", "test"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("changed")); - ASSERT_EQ (account_text1, "1"); - ASSERT_TRUE (system.wallet (0)->valid_password ()); - ASSERT_TRUE (system.wallet (0)->enter_password ("")); - ASSERT_FALSE (system.wallet (0)->valid_password ()); - ASSERT_FALSE (system.wallet (0)->enter_password ("test")); - ASSERT_TRUE (system.wallet (0)->valid_password ()); + ASSERT_EQ (200, response.status); + std::string account_text1 (response.json.get ("changed")); + ASSERT_EQ (account_text1, "1"); + ASSERT_TRUE (system.wallet (0)->valid_password ()); + ASSERT_TRUE (system.wallet (0)->enter_password ("")); + ASSERT_FALSE (system.wallet (0)->valid_password ()); + ASSERT_FALSE (system.wallet (0)->enter_password ("test")); + ASSERT_TRUE (system.wallet (0)->valid_password ()); } TEST (rpc, wallet_password_enter) { - rai::system system (24000, 1); + rai::system system (24000, 1); auto iterations (0); rai::raw_key password_l; password_l.data.clear (); @@ -414,269 +414,269 @@ TEST (rpc, wallet_password_enter) ASSERT_LT (iterations, 200); system.wallet (0)->store.password.value (password_l); } - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "password_enter"); - request.put ("password", ""); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "password_enter"); + request.put ("password", ""); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("valid")); - ASSERT_EQ (account_text1, "1"); + ASSERT_EQ (200, response.status); + std::string account_text1 (response.json.get ("valid")); + ASSERT_EQ (account_text1, "1"); } TEST (rpc, wallet_representative) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "wallet_representative"); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "wallet_representative"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("representative")); - ASSERT_EQ (account_text1, rai::genesis_account.to_account ()); + ASSERT_EQ (200, response.status); + std::string account_text1 (response.json.get ("representative")); + ASSERT_EQ (account_text1, rai::genesis_account.to_account ()); } TEST (rpc, wallet_representative_set) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - rai::keypair key; - request.put ("action", "wallet_representative_set"); - request.put ("representative", key.pub.to_account ()); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + rai::keypair key; + request.put ("action", "wallet_representative_set"); + request.put ("representative", key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (key.pub, system.nodes [0]->wallets.items.begin ()->second->store.representative (transaction)); + ASSERT_EQ (key.pub, system.nodes [0]->wallets.items.begin ()->second->store.representative (transaction)); } TEST (rpc, account_list) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - rai::keypair key2; + rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key2.prv); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "account_list"); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "account_list"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & accounts_node (response.json.get_child ("accounts")); - std::vector accounts; - for (auto i (accounts_node.begin ()), j (accounts_node.end ()); i != j; ++i) - { - auto account (i->second.get ("")); - rai::uint256_union number; - ASSERT_FALSE (number.decode_account (account)); - accounts.push_back (number); - } - ASSERT_EQ (2, accounts.size ()); - for (auto i (accounts.begin ()), j (accounts.end ()); i != j; ++i) - { - ASSERT_TRUE (system.wallet (0)->exists (*i)); - } + ASSERT_EQ (200, response.status); + auto & accounts_node (response.json.get_child ("accounts")); + std::vector accounts; + for (auto i (accounts_node.begin ()), j (accounts_node.end ()); i != j; ++i) + { + auto account (i->second.get ("")); + rai::uint256_union number; + ASSERT_FALSE (number.decode_account (account)); + accounts.push_back (number); + } + ASSERT_EQ (2, accounts.size ()); + for (auto i (accounts.begin ()), j (accounts.end ()); i != j; ++i) + { + ASSERT_TRUE (system.wallet (0)->exists (*i)); + } } TEST (rpc, wallet_key_valid) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - boost::property_tree::ptree request; - std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); - request.put ("wallet", wallet); - request.put ("action", "wallet_key_valid"); + system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); + boost::property_tree::ptree request; + std::string wallet; + system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + request.put ("wallet", wallet); + request.put ("action", "wallet_key_valid"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("valid")); - ASSERT_EQ ("1", exists_text); + ASSERT_EQ (200, response.status); + std::string exists_text (response.json.get ("valid")); + ASSERT_EQ ("1", exists_text); } TEST (rpc, wallet_create) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "wallet_create"); + boost::property_tree::ptree request; + request.put ("action", "wallet_create"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string wallet_text (response.json.get ("wallet")); - rai::uint256_union wallet_id; - ASSERT_FALSE (wallet_id.decode_hex (wallet_text)); - ASSERT_NE (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.find (wallet_id)); + ASSERT_EQ (200, response.status); + std::string wallet_text (response.json.get ("wallet")); + rai::uint256_union wallet_id; + ASSERT_FALSE (wallet_id.decode_hex (wallet_text)); + ASSERT_NE (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.find (wallet_id)); } TEST (rpc, wallet_export) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - boost::property_tree::ptree request; - request.put ("action", "wallet_export"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + boost::property_tree::ptree request; + request.put ("action", "wallet_export"); + request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string wallet_json (response.json.get ("json")); - bool error (false); + ASSERT_EQ (200, response.status); + std::string wallet_json (response.json.get ("json")); + bool error (false); rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); rai::kdf kdf; - rai::wallet_store store (error, kdf, transaction, rai::genesis_account, 1, "0", wallet_json); - ASSERT_FALSE (error); - ASSERT_TRUE (store.exists (transaction, rai::test_genesis_key.pub)); + rai::wallet_store store (error, kdf, transaction, rai::genesis_account, 1, "0", wallet_json); + ASSERT_FALSE (error); + ASSERT_TRUE (store.exists (transaction, rai::test_genesis_key.pub)); } TEST (rpc, wallet_destroy) { - rai::system system (24000, 1); - auto wallet_id (system.nodes [0]->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + auto wallet_id (system.nodes [0]->wallets.items.begin ()->first); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - boost::property_tree::ptree request; - request.put ("action", "wallet_destroy"); - request.put ("wallet", wallet_id.to_string ()); + boost::property_tree::ptree request; + request.put ("action", "wallet_destroy"); + request.put ("wallet", wallet_id.to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - ASSERT_EQ (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.find (wallet_id)); + ASSERT_EQ (200, response.status); + ASSERT_EQ (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.find (wallet_id)); } TEST (rpc, account_move) { - rai::system system (24000, 1); - auto wallet_id (system.nodes [0]->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + auto wallet_id (system.nodes [0]->wallets.items.begin ()->first); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - auto destination (system.wallet (0)); - rai::keypair key; + auto destination (system.wallet (0)); + rai::keypair key; destination->insert_adhoc (rai::test_genesis_key.prv); - rai::keypair source_id; - auto source (system.nodes [0]->wallets.create (source_id.pub)); + rai::keypair source_id; + auto source (system.nodes [0]->wallets.create (source_id.pub)); source->insert_adhoc (key.prv); - boost::property_tree::ptree request; - request.put ("action", "account_move"); - request.put ("wallet", wallet_id.to_string ()); - request.put ("source", source_id.pub.to_string ()); - boost::property_tree::ptree keys; - boost::property_tree::ptree entry; - entry.put ("", key.pub.to_string ()); - keys.push_back (std::make_pair ("", entry)); - request.add_child ("accounts", keys); + boost::property_tree::ptree request; + request.put ("action", "account_move"); + request.put ("wallet", wallet_id.to_string ()); + request.put ("source", source_id.pub.to_string ()); + boost::property_tree::ptree keys; + boost::property_tree::ptree entry; + entry.put ("", key.pub.to_string ()); + keys.push_back (std::make_pair ("", entry)); + request.add_child ("accounts", keys); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - ASSERT_EQ ("1", response.json.get ("moved")); - ASSERT_TRUE (destination->exists (key.pub)); - ASSERT_TRUE (destination->exists (rai::test_genesis_key.pub)); + ASSERT_EQ (200, response.status); + ASSERT_EQ ("1", response.json.get ("moved")); + ASSERT_TRUE (destination->exists (key.pub)); + ASSERT_TRUE (destination->exists (rai::test_genesis_key.pub)); rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (source->store.end (), source->store.begin (transaction)); + ASSERT_EQ (source->store.end (), source->store.begin (transaction)); } TEST (rpc, block) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "block"); + boost::property_tree::ptree request; + request.put ("action", "block"); request.put ("hash", system.nodes [0]->latest (rai::genesis_account).to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); auto contents (response.json.get ("contents")); - ASSERT_FALSE (contents.empty ()); + ASSERT_FALSE (contents.empty ()); } TEST (rpc, block_account) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); rai::genesis genesis; - boost::property_tree::ptree request; - request.put ("action", "block_account"); + boost::property_tree::ptree request; + request.put ("action", "block_account"); request.put ("hash", genesis.hash ().to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string account_text (response.json.get ("account")); - rai::account account; - ASSERT_FALSE (account.decode_account (account_text)); + ASSERT_EQ (200, response.status); + std::string account_text (response.json.get ("account")); + rai::account account; + ASSERT_FALSE (account.decode_account (account_text)); } TEST (rpc, chain) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key; auto genesis (system.nodes [0]->latest (rai::test_genesis_key.pub)); ASSERT_FALSE (genesis.is_zero ()); auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "chain"); + boost::property_tree::ptree request; + request.put ("action", "chain"); request.put ("block", block->hash().to_string ()); request.put ("count", std::to_string (std::numeric_limits ::max ())); test_response response (request, rpc, system.service); @@ -684,8 +684,8 @@ TEST (rpc, chain) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & blocks_node (response.json.get_child ("blocks")); + ASSERT_EQ (200, response.status); + auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { @@ -698,17 +698,17 @@ TEST (rpc, chain) TEST (rpc, chain_limit) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key; auto genesis (system.nodes [0]->latest (rai::test_genesis_key.pub)); ASSERT_FALSE (genesis.is_zero ()); auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "chain"); + boost::property_tree::ptree request; + request.put ("action", "chain"); request.put ("block", block->hash().to_string ()); request.put ("count", 1); test_response response (request, rpc, system.service); @@ -716,8 +716,8 @@ TEST (rpc, chain_limit) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & blocks_node (response.json.get_child ("blocks")); + ASSERT_EQ (200, response.status); + auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { @@ -729,7 +729,7 @@ TEST (rpc, chain_limit) TEST (rpc, frontier) { - rai::system system (24000, 1); + rai::system system (24000, 1); std::unordered_map source; { rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); @@ -741,10 +741,10 @@ TEST (rpc, frontier) } } rai::keypair key; - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "frontiers"); + boost::property_tree::ptree request; + request.put ("action", "frontiers"); request.put ("account", rai::account (0).to_account ()); request.put ("count", std::to_string (std::numeric_limits ::max ())); test_response response (request, rpc, system.service); @@ -752,24 +752,24 @@ TEST (rpc, frontier) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & frontiers_node (response.json.get_child ("frontiers")); - std::unordered_map frontiers; - for (auto i (frontiers_node.begin ()), j (frontiers_node.end ()); i != j; ++i) - { - rai::account account; + ASSERT_EQ (200, response.status); + auto & frontiers_node (response.json.get_child ("frontiers")); + std::unordered_map frontiers; + for (auto i (frontiers_node.begin ()), j (frontiers_node.end ()); i != j; ++i) + { + rai::account account; account.decode_account (i->first); rai::block_hash frontier; frontier.decode_hex (i->second.get ("")); - frontiers [account] = frontier; - } + frontiers [account] = frontier; + } ASSERT_EQ (1, frontiers.erase (rai::test_genesis_key.pub)); ASSERT_EQ (source, frontiers); } TEST (rpc, frontier_limited) { - rai::system system (24000, 1); + rai::system system (24000, 1); std::unordered_map source; { rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); @@ -781,10 +781,10 @@ TEST (rpc, frontier_limited) } } rai::keypair key; - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "frontiers"); + boost::property_tree::ptree request; + request.put ("action", "frontiers"); request.put ("account", rai::account (0).to_account ()); request.put ("count", std::to_string (100)); test_response response (request, rpc, system.service); @@ -792,14 +792,14 @@ TEST (rpc, frontier_limited) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & frontiers_node (response.json.get_child ("frontiers")); + ASSERT_EQ (200, response.status); + auto & frontiers_node (response.json.get_child ("frontiers")); ASSERT_EQ (100, frontiers_node.size ()); } TEST (rpc, frontier_startpoint) { - rai::system system (24000, 1); + rai::system system (24000, 1); std::unordered_map source; { rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); @@ -811,10 +811,10 @@ TEST (rpc, frontier_startpoint) } } rai::keypair key; - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "frontiers"); + boost::property_tree::ptree request; + request.put ("action", "frontiers"); request.put ("account", source.begin ()->first.to_account ()); request.put ("count", std::to_string (1)); test_response response (request, rpc, system.service); @@ -822,15 +822,15 @@ TEST (rpc, frontier_startpoint) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & frontiers_node (response.json.get_child ("frontiers")); + ASSERT_EQ (200, response.status); + auto & frontiers_node (response.json.get_child ("frontiers")); ASSERT_EQ (1, frontiers_node.size ()); ASSERT_EQ (source.begin ()->first.to_account (), frontiers_node.begin ()->first); } TEST (rpc, history) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto change (system.wallet (0)->change_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub)); ASSERT_NE (nullptr, change); @@ -838,10 +838,10 @@ TEST (rpc, history) ASSERT_NE (nullptr, send); auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, receive); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "history"); + boost::property_tree::ptree request; + request.put ("action", "history"); request.put ("hash", receive->hash().to_string ()); request.put ("count", 100); test_response response (request, rpc, system.service); @@ -849,9 +849,9 @@ TEST (rpc, history) { system.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); std::vector > history_l; - auto & history_node (response.json.get_child ("history")); + auto & history_node (response.json.get_child ("history")); for (auto i (history_node.begin ()), n (history_node.end ()); i != n; ++i) { history_l.push_back (std::make_tuple (i->second.get ("type"), i->second.get ("account"), i->second.get ("amount"), i->second.get ("hash"))); @@ -874,7 +874,7 @@ TEST (rpc, history) TEST (rpc, history_count) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto change (system.wallet (0)->change_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub)); ASSERT_NE (nullptr, change); @@ -882,10 +882,10 @@ TEST (rpc, history_count) ASSERT_NE (nullptr, send); auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, receive); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "history"); + boost::property_tree::ptree request; + request.put ("action", "history"); request.put ("hash", receive->hash().to_string ()); request.put ("count", 1); test_response response (request, rpc, system.service); @@ -893,8 +893,8 @@ TEST (rpc, history_count) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & history_node (response.json.get_child ("history")); + ASSERT_EQ (200, response.status); + auto & history_node (response.json.get_child ("history")); ASSERT_EQ (1, history_node.size ()); } @@ -925,16 +925,16 @@ TEST (rpc, process_block) TEST (rpc, process_block_no_work) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::keypair key; auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); auto & node1 (*system.nodes [0]); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); send.block_work_set(0); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "process"); + boost::property_tree::ptree request; + request.put ("action", "process"); std::string json; send.serialize_json (json); request.put ("block", json); @@ -943,22 +943,22 @@ TEST (rpc, process_block_no_work) { system.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); ASSERT_FALSE (response.json.get ("error").empty ()); } TEST (rpc, keepalive) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - node1->start (); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + node1->start (); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "keepalive"); - auto address (boost::str (boost::format ("%1%") % node1->network.endpoint ().address ())); - auto port (boost::str (boost::format ("%1%") % node1->network.endpoint ().port ())); + boost::property_tree::ptree request; + request.put ("action", "keepalive"); + auto address (boost::str (boost::format ("%1%") % node1->network.endpoint ().address ())); + auto port (boost::str (boost::format ("%1%") % node1->network.endpoint ().port ())); request.put ("address", address); request.put ("port", port); ASSERT_FALSE (system.nodes [0]->peers.known_peer (node1->network.endpoint ())); @@ -968,7 +968,7 @@ TEST (rpc, keepalive) { system.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); auto iterations (0); while (!system.nodes [0]->peers.known_peer (node1->network.endpoint ())) { @@ -982,15 +982,15 @@ TEST (rpc, keepalive) TEST (rpc, payment_init) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; + boost::property_tree::ptree request; request.put ("action", "payment_init"); request.put ("wallet", wallet_id.pub.to_string ()); test_response response (request, rpc, system.service); @@ -998,21 +998,21 @@ TEST (rpc, payment_init) { system.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); ASSERT_EQ ("Ready", response.json.get ("status")); } TEST (rpc, payment_begin_end) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.pub.to_string ()); test_response response1 (request1, rpc, system.service); @@ -1020,7 +1020,7 @@ TEST (rpc, payment_begin_end) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); auto account_text (response1.json.get ("account")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); @@ -1037,7 +1037,7 @@ TEST (rpc, payment_begin_end) ASSERT_LT (iteration, 200); } ASSERT_EQ (wallet->free_accounts.end (), wallet->free_accounts.find (account)); - boost::property_tree::ptree request2; + boost::property_tree::ptree request2; request2.put ("action", "payment_end"); request2.put ("wallet", wallet_id.pub.to_string ()); request2.put ("account", account.to_account ()); @@ -1046,7 +1046,7 @@ TEST (rpc, payment_begin_end) { system.poll (); } - ASSERT_EQ (200, response2.status); + ASSERT_EQ (200, response2.status); ASSERT_TRUE (wallet->exists (account)); ASSERT_NE (wallet->free_accounts.end (), wallet->free_accounts.find (account)); rpc.stop (); @@ -1055,15 +1055,15 @@ TEST (rpc, payment_begin_end) TEST (rpc, payment_end_nonempty) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->init_free_accounts (rai::transaction (node1->store.environment, nullptr, false)); auto wallet_id (node1->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "payment_end"); request1.put ("wallet", wallet_id.to_string ()); request1.put ("account", rai::test_genesis_key.pub.to_account ()); @@ -1072,21 +1072,21 @@ TEST (rpc, payment_end_nonempty) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_FALSE (response1.json.get ("error").empty ()); } TEST (rpc, payment_zero_balance) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->init_free_accounts (rai::transaction (node1->store.environment, nullptr, false)); auto wallet_id (node1->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.to_string ()); test_response response1 (request1, rpc, system.service); @@ -1094,7 +1094,7 @@ TEST (rpc, payment_zero_balance) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); auto account_text (response1.json.get ("account")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); @@ -1103,15 +1103,15 @@ TEST (rpc, payment_zero_balance) TEST (rpc, payment_begin_reuse) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.pub.to_string ()); test_response response1 (request1, rpc, system.service); @@ -1119,13 +1119,13 @@ TEST (rpc, payment_begin_reuse) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); auto account_text (response1.json.get ("account")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); ASSERT_TRUE (wallet->exists (account)); ASSERT_EQ (wallet->free_accounts.end (), wallet->free_accounts.find (account)); - boost::property_tree::ptree request2; + boost::property_tree::ptree request2; request2.put ("action", "payment_end"); request2.put ("wallet", wallet_id.pub.to_string ()); request2.put ("account", account.to_account ()); @@ -1134,7 +1134,7 @@ TEST (rpc, payment_begin_reuse) { system.poll (); } - ASSERT_EQ (200, response2.status); + ASSERT_EQ (200, response2.status); ASSERT_TRUE (wallet->exists (account)); ASSERT_NE (wallet->free_accounts.end (), wallet->free_accounts.find (account)); test_response response3 (request1, rpc, system.service); @@ -1142,7 +1142,7 @@ TEST (rpc, payment_begin_reuse) { system.poll (); } - ASSERT_EQ (200, response3.status); + ASSERT_EQ (200, response3.status); auto account2_text (response1.json.get ("account")); rai::uint256_union account2; ASSERT_FALSE (account2.decode_account (account2_text)); @@ -1151,9 +1151,9 @@ TEST (rpc, payment_begin_reuse) TEST (rpc, payment_begin_locked) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); { @@ -1162,9 +1162,9 @@ TEST (rpc, payment_begin_locked) ASSERT_TRUE (wallet->store.attempt_password(transaction, "")); } ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.pub.to_string ()); test_response response1 (request1, rpc, system.service); @@ -1172,21 +1172,21 @@ TEST (rpc, payment_begin_locked) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_FALSE (response1.json.get ("error").empty ()); } TEST (rpc, DISABLED_payment_wait) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "payment_wait"); request1.put ("account", key.pub.to_account ()); request1.put ("amount", rai::amount (rai::Mxrb_ratio).to_string_dec ()); @@ -1196,7 +1196,7 @@ TEST (rpc, DISABLED_payment_wait) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("nothing", response1.json.get ("status")); request1.put ("timeout", "100000"); system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, rai::Mxrb_ratio); @@ -1209,7 +1209,7 @@ TEST (rpc, DISABLED_payment_wait) { system.poll (); } - ASSERT_EQ (200, response2.status); + ASSERT_EQ (200, response2.status); ASSERT_EQ ("success", response2.json.get ("status")); request1.put ("amount", rai::amount (rai::Mxrb_ratio * 2).to_string_dec ()); test_response response3 (request1, rpc, system.service); @@ -1217,25 +1217,25 @@ TEST (rpc, DISABLED_payment_wait) { system.poll (); } - ASSERT_EQ (200, response3.status); + ASSERT_EQ (200, response3.status); ASSERT_EQ ("success", response2.json.get ("status")); } TEST (rpc, peers) { - rai::system system (24000, 2); + rai::system system (24000, 2); system.nodes [0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::from_string ("::ffff:80.80.80.80"), 4000), 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "peers"); + boost::property_tree::ptree request; + request.put ("action", "peers"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & peers_node (response.json.get_child ("peers")); + ASSERT_EQ (200, response.status); + auto & peers_node (response.json.get_child ("peers")); ASSERT_EQ (2, peers_node.size ()); } @@ -1338,22 +1338,22 @@ TEST (rpc_config, serialization) TEST (rpc, search_pending) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto wallet (system.nodes [0]->wallets.items.begin ()->first.to_string ()); rai::send_block block (system.nodes [0]->latest (rai::test_genesis_key.pub), rai::test_genesis_key.pub, rai::genesis_amount - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (rai::transaction (system.nodes [0]->store.environment, nullptr, true), block).code); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "search_pending"); + boost::property_tree::ptree request; + request.put ("action", "search_pending"); request.put ("wallet", wallet); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); auto iterations (0); while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount) { @@ -1365,24 +1365,24 @@ TEST (rpc, search_pending) TEST (rpc, version) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "version"); test_response response1 (request1, rpc, system.service); while (response1.status == 0) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("rpc_version")); - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("10", response1.json.get ("store_version")); ASSERT_EQ (boost::str (boost::format ("RaiBlocks %1%.%2%") % RAIBLOCKS_VERSION_MAJOR % RAIBLOCKS_VERSION_MINOR), response1.json.get ("node_vendor")); auto headers (response1.resp.base()); @@ -1394,16 +1394,16 @@ TEST (rpc, version) TEST (rpc, work_generate) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes [0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); rai::block_hash hash1 (1); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "work_generate"); request1.put ("hash", hash1.to_string ()); test_response response1 (request1, rpc, system.service); @@ -1411,7 +1411,7 @@ TEST (rpc, work_generate) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); auto work1 (response1.json.get ("work")); uint64_t work2; ASSERT_FALSE (rai::from_string_hex (work1, work2)); @@ -1420,16 +1420,16 @@ TEST (rpc, work_generate) TEST (rpc, work_cancel) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes [0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); rai::block_hash hash1 (1); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "work_cancel"); request1.put ("hash", hash1.to_string ()); boost::optional work; @@ -1448,14 +1448,14 @@ TEST (rpc, work_cancel) TEST (rpc, work_peer_bad) { - rai::system system (24000, 2); + rai::system system (24000, 2); rai::node_init init1; - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes [0]); + auto & node2 (*system.nodes [1]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); node2.config.work_peers.push_back (std::make_pair (boost::asio::ip::address_v6::any (), 0)); rai::block_hash hash1 (1); @@ -1472,14 +1472,14 @@ TEST (rpc, work_peer_bad) TEST (rpc, work_peer_one) { - rai::system system (24000, 2); + rai::system system (24000, 2); rai::node_init init1; - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes [0]); + auto & node2 (*system.nodes [1]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); node2.config.work_peers.push_back (std::make_pair (node1.network.endpoint ().address (), rpc.config.port)); rai::keypair key1; @@ -1496,27 +1496,27 @@ TEST (rpc, work_peer_one) TEST (rpc, work_peer_many) { - rai::system system1 (24000, 1); - rai::system system2 (24001, 1); - rai::system system3 (24002, 1); - rai::system system4 (24003, 1); + rai::system system1 (24000, 1); + rai::system system2 (24001, 1); + rai::system system3 (24002, 1); + rai::system system4 (24003, 1); rai::node_init init1; - auto & node1 (*system1.nodes [0]); - auto & node2 (*system2.nodes [0]); - auto & node3 (*system3.nodes [0]); - auto & node4 (*system4.nodes [0]); + auto & node1 (*system1.nodes [0]); + auto & node2 (*system2.nodes [0]); + auto & node3 (*system3.nodes [0]); + auto & node4 (*system4.nodes [0]); rai::keypair key; rai::rpc_config config2 (true); config2.port += 0; - rai::rpc rpc2 (system2.service, node2, config2); + rai::rpc rpc2 (system2.service, node2, config2); rpc2.start (); rai::rpc_config config3 (true); config3.port += 1; - rai::rpc rpc3 (system3.service, node3, config3); + rai::rpc rpc3 (system3.service, node3, config3); rpc3.start (); rai::rpc_config config4 (true); config4.port += 2; - rai::rpc rpc4 (system4.service, node4, config4); + rai::rpc rpc4 (system4.service, node4, config4); rpc4.start (); node1.config.work_peers.push_back (std::make_pair (node2.network.endpoint ().address (), rpc2.config.port)); node1.config.work_peers.push_back (std::make_pair (node3.network.endpoint ().address (), rpc3.config.port)); @@ -1541,38 +1541,38 @@ TEST (rpc, work_peer_many) TEST (rpc, block_count) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "block_count"); test_response response1 (request1, rpc, system.service); while (response1.status == 0) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("count")); ASSERT_EQ ("0", response1.json.get ("unchecked")); } TEST (rpc, frontier_count) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "frontier_count"); test_response response1 (request1, rpc, system.service); while (response1.status == 0) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("count")); } @@ -1614,12 +1614,12 @@ TEST (rpc, available_supply) TEST (rpc, mrai_to_raw) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "mrai_to_raw"); request1.put ("amount", "1"); test_response response1 (request1, rpc, system.service); @@ -1627,18 +1627,18 @@ TEST (rpc, mrai_to_raw) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ (rai::Mxrb_ratio.convert_to (), response1.json.get ("amount")); } TEST (rpc, mrai_from_raw) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "mrai_from_raw"); request1.put ("amount", rai::Mxrb_ratio.convert_to ()); test_response response1 (request1, rpc, system.service); @@ -1646,18 +1646,18 @@ TEST (rpc, mrai_from_raw) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("amount")); } TEST (rpc, krai_to_raw) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "krai_to_raw"); request1.put ("amount", "1"); test_response response1 (request1, rpc, system.service); @@ -1665,18 +1665,18 @@ TEST (rpc, krai_to_raw) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ (rai::kxrb_ratio.convert_to (), response1.json.get ("amount")); } TEST (rpc, krai_from_raw) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "krai_from_raw"); request1.put ("amount", rai::kxrb_ratio.convert_to ()); test_response response1 (request1, rpc, system.service); @@ -1684,18 +1684,18 @@ TEST (rpc, krai_from_raw) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("amount")); } TEST (rpc, rai_to_raw) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "rai_to_raw"); request1.put ("amount", "1"); test_response response1 (request1, rpc, system.service); @@ -1703,18 +1703,18 @@ TEST (rpc, rai_to_raw) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ (rai::xrb_ratio.convert_to (), response1.json.get ("amount")); } TEST (rpc, rai_from_raw) { - rai::system system (24000, 1); + rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); - rai::rpc rpc (system.service, node1, rai::rpc_config (true)); + auto & node1 (*system.nodes [0]); + rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request1; + boost::property_tree::ptree request1; request1.put ("action", "rai_from_raw"); request1.put ("amount", rai::xrb_ratio.convert_to ()); test_response response1 (request1, rpc, system.service); @@ -1722,59 +1722,59 @@ TEST (rpc, rai_from_raw) { system.poll (); } - ASSERT_EQ (200, response1.status); + ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("amount")); } TEST (rpc, account_representative) { - rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::system system (24000, 1); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - std::string wallet; - request.put ("account", rai::genesis_account.to_account ()); - request.put ("action", "account_representative"); + boost::property_tree::ptree request; + std::string wallet; + request.put ("account", rai::genesis_account.to_account ()); + request.put ("action", "account_representative"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("representative")); - ASSERT_EQ (account_text1, rai::genesis_account.to_account ()); + ASSERT_EQ (200, response.status); + std::string account_text1 (response.json.get ("representative")); + ASSERT_EQ (account_text1, rai::genesis_account.to_account ()); } TEST (rpc, account_representative_set) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; + boost::property_tree::ptree request; rai::keypair rep; - request.put ("account", rai::genesis_account.to_account ()); + request.put ("account", rai::genesis_account.to_account ()); request.put ("representative", rep.pub.to_account ()); request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); - request.put ("action", "account_representative_set"); + request.put ("action", "account_representative_set"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } - ASSERT_EQ (200, response.status); - std::string block_text1 (response.json.get ("block")); + ASSERT_EQ (200, response.status); + std::string block_text1 (response.json.get ("block")); rai::block_hash hash; ASSERT_FALSE (hash.decode_hex (block_text1)); ASSERT_FALSE (hash.is_zero ()); rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction, hash)); + ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction, hash)); ASSERT_EQ (rep.pub, system.nodes [0]->store.block_get (transaction, hash)->representative ()); } TEST (rpc, bootstrap) { - rai::system system0 (24000, 1); + rai::system system0 (24000, 1); rai::system system1 (24001, 1); auto latest (system1.nodes [0]->latest (rai::test_genesis_key.pub)); rai::send_block send (latest, rai::genesis_account, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system1.nodes [0]->generate_work (latest)); @@ -1782,11 +1782,11 @@ TEST (rpc, bootstrap) rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true); ASSERT_EQ (rai::process_result::progress, system1.nodes [0]->ledger.process (transaction, send).code); } - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; + boost::property_tree::ptree request; request.put ("action", "bootstrap"); - request.put ("address", "::ffff:127.0.0.1"); + request.put ("address", "::ffff:127.0.0.1"); request.put ("port", system1.nodes [0]->network.endpoint ().port ()); test_response response (request, rpc, system0.service); while (response.status == 0) @@ -1805,14 +1805,14 @@ TEST (rpc, bootstrap) TEST (rpc, account_remove) { - rai::system system0 (24000, 1); + rai::system system0 (24000, 1); auto key1 (system0.wallet (0)->deterministic_insert ()); ASSERT_TRUE (system0.wallet (0)->exists (key1)); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; + boost::property_tree::ptree request; request.put ("action", "account_remove"); - request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); request.put ("account", key1.to_account ()); test_response response (request, rpc, system0.service); while (response.status == 0) @@ -1849,7 +1849,7 @@ TEST (rpc, representatives) TEST (rpc, wallet_change_seed) { - rai::system system0 (24000, 1); + rai::system system0 (24000, 1); rai::keypair seed; { rai::transaction transaction (system0.nodes [0]->store.environment, nullptr, false); @@ -1857,18 +1857,18 @@ TEST (rpc, wallet_change_seed) system0.wallet (0)->store.seed (seed0, transaction); ASSERT_NE (seed.pub, seed0.data); } - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; + boost::property_tree::ptree request; request.put ("action", "wallet_change_seed"); - request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); request.put ("seed", seed.pub.to_string ()); test_response response (request, rpc, system0.service); while (response.status == 0) { system0.poll (); } - ASSERT_EQ (200, response.status); + ASSERT_EQ (200, response.status); { rai::transaction transaction (system0.nodes [0]->store.environment, nullptr, false); rai::raw_key seed0; @@ -1879,20 +1879,20 @@ TEST (rpc, wallet_change_seed) TEST (rpc, wallet_frontiers) { - rai::system system0 (24000, 1); + rai::system system0 (24000, 1); system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; + boost::property_tree::ptree request; request.put ("action", "wallet_frontiers"); - request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system0.service); while (response.status == 0) { system0.poll (); } - ASSERT_EQ (200, response.status); - auto & frontiers_node (response.json.get_child ("frontiers")); + ASSERT_EQ (200, response.status); + auto & frontiers_node (response.json.get_child ("frontiers")); std::vector frontiers; for (auto i (frontiers_node.begin ()), n (frontiers_node.end ()); i != n; ++i) { @@ -1940,17 +1940,17 @@ TEST (rpc, work_validate) TEST (rpc, successors) { - rai::system system (24000, 1); + rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key; auto genesis (system.nodes [0]->latest (rai::test_genesis_key.pub)); ASSERT_FALSE (genesis.is_zero ()); auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; - request.put ("action", "successors"); + boost::property_tree::ptree request; + request.put ("action", "successors"); request.put ("block", genesis.to_string ()); request.put ("count", std::to_string (std::numeric_limits ::max ())); test_response response (request, rpc, system.service); @@ -1958,8 +1958,8 @@ TEST (rpc, successors) { system.poll (); } - ASSERT_EQ (200, response.status); - auto & blocks_node (response.json.get_child ("blocks")); + ASSERT_EQ (200, response.status); + auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { @@ -1972,7 +1972,7 @@ TEST (rpc, successors) TEST (rpc, bootstrap_any) { - rai::system system0 (24000, 1); + rai::system system0 (24000, 1); rai::system system1 (24001, 1); auto latest (system1.nodes [0]->latest (rai::test_genesis_key.pub)); rai::send_block send (latest, rai::genesis_account, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system1.nodes [0]->generate_work (latest)); @@ -1980,9 +1980,9 @@ TEST (rpc, bootstrap_any) rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true); ASSERT_EQ (rai::process_result::progress, system1.nodes [0]->ledger.process (transaction, send).code); } - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); rpc.start (); - boost::property_tree::ptree request; + boost::property_tree::ptree request; request.put ("action", "bootstrap_any"); test_response response (request, rpc, system0.service); while (response.status == 0) diff --git a/rai/core_test/uint256_union.cpp b/rai/core_test/uint256_union.cpp index 272e9ca3..4a1e4134 100644 --- a/rai/core_test/uint256_union.cpp +++ b/rai/core_test/uint256_union.cpp @@ -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 { - 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 ::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 ::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 ::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 ::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 ::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 ::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 ()); diff --git a/rai/core_test/wallet.cpp b/rai/core_test/wallet.cpp index 2f343106..d9a3ac7c 100644 --- a/rai/core_test/wallet.cpp +++ b/rai/core_test/wallet.cpp @@ -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 ::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 ::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)); } diff --git a/rai/core_test/work_pool.cpp b/rai/core_test/work_pool.cpp index 3cc5b666..8c0fe73d 100644 --- a/rai/core_test/work_pool.cpp +++ b/rai/core_test/work_pool.cpp @@ -6,18 +6,18 @@ TEST (work, one) { rai::work_pool pool (std::numeric_limits ::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 ::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) diff --git a/rai/lib/blocks.cpp b/rai/lib/blocks.cpp index d9a3112e..a4922553 100644 --- a/rai/lib/blocks.cpp +++ b/rai/lib/blocks.cpp @@ -890,7 +890,7 @@ std::unique_ptr 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) : diff --git a/rai/lib/numbers.cpp b/rai/lib/numbers.cpp index 6192b708..def158d0 100644 --- a/rai/lib/numbers.cpp +++ b/rai/lib/numbers.cpp @@ -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 diff --git a/rai/lib/work.cpp b/rai/lib/work.cpp index 33321c7b..4cb7ef5c 100644 --- a/rai/lib/work.cpp +++ b/rai/lib/work.cpp @@ -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 (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 lock (mutex); while (!done || !pending.empty()) diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index d2eaebb4..2027ea36 100755 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -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 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 & lock_a) { - auto result (true); - auto connection_l (connection (lock_a)); - if (connection_l) - { - std::future future; - { - auto client (std::make_shared (connection_l)); - client->run (); + auto result (true); + auto connection_l (connection (lock_a)); + if (connection_l) + { + std::future future; + { + auto client (std::make_shared (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 & lock_a) @@ -843,30 +843,30 @@ void rai::bootstrap_attempt::request_pull (std::unique_lock & lock_ bool rai::bootstrap_attempt::request_push (std::unique_lock & lock_a) { - auto result (true); - auto connection_l (connection (lock_a)); - if (connection_l) - { - std::future future; - { - auto client (std::make_shared (connection_l)); - client->start (); + auto result (true); + auto connection_l (connection (lock_a)); + if (connection_l) + { + std::future future; + { + auto client (std::make_shared (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_attempt::connection (std: { while (!stopped && idle.empty ()) { - condition.wait (lock_a); + condition.wait (lock_a); + } + std::shared_ptr result; + if (!idle.empty ()) + { + result = idle.back (); + idle.pop_back (); } - std::shared_ptr result; - if (!idle.empty ()) - { - result = idle.back (); - idle.pop_back (); - } return result; } bool rai::bootstrap_attempt::consume_future (std::future & 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 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 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 (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 message_a) { std::lock_guard 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 (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 (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 const & connection_a, std::unique_ptr 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_limitsage)>::max ()) - { - auto now (connection->node->store.now ()); - while (!current.is_zero () && (now - info.modified) >= request->age) - { - next (); - } - } + if (request->age != std::numeric_limitsage)>::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 () diff --git a/rai/node/bootstrap.hpp b/rai/node/bootstrap.hpp index 59c5c3c9..66f1cacd 100644 --- a/rai/node/bootstrap.hpp +++ b/rai/node/bootstrap.hpp @@ -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 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 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 blocks; }; class push_synchronization : public rai::block_synchronization { public: - push_synchronization (rai::node &, std::function const &); - bool synchronized (MDB_txn *, rai::block_hash const &) override; - std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) override; - rai::sync_result target (MDB_txn *, rai::block const &) override; + push_synchronization (rai::node &, std::function const &); + bool synchronized (MDB_txn *, rai::block_hash const &) override; + std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) override; + rai::sync_result target (MDB_txn *, rai::block const &) override; std::function target_m; rai::node & node; }; @@ -68,11 +68,11 @@ public: ~bootstrap_attempt (); void run (); std::shared_ptr connection (std::unique_lock &); - bool consume_future (std::future &); + bool consume_future (std::future &); void populate_connections (); - bool request_frontier (std::unique_lock &); - void request_pull (std::unique_lock &); - bool request_push (std::unique_lock &); + bool request_frontier (std::unique_lock &); + void request_pull (std::unique_lock &); + bool request_push (std::unique_lock &); void add_connection (rai::endpoint const &); void pool_connection (std::shared_ptr ); void stop (); @@ -81,10 +81,10 @@ public: std::deque > clients; std::weak_ptr frontiers; std::weak_ptr push; - std::deque pulls; + std::deque pulls; std::vector > idle; std::atomic connections; - std::atomic pulling; + std::atomic pulling; std::shared_ptr node; std::atomic account_count; bool stopped; @@ -94,16 +94,16 @@ public: class frontier_req_client : public std::enable_shared_from_this { public: - frontier_req_client (std::shared_ptr ); - ~frontier_req_client (); + frontier_req_client (std::shared_ptr ); + ~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 connection; + std::shared_ptr connection; rai::account current; rai::account_info info; unsigned count; @@ -130,29 +130,29 @@ class bootstrap_client : public std::enable_shared_from_this { public: bootstrap_client (std::shared_ptr , std::shared_ptr , rai::tcp_endpoint const &); - ~bootstrap_client (); - void run (); + ~bootstrap_client (); + void run (); std::shared_ptr shared (); void start_timeout (); void stop_timeout (); - std::shared_ptr node; + std::shared_ptr node; std::shared_ptr attempt; - boost::asio::ip::tcp::socket socket; - std::array receive_buffer; + boost::asio::ip::tcp::socket socket; + std::array receive_buffer; rai::tcp_endpoint endpoint; boost::asio::deadline_timer timeout; }; class bulk_push_client : public std::enable_shared_from_this { public: - bulk_push_client (std::shared_ptr const &); - ~bulk_push_client (); - void start (); - void push (MDB_txn *); - void push_block (rai::block const &); - void send_finished (); - std::shared_ptr connection; - rai::push_synchronization synchronization; + bulk_push_client (std::shared_ptr const &); + ~bulk_push_client (); + void start (); + void push (MDB_txn *); + void push_block (rai::block const &); + void send_finished (); + std::shared_ptr connection; + rai::push_synchronization synchronization; std::promise 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 const &); bool in_progress (); @@ -171,7 +171,7 @@ public: std::unique_ptr attempt_thread; bool stopped; private: - void stop_attempt (std::unique_lock &); + void stop_attempt (std::unique_lock &); std::mutex mutex; std::condition_variable condition; std::vector > 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 ); - std::mutex mutex; - std::unordered_map > 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 ); + std::mutex mutex; + std::unordered_map > 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 { public: - bootstrap_server (std::shared_ptr , std::shared_ptr ); - ~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 ); - void finish_request (); - void run_next (); - std::array receive_buffer; - std::shared_ptr socket; - std::shared_ptr node; - std::mutex mutex; - std::queue > requests; + bootstrap_server (std::shared_ptr , std::shared_ptr ); + ~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 ); + void finish_request (); + void run_next (); + std::array receive_buffer; + std::shared_ptr socket; + std::shared_ptr node; + std::mutex mutex; + std::queue > requests; }; class bulk_pull; class bulk_pull_server : public std::enable_shared_from_this { public: - bulk_pull_server (std::shared_ptr const &, std::unique_ptr ); - void set_current_end (); - std::unique_ptr 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 connection; - std::unique_ptr request; - std::vector send_buffer; - rai::block_hash current; + bulk_pull_server (std::shared_ptr const &, std::unique_ptr ); + void set_current_end (); + std::unique_ptr 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 connection; + std::unique_ptr request; + std::vector send_buffer; + rai::block_hash current; }; class bulk_push_server : public std::enable_shared_from_this { public: - bulk_push_server (std::shared_ptr const &); - void receive (); - void receive_block (); - void received_type (); - void received_block (boost::system::error_code const &, size_t); - std::array receive_buffer; - std::shared_ptr connection; + bulk_push_server (std::shared_ptr const &); + void receive (); + void receive_block (); + void received_type (); + void received_block (boost::system::error_code const &, size_t); + std::array receive_buffer; + std::shared_ptr connection; }; class frontier_req; class frontier_req_server : public std::enable_shared_from_this { public: - frontier_req_server (std::shared_ptr const &, std::unique_ptr ); - 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 const &, std::unique_ptr ); + 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 connection; + std::shared_ptr connection; rai::account current; rai::account_info info; - std::unique_ptr request; - std::vector send_buffer; - size_t count; + std::unique_ptr request; + std::vector send_buffer; + size_t count; }; } diff --git a/rai/node/common.hpp b/rai/node/common.hpp index 5ab79c9c..880dc293 100644 --- a/rai/node/common.hpp +++ b/rai/node/common.hpp @@ -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 (big) ^ static_cast (big >> 32)); return result; - } + } }; template <> struct hash { - size_t operator () (rai::endpoint const & endpoint_a) const - { - endpoint_hash ehash; - return ehash (endpoint_a); - } + size_t operator () (rai::endpoint const & endpoint_a) const + { + endpoint_hash ehash; + return ehash (endpoint_a); + } }; } namespace boost @@ -72,11 +72,11 @@ namespace boost template <> struct hash { - size_t operator () (rai::endpoint const & endpoint_a) const - { - std::hash hash; - return hash (endpoint_a); - } + size_t operator () (rai::endpoint const & endpoint_a) const + { + std::hash 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 constexpr magic_number = rai::rai_network == rai::rai_networks::rai_test_network ? std::array ({ 'R', 'A' }) : rai::rai_network == rai::rai_networks::rai_beta_network ? std::array ({ 'R', 'B' }) : std::array ({ '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 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 peers; }; class publish : public message { public: - publish (); - publish (std::shared_ptr ); - 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 block; + publish (); + publish (std::shared_ptr ); + 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 block; }; class confirm_req : public message { public: - confirm_req (); - confirm_req (std::shared_ptr ); - 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 block; + confirm_req (); + confirm_req (std::shared_ptr ); + 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 block; }; class confirm_ack : public message { public: confirm_ack (bool &, rai::stream &); confirm_ack (std::shared_ptr ); - 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 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; }; } diff --git a/rai/node/node.cpp b/rai/node/node.cpp index 1537e22c..8288c2be 100755 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -53,12 +53,12 @@ error_count (0) void rai::network::receive () { - if (node.config.logging.network_packet_logging ()) - { - BOOST_LOG (node.log) << "Receiving packet"; - } - std::unique_lock lock (socket_mutex); - socket.async_receive_from (boost::asio::buffer (buffer.data (), buffer.size ()), remote, [this] (boost::system::error_code const & error, size_t size_a) + if (node.config.logging.network_packet_logging ()) + { + BOOST_LOG (node.log) << "Receiving packet"; + } + std::unique_lock lock (socket_mutex); + socket.async_receive_from (boost::asio::buffer (buffer.data (), buffer.size ()), remote, [this] (boost::system::error_code const & error, size_t size_a) { receive_action (error, size_a); }); @@ -66,9 +66,9 @@ void rai::network::receive () void rai::network::stop () { - on = false; - socket.close (); - resolver.cancel (); + on = false; + socket.close (); + resolver.cancel (); } void rai::network::send_keepalive (rai::endpoint const & endpoint_a) @@ -168,7 +168,7 @@ void rai::network::rebroadcast_reps (std::shared_ptr block_a) template bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, T & list_a, std::shared_ptr block_a) { - bool result (false); + bool result (false); if (node_a.config.enable_voting) { node_a.wallets.foreach_representative (transaction_a, [&result, &block_a, &list_a, &node_a, &transaction_a] (rai::public_key const & pub_a, rai::raw_key const & prv_a) @@ -187,7 +187,7 @@ bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, T & list_a, std } }); } - return result; + return result; } template <> @@ -205,24 +205,24 @@ void rai::network::republish_block (MDB_txn * transaction, std::shared_ptr hash ()); auto list (node.peers.list_sqrt ()); // If we're a representative, broadcast a signed confirm, otherwise an unsigned publish - if (!confirm_block (transaction, node, list, block)) - { - rai::publish message (block); - std::shared_ptr > bytes (new std::vector ); - { - rai::vectorstream stream (*bytes); - message.serialize (stream); - } + if (!confirm_block (transaction, node, list, block)) + { + rai::publish message (block); + std::shared_ptr > bytes (new std::vector ); + { + rai::vectorstream stream (*bytes); + message.serialize (stream); + } auto hash (block->hash ()); - for (auto i (list.begin ()), n (list.end ()); i != n; ++i) - { + for (auto i (list.begin ()), n (list.end ()); i != n; ++i) + { republish (hash, bytes, *i); - } + } if (node.config.logging.network_logging ()) { BOOST_LOG (node.log) << boost::str (boost::format ("Block %1% was republished to peers") % hash.to_string ()); } - } + } else { if (node.config.logging.network_logging ()) @@ -264,27 +264,27 @@ void rai::network::broadcast_confirm_req (std::shared_ptr block_a) { node.network.send_confirm_req (i->endpoint, block_a); } - if (node.config.logging.network_logging ()) - { - BOOST_LOG (node.log) << boost::str (boost::format ("Broadcasted confirm req to %1% representatives") % list.size ()); - } + if (node.config.logging.network_logging ()) + { + BOOST_LOG (node.log) << boost::str (boost::format ("Broadcasted confirm req to %1% representatives") % list.size ()); + } } void rai::network::send_confirm_req (rai::endpoint const & endpoint_a, std::shared_ptr block) { - rai::confirm_req message (block); - std::shared_ptr > bytes (new std::vector ); - { - rai::vectorstream stream (*bytes); - message.serialize (stream); - } - if (node.config.logging.network_message_logging ()) - { - BOOST_LOG (node.log) << boost::str (boost::format ("Sending confirm req to %1%") % endpoint_a); - } - std::weak_ptr node_w (node.shared ()); + rai::confirm_req message (block); + std::shared_ptr > bytes (new std::vector ); + { + rai::vectorstream stream (*bytes); + message.serialize (stream); + } + if (node.config.logging.network_message_logging ()) + { + BOOST_LOG (node.log) << boost::str (boost::format ("Sending confirm req to %1%") % endpoint_a); + } + std::weak_ptr node_w (node.shared ()); ++outgoing.confirm_req; - send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w] (boost::system::error_code const & ec, size_t size) + send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w] (boost::system::error_code const & ec, size_t size) { if (auto node_l = node_w.lock ()) { @@ -334,58 +334,58 @@ namespace class network_message_visitor : public rai::message_visitor { public: - network_message_visitor (rai::node & node_a, rai::endpoint const & sender_a) : - node (node_a), - sender (sender_a) - { - } - void keepalive (rai::keepalive const & message_a) override - { - if (node.config.logging.network_keepalive_logging ()) - { - BOOST_LOG (node.log) << boost::str (boost::format ("Received keepalive message from %1%") % sender); - } - ++node.network.incoming.keepalive; - node.peers.contacted (sender, message_a.version_using); - node.network.merge_peers (message_a.peers); - } - void publish (rai::publish const & message_a) override - { - if (node.config.logging.network_message_logging ()) - { - BOOST_LOG (node.log) << boost::str (boost::format ("Publish message from %1% for %2%") % sender % message_a.block->hash ().to_string ()); - } - ++node.network.incoming.publish; - node.peers.contacted (sender, message_a.version_using); - node.peers.insert (sender, message_a.version_using); - node.process_active (message_a.block); - } - void confirm_req (rai::confirm_req const & message_a) override - { - if (node.config.logging.network_message_logging ()) - { - BOOST_LOG (node.log) << boost::str (boost::format ("Confirm_req message from %1% for %2%") % sender % message_a.block->hash ().to_string ()); - } - ++node.network.incoming.confirm_req; - node.peers.contacted (sender, message_a.version_using); - node.peers.insert (sender, message_a.version_using); - node.process_active (message_a.block); + network_message_visitor (rai::node & node_a, rai::endpoint const & sender_a) : + node (node_a), + sender (sender_a) + { + } + void keepalive (rai::keepalive const & message_a) override + { + if (node.config.logging.network_keepalive_logging ()) + { + BOOST_LOG (node.log) << boost::str (boost::format ("Received keepalive message from %1%") % sender); + } + ++node.network.incoming.keepalive; + node.peers.contacted (sender, message_a.version_using); + node.network.merge_peers (message_a.peers); + } + void publish (rai::publish const & message_a) override + { + if (node.config.logging.network_message_logging ()) + { + BOOST_LOG (node.log) << boost::str (boost::format ("Publish message from %1% for %2%") % sender % message_a.block->hash ().to_string ()); + } + ++node.network.incoming.publish; + node.peers.contacted (sender, message_a.version_using); + node.peers.insert (sender, message_a.version_using); + node.process_active (message_a.block); + } + void confirm_req (rai::confirm_req const & message_a) override + { + if (node.config.logging.network_message_logging ()) + { + BOOST_LOG (node.log) << boost::str (boost::format ("Confirm_req message from %1% for %2%") % sender % message_a.block->hash ().to_string ()); + } + ++node.network.incoming.confirm_req; + node.peers.contacted (sender, message_a.version_using); + node.peers.insert (sender, message_a.version_using); + node.process_active (message_a.block); rai::transaction transaction_a (node.store.environment, nullptr, false); if (node.store.block_exists (transaction_a, message_a.block->hash ())) - { - confirm_block (transaction_a, node, sender, message_a.block); - } - } - void confirm_ack (rai::confirm_ack const & message_a) override - { - if (node.config.logging.network_message_logging ()) - { + { + confirm_block (transaction_a, node, sender, message_a.block); + } + } + void confirm_ack (rai::confirm_ack const & message_a) override + { + if (node.config.logging.network_message_logging ()) + { BOOST_LOG (node.log) << boost::str (boost::format ("Received confirm_ack message from %1% for %2% sequence %3%") % sender % message_a.vote->block->hash ().to_string () % std::to_string (message_a.vote->sequence)); - } - ++node.network.incoming.confirm_ack; - node.peers.contacted (sender, message_a.version_using); - node.peers.insert (sender, message_a.version_using); - node.process_active (message_a.vote->block); + } + ++node.network.incoming.confirm_ack; + node.peers.contacted (sender, message_a.version_using); + node.peers.insert (sender, message_a.version_using); + node.process_active (message_a.vote->block); auto vote (node.vote_processor.vote (message_a.vote, sender)); if (vote.code == rai::vote_code::replay) { @@ -404,56 +404,56 @@ public: node.network.confirm_send (confirm, bytes, sender); } } - } - void bulk_pull (rai::bulk_pull const &) override - { - assert (false); - } - void bulk_push (rai::bulk_push const &) override - { - assert (false); - } - void frontier_req (rai::frontier_req const &) override - { - assert (false); - } - rai::node & node; - rai::endpoint sender; + } + void bulk_pull (rai::bulk_pull const &) override + { + assert (false); + } + void bulk_push (rai::bulk_push const &) override + { + assert (false); + } + void frontier_req (rai::frontier_req const &) override + { + assert (false); + } + rai::node & node; + rai::endpoint sender; }; } void rai::network::receive_action (boost::system::error_code const & error, size_t size_a) { - if (!error && on) - { - if (!rai::reserved_address (remote) && remote != endpoint ()) - { - network_message_visitor visitor (node, remote); - rai::message_parser parser (visitor, node.work); - parser.deserialize_buffer (buffer.data (), size_a); - if (parser.error) - { - ++error_count; - } - else if (parser.insufficient_work) - { - if (node.config.logging.insufficient_work_logging ()) - { - BOOST_LOG (node.log) << "Insufficient work in message"; - } - ++insufficient_work_count; - } - } - else - { - if (node.config.logging.network_logging ()) - { - BOOST_LOG (node.log) << boost::str (boost::format ("Reserved sender %1%") % remote.address ().to_string ()); - } - ++bad_sender_count; - } - receive (); - } + if (!error && on) + { + if (!rai::reserved_address (remote) && remote != endpoint ()) + { + network_message_visitor visitor (node, remote); + rai::message_parser parser (visitor, node.work); + parser.deserialize_buffer (buffer.data (), size_a); + if (parser.error) + { + ++error_count; + } + else if (parser.insufficient_work) + { + if (node.config.logging.insufficient_work_logging ()) + { + BOOST_LOG (node.log) << "Insufficient work in message"; + } + ++insufficient_work_count; + } + } + else + { + if (node.config.logging.network_logging ()) + { + BOOST_LOG (node.log) << boost::str (boost::format ("Reserved sender %1%") % remote.address ().to_string ()); + } + ++bad_sender_count; + } + receive (); + } else { if (error) @@ -484,7 +484,7 @@ void rai::network::merge_peers (std::array const & peers_a) bool rai::operation::operator > (rai::operation const & other_a) const { - return wakeup > other_a.wakeup; + return wakeup > other_a.wakeup; } rai::alarm::alarm (boost::asio::io_service & service_a) : @@ -501,13 +501,13 @@ rai::alarm::~alarm () void rai::alarm::run () { - std::unique_lock lock (mutex); + std::unique_lock lock (mutex); auto done (false); - while (!done) - { - if (!operations.empty ()) - { - auto & operation (operations.top ()); + while (!done) + { + if (!operations.empty ()) + { + auto & operation (operations.top ()); if (operation.function) { if (operation.wakeup <= std::chrono::system_clock::now ()) @@ -525,17 +525,17 @@ void rai::alarm::run () { done = true; } - } - else - { - condition.wait (lock); - } - } + } + else + { + condition.wait (lock); + } + } } void rai::alarm::add (std::chrono::system_clock::time_point const & wakeup_a, std::function const & operation) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); operations.push (rai::operation ({wakeup_a, operation})); condition.notify_all (); } @@ -735,7 +735,7 @@ wallet_init (false) bool rai::node_init::error () { - return block_store_init || wallet_init; + return block_store_init || wallet_init; } rai::node_config::node_config () : @@ -1092,7 +1092,7 @@ node (node_a) rai::block_processor::~block_processor () { - stop (); + stop (); } void rai::block_processor::stop () @@ -1104,18 +1104,18 @@ void rai::block_processor::stop () void rai::block_processor::flush () { - std::unique_lock lock (mutex); - while (!stopped && (!blocks.empty () || !idle)) - { - condition.wait (lock); - } + std::unique_lock lock (mutex); + while (!stopped && (!blocks.empty () || !idle)) + { + condition.wait (lock); + } } void rai::block_processor::add (rai::block_processor_item const & item_a) { - std::lock_guard lock (mutex); - blocks.push_back (item_a); - condition.notify_all (); + std::lock_guard lock (mutex); + blocks.push_back (item_a); + condition.notify_all (); } void rai::block_processor::process_blocks () @@ -1135,10 +1135,10 @@ void rai::block_processor::process_blocks () } else { - idle = true; - condition.notify_all (); + idle = true; + condition.notify_all (); condition.wait (lock); - idle = false; + idle = false; } } } @@ -1480,14 +1480,14 @@ block_processor_thread ([this] () { this->block_processor.process_blocks (); }) this->network.send_keepalive (endpoint_a); rep_query (*this, endpoint_a); }); - observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const &) - { + observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const &) + { active.vote (vote_a); - }); - observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const &) - { + }); + observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const &) + { this->gap_cache.vote (vote_a); - }); + }); observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const & endpoint_a) { if (this->rep_crawler.exists (vote_a->block->hash ())) @@ -1529,13 +1529,13 @@ rai::node::~node () void rai::node::send_keepalive (rai::endpoint const & endpoint_a) { - auto endpoint_l (endpoint_a); - if (endpoint_l.address ().is_v4 ()) - { - endpoint_l = rai::endpoint (boost::asio::ip::address_v6::v4_mapped (endpoint_l.address ().to_v4 ()), endpoint_l.port ()); - } - assert (endpoint_l.address ().is_v6 ()); - network.send_keepalive (endpoint_l); + auto endpoint_l (endpoint_a); + if (endpoint_l.address ().is_v4 ()) + { + endpoint_l = rai::endpoint (boost::asio::ip::address_v6::v4_mapped (endpoint_l.address ().to_v4 ()), endpoint_l.port ()); + } + assert (endpoint_l.address ().is_v6 ()); + network.send_keepalive (endpoint_l); } rai::gap_cache::gap_cache (rai::node & node_a) : @@ -1546,23 +1546,23 @@ node (node_a) void rai::gap_cache::add (MDB_txn * transaction_a, std::shared_ptr block_a) { auto hash (block_a->hash ()); - std::lock_guard lock (mutex); - auto existing (blocks.get <1>().find (hash)); - if (existing != blocks.get <1> ().end ()) - { - blocks.get <1> ().modify (existing, [] (rai::gap_information & info) + std::lock_guard lock (mutex); + auto existing (blocks.get <1>().find (hash)); + if (existing != blocks.get <1> ().end ()) + { + blocks.get <1> ().modify (existing, [] (rai::gap_information & info) { info.arrival = std::chrono::system_clock::now (); }); - } - else - { + } + else + { blocks.insert ({std::chrono::system_clock::now (), hash, std::unique_ptr (new rai::votes (block_a))}); - if (blocks.size () > max) - { - blocks.get <0> ().erase (blocks.get <0> ().begin ()); - } - } + if (blocks.size () > max) + { + blocks.get <0> ().erase (blocks.get <0> ().begin ()); + } + } } void rai::gap_cache::vote (std::shared_ptr vote_a) @@ -1597,14 +1597,14 @@ void rai::gap_cache::vote (std::shared_ptr vote_a) rai::uint128_t rai::gap_cache::bootstrap_threshold (MDB_txn * transaction_a) { - auto result ((node.ledger.supply (transaction_a) / 256) * node.config.bootstrap_fraction_numerator); + auto result ((node.ledger.supply (transaction_a) / 256) * node.config.bootstrap_fraction_numerator); return result; } void rai::gap_cache::purge_old () { auto cutoff (std::chrono::system_clock::now () - std::chrono::seconds (10)); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto done (false); while (!done && !blocks.empty ()) { @@ -1622,13 +1622,13 @@ void rai::gap_cache::purge_old () void rai::network::confirm_send (rai::confirm_ack const & confirm_a, std::shared_ptr > bytes_a, rai::endpoint const & endpoint_a) { - if (node.config.logging.network_publish_logging ()) - { + if (node.config.logging.network_publish_logging ()) + { BOOST_LOG (node.log) << boost::str (boost::format ("Sending confirm_ack for block %1% to %2% sequence %3%") % confirm_a.vote->block->hash ().to_string () % endpoint_a % std::to_string (confirm_a.vote->sequence)); - } - std::weak_ptr node_w (node.shared ()); + } + std::weak_ptr node_w (node.shared ()); ++outgoing.confirm_ack; - node.network.send_buffer (bytes_a->data (), bytes_a->size (), endpoint_a, [bytes_a, node_w, endpoint_a] (boost::system::error_code const & ec, size_t size_a) + node.network.send_buffer (bytes_a->data (), bytes_a->size (), endpoint_a, [bytes_a, node_w, endpoint_a] (boost::system::error_code const & ec, size_t size_a) { if (auto node_l = node_w.lock ()) { @@ -1671,15 +1671,15 @@ std::vector rai::peer_container::list_sqrt () std::vector rai::peer_container::list () { - std::vector result; - std::lock_guard lock (mutex); - result.reserve (peers.size ()); - for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i) - { - result.push_back (i->endpoint); - } + std::vector result; + std::lock_guard lock (mutex); + result.reserve (peers.size ()); + for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i) + { + result.push_back (i->endpoint); + } std::random_shuffle (result.begin (), result.end ()); - return result; + return result; } std::map rai::peer_container::list_version () @@ -1695,8 +1695,8 @@ std::map rai::peer_container::list_version () rai::endpoint rai::peer_container::bootstrap_peer () { - rai::endpoint result (boost::asio::ip::address_v6::any (), 0); - std::lock_guard lock (mutex); + rai::endpoint result (boost::asio::ip::address_v6::any (), 0); + std::lock_guard lock (mutex); ; for (auto i (peers.get <4> ().begin ()), n (peers.get <4> ().end ()); i != n;) { @@ -1713,8 +1713,8 @@ rai::endpoint rai::peer_container::bootstrap_peer () { ++i; } - } - return result; + } + return result; } bool rai::parse_port (std::string const & string_a, uint16_t & port_a) @@ -1728,78 +1728,78 @@ bool rai::parse_port (std::string const & string_a, uint16_t & port_a) bool rai::parse_address_port (std::string const & string, boost::asio::ip::address & address_a, uint16_t & port_a) { - auto result (false); - auto port_position (string.rfind (':')); - if (port_position != std::string::npos && port_position > 0) - { - std::string port_string (string.substr (port_position + 1)); - try - { + auto result (false); + auto port_position (string.rfind (':')); + if (port_position != std::string::npos && port_position > 0) + { + std::string port_string (string.substr (port_position + 1)); + try + { uint16_t port; result = parse_port (port_string, port); - if (!result) - { - boost::system::error_code ec; - auto address (boost::asio::ip::address_v6::from_string (string.substr (0, port_position), ec)); - if (ec == 0) - { - address_a = address; - port_a = port; - } - else - { - result = true; - } - } - else - { - result = true; - } - } - catch (...) - { - result = true; - } - } - else - { - result = true; - } - return result; + if (!result) + { + boost::system::error_code ec; + auto address (boost::asio::ip::address_v6::from_string (string.substr (0, port_position), ec)); + if (ec == 0) + { + address_a = address; + port_a = port; + } + else + { + result = true; + } + } + else + { + result = true; + } + } + catch (...) + { + result = true; + } + } + else + { + result = true; + } + return result; } bool rai::parse_endpoint (std::string const & string, rai::endpoint & endpoint_a) { - boost::asio::ip::address address; - uint16_t port; - auto result (parse_address_port (string, address, port)); - if (!result) - { - endpoint_a = rai::endpoint (address, port); - } - return result; + boost::asio::ip::address address; + uint16_t port; + auto result (parse_address_port (string, address, port)); + if (!result) + { + endpoint_a = rai::endpoint (address, port); + } + return result; } bool rai::parse_tcp_endpoint (std::string const & string, rai::tcp_endpoint & endpoint_a) { - boost::asio::ip::address address; - uint16_t port; - auto result (parse_address_port (string, address, port)); - if (!result) - { - endpoint_a = rai::tcp_endpoint (address, port); - } - return result; + boost::asio::ip::address address; + uint16_t port; + auto result (parse_address_port (string, address, port)); + if (!result) + { + endpoint_a = rai::tcp_endpoint (address, port); + } + return result; } void rai::node::start () { - network.receive (); - ongoing_keepalive (); + network.receive (); + ongoing_keepalive (); ongoing_bootstrap (); ongoing_store_flush (); ongoing_rep_crawl (); - bootstrap.start (); + bootstrap.start (); backup_wallet (); active.announce_votes (); port_mapping.start (); @@ -1809,20 +1809,20 @@ void rai::node::start () void rai::node::stop () { - BOOST_LOG (log) << "Node stopping"; + BOOST_LOG (log) << "Node stopping"; block_processor.stop (); if (block_processor_thread.joinable ()) { block_processor_thread.join (); } active.stop (); - network.stop (); + network.stop (); bootstrap_initiator.stop (); - bootstrap.stop (); + bootstrap.stop (); port_mapping.stop (); - if (block_processor_thread.joinable ()) - { - block_processor_thread.join (); + if (block_processor_thread.joinable ()) + { + block_processor_thread.join (); } } @@ -2205,7 +2205,7 @@ std::atomic_flag completed; void rai::node::generate_work (rai::block & block_a) { - block_a.block_work_set (generate_work (block_a.root ())); + block_a.block_work_set (generate_work (block_a.root ())); } void rai::node::generate_work (rai::uint256_union const & hash_a, std::function callback_a) @@ -2234,15 +2234,15 @@ namespace class confirmed_visitor : public rai::block_visitor { public: - confirmed_visitor (rai::node & node_a, std::shared_ptr block_a) : - node (node_a), + confirmed_visitor (rai::node & node_a, std::shared_ptr block_a) : + node (node_a), block (block_a) - { - } - void send_block (rai::send_block const & block_a) override - { - for (auto i (node.wallets.items.begin ()), n (node.wallets.items.end ()); i != n; ++i) - { + { + } + void send_block (rai::send_block const & block_a) override + { + for (auto i (node.wallets.items.begin ()), n (node.wallets.items.end ()); i != n; ++i) + { auto wallet (i->second); if (wallet->exists (block_a.hashables.destination)) { @@ -2266,26 +2266,26 @@ public: } } } - } - } - void receive_block (rai::receive_block const &) override - { - } - void open_block (rai::open_block const &) override - { - } - void change_block (rai::change_block const &) override - { - } - rai::node & node; + } + } + void receive_block (rai::receive_block const &) override + { + } + void open_block (rai::open_block const &) override + { + } + void change_block (rai::change_block const &) override + { + } + rai::node & node; std::shared_ptr block; }; } void rai::node::process_confirmed (std::shared_ptr confirmed_a) { - confirmed_visitor visitor (*this, confirmed_a); - confirmed_a->visit (visitor); + confirmed_visitor visitor (*this, confirmed_a); + confirmed_a->visit (visitor); } void rai::node::process_message (rai::message & message_a, rai::endpoint const & sender_a) @@ -2302,14 +2302,14 @@ rai::endpoint rai::network::endpoint () { BOOST_LOG (node.log) << "Unable to retrieve port: " << ec.message (); } - return rai::endpoint (boost::asio::ip::address_v6::loopback (), port); + return rai::endpoint (boost::asio::ip::address_v6::loopback (), port); } void rai::block_arrival::add (rai::block_hash const & hash_a) { - std::lock_guard lock (mutex); - auto now (std::chrono::system_clock::now ()); - arrival.insert (rai::block_arrival_info {now, hash_a}); + std::lock_guard lock (mutex); + auto now (std::chrono::system_clock::now ()); + arrival.insert (rai::block_arrival_info {now, hash_a}); } bool rai::block_arrival::recent (rai::block_hash const & hash_a) @@ -2320,7 +2320,7 @@ bool rai::block_arrival::recent (rai::block_hash const & hash_a) { arrival.erase (arrival.begin ()); } - return arrival.get <1> ().find (hash_a) != arrival.get <1> ().end (); + return arrival.get <1> ().find (hash_a) != arrival.get <1> ().end (); } std::unordered_set rai::peer_container::random_set (size_t count_a) @@ -2351,18 +2351,18 @@ std::unordered_set rai::peer_container::random_set (size_t count void rai::peer_container::random_fill (std::array & target_a) { - auto peers (random_set (target_a.size ())); - assert (peers.size () <= target_a.size ()); - auto endpoint (rai::endpoint (boost::asio::ip::address_v6 {}, 0)); - assert (endpoint.address ().is_v6 ()); - std::fill (target_a.begin (), target_a.end (), endpoint); - auto j (target_a.begin ()); - for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i, ++j) - { - assert (i->address ().is_v6 ()); - assert (j < target_a.end ()); - *j = *i; - } + auto peers (random_set (target_a.size ())); + assert (peers.size () <= target_a.size ()); + auto endpoint (rai::endpoint (boost::asio::ip::address_v6 {}, 0)); + assert (endpoint.address ().is_v6 ()); + std::fill (target_a.begin (), target_a.end (), endpoint); + auto j (target_a.begin ()); + for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i, ++j) + { + assert (i->address ().is_v6 ()); + assert (j < target_a.end ()); + *j = *i; + } } // Request a list of the top known representatives @@ -2403,7 +2403,7 @@ std::vector rai::peer_container::purge_list (std::chrono { disconnect_observer (); } - return result; + return result; } std::vector rai::peer_container::rep_crawl () @@ -2421,8 +2421,8 @@ std::vector rai::peer_container::rep_crawl () size_t rai::peer_container::size () { - std::lock_guard lock (mutex); - return peers.size (); + std::lock_guard lock (mutex); + return peers.size (); } size_t rai::peer_container::size_sqrt () @@ -2433,34 +2433,34 @@ size_t rai::peer_container::size_sqrt () bool rai::peer_container::empty () { - return size () == 0; + return size () == 0; } bool rai::peer_container::not_a_peer (rai::endpoint const & endpoint_a) { - bool result (false); - if (endpoint_a.address ().to_v6 ().is_unspecified ()) - { - result = true; - } - else if (rai::reserved_address (endpoint_a)) - { - result = true; - } - else if (endpoint_a == self) - { - result = true; - } - return result; + bool result (false); + if (endpoint_a.address ().to_v6 ().is_unspecified ()) + { + result = true; + } + else if (rai::reserved_address (endpoint_a)) + { + result = true; + } + else if (endpoint_a == self) + { + result = true; + } + return result; } bool rai::peer_container::rep_response (rai::endpoint const & endpoint_a, rai::amount const & weight_a) { auto updated (false); - std::lock_guard lock (mutex); - auto existing (peers.find (endpoint_a)); - if (existing != peers.end ()) - { + std::lock_guard lock (mutex); + auto existing (peers.find (endpoint_a)); + if (existing != peers.end ()) + { peers.modify (existing, [weight_a, &updated] (rai::peer_information & info) { info.last_rep_response = std::chrono::system_clock::now (); @@ -2470,21 +2470,21 @@ bool rai::peer_container::rep_response (rai::endpoint const & endpoint_a, rai::a info.rep_weight = weight_a; } }); - } + } return updated; } void rai::peer_container::rep_request (rai::endpoint const & endpoint_a) { - std::lock_guard lock (mutex); - auto existing (peers.find (endpoint_a)); - if (existing != peers.end ()) - { + std::lock_guard lock (mutex); + auto existing (peers.find (endpoint_a)); + if (existing != peers.end ()) + { peers.modify (existing, [] (rai::peer_information & info) { info.last_rep_request = std::chrono::system_clock::now (); }); - } + } } bool rai::peer_container::reachout (rai::endpoint const & endpoint_a) @@ -2504,42 +2504,42 @@ bool rai::peer_container::reachout (rai::endpoint const & endpoint_a) bool rai::peer_container::insert (rai::endpoint const & endpoint_a, unsigned version_a) { auto unknown (false); - auto result (not_a_peer (endpoint_a)); - if (!result) - { - std::lock_guard lock (mutex); - auto existing (peers.find (endpoint_a)); - if (existing != peers.end ()) - { - peers.modify (existing, [] (rai::peer_information & info) - { - info.last_contact = std::chrono::system_clock::now (); - }); - result = true; - } - else - { - peers.insert (rai::peer_information (endpoint_a, version_a)); + auto result (not_a_peer (endpoint_a)); + if (!result) + { + std::lock_guard lock (mutex); + auto existing (peers.find (endpoint_a)); + if (existing != peers.end ()) + { + peers.modify (existing, [] (rai::peer_information & info) + { + info.last_contact = std::chrono::system_clock::now (); + }); + result = true; + } + else + { + peers.insert (rai::peer_information (endpoint_a, version_a)); unknown = true; - } - } + } + } if (unknown && !result) { peer_observer (endpoint_a); } - return result; + return result; } namespace { boost::asio::ip::address_v6 mapped_from_v4_bytes (unsigned long address_a) { - return boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (address_a)); + return boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (address_a)); } } bool rai::reserved_address (rai::endpoint const & endpoint_a) { - assert (endpoint_a.address ().is_v6 ()); + assert (endpoint_a.address ().is_v6 ()); auto bytes (endpoint_a.address ().to_v6 ()); auto result (false); static auto const rfc1700_min (mapped_from_v4_bytes (0x00000000ul)); @@ -2562,7 +2562,7 @@ bool rai::reserved_address (rai::endpoint const & endpoint_a) static auto const rfc3849_max (boost::asio::ip::address_v6::from_string ("2001:db8:ffff:ffff:ffff:ffff:ffff:ffff")); static auto const ipv6_multicast_min (boost::asio::ip::address_v6::from_string ("ff00::")); static auto const ipv6_multicast_max (boost::asio::ip::address_v6::from_string ("ff00:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); - if (bytes >= rfc1700_min && bytes <= rfc1700_max) + if (bytes >= rfc1700_min && bytes <= rfc1700_max) { result = true; } @@ -2641,22 +2641,22 @@ disconnect_observer ([] () {}) void rai::peer_container::contacted (rai::endpoint const & endpoint_a, unsigned version_a) { - auto endpoint_l (endpoint_a); - if (endpoint_l.address ().is_v4 ()) - { - endpoint_l = rai::endpoint (boost::asio::ip::address_v6::v4_mapped (endpoint_l.address ().to_v4 ()), endpoint_l.port ()); - } - assert (endpoint_l.address ().is_v6 ()); + auto endpoint_l (endpoint_a); + if (endpoint_l.address ().is_v4 ()) + { + endpoint_l = rai::endpoint (boost::asio::ip::address_v6::v4_mapped (endpoint_l.address ().to_v4 ()), endpoint_l.port ()); + } + assert (endpoint_l.address ().is_v6 ()); insert (endpoint_l, version_a); } std::ostream & operator << (std::ostream & stream_a, std::chrono::system_clock::time_point const & time_a) { - time_t last_contact (std::chrono::system_clock::to_time_t (time_a)); - std::string string (ctime (&last_contact)); - string.pop_back (); - stream_a << string; - return stream_a; + time_t last_contact (std::chrono::system_clock::to_time_t (time_a)); + std::string string (ctime (&last_contact)); + string.pop_back (); + stream_a << string; + return stream_a; } void rai::network::send_buffer (uint8_t const * data_a, size_t size_a, rai::endpoint const & endpoint_a, std::function callback_a) @@ -2678,22 +2678,22 @@ void rai::network::send_buffer (uint8_t const * data_a, size_t size_a, rai::endp uint64_t rai::block_store::now () { - boost::posix_time::ptime epoch (boost::gregorian::date (1970, 1, 1)); - auto now (boost::posix_time::second_clock::universal_time ()); - auto diff (now - epoch); - return diff.total_seconds (); + boost::posix_time::ptime epoch (boost::gregorian::date (1970, 1, 1)); + auto now (boost::posix_time::second_clock::universal_time ()); + auto diff (now - epoch); + return diff.total_seconds (); } bool rai::peer_container::known_peer (rai::endpoint const & endpoint_a) { - std::lock_guard lock (mutex); - auto existing (peers.find (endpoint_a)); - return existing != peers.end (); + std::lock_guard lock (mutex); + auto existing (peers.find (endpoint_a)); + return existing != peers.end (); } std::shared_ptr rai::node::shared () { - return shared_from_this (); + return shared_from_this (); } rai::election::election (MDB_txn * transaction_a, rai::node & node_a, std::shared_ptr block_a, std::function )> const & confirmation_action_a) : @@ -2730,7 +2730,7 @@ void rai::election::broadcast_winner () rai::uint128_t rai::election::quorum_threshold (MDB_txn * transaction_a, rai::ledger & ledger_a) { // Threshold over which unanimous voting implies confirmation - return ledger_a.supply (transaction_a) / 2; + return ledger_a.supply (transaction_a) / 2; } rai::uint128_t rai::election::minimum_threshold (MDB_txn * transaction_a, rai::ledger & ledger_a) @@ -2911,7 +2911,7 @@ void rai::active_transactions::vote (std::shared_ptr vote_a) bool rai::active_transactions::active (rai::block const & block_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); return roots.find (block_a.root ()) != roots.end (); } @@ -3037,8 +3037,8 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) result = true; } } - else if (vm.count ("account_get") > 0) - { + else if (vm.count ("account_get") > 0) + { if (vm.count ("key") == 1) { rai::uint256_union pub; @@ -3050,7 +3050,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) std::cerr << "account comand requires one option\n"; result = true; } - } + } else if (vm.count ("account_key") > 0) { if (vm.count ("account") == 1) @@ -3093,11 +3093,11 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) std::cout << "Error initializing OpenCL" << std::endl; } } - else if (vm.count ("key_create")) - { - rai::keypair pair; - std::cout << "Private: " << pair.prv.data.to_string () << std::endl << "Public: " << pair.pub.to_string () << std::endl << "Account: " << pair.pub.to_account () << std::endl; - } + else if (vm.count ("key_create")) + { + rai::keypair pair; + std::cout << "Private: " << pair.prv.data.to_string () << std::endl << "Public: " << pair.pub.to_string () << std::endl << "Account: " << pair.pub.to_account () << std::endl; + } else if (vm.count ("key_expand")) { if (vm.count ("key") == 1) diff --git a/rai/node/node.hpp b/rai/node/node.hpp index fc831f7b..90e75831 100644 --- a/rai/node/node.hpp +++ b/rai/node/node.hpp @@ -42,7 +42,7 @@ class election : public std::enable_shared_from_this std::function )> confirmation_action; void confirm_once (MDB_txn *); public: - election (MDB_txn *, rai::node &, std::shared_ptr , std::function )> const &); + election (MDB_txn *, rai::node &, std::shared_ptr , std::function )> const &); void vote (std::shared_ptr ); // 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 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 function; + bool operator > (rai::operation const &) const; + std::chrono::system_clock::time_point wakeup; + std::function 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 const &); + void add (std::chrono::system_clock::time_point const &, std::function const &); void run (); boost::asio::io_service & service; - std::mutex mutex; - std::condition_variable condition; - std::priority_queue , std::greater > operations; + std::mutex mutex; + std::condition_variable condition; + std::priority_queue , std::greater > 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 votes; }; class gap_cache { public: - gap_cache (rai::node &); - void add (MDB_txn *, std::shared_ptr ); - void vote (std::shared_ptr ); - rai::uint128_t bootstrap_threshold (MDB_txn *); + gap_cache (rai::node &); + void add (MDB_txn *, std::shared_ptr ); + void vote (std::shared_ptr ); + 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::hashed_unique > - > - > 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::hashed_unique > + > + > 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 keepalive; - std::atomic publish; - std::atomic confirm_req; - std::atomic confirm_ack; + std::atomic keepalive; + std::atomic publish; + std::atomic confirm_req; + std::atomic 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::hashed_unique > - > - > 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::hashed_unique > + > + > 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 ); void republish_vote (std::chrono::system_clock::time_point const &, std::shared_ptr ); - void republish_block (MDB_txn *, std::shared_ptr ); + void republish_block (MDB_txn *, std::shared_ptr ); void republish (rai::block_hash const &, std::shared_ptr >, rai::endpoint); - void publish_broadcast (std::vector &, std::unique_ptr ); + void publish_broadcast (std::vector &, std::unique_ptr ); void confirm_send (rai::confirm_ack const &, std::shared_ptr >, rai::endpoint const &); - void merge_peers (std::array const &); - void send_keepalive (rai::endpoint const &); + void merge_peers (std::array const &); + void send_keepalive (rai::endpoint const &); void broadcast_confirm_req (std::shared_ptr ); - void send_confirm_req (rai::endpoint const &, std::shared_ptr ); - void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function ); - rai::endpoint endpoint (); - rai::endpoint remote; - std::array 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 ); + void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function ); + rai::endpoint endpoint (); + rai::endpoint remote; + std::array 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 { 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 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 shared (); + void start (); + void stop (); + std::shared_ptr shared (); int store_version (); - void process_confirmed (std::shared_ptr ); + void process_confirmed (std::shared_ptr ); void process_message (rai::message &, rai::endpoint const &); void process_active (std::shared_ptr ); rai::process_return process (rai::block const &); - void keepalive_preconfigured (std::vector const &); + void keepalive_preconfigured (std::vector const &); rai::block_hash latest (rai::account const &); rai::uint128_t balance (rai::account const &); std::unique_ptr block (rai::block_hash const &); std::pair 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 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 diff --git a/rai/node/openclwork.cpp b/rai/node/openclwork.cpp index c76b7e59..b3259f2b 100644 --- a/rai/node/openclwork.cpp +++ b/rai/node/openclwork.cpp @@ -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 ("platform")); auto device_l (tree_a.get ("device")); auto threads_l (tree_a.get ("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; } diff --git a/rai/node/openclwork.hpp b/rai/node/openclwork.hpp index a0c2ea29..b7cc42db 100644 --- a/rai/node/openclwork.hpp +++ b/rai/node/openclwork.hpp @@ -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; diff --git a/rai/node/rpc.cpp b/rai/node/rpc.cpp index ca78facc..2c0f71d9 100755 --- a/rai/node/rpc.cpp +++ b/rai/node/rpc.cpp @@ -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 ("address")); auto port_l (tree_a.get ("port")); enable_control = tree_a.get ("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; } diff --git a/rai/node/rpc.hpp b/rai/node/rpc.hpp index 525352d7..3b2bbf35 100644 --- a/rai/node/rpc.hpp +++ b/rai/node/rpc.hpp @@ -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 > 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 { diff --git a/rai/node/testing.cpp b/rai/node/testing.cpp index 20a62539..5f1c1b85 100644 --- a/rai/node/testing.cpp +++ b/rai/node/testing.cpp @@ -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 (init, service, rai::unique_path (), alarm, config, work)); - assert (!init.error ()); - node->start (); + auto node (std::make_shared (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 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::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 { public: - traffic_generator (uint32_t count_a, uint32_t wait_a, std::shared_ptr 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 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 accounts; - uint32_t count; - uint32_t wait; - std::shared_ptr node; - rai::system & system; + uint32_t count; + uint32_t wait; + std::shared_ptr 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 (count_a, wait_a, nodes [index_a], *this)); - generate->run (); + assert (nodes.size () > index_a); + assert (count_a > 0); + auto generate (std::make_shared (count_a, wait_a, nodes [index_a], *this)); + generate->run (); } void rai::system::generate_rollback (rai::node & node_a, std::vector & 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 & 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 & accounts_a) @@ -221,13 +221,13 @@ rai::account rai::system::get_random_account (std::vector & 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 ()); - 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 ::max ()}).convert_to ()); - std::string text (result.convert_to ()); - return result; + rai::uint128_t balance (node_a.ledger.account_balance (transaction_a, account_a)); + std::string balance_text (balance.convert_to ()); + 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 ::max ()}).convert_to ()); + std::string text (result.convert_to ()); + return result; } void rai::system::generate_send_existing (rai::node & node_a, std::vector & accounts_a) @@ -281,7 +281,7 @@ void rai::system::generate_change_unknown (rai::node & node_a, std::vector & 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 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 (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 (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 () diff --git a/rai/node/testing.hpp b/rai/node/testing.hpp index 25ea76bc..236024c9 100644 --- a/rai/node/testing.hpp +++ b/rai/node/testing.hpp @@ -7,27 +7,27 @@ namespace rai class system { public: - system (uint16_t, size_t); - ~system (); - void generate_activity (rai::node &, std::vector &); - 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 &); + 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::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 &); void generate_change_known (rai::node &, std::vector &); void generate_change_unknown (rai::node &, std::vector &); void generate_receive (rai::node &); - void generate_send_new (rai::node &, std::vector &); - void generate_send_existing (rai::node &, std::vector &); - std::shared_ptr wallet (size_t); - rai::account account (MDB_txn *, size_t); + void generate_send_new (rai::node &, std::vector &); + void generate_send_existing (rai::node &, std::vector &); + std::shared_ptr wallet (size_t); + rai::account account (MDB_txn *, size_t); void poll (); void stop (); - boost::asio::io_service service; - rai::alarm alarm; - std::vector > nodes; + boost::asio::io_service service; + rai::alarm alarm; + std::vector > nodes; rai::logging logging; rai::work_pool work; }; diff --git a/rai/node/utility.hpp b/rai/node/utility.hpp index 5720e5ad..70d1c6e5 100755 --- a/rai/node/utility.hpp +++ b/rai/node/utility.hpp @@ -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); diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index e28011c3..dd8cc1c7 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -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 first (new rai::uint256_union (key)); - for (auto i (1); i < count_a; ++i) - { - std::unique_ptr 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 first (new rai::uint256_union (key)); + for (auto i (1); i < count_a; ++i) + { + std::unique_ptr 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 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::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 block; if (node.config.receive_minimum.number () <= amount_a.number ()) { @@ -872,7 +872,7 @@ std::shared_ptr rai::wallet::receive_action (rai::send_block const }); } } - return block; + return block; } std::shared_ptr 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::system_clock::now () - begin).count ()) << " us"; @@ -1256,34 +1256,34 @@ node (node_a) std::shared_ptr rai::wallets::open (rai::uint256_union const & id_a) { - std::shared_ptr result; - auto existing (items.find (id_a)); - if (existing != items.end ()) - { - result = existing->second; - } - return result; + std::shared_ptr result; + auto existing (items.find (id_a)); + if (existing != items.end ()) + { + result = existing->second; + } + return result; } std::shared_ptr rai::wallets::create (rai::uint256_union const & id_a) { - assert (items.find (id_a) == items.end ()); - std::shared_ptr result; - bool error; + assert (items.find (id_a) == items.end ()); + std::shared_ptr result; + bool error; { rai::transaction transaction (node.store.environment, nullptr, true); result = std::make_shared (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) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 4e3d7810..0cd8f2ae 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -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 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::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"); + } } diff --git a/rai/qt/qt.hpp b/rai/qt/qt.hpp index 5c9bd58a..54c26b75 100644 --- a/rai/qt/qt.hpp +++ b/rai/qt/qt.hpp @@ -10,7 +10,7 @@ #include namespace rai_qt { - class wallet; + class wallet; class eventloop_processor : public QObject { public: @@ -22,32 +22,32 @@ namespace rai_qt { eventloop_event (std::function const &); std::function 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; diff --git a/rai/qt_system/entry.cpp b/rai/qt_system/entry.cpp index cd741a83..ac424fd5 100644 --- a/rai/qt_system/entry.cpp +++ b/rai/qt_system/entry.cpp @@ -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 client_tabs (new QTabWidget); - std::vector > 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 (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 client_tabs (new QTabWidget); + std::vector > 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 (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; } diff --git a/rai/qt_test/entry.cpp b/rai/qt_test/entry.cpp index efcd22e2..89183178 100644 --- a/rai/qt_test/entry.cpp +++ b/rai/qt_test/entry.cpp @@ -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 (); diff --git a/rai/qt_test/qt.cpp b/rai/qt_test/qt.cpp index 0140ac4a..212d5fb0 100644 --- a/rai/qt_test/qt.cpp +++ b/rai/qt_test/qt.cpp @@ -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 (*test_application, processor, *system.nodes [0], wallet_l, key)); + auto wallet (std::make_shared (*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 (*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 (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], wallet_l, key1)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [1], system.wallet (1), key2.pub)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), key1.pub)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), wallet_key)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*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 (*test_application, processor, *system0.nodes [0], system0.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system0.nodes [0], system0.wallet (0), key1)); wallet->start (); { rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true); diff --git a/rai/rai_node/daemon.cpp b/rai/rai_node/daemon.cpp index 0ef2113d..6f34531f 100644 --- a/rai/rai_node/daemon.cpp +++ b/rai/rai_node/daemon.cpp @@ -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 runner; + rai_daemon::daemon_config config (data_path); + auto config_path ((data_path / "config.json")); + std::fstream config_file; + std::unique_ptr runner; auto error (rai::fetch_object (config, config_path, config_file)); if (!error) { diff --git a/rai/rai_node/daemon.hpp b/rai/rai_node/daemon.hpp index 545eeccc..b8ce102e 100644 --- a/rai/rai_node/daemon.hpp +++ b/rai/rai_node/daemon.hpp @@ -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; - }; + }; } diff --git a/rai/rai_node/entry.cpp b/rai/rai_node/entry.cpp index 9e292635..69851a4b 100644 --- a/rai/rai_node/entry.cpp +++ b/rai/rai_node/entry.cpp @@ -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 (data)), n (reinterpret_cast (data) + 1024 * 1024); i != n; ++i) - { - *i = rng.next (); - } + xorshift128 rng; + rng.s [0] = 1; + rng.s [1] = 0; + for (auto i (reinterpret_cast (data)), n (reinterpret_cast (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 (data)), n (reinterpret_cast (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 (data)), n (reinterpret_cast (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 diff --git a/rai/rai_wallet/entry.cpp b/rai/rai_wallet/entry.cpp index d38eb812..47dd2379 100755 --- a/rai/rai_wallet/entry.cpp +++ b/rai/rai_wallet/entry.cpp @@ -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 node; std::shared_ptr gui; diff --git a/rai/secure.cpp b/rai/secure.cpp index df17375e..759c2f7c 100755 --- a/rai/secure.cpp +++ b/rai/secure.cpp @@ -20,30 +20,30 @@ char const * test_public_key_data = "B0311EA55708D6A53C75CDBF88300259C6D018522FE char const * beta_public_key_data = "9D3A5B66B478670455B241D6BAC3D3FE1CBB7E7B7EAA429FA036C2704C3DC0A4"; // xrb_39btdfmday591jcu6igpqd3x9ziwqfz9pzocacht1fp4g385ui76a87x6phk char const * live_public_key_data = "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"; // xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3 char const * test_genesis_data = R"%%%({ - "type": "open", - "source": "B0311EA55708D6A53C75CDBF88300259C6D018522FE3D4D0A242E431F9E8B6D0", - "representative": "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", - "account": "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", - "work": "9680625b39d3363d", - "signature": "ECDA914373A2F0CA1296475BAEE40500A7F0A7AD72A5A80C81D7FAB7F6C802B2CC7DB50F5DD0FB25B2EF11761FA7344A158DD5A700B21BD47DE5BD0F63153A02" + "type": "open", + "source": "B0311EA55708D6A53C75CDBF88300259C6D018522FE3D4D0A242E431F9E8B6D0", + "representative": "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", + "account": "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", + "work": "9680625b39d3363d", + "signature": "ECDA914373A2F0CA1296475BAEE40500A7F0A7AD72A5A80C81D7FAB7F6C802B2CC7DB50F5DD0FB25B2EF11761FA7344A158DD5A700B21BD47DE5BD0F63153A02" })%%%"; char const * beta_genesis_data = R"%%%({ - "type": "open", - "source": "9D3A5B66B478670455B241D6BAC3D3FE1CBB7E7B7EAA429FA036C2704C3DC0A4", - "representative": "xrb_39btdfmday591jcu6igpqd3x9ziwqfz9pzocacht1fp4g385ui76a87x6phk", - "account": "xrb_39btdfmday591jcu6igpqd3x9ziwqfz9pzocacht1fp4g385ui76a87x6phk", - "work": "6eb12d4c42dba31e", - "signature": "BD0D374FCEB33EAABDF728E9B4DCDBF3B226DA97EEAB8EA5B7EDE286B1282C24D6EB544644FE871235E4F58CD94DF66D9C555309895F67A7D1F922AAC12CE907" + "type": "open", + "source": "9D3A5B66B478670455B241D6BAC3D3FE1CBB7E7B7EAA429FA036C2704C3DC0A4", + "representative": "xrb_39btdfmday591jcu6igpqd3x9ziwqfz9pzocacht1fp4g385ui76a87x6phk", + "account": "xrb_39btdfmday591jcu6igpqd3x9ziwqfz9pzocacht1fp4g385ui76a87x6phk", + "work": "6eb12d4c42dba31e", + "signature": "BD0D374FCEB33EAABDF728E9B4DCDBF3B226DA97EEAB8EA5B7EDE286B1282C24D6EB544644FE871235E4F58CD94DF66D9C555309895F67A7D1F922AAC12CE907" })%%%"; char const * live_genesis_data = R"%%%({ - "type": "open", - "source": "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA", - "representative": "xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3", - "account": "xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3", - "work": "62f05417dd3fb691", - "signature": "9F0C933C8ADE004D808EA1985FA746A7E95BA2A38F867640F53EC8F180BDFE9E2C1268DEAD7C2664F356E37ABA362BC58E46DBA03E523A7B5A19E4B6EB12BB02" + "type": "open", + "source": "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA", + "representative": "xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3", + "account": "xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3", + "work": "62f05417dd3fb691", + "signature": "9F0C933C8ADE004D808EA1985FA746A7E95BA2A38F867640F53EC8F180BDFE9E2C1268DEAD7C2664F356E37ABA362BC58E46DBA03E523A7B5A19E4B6EB12BB02" })%%%"; class ledger_constants @@ -206,7 +206,7 @@ rai::tally_result rai::votes::vote (std::shared_ptr vote_a) // Create a new random keypair rai::keypair::keypair () { - random_pool.GenerateBlock (prv.data.bytes.data (), prv.data.bytes.size ()); + random_pool.GenerateBlock (prv.data.bytes.data (), prv.data.bytes.size ()); ed25519_publickey (prv.data.bytes.data (), pub.bytes.data ()); } @@ -227,8 +227,8 @@ inactive_supply (inactive_supply_a) // Serialize a block prefixed with an 8-bit typecode void rai::serialize_block (rai::stream & stream_a, rai::block const & block_a) { - write (stream_a, block_a.type ()); - block_a.serialize (stream_a); + write (stream_a, block_a.type ()); + block_a.serialize (stream_a); } std::unique_ptr rai::deserialize_block (MDB_val const & val_a) @@ -266,22 +266,22 @@ block_count (block_count_a) void rai::account_info::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, block_count); + write (stream_a, balance.bytes); + write (stream_a, modified); + write (stream_a, block_count); } bool rai::account_info::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) { @@ -295,19 +295,19 @@ bool rai::account_info::deserialize (rai::stream & stream_a) } } } - } - } - return result; + } + } + return result; } bool rai::account_info::operator == (rai::account_info const & other_a) const { - return head == other_a.head && rep_block == other_a.rep_block && open_block == other_a.open_block && balance == other_a.balance && modified == other_a.modified && block_count == other_a.block_count; + return head == other_a.head && rep_block == other_a.rep_block && open_block == other_a.open_block && balance == other_a.balance && modified == other_a.modified && block_count == other_a.block_count; } bool rai::account_info::operator != (rai::account_info const & other_a) const { - return ! (*this == other_a); + return ! (*this == other_a); } rai::mdb_val rai::account_info::val () const @@ -329,12 +329,12 @@ void rai::store_entry::clear () rai::store_entry * rai::store_entry::operator -> () { - return this; + return this; } rai::store_entry & rai::store_iterator::operator -> () { - return current; + return current; } rai::store_iterator::store_iterator (MDB_txn * transaction_a, MDB_dbi db_a) : @@ -402,7 +402,7 @@ rai::store_iterator & rai::store_iterator::operator ++ () { current.clear (); } - return *this; + return *this; } void rai::store_iterator::next_dup () @@ -439,7 +439,7 @@ bool rai::store_iterator::operator == (rai::store_iterator const & other_a) cons bool rai::store_iterator::operator != (rai::store_iterator const & other_a) const { - return !(*this == other_a); + return !(*this == other_a); } rai::block_counts::block_counts () : @@ -589,14 +589,14 @@ void rai::block_store::upgrade_v1_to_v2 (MDB_txn * transaction_a) class representative_visitor : public rai::block_visitor { public: - representative_visitor (MDB_txn * transaction_a, rai::block_store & store_a) : + representative_visitor (MDB_txn * transaction_a, rai::block_store & store_a) : transaction (transaction_a), - store (store_a), + store (store_a), result (0) - { - } - void compute (rai::block_hash const & hash_a) - { + { + } + void compute (rai::block_hash const & hash_a) + { current = hash_a; while (result.is_zero ()) { @@ -604,27 +604,27 @@ public: assert (block != nullptr); block->visit (*this); } - } - void send_block (rai::send_block const & block_a) override - { - current = block_a.previous (); - } - void receive_block (rai::receive_block const & block_a) override - { + } + void send_block (rai::send_block const & block_a) override + { current = block_a.previous (); - } - void open_block (rai::open_block const & block_a) override - { - result = block_a.hash (); - } - void change_block (rai::change_block const & block_a) override - { - result = block_a.hash (); - } + } + void receive_block (rai::receive_block const & block_a) override + { + current = block_a.previous (); + } + void open_block (rai::open_block const & block_a) override + { + result = block_a.hash (); + } + void change_block (rai::change_block const & block_a) override + { + result = block_a.hash (); + } MDB_txn * transaction; - rai::block_store & store; + rai::block_store & store; rai::block_hash current; - rai::block_hash result; + rai::block_hash result; }; void rai::block_store::upgrade_v2_to_v3 (MDB_txn * transaction_a) @@ -1077,7 +1077,7 @@ rai::block_counts rai::block_store::block_count (MDB_txn * transaction_a) void rai::block_store::account_del (MDB_txn * transaction_a, rai::account const & account_a) { auto status (mdb_del (transaction_a, accounts, rai::mdb_val (account_a), nullptr)); - assert (status == 0); + assert (status == 0); } bool rai::block_store::account_exists (MDB_txn * transaction_a, rai::account const & account_a) @@ -1142,19 +1142,19 @@ size_t rai::block_store::frontier_count (MDB_txn * transaction_a) void rai::block_store::account_put (MDB_txn * transaction_a, rai::account const & account_a, rai::account_info const & info_a) { auto status (mdb_put (transaction_a, accounts, rai::mdb_val (account_a), info_a.val (), 0)); - assert (status == 0); + assert (status == 0); } void rai::block_store::pending_put (MDB_txn * transaction_a, rai::pending_key const & key_a, rai::pending_info const & pending_a) { auto status (mdb_put (transaction_a, pending, key_a.val (), pending_a.val (), 0)); - assert (status == 0); + assert (status == 0); } void rai::block_store::pending_del (MDB_txn * transaction_a, rai::pending_key const & key_a) { auto status (mdb_del (transaction_a, pending, key_a.val (), nullptr)); - assert (status == 0); + assert (status == 0); } bool rai::block_store::pending_exists (MDB_txn * transaction_a, rai::pending_key const & key_a) @@ -1194,14 +1194,14 @@ rai::store_iterator rai::block_store::pending_begin (MDB_txn * transaction_a, ra rai::store_iterator rai::block_store::pending_begin (MDB_txn * transaction_a) { - rai::store_iterator result (transaction_a, pending); - return result; + rai::store_iterator result (transaction_a, pending); + return result; } rai::store_iterator rai::block_store::pending_end () { - rai::store_iterator result (nullptr); - return result; + rai::store_iterator result (nullptr); + return result; } rai::pending_info::pending_info () : @@ -1225,23 +1225,23 @@ amount (amount_a) void rai::pending_info::serialize (rai::stream & stream_a) const { - rai::write (stream_a, source.bytes); - rai::write (stream_a, amount.bytes); + rai::write (stream_a, source.bytes); + rai::write (stream_a, amount.bytes); } bool rai::pending_info::deserialize (rai::stream & stream_a) { - auto result (rai::read (stream_a, source.bytes)); - if (!result) - { - result = rai::read (stream_a, amount.bytes); - } - return result; + auto result (rai::read (stream_a, source.bytes)); + if (!result) + { + result = rai::read (stream_a, amount.bytes); + } + return result; } bool rai::pending_info::operator == (rai::pending_info const & other_a) const { - return source == other_a.source && amount == other_a.amount; + return source == other_a.source && amount == other_a.amount; } rai::mdb_val rai::pending_info::val () const @@ -1291,7 +1291,7 @@ rai::mdb_val rai::pending_key::val () const void rai::block_store::block_info_put (MDB_txn * transaction_a, rai::block_hash const & hash_a, rai::block_info const & block_info_a) { auto status (mdb_put (transaction_a, blocks_info, rai::mdb_val (hash_a), block_info_a.val (), 0)); - assert (status == 0); + assert (status == 0); } void rai::block_store::block_info_del (MDB_txn * transaction_a, rai::block_hash const & hash_a) @@ -1337,14 +1337,14 @@ rai::store_iterator rai::block_store::block_info_begin (MDB_txn * transaction_a, rai::store_iterator rai::block_store::block_info_begin (MDB_txn * transaction_a) { - rai::store_iterator result (transaction_a, blocks_info); - return result; + rai::store_iterator result (transaction_a, blocks_info); + return result; } rai::store_iterator rai::block_store::block_info_end () { - rai::store_iterator result (nullptr); - return result; + rai::store_iterator result (nullptr); + return result; } rai::block_info::block_info () : @@ -1374,17 +1374,17 @@ void rai::block_info::serialize (rai::stream & stream_a) const bool rai::block_info::deserialize (rai::stream & stream_a) { - auto result (rai::read (stream_a, account.bytes)); - if (!result) - { - result = rai::read (stream_a, balance.bytes); - } - return result; + auto result (rai::read (stream_a, account.bytes)); + if (!result) + { + result = rai::read (stream_a, balance.bytes); + } + return result; } bool rai::block_info::operator == (rai::block_info const & other_a) const { - return account == other_a.account && balance == other_a.balance; + return account == other_a.account && balance == other_a.balance; } rai::mdb_val rai::block_info::val () const @@ -1456,8 +1456,8 @@ std::vector > rai::block_store::unchecked_get (MDB_ } for (auto i (unchecked_begin (transaction_a, hash_a)), n (unchecked_end ()); i != n && rai::block_hash (i->first.uint256 ()) == hash_a; i.next_dup ()) { - rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size()); - result.push_back (rai::deserialize_block (stream)); + rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size()); + result.push_back (rai::deserialize_block (stream)); } return result; } @@ -1478,19 +1478,19 @@ void rai::block_store::unchecked_del (MDB_txn * transaction_a, rai::block_hash c } } } - std::vector vector; - { - rai::vectorstream stream (vector); - rai::serialize_block (stream, block_a); - } + std::vector vector; + { + rai::vectorstream stream (vector); + rai::serialize_block (stream, block_a); + } auto status (mdb_del (transaction_a, unchecked, rai::mdb_val (hash_a), rai::mdb_val (vector.size (), vector.data ()))); assert (status == 0 || status == MDB_NOTFOUND); } rai::store_iterator rai::block_store::unchecked_begin (MDB_txn * transaction_a) { - rai::store_iterator result (transaction_a, unchecked); - return result; + rai::store_iterator result (transaction_a, unchecked); + return result; } rai::store_iterator rai::block_store::unchecked_begin (MDB_txn * transaction_a, rai::block_hash const & hash_a) @@ -1501,8 +1501,8 @@ rai::store_iterator rai::block_store::unchecked_begin (MDB_txn * transaction_a, rai::store_iterator rai::block_store::unchecked_end () { - rai::store_iterator result (nullptr); - return result; + rai::store_iterator result (nullptr); + return result; } size_t rai::block_store::unchecked_count (MDB_txn * transaction_a) @@ -1534,7 +1534,7 @@ bool rai::block_store::unsynced_exists (MDB_txn * transaction_a, rai::block_hash rai::store_iterator rai::block_store::unsynced_begin (MDB_txn * transaction_a) { - return rai::store_iterator (transaction_a, unsynced); + return rai::store_iterator (transaction_a, unsynced); } rai::store_iterator rai::block_store::unsynced_begin (MDB_txn * transaction_a, rai::uint256_union const & val_a) @@ -1725,25 +1725,25 @@ namespace class root_visitor : public rai::block_visitor { public: - root_visitor (rai::block_store & store_a) : - store (store_a) - { - } - void send_block (rai::send_block const & block_a) override - { - result = block_a.previous (); - } - void receive_block (rai::receive_block const & block_a) override - { - result = block_a.previous (); - } - // Open blocks have no previous () so we use the account number - void open_block (rai::open_block const & block_a) override - { + root_visitor (rai::block_store & store_a) : + store (store_a) + { + } + void send_block (rai::send_block const & block_a) override + { + result = block_a.previous (); + } + void receive_block (rai::receive_block const & block_a) override + { + result = block_a.previous (); + } + // Open blocks have no previous () so we use the account number + void open_block (rai::open_block const & block_a) override + { rai::transaction transaction (store.environment, nullptr, false); - auto hash (block_a.source ()); - auto source (store.block_get (transaction, hash)); - if (source != nullptr) + auto hash (block_a.source ()); + auto source (store.block_get (transaction, hash)); + if (source != nullptr) { auto send (dynamic_cast (source.get ())); if (send != nullptr) @@ -1759,32 +1759,32 @@ public: { result.clear (); } - } - void change_block (rai::change_block const & block_a) override - { - result = block_a.previous (); - } - rai::block_store & store; - rai::block_hash result; + } + void change_block (rai::change_block const & block_a) override + { + result = block_a.previous (); + } + rai::block_store & store; + rai::block_hash result; }; } rai::store_iterator rai::block_store::latest_begin (MDB_txn * transaction_a, rai::account const & account_a) { - rai::store_iterator result (transaction_a, accounts, rai::mdb_val (account_a)); - return result; + rai::store_iterator result (transaction_a, accounts, rai::mdb_val (account_a)); + return result; } rai::store_iterator rai::block_store::latest_begin (MDB_txn * transaction_a) { - rai::store_iterator result (transaction_a, accounts); - return result; + rai::store_iterator result (transaction_a, accounts); + return result; } rai::store_iterator rai::block_store::latest_end () { - rai::store_iterator result (nullptr); - return result; + rai::store_iterator result (nullptr); + return result; } namespace @@ -1792,46 +1792,46 @@ namespace class ledger_processor : public rai::block_visitor { public: - ledger_processor (rai::ledger &, MDB_txn *); - void send_block (rai::send_block const &) override; - void receive_block (rai::receive_block const &) override; - void open_block (rai::open_block const &) override; - void change_block (rai::change_block const &) override; - rai::ledger & ledger; + ledger_processor (rai::ledger &, MDB_txn *); + void send_block (rai::send_block const &) override; + void receive_block (rai::receive_block const &) override; + void open_block (rai::open_block const &) override; + void change_block (rai::change_block const &) override; + rai::ledger & ledger; MDB_txn * transaction; - rai::process_return result; + rai::process_return result; }; // Determine the amount delta resultant from this block class amount_visitor : public rai::block_visitor { public: - amount_visitor (MDB_txn *, rai::block_store &); - void compute (rai::block_hash const &); - void send_block (rai::send_block const &) override; - void receive_block (rai::receive_block const &) override; - void open_block (rai::open_block const &) override; - void change_block (rai::change_block const &) override; - void from_send (rai::block_hash const &); + amount_visitor (MDB_txn *, rai::block_store &); + void compute (rai::block_hash const &); + void send_block (rai::send_block const &) override; + void receive_block (rai::receive_block const &) override; + void open_block (rai::open_block const &) override; + void change_block (rai::change_block const &) override; + void from_send (rai::block_hash const &); MDB_txn * transaction; - rai::block_store & store; - rai::uint128_t result; + rai::block_store & store; + rai::uint128_t result; }; // Determine the balance as of this block class balance_visitor : public rai::block_visitor { public: - balance_visitor (MDB_txn *, rai::block_store &); - void compute (rai::block_hash const &); - void send_block (rai::send_block const &) override; - void receive_block (rai::receive_block const &) override; - void open_block (rai::open_block const &) override; - void change_block (rai::change_block const &) override; + balance_visitor (MDB_txn *, rai::block_store &); + void compute (rai::block_hash const &); + void send_block (rai::send_block const &) override; + void receive_block (rai::receive_block const &) override; + void open_block (rai::open_block const &) override; + void change_block (rai::change_block const &) override; MDB_txn * transaction; - rai::block_store & store; + rai::block_store & store; rai::block_hash current; - rai::uint128_t result; + rai::uint128_t result; }; amount_visitor::amount_visitor (MDB_txn * transaction_a, rai::block_store & store_a) : @@ -1842,14 +1842,14 @@ store (store_a) void amount_visitor::send_block (rai::send_block const & block_a) { - balance_visitor prev (transaction, store); - prev.compute (block_a.hashables.previous); - result = prev.result - block_a.hashables.balance.number (); + balance_visitor prev (transaction, store); + prev.compute (block_a.hashables.previous); + result = prev.result - block_a.hashables.balance.number (); } void amount_visitor::receive_block (rai::receive_block const & block_a) { - from_send (block_a.hashables.source); + from_send (block_a.hashables.source); } void amount_visitor::open_block (rai::open_block const & block_a) @@ -1871,8 +1871,8 @@ void amount_visitor::change_block (rai::change_block const & block_a) void amount_visitor::from_send (rai::block_hash const & hash_a) { - auto source_block (store.block_get (transaction, hash_a)); - assert (source_block != nullptr); + auto source_block (store.block_get (transaction, hash_a)); + assert (source_block != nullptr); source_block->visit (*this); } @@ -1886,7 +1886,7 @@ result (0) void balance_visitor::send_block (rai::send_block const & block_a) { - result += block_a.hashables.balance.number (); + result += block_a.hashables.balance.number (); current = 0; } @@ -1908,9 +1908,9 @@ void balance_visitor::receive_block (rai::receive_block const & block_a) void balance_visitor::open_block (rai::open_block const & block_a) { - amount_visitor source (transaction, store); - source.compute (block_a.hashables.source); - result += source.result; + amount_visitor source (transaction, store); + source.compute (block_a.hashables.source); + result += source.result; current = 0; } @@ -1931,13 +1931,13 @@ void balance_visitor::change_block (rai::change_block const & block_a) class rollback_visitor : public rai::block_visitor { public: - rollback_visitor (MDB_txn * transaction_a, rai::ledger & ledger_a) : + rollback_visitor (MDB_txn * transaction_a, rai::ledger & ledger_a) : transaction (transaction_a), - ledger (ledger_a) - { - } - void send_block (rai::send_block const & block_a) override - { + ledger (ledger_a) + { + } + void send_block (rai::send_block const & block_a) override + { auto hash (block_a.hash ()); rai::pending_info pending; rai::pending_key key (block_a.hashables.destination, hash); @@ -1959,9 +1959,9 @@ public: { ledger.store.block_info_del (transaction, hash); } - } - void receive_block (rai::receive_block const & block_a) override - { + } + void receive_block (rai::receive_block const & block_a) override + { auto hash (block_a.hash ()); auto representative (ledger.representative (transaction, block_a.hashables.previous)); auto amount (ledger.amount (transaction, block_a.hashables.source)); @@ -1980,9 +1980,9 @@ public: { ledger.store.block_info_del (transaction, hash); } - } - void open_block (rai::open_block const & block_a) override - { + } + void open_block (rai::open_block const & block_a) override + { auto hash (block_a.hash ()); auto amount (ledger.amount (transaction, block_a.hashables.source)); auto destination_account (ledger.account (transaction, hash)); @@ -1991,9 +1991,9 @@ public: ledger.store.block_del (transaction, hash); ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), {ledger.account (transaction, block_a.hashables.source), amount}); ledger.store.frontier_del (transaction, hash); - } - void change_block (rai::change_block const & block_a) override - { + } + void change_block (rai::change_block const & block_a) override + { auto hash (block_a.hash ()); auto representative (ledger.representative (transaction, block_a.hashables.previous)); auto account (ledger.account (transaction, block_a.hashables.previous)); @@ -2012,15 +2012,15 @@ public: { ledger.store.block_info_del (transaction, hash); } - } + } MDB_txn * transaction; - rai::ledger & ledger; + rai::ledger & ledger; }; } void amount_visitor::compute (rai::block_hash const & block_hash) { - auto block (store.block_get (transaction, block_hash)); + auto block (store.block_get (transaction, block_hash)); if (block != nullptr) { block->visit (*this); @@ -2053,29 +2053,29 @@ void balance_visitor::compute (rai::block_hash const & block_hash) // Balance for account containing hash rai::uint128_t rai::ledger::balance (MDB_txn * transaction_a, rai::block_hash const & hash_a) { - balance_visitor visitor (transaction_a, store); - visitor.compute (hash_a); - return visitor.result; + balance_visitor visitor (transaction_a, store); + visitor.compute (hash_a); + return visitor.result; } rai::uint128_t rai::block_store::block_balance (MDB_txn * transaction_a, rai::block_hash const & hash_a) { - balance_visitor visitor (transaction_a, *this); - visitor.compute (hash_a); - return visitor.result; + balance_visitor visitor (transaction_a, *this); + visitor.compute (hash_a); + return visitor.result; } // Balance for an account by account number rai::uint128_t rai::ledger::account_balance (MDB_txn * transaction_a, rai::account const & account_a) { - rai::uint128_t result (0); - rai::account_info info; - auto none (store.account_get (transaction_a, account_a, info)); - if (!none) - { - result = info.balance.number (); - } - return result; + rai::uint128_t result (0); + rai::account_info info; + auto none (store.account_get (transaction_a, account_a, info)); + if (!none) + { + result = info.balance.number (); + } + return result; } rai::uint128_t rai::ledger::account_pending (MDB_txn * transaction_a, rai::account const & account_a) @@ -2109,16 +2109,16 @@ rai::uint128_t rai::ledger::supply (MDB_txn * transaction_a) rai::block_hash rai::ledger::representative (MDB_txn * transaction_a, rai::block_hash const & hash_a) { - auto result (representative_calculated (transaction_a, hash_a)); + auto result (representative_calculated (transaction_a, hash_a)); assert (result.is_zero () || store.block_exists (transaction_a, result)); - return result; + return result; } rai::block_hash rai::ledger::representative_calculated (MDB_txn * transaction_a, rai::block_hash const & hash_a) { - representative_visitor visitor (transaction_a, store); - visitor.compute (hash_a); - return visitor.result; + representative_visitor visitor (transaction_a, store); + visitor.compute (hash_a); + return visitor.result; } bool rai::ledger::block_exists (rai::block_hash const & hash_a) @@ -2148,23 +2148,23 @@ std::string rai::ledger::block_text (rai::block_hash const & hash_a) // Vote weight of an account rai::uint128_t rai::ledger::weight (MDB_txn * transaction_a, rai::account const & account_a) { - return store.representation_get (transaction_a, account_a); + return store.representation_get (transaction_a, account_a); } // Rollback blocks until `block_a' doesn't exist void rai::ledger::rollback (MDB_txn * transaction_a, rai::block_hash const & block_a) { assert (store.block_exists (transaction_a, block_a)); - auto account_l (account (transaction_a, block_a)); - rollback_visitor rollback (transaction_a, *this); - rai::account_info info; - while (store.block_exists (transaction_a, block_a)) - { - auto latest_error (store.account_get (transaction_a, account_l, info)); - assert (!latest_error); - auto block (store.block_get (transaction_a, info.head)); - block->visit (rollback); - } + auto account_l (account (transaction_a, block_a)); + rollback_visitor rollback (transaction_a, *this); + rai::account_info info; + while (store.block_exists (transaction_a, block_a)) + { + auto latest_error (store.account_get (transaction_a, account_l, info)); + assert (!latest_error); + auto block (store.block_get (transaction_a, info.head)); + block->visit (rollback); + } } // Return account containing hash @@ -2198,9 +2198,9 @@ rai::account rai::ledger::account (MDB_txn * transaction_a, rai::block_hash cons // Return amount decrease or increase for block rai::uint128_t rai::ledger::amount (MDB_txn * transaction_a, rai::block_hash const & hash_a) { - amount_visitor amount (transaction_a, store); - amount.compute (hash_a); - return amount.result; + amount_visitor amount (transaction_a, store); + amount.compute (hash_a); + return amount.result; } void rai::block_store::representation_add (MDB_txn * transaction_a, rai::block_hash const & source_a, rai::uint128_t const & amount_a) @@ -2209,86 +2209,86 @@ void rai::block_store::representation_add (MDB_txn * transaction_a, rai::block_h assert (source_block != nullptr); auto source_rep (source_block->representative ()); assert (!source_rep.is_zero ()); - auto source_previous (representation_get (transaction_a, source_rep)); - representation_put (transaction_a, source_rep, source_previous + amount_a); + auto source_previous (representation_get (transaction_a, source_rep)); + representation_put (transaction_a, source_rep, source_previous + amount_a); } // Return latest block for account rai::block_hash rai::ledger::latest (MDB_txn * transaction_a, rai::account const & account_a) { - rai::account_info info; - auto latest_error (store.account_get (transaction_a, account_a, info)); + rai::account_info info; + auto latest_error (store.account_get (transaction_a, account_a, info)); return latest_error ? 0 : info.head; } // Return latest root for account, account number of there are no blocks for this account. rai::block_hash rai::ledger::latest_root (MDB_txn * transaction_a, rai::account const & account_a) { - rai::account_info info; - auto latest_error (store.account_get (transaction_a, account_a, info)); - rai::block_hash result; - if (latest_error) - { - result = account_a; - } - else - { - result = info.head; - } - return result; + rai::account_info info; + auto latest_error (store.account_get (transaction_a, account_a, info)); + rai::block_hash result; + if (latest_error) + { + result = account_a; + } + else + { + result = info.head; + } + return result; } rai::checksum rai::ledger::checksum (MDB_txn * transaction_a, rai::account const & begin_a, rai::account const & end_a) { - rai::checksum result; - auto error (store.checksum_get (transaction_a, 0, 0, result)); - assert (!error); - return result; + rai::checksum result; + auto error (store.checksum_get (transaction_a, 0, 0, result)); + assert (!error); + return result; } void rai::ledger::dump_account_chain (rai::account const & account_a) { rai::transaction transaction (store.environment, nullptr, false); - auto hash (latest (transaction, account_a)); - while (!hash.is_zero ()) - { - auto block (store.block_get (transaction, hash)); - assert (block != nullptr); - std::cerr << hash.to_string () << std::endl; - hash = block->previous (); - } + auto hash (latest (transaction, account_a)); + while (!hash.is_zero ()) + { + auto block (store.block_get (transaction, hash)); + assert (block != nullptr); + std::cerr << hash.to_string () << std::endl; + hash = block->previous (); + } } void rai::ledger::checksum_update (MDB_txn * transaction_a, rai::block_hash const & hash_a) { rai::checksum value; - auto error (store.checksum_get (transaction_a, 0, 0, value)); - assert (!error); - value ^= hash_a; - store.checksum_put (transaction_a, 0, 0, value); + auto error (store.checksum_get (transaction_a, 0, 0, value)); + assert (!error); + value ^= hash_a; + store.checksum_put (transaction_a, 0, 0, value); } void rai::ledger::change_latest (MDB_txn * transaction_a, rai::account const & account_a, rai::block_hash const & hash_a, rai::block_hash const & rep_block_a, rai::amount const & balance_a, uint64_t block_count_a) { - rai::account_info info; - auto exists (!store.account_get (transaction_a, account_a, info)); - if (exists) - { - checksum_update (transaction_a, info.head); - } + rai::account_info info; + auto exists (!store.account_get (transaction_a, account_a, info)); + if (exists) + { + checksum_update (transaction_a, info.head); + } else { assert (dynamic_cast (store.block_get (transaction_a, hash_a).get ()) != nullptr); info.open_block = hash_a; } - if (!hash_a.is_zero()) - { - info.head = hash_a; - info.rep_block = rep_block_a; - info.balance = balance_a; - info.modified = store.now (); + if (!hash_a.is_zero()) + { + info.head = hash_a; + info.rep_block = rep_block_a; + info.balance = balance_a; + info.modified = store.now (); info.block_count = block_count_a; - store.account_put (transaction_a, account_a, info); + store.account_put (transaction_a, account_a, info); if (!(block_count_a % store.block_info_max)) { rai::block_info block_info; @@ -2296,18 +2296,18 @@ void rai::ledger::change_latest (MDB_txn * transaction_a, rai::account const & a block_info.balance = balance_a; store.block_info_put (transaction_a, hash_a, block_info); } - checksum_update (transaction_a, hash_a); - } - else - { - store.account_del (transaction_a, account_a); - } + checksum_update (transaction_a, hash_a); + } + else + { + store.account_del (transaction_a, account_a); + } } std::unique_ptr rai::ledger::successor (MDB_txn * transaction_a, rai::block_hash const & block_a) { - assert (store.account_exists (transaction_a, block_a) || store.block_exists (transaction_a, block_a)); - assert (store.account_exists (transaction_a, block_a) || latest (transaction_a, account (transaction_a, block_a)) != block_a); + assert (store.account_exists (transaction_a, block_a) || store.block_exists (transaction_a, block_a)); + assert (store.account_exists (transaction_a, block_a) || latest (transaction_a, account (transaction_a, block_a)) != block_a); rai::block_hash successor; if (store.account_exists (transaction_a, block_a)) { @@ -2323,7 +2323,7 @@ std::unique_ptr rai::ledger::successor (MDB_txn * transaction_a, ra assert (!successor.is_zero ()); auto result (store.block_get (transaction_a, successor)); assert (result != nullptr); - return result; + return result; } std::unique_ptr rai::ledger::forked_block (MDB_txn * transaction_a, rai::block const & block_a) @@ -2345,16 +2345,16 @@ std::unique_ptr rai::ledger::forked_block (MDB_txn * transaction_a, void ledger_processor::change_block (rai::change_block const & block_a) { - auto hash (block_a.hash ()); - auto existing (ledger.store.block_exists (transaction, hash)); - result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block before? (Harmless) - if (result.code == rai::process_result::progress) - { - auto previous (ledger.store.block_exists (transaction, block_a.hashables.previous)); - result.code = previous ? rai::process_result::progress : rai::process_result::gap_previous; // Have we seen the previous block already? (Harmless) - if (result.code == rai::process_result::progress) - { - auto account (ledger.store.frontier_get (transaction, block_a.hashables.previous)); + auto hash (block_a.hash ()); + auto existing (ledger.store.block_exists (transaction, hash)); + result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block before? (Harmless) + if (result.code == rai::process_result::progress) + { + auto previous (ledger.store.block_exists (transaction, block_a.hashables.previous)); + result.code = previous ? rai::process_result::progress : rai::process_result::gap_previous; // Have we seen the previous block already? (Harmless) + if (result.code == rai::process_result::progress) + { + auto account (ledger.store.frontier_get (transaction, block_a.hashables.previous)); result.code = account.is_zero () ? rai::process_result::fork : rai::process_result::progress; if (result.code == rai::process_result::progress) { @@ -2376,22 +2376,22 @@ void ledger_processor::change_block (rai::change_block const & block_a) result.amount = 0; } } - } - } + } + } } void ledger_processor::send_block (rai::send_block const & block_a) { - auto hash (block_a.hash ()); - auto existing (ledger.store.block_exists (transaction, hash)); - result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block before? (Harmless) - if (result.code == rai::process_result::progress) - { - auto previous (ledger.store.block_exists (transaction, block_a.hashables.previous)); - result.code = previous ? rai::process_result::progress : rai::process_result::gap_previous; // Have we seen the previous block already? (Harmless) - if (result.code == rai::process_result::progress) - { - auto account (ledger.store.frontier_get (transaction, block_a.hashables.previous)); + auto hash (block_a.hash ()); + auto existing (ledger.store.block_exists (transaction, hash)); + result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block before? (Harmless) + if (result.code == rai::process_result::progress) + { + auto previous (ledger.store.block_exists (transaction, block_a.hashables.previous)); + result.code = previous ? rai::process_result::progress : rai::process_result::gap_previous; // Have we seen the previous block already? (Harmless) + if (result.code == rai::process_result::progress) + { + auto account (ledger.store.frontier_get (transaction, block_a.hashables.previous)); result.code = account.is_zero () ? rai::process_result::fork : rai::process_result::progress; if (result.code == rai::process_result::progress) { @@ -2417,20 +2417,20 @@ void ledger_processor::send_block (rai::send_block const & block_a) } } } - } - } + } + } } void ledger_processor::receive_block (rai::receive_block const & block_a) { - auto hash (block_a.hash ()); - auto existing (ledger.store.block_exists (transaction, hash)); - result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block already? (Harmless) - if (result.code == rai::process_result::progress) - { - result.code = ledger.store.block_exists (transaction, block_a.hashables.source) ? rai::process_result::progress: rai::process_result::gap_source; // Have we seen the source block already? (Harmless) - if (result.code == rai::process_result::progress) - { + auto hash (block_a.hash ()); + auto existing (ledger.store.block_exists (transaction, hash)); + result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block already? (Harmless) + if (result.code == rai::process_result::progress) + { + result.code = ledger.store.block_exists (transaction, block_a.hashables.source) ? rai::process_result::progress: rai::process_result::gap_source; // Have we seen the source block already? (Harmless) + if (result.code == rai::process_result::progress) + { auto account (ledger.store.frontier_get (transaction, block_a.hashables.previous)); result.code = account.is_zero () ? rai::process_result::gap_previous : rai::process_result::progress; //Have we seen the previous block? No entries for account at all (Harmless) if (result.code == rai::process_result::progress) @@ -2448,10 +2448,10 @@ void ledger_processor::receive_block (rai::receive_block const & block_a) result.code = ledger.store.pending_get (transaction, key, pending) ? rai::process_result::unreceivable : rai::process_result::progress; // Has this source already been received (Malformed) if (result.code == rai::process_result::progress) { - auto new_balance (info.balance.number () + pending.amount.number ()); - rai::account_info source_info; - auto error (ledger.store.account_get (transaction, pending.source, source_info)); - assert (!error); + auto new_balance (info.balance.number () + pending.amount.number ()); + rai::account_info source_info; + auto error (ledger.store.account_get (transaction, pending.source, source_info)); + assert (!error); ledger.store.pending_del (transaction, key); ledger.store.block_put (transaction, hash, block_a); ledger.change_latest (transaction, account, hash, info.rep_block, new_balance, info.block_count + 1); @@ -2460,29 +2460,29 @@ void ledger_processor::receive_block (rai::receive_block const & block_a) ledger.store.frontier_put (transaction, hash, account); result.account = account; result.amount = pending.amount; - } - } - } - } + } + } + } + } else { result.code = ledger.store.block_exists (transaction, block_a.hashables.previous) ? rai::process_result::fork : rai::process_result::gap_previous; // If we have the block but it's not the latest we have a signed fork (Malicious) } - } - } + } + } } void ledger_processor::open_block (rai::open_block const & block_a) { - auto hash (block_a.hash ()); - auto existing (ledger.store.block_exists (transaction, hash)); - result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block already? (Harmless) - if (result.code == rai::process_result::progress) - { - auto source_missing (!ledger.store.block_exists (transaction, block_a.hashables.source)); - result.code = source_missing ? rai::process_result::gap_source : rai::process_result::progress; // Have we seen the source block? (Harmless) - if (result.code == rai::process_result::progress) - { + auto hash (block_a.hash ()); + auto existing (ledger.store.block_exists (transaction, hash)); + result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block already? (Harmless) + if (result.code == rai::process_result::progress) + { + auto source_missing (!ledger.store.block_exists (transaction, block_a.hashables.source)); + result.code = source_missing ? rai::process_result::gap_source : rai::process_result::progress; // Have we seen the source block? (Harmless) + if (result.code == rai::process_result::progress) + { result.code = rai::validate_message (block_a.hashables.account, hash, block_a.signature) ? rai::process_result::bad_signature : rai::process_result::progress; // Is the signature valid (Malformed) if (result.code == rai::process_result::progress) { @@ -2512,8 +2512,8 @@ void ledger_processor::open_block (rai::open_block const & block_a) } } } - } - } + } + } } ledger_processor::ledger_processor (rai::ledger & ledger_a, MDB_txn * transaction_a) : @@ -2595,18 +2595,18 @@ rai::vote::vote (MDB_val const & value_a) rai::uint256_union rai::vote::hash () const { - rai::uint256_union result; - blake2b_state hash; + rai::uint256_union result; + blake2b_state hash; blake2b_init (&hash, sizeof (result.bytes)); - blake2b_update (&hash, block->hash ().bytes.data (), sizeof (result.bytes)); - union { - uint64_t qword; - std::array bytes; - }; - qword = sequence; - blake2b_update (&hash, bytes.data (), sizeof (bytes)); - blake2b_final (&hash, result.bytes.data (), sizeof (result.bytes)); - return result; + blake2b_update (&hash, block->hash ().bytes.data (), sizeof (result.bytes)); + union { + uint64_t qword; + std::array bytes; + }; + qword = sequence; + blake2b_update (&hash, bytes.data (), sizeof (bytes)); + blake2b_final (&hash, result.bytes.data (), sizeof (result.bytes)); + return result; } void rai::vote::serialize (rai::stream & stream_a, rai::block_type) @@ -2648,5 +2648,5 @@ void rai::genesis::initialize (MDB_txn * transaction_a, rai::block_store & store rai::block_hash rai::genesis::hash () const { - return open->hash (); + return open->hash (); } diff --git a/rai/slow_test/node.cpp b/rai/slow_test/node.cpp index 6dc3308a..d72b3f85 100644 --- a/rai/slow_test/node.cpp +++ b/rai/slow_test/node.cpp @@ -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 (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 (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); for (auto i (0); i < 1000000; ++i) diff --git a/rai/versioning.cpp b/rai/versioning.cpp index 8762ecbf..fd0bc945 100644 --- a/rai/versioning.cpp +++ b/rai/versioning.cpp @@ -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