diff --git a/rai/core_test/node.cpp b/rai/core_test/node.cpp index 91f151ef..906b959d 100644 --- a/rai/core_test/node.cpp +++ b/rai/core_test/node.cpp @@ -600,45 +600,6 @@ TEST (node_config, v1_v2_upgrade) ASSERT_TRUE (!!tree.get_child_optional ("work_peers")); } -TEST (node_config, unversioned_v2_upgrade) -{ - auto path (rai::unique_path ()); - rai::logging logging1; - logging1.init (path); - boost::property_tree::ptree tree; - tree.put ("peering_port", std::to_string (0)); - tree.put ("packet_delay_microseconds", std::to_string (0)); - tree.put ("bootstrap_fraction_numerator", std::to_string (0)); - tree.put ("creation_rebroadcast", std::to_string (0)); - tree.put ("rebroadcast_delay", std::to_string (0)); - tree.put ("receive_minimum", rai::amount (0).to_string_dec ()); - boost::property_tree::ptree logging_l; - logging1.serialize_json (logging_l); - tree.add_child ("logging", logging_l); - boost::property_tree::ptree preconfigured_peers_l; - tree.add_child ("preconfigured_peers", preconfigured_peers_l); - boost::property_tree::ptree preconfigured_representatives_l; - boost::property_tree::ptree entry; - entry.put ("", "TR6ZJ4pdp6HC76xMRpVDny5x2s8AEbrhFue3NKVxYYdmKuTEib"); - preconfigured_representatives_l.push_back (std::make_pair ("", entry)); - tree.add_child ("preconfigured_representatives", preconfigured_representatives_l); - boost::property_tree::ptree work_peers_l; - tree.add_child ("work_peers", work_peers_l); - bool upgraded (false); - rai::node_config config1; - config1.logging.init (path); - ASSERT_FALSE (tree.get_optional ("version")); - config1.deserialize_json (upgraded, tree); - ASSERT_TRUE (upgraded); - ASSERT_EQ (1, config1.preconfigured_representatives.size ()); - ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", config1.preconfigured_representatives[0].to_account ()); - auto reps (tree.get_child ("preconfigured_representatives")); - ASSERT_EQ (1, reps.size ()); - ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", reps.begin ()->second.get ("")); - auto version (tree.get ("version")); - ASSERT_GT (std::stoull (version), 1); -} - TEST (node_config, v2_v3_upgrade) { auto path (rai::unique_path ()); diff --git a/rai/core_test/uint256_union.cpp b/rai/core_test/uint256_union.cpp index cffe1e82..fc5eb44a 100644 --- a/rai/core_test/uint256_union.cpp +++ b/rai/core_test/uint256_union.cpp @@ -307,11 +307,11 @@ TEST (uint256_union, big_endian_union_function) ASSERT_EQ (rai::uint512_t (1), bytes2.number ()); } -TEST (uint256_union, decode_account_v1) +TEST (uint256_union, decode_nano_variant) { rai::uint256_union key; - ASSERT_FALSE (key.decode_account ("TR6ZJ4pdp6HC76xMRpVDny5x2s8AEbrhFue3NKVxYYdmKuTEib")); - ASSERT_EQ (rai::rai_test_account, key); + ASSERT_FALSE (key.decode_account ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp")); + ASSERT_FALSE (key.decode_account ("nano_1111111111111111111111111111111111111111111111111111hifc8npp")); } TEST (uint256_union, decode_account_variations) diff --git a/rai/lib/numbers.cpp b/rai/lib/numbers.cpp index 146b6f06..fcac09eb 100644 --- a/rai/lib/numbers.cpp +++ b/rai/lib/numbers.cpp @@ -73,89 +73,59 @@ std::string rai::uint256_union::to_account () const return result; } -bool rai::uint256_union::decode_account_v1 (std::string const & source_a) -{ - auto error (source_a.size () != 50); - if (!error) - { - rai::uint512_t number_l; - for (auto i (source_a.begin ()), j (source_a.end ()); !error && i != j; ++i) - { - uint8_t character (*i); - error = character < 0x30 || character >= 0x80; - if (!error) - { - uint8_t byte (base58_decode (character)); - error = byte == '~'; - if (!error) - { - number_l *= 58; - number_l += byte; - } - } - } - if (!error) - { - *this = number_l.convert_to (); - error = (number_l >> (256 + 32)) != 13; - if (!error) - { - uint32_t check (number_l >> static_cast (256)); - uint32_t validation (0); - blake2b_state hash; - blake2b_init (&hash, sizeof (validation)); - blake2b_update (&hash, bytes.data (), bytes.size ()); - blake2b_final (&hash, reinterpret_cast (&validation), sizeof (validation)); - error = check != validation; - } - } - } - return error; -} - bool rai::uint256_union::decode_account (std::string const & source_a) { - auto error (source_a.size () != 64); + auto error (source_a.size () < 5); if (!error) { - if (source_a[0] == 'x' && source_a[1] == 'r' && source_a[2] == 'b' && (source_a[3] == '_' || source_a[3] == '-') && (source_a[4] == '1' || source_a[4] == '3')) + auto xrb_prefix (source_a[0] == 'x' && source_a[1] == 'r' && source_a[2] == 'b' && (source_a[3] == '_' || source_a[3] == '-')); + auto nano_prefix (source_a[0] == 'n' && source_a[1] == 'a' && source_a[2] == 'n' && source_a[3] == 'o' && (source_a[4] == '_' || source_a[4] == '-')); + error = (xrb_prefix && source_a.size () != 64) || (nano_prefix && source_a.size () != 65); + if (!error) { - rai::uint512_t number_l; - for (auto i (source_a.begin () + 4), j (source_a.end ()); !error && i != j; ++i) + if (xrb_prefix || nano_prefix) { - uint8_t character (*i); - error = character < 0x30 || character >= 0x80; - if (!error) + auto i (source_a.begin () + (xrb_prefix ? 4 : 5)); + if (*i == '1' || *i == '3') { - uint8_t byte (account_decode (character)); - error = byte == '~'; + rai::uint512_t number_l; + for (auto j (source_a.end ()); !error && i != j; ++i) + { + uint8_t character (*i); + error = character < 0x30 || character >= 0x80; + if (!error) + { + uint8_t byte (account_decode (character)); + error = byte == '~'; + if (!error) + { + number_l <<= 5; + number_l += byte; + } + } + } if (!error) { - number_l <<= 5; - number_l += byte; + *this = (number_l >> 40).convert_to (); + uint64_t check (number_l & static_cast (0xffffffffff)); + uint64_t validation (0); + blake2b_state hash; + blake2b_init (&hash, 5); + blake2b_update (&hash, bytes.data (), bytes.size ()); + blake2b_final (&hash, reinterpret_cast (&validation), 5); + error = check != validation; } } + else + { + error = true; + } } - if (!error) + else { - *this = (number_l >> 40).convert_to (); - uint64_t check (number_l & static_cast (0xffffffffff)); - uint64_t validation (0); - blake2b_state hash; - blake2b_init (&hash, 5); - blake2b_update (&hash, bytes.data (), bytes.size ()); - blake2b_final (&hash, reinterpret_cast (&validation), 5); - error = check != validation; + error = true; } } - else - { - error = true; - } - } - else - { - error = decode_account_v1 (source_a); } return error; } diff --git a/rai/lib/numbers.hpp b/rai/lib/numbers.hpp index 0b33a77f..ede76f80 100644 --- a/rai/lib/numbers.hpp +++ b/rai/lib/numbers.hpp @@ -70,7 +70,6 @@ union uint256_union void encode_account (std::string &) const; std::string to_account () const; std::string to_account_split () const; - bool decode_account_v1 (std::string const &); bool decode_account (std::string const &); std::array bytes; std::array chars; diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index 0df614d1..abc5da3f 100644 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -894,16 +894,16 @@ void rai::bootstrap_attempt::process_fork (MDB_txn * transaction_a, std::shared_ if (!node->active.start (std::make_pair (ledger_block, block_a), [this_w, root](std::shared_ptr) { if (auto this_l = this_w.lock ()) { - rai::transaction transaction (this_l->node->store.environment, nullptr, false); - auto account (this_l->node->ledger.store.frontier_get (transaction, root)); - if (!account.is_zero ()) - { - this_l->requeue_pull (rai::pull_info (account, root, root)); - } - else if (this_l->node->ledger.store.account_exists (transaction, root)) - { - this_l->requeue_pull (rai::pull_info (root, rai::block_hash (0), rai::block_hash (0))); - } + rai::transaction transaction (this_l->node->store.environment, nullptr, false); + auto account (this_l->node->ledger.store.frontier_get (transaction, root)); + if (!account.is_zero ()) + { + this_l->requeue_pull (rai::pull_info (account, root, root)); + } + else if (this_l->node->ledger.store.account_exists (transaction, root)) + { + this_l->requeue_pull (rai::pull_info (root, rai::block_hash (0), rai::block_hash (0))); + } } })) {