Merge pull request #4465 from clemahieu/block_fields

This commit is contained in:
clemahieu 2024-03-09 12:10:04 +00:00 committed by GitHub
commit 7561a796c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 1033 additions and 1018 deletions

View file

@ -490,14 +490,14 @@ TEST (active_transactions, inactive_votes_cache_election_start)
auto send3 = send_block_builder.make_block ()
.previous (send2->hash ())
.destination (nano::keypair ().pub)
.balance (send2->balance ().number () - 1)
.balance (send2->balance_field ().value ().number () - 1)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send2->hash ()))
.build ();
auto send4 = send_block_builder.make_block ()
.previous (send3->hash ())
.destination (nano::keypair ().pub)
.balance (send3->balance ().number () - 1)
.balance (send3->balance_field ().value ().number () - 1)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send3->hash ()))
.build ();

View file

@ -33,9 +33,7 @@ TEST (backlog, population)
auto all_activated = [&] () {
nano::lock_guard<nano::mutex> lock{ mutex };
return std::all_of (blocks.begin (), blocks.end (), [&] (auto const & item) {
auto account = item->account ();
debug_assert (!account.is_zero ());
return activated.count (account) != 0;
return activated.count (item->account ()) != 0;
});
};
ASSERT_TIMELY (5s, all_activated ());

View file

@ -657,9 +657,9 @@ TEST (block_builder, state)
.link_hex ("E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F");
ASSERT_TRUE (block->source ().is_zero ());
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86");
ASSERT_FALSE (block->source_field ());
ASSERT_FALSE (block->destination_field ());
ASSERT_EQ (block->link_field ().value ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86");
}
TEST (block_builder, state_missing_rep)
@ -730,9 +730,9 @@ TEST (block_builder, open)
.source_hex ("E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948");
ASSERT_EQ (block->source ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA");
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_TRUE (block->link ().is_zero ());
ASSERT_EQ (block->source_field ().value ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA");
ASSERT_FALSE (block->destination_field ());
ASSERT_FALSE (block->link_field ());
}
TEST (block_builder, open_equality)
@ -769,9 +769,9 @@ TEST (block_builder, change)
.previous_hex ("088EE46429CA936F76C4EAA20B97F6D33E5D872971433EE0C1311BCB98764456")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077");
ASSERT_TRUE (block->source ().is_zero ());
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_TRUE (block->link ().is_zero ());
ASSERT_FALSE (block->source_field ());
ASSERT_FALSE (block->destination_field ());
ASSERT_FALSE (block->link_field ());
}
TEST (block_builder, change_equality)
@ -808,9 +808,9 @@ TEST (block_builder, send)
.balance_hex ("00F035A9C7D818E7C34148C524FFFFEE")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD");
ASSERT_TRUE (block->source ().is_zero ());
ASSERT_EQ (block->destination ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb");
ASSERT_TRUE (block->link ().is_zero ());
ASSERT_FALSE (block->source_field ());
ASSERT_EQ (block->destination_field ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb");
ASSERT_FALSE (block->link_field ());
}
TEST (block_builder, send_equality)
@ -870,7 +870,7 @@ TEST (block_builder, receive)
.source_hex ("7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135")
.build (ec);
ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722");
ASSERT_EQ (block->source ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135");
ASSERT_TRUE (block->destination ().is_zero ());
ASSERT_TRUE (block->link ().is_zero ());
ASSERT_EQ (block->source_field ().value ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135");
ASSERT_FALSE (block->destination_field ());
ASSERT_FALSE (block->link_field ());
}

View file

@ -383,7 +383,7 @@ TEST (block_store, genesis)
auto transaction (store->tx_begin_write ());
store->initialize (transaction, ledger_cache, nano::dev::constants);
nano::account_info info;
ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis->account (), info));
ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis_key.pub, info));
ASSERT_EQ (nano::dev::genesis->hash (), info.head);
auto block1 (store->block.get (transaction, info.head));
ASSERT_NE (nullptr, block1);
@ -393,13 +393,13 @@ TEST (block_store, genesis)
ASSERT_EQ (info.block_count, 1);
// Genesis block should be confirmed by default
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (store->confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info));
ASSERT_FALSE (store->confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info));
ASSERT_EQ (confirmation_height_info.height, 1);
ASSERT_EQ (confirmation_height_info.frontier, nano::dev::genesis->hash ());
auto dev_pub_text (nano::dev::genesis_key.pub.to_string ());
auto dev_pub_account (nano::dev::genesis_key.pub.to_account ());
auto dev_prv_text (nano::dev::genesis_key.prv.to_string ());
ASSERT_EQ (nano::dev::genesis->account (), nano::dev::genesis_key.pub);
ASSERT_EQ (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub);
}
TEST (block_store, empty_accounts)

View file

@ -159,7 +159,7 @@ TEST (bulk_pull, ascending_two_account)
auto socket = std::make_shared<nano::transport::socket> (node, nano::transport::socket::endpoint_type_t::server);
auto connection = std::make_shared<nano::transport::tcp_server> (socket, system.nodes[0]);
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = nano::dev::genesis->account ();
req->start = nano::dev::genesis_key.pub;
req->end.clear ();
req->header.flag_set (nano::message_header::bulk_pull_ascending_flag);
auto request = std::make_shared<nano::bulk_pull_server> (connection, std::move (req));
@ -2123,9 +2123,9 @@ TEST (bulk_pull_account, basics)
nano::keypair key1;
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
system.wallet (0)->insert_adhoc (key1.prv);
auto send1 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 25));
auto send2 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 10));
auto send3 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 2));
auto send1 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 25));
auto send2 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 10));
auto send3 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 2));
ASSERT_TIMELY_EQ (5s, system.nodes[0]->balance (key1.pub), 25);
auto connection (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0]));
@ -2143,7 +2143,7 @@ TEST (bulk_pull_account, basics)
auto block_data (request->get_next ());
ASSERT_EQ (send2->hash (), block_data.first.get ()->hash);
ASSERT_EQ (nano::uint128_union (10), block_data.second.get ()->amount);
ASSERT_EQ (nano::dev::genesis->account (), block_data.second.get ()->source);
ASSERT_EQ (nano::dev::genesis_key.pub, block_data.second.get ()->source);
ASSERT_EQ (nullptr, request->get_next ().first.get ());
}
@ -2157,7 +2157,7 @@ TEST (bulk_pull_account, basics)
auto block_data (request->get_next ());
ASSERT_NE (nullptr, block_data.first.get ());
ASSERT_NE (nullptr, block_data.second.get ());
ASSERT_EQ (nano::dev::genesis->account (), block_data.second.get ()->source);
ASSERT_EQ (nano::dev::genesis_key.pub, block_data.second.get ()->source);
block_data = request->get_next ();
ASSERT_EQ (nullptr, block_data.first.get ());
ASSERT_EQ (nullptr, block_data.second.get ());

View file

@ -133,7 +133,7 @@ TEST (confirmation_height, multiple_accounts)
auto open1 = builder
.open ()
.source (send1->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key1.pub)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1.pub))
@ -141,7 +141,7 @@ TEST (confirmation_height, multiple_accounts)
auto open2 = builder
.open ()
.source (send2->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key2.pub)
.sign (key2.prv, key2.pub)
.work (*system.work.generate (key2.pub))
@ -149,7 +149,7 @@ TEST (confirmation_height, multiple_accounts)
auto open3 = builder
.open ()
.source (send3->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key3.pub)
.sign (key3.prv, key3.pub)
.work (*system.work.generate (key3.pub))
@ -320,9 +320,9 @@ TEST (confirmation_height, gap_bootstrap)
nano::block_builder builder;
auto send1 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (destination.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -331,9 +331,9 @@ TEST (confirmation_height, gap_bootstrap)
node1.work_generate_blocking (*send1);
auto send2 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (send1->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 2 * nano::Gxrb_ratio)
.link (destination.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -342,9 +342,9 @@ TEST (confirmation_height, gap_bootstrap)
node1.work_generate_blocking (*send2);
auto send3 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (send2->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 3 * nano::Gxrb_ratio)
.link (destination.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -453,9 +453,9 @@ TEST (confirmation_height, gap_live)
nano::block_builder builder;
auto send1 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 1)
.link (destination.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -464,9 +464,9 @@ TEST (confirmation_height, gap_live)
node->work_generate_blocking (*send1);
auto send2 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (send1->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 2)
.link (destination.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -475,9 +475,9 @@ TEST (confirmation_height, gap_live)
node->work_generate_blocking (*send2);
auto send3 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (send2->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 3)
.link (destination.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -593,7 +593,7 @@ TEST (confirmation_height, send_receive_between_2_accounts)
auto open1 = builder
.open ()
.source (send1->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key1.pub)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1.pub))
@ -601,7 +601,7 @@ TEST (confirmation_height, send_receive_between_2_accounts)
auto send2 = builder
.send ()
.previous (open1->hash ())
.destination (nano::dev::genesis->account ())
.destination (nano::dev::genesis_key.pub)
.balance (1000)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (open1->hash ()))
@ -609,7 +609,7 @@ TEST (confirmation_height, send_receive_between_2_accounts)
auto send3 = builder
.send ()
.previous (send2->hash ())
.destination (nano::dev::genesis->account ())
.destination (nano::dev::genesis_key.pub)
.balance (900)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (send2->hash ()))
@ -617,7 +617,7 @@ TEST (confirmation_height, send_receive_between_2_accounts)
auto send4 = builder
.send ()
.previous (send3->hash ())
.destination (nano::dev::genesis->account ())
.destination (nano::dev::genesis_key.pub)
.balance (500)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (send3->hash ()))
@ -1013,9 +1013,9 @@ TEST (confirmation_height, all_block_types)
.build ();
auto state_receive3 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (send1->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2 + 1)
.link (state_send4->hash ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -1292,7 +1292,7 @@ TEST (confirmation_heightDeathTest, modified_chain)
}
ASSERT_EQ (nano::block_status::progress, ledger.process (store->tx_begin_write (), send));
store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis->account (), { 1, nano::dev::genesis->hash () });
store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis_key.pub, { 1, nano::dev::genesis->hash () });
nano::confirmation_height_unbounded unbounded_processor (
ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; });
@ -1381,7 +1381,7 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed)
// Reset conditions and test with the bounded processor
ASSERT_EQ (nano::block_status::progress, ledger.process (store->tx_begin_write (), open));
store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis->account (), { 1, nano::dev::genesis->hash () });
store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis_key.pub, { 1, nano::dev::genesis->hash () });
nano::confirmation_height_bounded bounded_processor (
ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; });
@ -1663,7 +1663,7 @@ TEST (confirmation_height, cemented_gap_below_receive)
auto open = builder
.open ()
.source (send->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key1.pub)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1.pub))
@ -1722,7 +1722,7 @@ TEST (confirmation_height, cemented_gap_below_receive)
auto open1 = builder
.open ()
.source (send3->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key2.pub)
.sign (key2.prv, key2.pub)
.work (*system.work.generate (key2.pub))
@ -1823,7 +1823,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache)
auto open = builder
.open ()
.source (send->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key1.pub)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1.pub))
@ -1882,7 +1882,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache)
auto open1 = builder
.open ()
.source (send3->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key2.pub)
.sign (key2.prv, key2.pub)
.work (*system.work.generate (key2.pub))
@ -1910,7 +1910,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache)
// Force some blocks to be cemented so that the cached confirmed info variable is empty
{
auto transaction (node->store.tx_begin_write ());
node->store.confirmation_height.put (transaction, nano::dev::genesis->account (), nano::confirmation_height_info{ 3, send1->hash () });
node->store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, nano::confirmation_height_info{ 3, send1->hash () });
node->store.confirmation_height.put (transaction, key1.pub, nano::confirmation_height_info{ 2, receive1->hash () });
}

View file

@ -18,10 +18,10 @@ TEST (distributed_work, no_peers)
nano::test::system system (1);
auto node (system.nodes[0]);
nano::block_hash hash{ 1 };
boost::optional<uint64_t> work;
std::optional<uint64_t> work;
std::atomic<bool> done{ false };
auto callback = [&work, &done] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
auto callback = [&work, &done] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
work = work_a;
done = true;
};
@ -54,8 +54,8 @@ TEST (distributed_work, no_peers_cancel)
auto & node = *system.add_node (node_config);
nano::block_hash hash{ 1 };
bool done{ false };
auto callback_to_cancel = [&done] (boost::optional<uint64_t> work_a) {
ASSERT_FALSE (work_a.is_initialized ());
auto callback_to_cancel = [&done] (std::optional<uint64_t> work_a) {
ASSERT_FALSE (work_a.has_value ());
done = true;
};
ASSERT_FALSE (node.distributed_work.make (nano::work_version::work_1, hash, node.config.work_peers, nano::difficulty::from_multiplier (1e6, node.network_params.work.base), callback_to_cancel));
@ -83,8 +83,8 @@ TEST (distributed_work, no_peers_multi)
nano::block_hash hash{ 1 };
unsigned total{ 10 };
std::atomic<unsigned> count{ 0 };
auto callback = [&count] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
auto callback = [&count] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
++count;
};
// Test many works for the same root
@ -125,10 +125,10 @@ TEST (distributed_work, peer)
auto node (system.add_node (node_config));
ASSERT_FALSE (node->local_work_generation_enabled ());
nano::block_hash hash{ 1 };
boost::optional<uint64_t> work;
std::optional<uint64_t> work;
std::atomic<bool> done{ false };
auto callback = [&work, &done] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
auto callback = [&work, &done] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
work = work_a;
done = true;
};
@ -151,10 +151,10 @@ TEST (distributed_work, peer_malicious)
auto node (system.nodes[0]);
ASSERT_TRUE (node->local_work_generation_enabled ());
nano::block_hash hash{ 1 };
boost::optional<uint64_t> work;
std::optional<uint64_t> work;
std::atomic<bool> done{ false };
auto callback = [&work, &done] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
auto callback = [&work, &done] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
work = work_a;
done = true;
};
@ -194,10 +194,10 @@ TEST (distributed_work, DISABLED_peer_multi)
auto node (system.nodes[0]);
ASSERT_TRUE (node->local_work_generation_enabled ());
nano::block_hash hash{ 1 };
boost::optional<uint64_t> work;
std::optional<uint64_t> work;
std::atomic<bool> done{ false };
auto callback = [&work, &done] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
auto callback = [&work, &done] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
work = work_a;
done = true;
};
@ -233,10 +233,10 @@ TEST (distributed_work, fail_resolve)
nano::test::system system (1);
auto node (system.nodes[0]);
nano::block_hash hash{ 1 };
boost::optional<uint64_t> work;
std::optional<uint64_t> work;
std::atomic<bool> done{ false };
auto callback = [&work, &done] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
auto callback = [&work, &done] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
work = work_a;
done = true;
};

File diff suppressed because it is too large Load diff

View file

@ -48,19 +48,19 @@ TEST (node, work_generate)
{
auto difficulty = nano::difficulty::from_multiplier (1.5, node.network_params.work.base);
auto work = node.work_generate_blocking (version, root, difficulty);
ASSERT_TRUE (work.is_initialized ());
ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, *work), difficulty);
ASSERT_TRUE (work.has_value ());
ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, work.value ()), difficulty);
}
{
auto difficulty = nano::difficulty::from_multiplier (0.5, node.network_params.work.base);
boost::optional<uint64_t> work;
std::optional<uint64_t> work;
do
{
work = node.work_generate_blocking (version, root, difficulty);
} while (nano::dev::network_params.work.difficulty (version, root, *work) >= node.network_params.work.base);
ASSERT_TRUE (work.is_initialized ());
ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, *work), difficulty);
ASSERT_FALSE (nano::dev::network_params.work.difficulty (version, root, *work) >= node.network_params.work.base);
} while (nano::dev::network_params.work.difficulty (version, root, work.value ()) >= node.network_params.work.base);
ASSERT_TRUE (work.has_value ());
ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, work.value ()), difficulty);
ASSERT_FALSE (nano::dev::network_params.work.difficulty (version, root, work.value ()) >= node.network_params.work.base);
}
}
@ -1567,7 +1567,7 @@ TEST (node, unconfirmed_send)
// firstly, send two units from node1 to node2 and expect that both nodes see the block as confirmed
// (node1 will start an election for it, vote on it and node2 gets synced up)
auto send1 = wallet1->send_action (nano::dev::genesis->account (), key2.pub, 2 * nano::Mxrb_ratio);
auto send1 = wallet1->send_action (nano::dev::genesis_key.pub, key2.pub, 2 * nano::Mxrb_ratio);
ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ()));
ASSERT_TIMELY (5s, node2.block_confirmed (send1->hash ()));
@ -1583,19 +1583,19 @@ TEST (node, unconfirmed_send)
.previous (recv1->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::Mxrb_ratio)
.link (nano::dev::genesis->account ())
.link (nano::dev::genesis_key.pub)
.sign (key2.prv, key2.pub)
.work (*system.work.generate (recv1->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, node2.process (send2));
auto send3 = wallet2->send_action (key2.pub, nano::dev::genesis->account (), nano::Mxrb_ratio);
auto send3 = wallet2->send_action (key2.pub, nano::dev::genesis_key.pub, nano::Mxrb_ratio);
ASSERT_TIMELY (5s, node2.block_confirmed (send2->hash ()));
ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ()));
ASSERT_TIMELY (5s, node2.block_confirmed (send3->hash ()));
ASSERT_TIMELY (5s, node1.block_confirmed (send3->hash ()));
ASSERT_TIMELY_EQ (5s, node2.ledger.cache.cemented_count, 7);
ASSERT_TIMELY_EQ (5s, node1.balance (nano::dev::genesis->account ()), nano::dev::constants.genesis_amount);
ASSERT_TIMELY_EQ (5s, node1.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount);
}
// Test that nodes can disable representative voting
@ -2312,9 +2312,9 @@ TEST (node, DISABLED_vote_by_hash_epoch_block_republish)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
auto epoch1 = nano::state_block_builder ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount)
.link (node1.ledger.epoch_link (nano::epoch::epoch_1))
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -3067,7 +3067,7 @@ TEST (node, rollback_vote_self)
auto send2 = builder.make_block ()
.from (*send1)
.previous (send1->hash ())
.balance (send1->balance ().number () - 1)
.balance (send1->balance_field ().value ().number () - 1)
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send1->hash ()))
@ -3076,7 +3076,7 @@ TEST (node, rollback_vote_self)
// fork of send2 block
auto fork = builder.make_block ()
.from (*send2)
.balance (send1->balance ().number () - 2)
.balance (send1->balance_field ().value ().number () - 2)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.build ();
@ -3164,7 +3164,7 @@ TEST (node, rollback_gap_source)
auto send2 = builder.make_block ()
.from (*send1)
.previous (send1->hash ())
.balance (send1->balance ().number () - 1)
.balance (send1->balance_field ().value ().number () - 1)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send1->hash ()))
@ -3255,7 +3255,7 @@ TEST (node, dependency_graph)
.from (*gen_receive)
.previous (gen_receive->hash ())
.link (key2.pub)
.balance (gen_receive->balance ().number () - 2)
.balance (gen_receive->balance_field ().value ().number () - 2)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (gen_receive->hash ()))
.build ();
@ -3294,7 +3294,7 @@ TEST (node, dependency_graph)
.from (*key2_send1)
.previous (key2_send1->hash ())
.link (key1.pub)
.balance (key2_send1->balance ().number () - 1)
.balance (key2_send1->balance_field ().value ().number () - 1)
.sign (key2.prv, key2.pub)
.work (*system.work.generate (key2_send1->hash ()))
.build ();
@ -3303,7 +3303,7 @@ TEST (node, dependency_graph)
.from (*key1_send1)
.previous (key1_send1->hash ())
.link (key2_send2->hash ())
.balance (key1_send1->balance ().number () + 1)
.balance (key1_send1->balance_field ().value ().number () + 1)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1_send1->hash ()))
.build ();
@ -3312,7 +3312,7 @@ TEST (node, dependency_graph)
.from (*key1_receive)
.previous (key1_receive->hash ())
.link (key3.pub)
.balance (key1_receive->balance ().number () - 1)
.balance (key1_receive->balance_field ().value ().number () - 1)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1_receive->hash ()))
.build ();
@ -3321,7 +3321,7 @@ TEST (node, dependency_graph)
.from (*key3_open)
.previous (key3_open->hash ())
.link (key1_send2->hash ())
.balance (key3_open->balance ().number () + 1)
.balance (key3_open->balance_field ().value ().number () + 1)
.sign (key3.prv, key3.pub)
.work (*system.work.generate (key3_open->hash ()))
.build ();
@ -3330,7 +3330,7 @@ TEST (node, dependency_graph)
.from (*key3_receive)
.previous (key3_receive->hash ())
.link (node.ledger.epoch_link (nano::epoch::epoch_1))
.balance (key3_receive->balance ())
.balance (key3_receive->balance_field ().value ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (key3_receive->hash ()))
.build ();
@ -3456,7 +3456,7 @@ TEST (node, dependency_graph_frontier)
.from (*gen_receive)
.previous (gen_receive->hash ())
.link (key2.pub)
.balance (gen_receive->balance ().number () - 2)
.balance (gen_receive->balance_field ().value ().number () - 2)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (gen_receive->hash ()))
.build ();
@ -3495,7 +3495,7 @@ TEST (node, dependency_graph_frontier)
.from (*key2_send1)
.previous (key2_send1->hash ())
.link (key1.pub)
.balance (key2_send1->balance ().number () - 1)
.balance (key2_send1->balance_field ().value ().number () - 1)
.sign (key2.prv, key2.pub)
.work (*system.work.generate (key2_send1->hash ()))
.build ();
@ -3504,7 +3504,7 @@ TEST (node, dependency_graph_frontier)
.from (*key1_send1)
.previous (key1_send1->hash ())
.link (key2_send2->hash ())
.balance (key1_send1->balance ().number () + 1)
.balance (key1_send1->balance_field ().value ().number () + 1)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1_send1->hash ()))
.build ();
@ -3513,7 +3513,7 @@ TEST (node, dependency_graph_frontier)
.from (*key1_receive)
.previous (key1_receive->hash ())
.link (key3.pub)
.balance (key1_receive->balance ().number () - 1)
.balance (key1_receive->balance_field ().value ().number () - 1)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1_receive->hash ()))
.build ();
@ -3522,7 +3522,7 @@ TEST (node, dependency_graph_frontier)
.from (*key3_open)
.previous (key3_open->hash ())
.link (key1_send2->hash ())
.balance (key3_open->balance ().number () + 1)
.balance (key3_open->balance_field ().value ().number () + 1)
.sign (key3.prv, key3.pub)
.work (*system.work.generate (key3_open->hash ()))
.build ();
@ -3531,7 +3531,7 @@ TEST (node, dependency_graph_frontier)
.from (*key3_receive)
.previous (key3_receive->hash ())
.link (node1.ledger.epoch_link (nano::epoch::epoch_1))
.balance (key3_receive->balance ())
.balance (key3_receive->balance_field ().value ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (key3_receive->hash ()))
.build ();
@ -3601,7 +3601,7 @@ TEST (node, deferred_dependent_elections)
auto send2 = builder.make_block ()
.from (*send1)
.previous (send1->hash ())
.balance (send1->balance ().number () - 1)
.balance (send1->balance_field ().value ().number () - 1)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send1->hash ()))

View file

@ -461,7 +461,7 @@ TEST (request_aggregator, cannot_vote)
auto send2 = builder.make_block ()
.from (*send1)
.previous (send1->hash ())
.balance (send1->balance ().number () - 1)
.balance (send1->balance_field ().value ().number () - 1)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send1->hash ()))
.build ();

View file

@ -31,7 +31,7 @@ TEST (system, system_genesis)
for (auto & i : system.nodes)
{
auto transaction (i->store.tx_begin_read ());
ASSERT_EQ (nano::dev::constants.genesis_amount, i->ledger.account_balance (transaction, nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, i->ledger.account_balance (transaction, nano::dev::genesis_key.pub));
}
}
@ -42,7 +42,7 @@ TEST (system, DISABLED_generate_send_existing)
nano::thread_runner runner (system.io_ctx, node1.config.io_threads);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
nano::keypair stake_preserver;
auto send_block (system.wallet (0)->send_action (nano::dev::genesis->account (), stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true));
auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true));
auto info1 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
std::vector<nano::account> accounts;
@ -55,7 +55,7 @@ TEST (system, DISABLED_generate_send_existing)
auto open_block = builder
.open ()
.source (send_block->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (stake_preserver.pub)
.sign (stake_preserver.prv, stake_preserver.pub)
.work (0)
@ -63,7 +63,7 @@ TEST (system, DISABLED_generate_send_existing)
node1.work_generate_blocking (*open_block);
ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, open_block));
}
ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis->account ()));
ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis_key.pub));
auto info2 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub);
ASSERT_TRUE (info2);
ASSERT_NE (info1->head, info2->head);
@ -99,14 +99,14 @@ TEST (system, DISABLED_generate_send_new)
ASSERT_EQ (node1.store.account.end (), iterator1);
}
nano::keypair stake_preserver;
auto send_block (system.wallet (0)->send_action (nano::dev::genesis->account (), stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true));
auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true));
{
auto transaction (node1.store.tx_begin_write ());
nano::block_builder builder;
auto open_block = builder
.open ()
.source (send_block->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (stake_preserver.pub)
.sign (stake_preserver.prv, stake_preserver.pub)
.work (0)
@ -114,7 +114,7 @@ TEST (system, DISABLED_generate_send_new)
node1.work_generate_blocking (*open_block);
ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, open_block));
}
ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis->account ()));
ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis_key.pub));
std::vector<nano::account> accounts;
accounts.push_back (nano::dev::genesis_key.pub);
// This indirectly waits for online weight to stabilize, required to prevent intermittent failures

View file

@ -147,14 +147,14 @@ TEST (unchecked, multiple)
// Enqueues the first block
unchecked.put (block->previous (), nano::unchecked_info (block));
// Enqueues a second block
unchecked.put (block->source (), nano::unchecked_info (block));
unchecked.put (6, nano::unchecked_info (block));
auto check_block_is_listed = [&] (nano::block_hash const & block_hash_a) {
return unchecked.get (block_hash_a).size () > 0;
};
// Waits for and asserts the first block gets saved in the database
ASSERT_TIMELY (5s, check_block_is_listed (block->previous ()));
// Waits for and asserts the second block gets saved in the database
ASSERT_TIMELY (5s, check_block_is_listed (block->source ()));
ASSERT_TIMELY (5s, check_block_is_listed (6));
}
// This test ensures that a block can't occur twice in the unchecked table.

View file

@ -17,7 +17,7 @@ TEST (wallet, no_special_keys_accounts)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::keypair key1;
ASSERT_FALSE (wallet.exists (transaction, key1.pub));
@ -38,7 +38,7 @@ TEST (wallet, no_key)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::keypair key1;
nano::raw_key prv1;
@ -53,7 +53,7 @@ TEST (wallet, fetch_locked)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_TRUE (wallet.valid_password (transaction));
nano::keypair key1;
ASSERT_EQ (key1.pub, wallet.insert_adhoc (transaction, key1.prv));
@ -75,7 +75,7 @@ TEST (wallet, retrieval)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::keypair key1;
ASSERT_TRUE (wallet.valid_password (transaction));
@ -97,7 +97,7 @@ TEST (wallet, empty_iteration)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
auto i (wallet.begin (transaction));
auto j (wallet.end ());
@ -111,7 +111,7 @@ TEST (wallet, one_item_iteration)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::keypair key1;
wallet.insert_adhoc (transaction, key1.prv);
@ -139,7 +139,7 @@ TEST (wallet, two_item_iteration)
nano::kdf kdf{ nano::dev::network_params.kdf_work };
{
auto transaction (env.tx_begin_write ());
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
wallet.insert_adhoc (transaction, key1.prv);
wallet.insert_adhoc (transaction, key2.prv);
@ -259,7 +259,7 @@ TEST (wallet, find_none)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::account account (1000);
ASSERT_EQ (wallet.end (), wallet.find (transaction, account));
@ -272,7 +272,7 @@ TEST (wallet, find_existing)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::keypair key1;
ASSERT_FALSE (wallet.exists (transaction, key1.pub));
@ -291,7 +291,7 @@ TEST (wallet, rekey)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::raw_key password;
wallet.password.value (password);
@ -363,7 +363,7 @@ TEST (wallet, hash_password)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
nano::raw_key hash1;
wallet.derive_key (hash1, transaction, "");
@ -413,25 +413,25 @@ TEST (wallet, reopen_default_password)
ASSERT_FALSE (init);
nano::kdf kdf{ nano::dev::network_params.kdf_work };
{
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
ASSERT_TRUE (wallet.valid_password (transaction));
}
{
bool init;
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
ASSERT_TRUE (wallet.valid_password (transaction));
}
{
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
wallet.rekey (transaction, "");
ASSERT_TRUE (wallet.valid_password (transaction));
}
{
bool init;
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (init);
ASSERT_FALSE (wallet.valid_password (transaction));
wallet.attempt_password (transaction, " ");
@ -448,10 +448,10 @@ TEST (wallet, representative)
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (error);
ASSERT_FALSE (wallet.is_representative (transaction));
ASSERT_EQ (nano::dev::genesis->account (), wallet.representative (transaction));
ASSERT_EQ (nano::dev::genesis_key.pub, wallet.representative (transaction));
ASSERT_FALSE (wallet.is_representative (transaction));
nano::keypair key;
wallet.representative_set (transaction, key.pub);
@ -469,11 +469,11 @@ TEST (wallet, serialize_json_empty)
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (error);
std::string serialized;
wallet1.serialize_json (transaction, serialized);
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1", serialized);
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1", serialized);
ASSERT_FALSE (error);
nano::raw_key password1;
nano::raw_key password2;
@ -494,13 +494,13 @@ TEST (wallet, serialize_json_one)
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (error);
nano::keypair key;
wallet1.insert_adhoc (transaction, key.prv);
std::string serialized;
wallet1.serialize_json (transaction, serialized);
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1", serialized);
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1", serialized);
ASSERT_FALSE (error);
nano::raw_key password1;
nano::raw_key password2;
@ -523,14 +523,14 @@ TEST (wallet, serialize_json_password)
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (error);
nano::keypair key;
wallet1.rekey (transaction, "password");
wallet1.insert_adhoc (transaction, key.prv);
std::string serialized;
wallet1.serialize_json (transaction, serialized);
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1", serialized);
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1", serialized);
ASSERT_FALSE (error);
ASSERT_FALSE (wallet2.valid_password (transaction));
ASSERT_FALSE (wallet2.attempt_password (transaction, "password"));
@ -556,11 +556,11 @@ TEST (wallet_store, move)
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
ASSERT_FALSE (error);
nano::keypair key1;
wallet1.insert_adhoc (transaction, key1.prv);
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1");
nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1");
ASSERT_FALSE (error);
nano::keypair key2;
wallet2.insert_adhoc (transaction, key2.prv);
@ -714,7 +714,7 @@ TEST (wallet, deterministic_keys)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
auto key1 = wallet.deterministic_key (transaction, 0);
auto key2 = wallet.deterministic_key (transaction, 0);
ASSERT_EQ (key1, key2);
@ -757,7 +757,7 @@ TEST (wallet, reseed)
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0");
nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0");
nano::raw_key seed1;
seed1 = 1;
nano::raw_key seed2;
@ -1001,7 +1001,7 @@ TEST (wallet, epoch_2_validation)
ASSERT_EQ (nano::epoch::epoch_2, send->sideband ().details.epoch);
ASSERT_EQ (nano::epoch::epoch_0, send->sideband ().source_epoch); // Not used for send state blocks
auto receive = wallet.receive_action (send->hash (), nano::dev::genesis_key.pub, amount, send->link ().as_account (), 1);
auto receive = wallet.receive_action (send->hash (), nano::dev::genesis_key.pub, amount, send->destination (), 1);
ASSERT_NE (nullptr, receive);
if (nano::dev::network_params.work.difficulty (*receive) < node.network_params.work.base)
{
@ -1043,7 +1043,7 @@ TEST (wallet, epoch_2_receive_propagation)
auto amount = node.config.receive_minimum.number ();
auto send1 = wallet.send_action (nano::dev::genesis_key.pub, key.pub, amount, 1);
ASSERT_NE (nullptr, send1);
ASSERT_NE (nullptr, wallet.receive_action (send1->hash (), nano::dev::genesis_key.pub, amount, send1->link ().as_account (), 1));
ASSERT_NE (nullptr, wallet.receive_action (send1->hash (), nano::dev::genesis_key.pub, amount, send1->destination (), 1));
// Upgrade the genesis account to epoch 2
auto epoch2 = system.upgrade_genesis_epoch (node, nano::epoch::epoch_2);
@ -1053,7 +1053,7 @@ TEST (wallet, epoch_2_receive_propagation)
auto send2 = wallet.send_action (nano::dev::genesis_key.pub, key.pub, amount, 1);
ASSERT_NE (nullptr, send2);
auto receive2 = wallet.receive_action (send2->hash (), key.pub, amount, send2->link ().as_account (), 1);
auto receive2 = wallet.receive_action (send2->hash (), key.pub, amount, send2->destination (), 1);
ASSERT_NE (nullptr, receive2);
if (nano::dev::network_params.work.difficulty (*receive2) < node.network_params.work.base)
{
@ -1106,7 +1106,7 @@ TEST (wallet, epoch_2_receive_unopened)
wallet.insert_adhoc (key.prv, false);
auto receive1 = wallet.receive_action (send1->hash (), key.pub, amount, send1->link ().as_account (), 1);
auto receive1 = wallet.receive_action (send1->hash (), key.pub, amount, send1->destination (), 1);
ASSERT_NE (nullptr, receive1);
if (nano::dev::network_params.work.difficulty (*receive1) < node.network_params.work.base)
{
@ -1155,11 +1155,11 @@ TEST (wallet, search_receivable)
wallet.insert_adhoc (nano::dev::genesis_key.prv);
nano::block_builder builder;
auto send = builder.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - node.config.receive_minimum.number ())
.link (nano::dev::genesis->account ())
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
@ -1172,7 +1172,7 @@ TEST (wallet, search_receivable)
ASSERT_TIMELY (5s, election = node.active.election (send->qualified_root ()));
// Erase the key so the confirmation does not trigger an automatic receive
wallet.store.erase (node.wallets.tx_begin_write (), nano::dev::genesis->account ());
wallet.store.erase (node.wallets.tx_begin_write (), nano::dev::genesis_key.pub);
// Now confirm the election
election->force_confirm ();
@ -1185,12 +1185,12 @@ TEST (wallet, search_receivable)
// Pending search should create the receive block
ASSERT_EQ (2, node.ledger.cache.block_count);
ASSERT_FALSE (wallet.search_receivable (wallet.wallets.tx_begin_read ()));
ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis->account ()), nano::dev::constants.genesis_amount);
auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis->account ());
ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount);
auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis_key.pub);
auto receive = node.block (receive_hash);
ASSERT_NE (nullptr, receive);
ASSERT_EQ (receive->sideband ().height, 3);
ASSERT_EQ (send->hash (), receive->link ().as_block_hash ());
ASSERT_EQ (send->hash (), receive->source ());
}
TEST (wallet, receive_pruned)
@ -1228,7 +1228,7 @@ TEST (wallet, receive_pruned)
wallet2.insert_adhoc (key.prv, false);
auto open1 = wallet2.receive_action (send1->hash (), key.pub, amount, send1->link ().as_account (), 1);
auto open1 = wallet2.receive_action (send1->hash (), key.pub, amount, send1->destination (), 1);
ASSERT_NE (nullptr, open1);
ASSERT_EQ (amount, node2.ledger.balance (node2.store.tx_begin_read (), open1->hash ()));
ASSERT_TIMELY_EQ (5s, node2.ledger.cache.cemented_count, 4);

View file

@ -205,11 +205,11 @@ TEST (wallets, search_receivable)
wallet->insert_adhoc (nano::dev::genesis_key.prv);
nano::block_builder builder;
auto send = builder.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - node.config.receive_minimum.number ())
.link (nano::dev::genesis->account ())
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
@ -229,7 +229,7 @@ TEST (wallets, search_receivable)
ASSERT_TIMELY (5s, election = node.active.election (send->qualified_root ()));
// Erase the key so the confirmation does not trigger an automatic receive
wallet->store.erase (node.wallets.tx_begin_write (), nano::dev::genesis->account ());
wallet->store.erase (node.wallets.tx_begin_write (), nano::dev::genesis_key.pub);
// Now confirm the election
election->force_confirm ();
@ -249,11 +249,11 @@ TEST (wallets, search_receivable)
{
node.wallets.search_receivable (wallet_id);
}
ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis->account ()), nano::dev::constants.genesis_amount);
auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis->account ());
ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount);
auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis_key.pub);
auto receive = node.block (receive_hash);
ASSERT_NE (nullptr, receive);
ASSERT_EQ (receive->sideband ().height, 3);
ASSERT_EQ (send->hash (), receive->link ().as_block_hash ());
ASSERT_EQ (send->hash (), receive->source ());
}
}

View file

@ -796,7 +796,7 @@ TEST (websocket, work)
// Generate work
nano::block_hash hash{ 1 };
auto work (node1->work_generate_blocking (hash));
ASSERT_TRUE (work.is_initialized ());
ASSERT_TRUE (work.has_value ());
// Wait for the work notification
ASSERT_TIMELY_EQ (5s, future.wait_for (0s), std::future_status::ready);
@ -827,7 +827,7 @@ TEST (websocket, work)
nano::from_string_hex (result.get<std::string> ("difficulty"), result_difficulty);
ASSERT_GE (result_difficulty, node1->default_difficulty (nano::work_version::work_1));
ASSERT_NEAR (result.get<double> ("multiplier"), nano::difficulty::to_multiplier (result_difficulty, node1->default_difficulty (nano::work_version::work_1)), 1e-6);
ASSERT_EQ (result.get<std::string> ("work"), nano::to_string_hex (work.get ()));
ASSERT_EQ (result.get<std::string> ("work"), nano::to_string_hex (work.value ()));
ASSERT_EQ (1, contents.count ("bad_peers"));
auto & bad_peers = contents.get_child ("bad_peers");

View file

@ -115,6 +115,53 @@ void nano::block::refresh ()
}
}
bool nano::block::is_send () const noexcept
{
release_assert (has_sideband ());
switch (type ())
{
case nano::block_type::send:
return true;
case nano::block_type::state:
return sideband ().details.is_send;
default:
return false;
}
}
bool nano::block::is_receive () const noexcept
{
release_assert (has_sideband ());
switch (type ())
{
case nano::block_type::receive:
case nano::block_type::open:
return true;
case nano::block_type::state:
return sideband ().details.is_receive;
default:
return false;
}
}
bool nano::block::is_change () const noexcept
{
release_assert (has_sideband ());
switch (type ())
{
case nano::block_type::change:
return true;
case nano::block_type::state:
if (link_field ().value ().is_zero ())
{
return true;
}
return false;
default:
return false;
}
}
nano::block_hash const & nano::block::hash () const
{
if (!cached_hash.is_zero ())
@ -161,34 +208,108 @@ bool nano::block::has_sideband () const
return sideband_m.is_initialized ();
}
nano::account const & nano::block::representative () const
std::optional<nano::account> nano::block::representative_field () const
{
static nano::account representative{};
return representative;
return std::nullopt;
}
nano::block_hash const & nano::block::source () const
std::optional<nano::block_hash> nano::block::source_field () const
{
static nano::block_hash source{ 0 };
return source;
return std::nullopt;
}
nano::account const & nano::block::destination () const
std::optional<nano::account> nano::block::destination_field () const
{
static nano::account destination{};
return destination;
return std::nullopt;
}
nano::link const & nano::block::link () const
std::optional<nano::link> nano::block::link_field () const
{
static nano::link link{ 0 };
return link;
return std::nullopt;
}
nano::account const & nano::block::account () const
nano::account nano::block::account () const noexcept
{
static nano::account account{};
return account;
release_assert (has_sideband ());
switch (type ())
{
case block_type::open:
case block_type::state:
return account_field ().value ();
case block_type::change:
case block_type::send:
case block_type::receive:
return sideband ().account;
default:
release_assert (false);
}
}
nano::amount nano::block::balance () const noexcept
{
release_assert (has_sideband ());
switch (type ())
{
case nano::block_type::open:
case nano::block_type::receive:
case nano::block_type::change:
return sideband ().balance;
case nano::block_type::send:
case nano::block_type::state:
return balance_field ().value ();
default:
release_assert (false);
}
}
nano::account nano::block::destination () const noexcept
{
release_assert (has_sideband ());
switch (type ())
{
case nano::block_type::send:
return destination_field ().value ();
case nano::block_type::state:
release_assert (sideband ().details.is_send);
return link_field ().value ().as_account ();
default:
release_assert (false);
}
}
nano::block_hash nano::block::source () const noexcept
{
release_assert (has_sideband ());
switch (type ())
{
case nano::block_type::open:
case nano::block_type::receive:
return source_field ().value ();
case nano::block_type::state:
release_assert (sideband ().details.is_receive);
return link_field ().value ().as_block_hash ();
default:
release_assert (false);
}
}
// TODO - Remove comments below and fixup usages to not need to check .is_zero ()
// std::optional<nano::block_hash> nano::block::previous () const
nano::block_hash nano::block::previous () const noexcept
{
std::optional<nano::block_hash> result = previous_field ();
/*
if (result && result.value ().is_zero ())
{
return std::nullopt;
}
return result;*/
return result.value_or (0);
}
std::optional<nano::account> nano::block::account_field () const
{
return std::nullopt;
}
nano::qualified_root nano::block::qualified_root () const
@ -196,10 +317,9 @@ nano::qualified_root nano::block::qualified_root () const
return { root (), previous () };
}
nano::amount const & nano::block::balance () const
std::optional<nano::amount> nano::block::balance_field () const
{
static nano::amount amount{ 0 };
return amount;
return std::nullopt;
}
void nano::block::operator() (nano::object_stream & obs) const
@ -467,12 +587,12 @@ bool nano::send_block::operator== (nano::send_block const & other_a) const
return result;
}
nano::block_hash const & nano::send_block::previous () const
std::optional<nano::block_hash> nano::send_block::previous_field () const
{
return hashables.previous;
}
nano::account const & nano::send_block::destination () const
std::optional<nano::account> nano::send_block::destination_field () const
{
return hashables.destination;
}
@ -482,7 +602,7 @@ nano::root const & nano::send_block::root () const
return hashables.previous;
}
nano::amount const & nano::send_block::balance () const
std::optional<nano::amount> nano::send_block::balance_field () const
{
return hashables.balance;
}
@ -637,13 +757,12 @@ void nano::open_block::block_work_set (uint64_t work_a)
work = work_a;
}
nano::block_hash const & nano::open_block::previous () const
std::optional<nano::block_hash> nano::open_block::previous_field () const
{
static nano::block_hash result{ 0 };
return result;
return std::nullopt;
}
nano::account const & nano::open_block::account () const
std::optional<nano::account> nano::open_block::account_field () const
{
return hashables.account;
}
@ -689,7 +808,7 @@ void nano::open_block::serialize_json (boost::property_tree::ptree & tree) const
{
tree.put ("type", "open");
tree.put ("source", hashables.source.to_string ());
tree.put ("representative", representative ().to_account ());
tree.put ("representative", hashables.representative.to_account ());
tree.put ("account", hashables.account.to_account ());
std::string signature_l;
signature.encode_hex (signature_l);
@ -763,7 +882,7 @@ bool nano::open_block::valid_predecessor (nano::block const & block_a) const
return false;
}
nano::block_hash const & nano::open_block::source () const
std::optional<nano::block_hash> nano::open_block::source_field () const
{
return hashables.source;
}
@ -773,7 +892,7 @@ nano::root const & nano::open_block::root () const
return hashables.account;
}
nano::account const & nano::open_block::representative () const
std::optional<nano::account> nano::open_block::representative_field () const
{
return hashables.representative;
}
@ -909,7 +1028,7 @@ void nano::change_block::block_work_set (uint64_t work_a)
work = work_a;
}
nano::block_hash const & nano::change_block::previous () const
std::optional<nano::block_hash> nano::change_block::previous_field () const
{
return hashables.previous;
}
@ -953,7 +1072,7 @@ void nano::change_block::serialize_json (boost::property_tree::ptree & tree) con
{
tree.put ("type", "change");
tree.put ("previous", hashables.previous.to_string ());
tree.put ("representative", representative ().to_account ());
tree.put ("representative", hashables.representative.to_account ());
tree.put ("work", nano::to_string_hex (work));
std::string signature_l;
signature.encode_hex (signature_l);
@ -1039,7 +1158,7 @@ nano::root const & nano::change_block::root () const
return hashables.previous;
}
nano::account const & nano::change_block::representative () const
std::optional<nano::account> nano::change_block::representative_field () const
{
return hashables.representative;
}
@ -1208,12 +1327,12 @@ void nano::state_block::block_work_set (uint64_t work_a)
work = work_a;
}
nano::block_hash const & nano::state_block::previous () const
std::optional<nano::block_hash> nano::state_block::previous_field () const
{
return hashables.previous;
}
nano::account const & nano::state_block::account () const
std::optional<nano::account> nano::state_block::account_field () const
{
return hashables.account;
}
@ -1265,7 +1384,7 @@ void nano::state_block::serialize_json (boost::property_tree::ptree & tree) cons
tree.put ("type", "state");
tree.put ("account", hashables.account.to_account ());
tree.put ("previous", hashables.previous.to_string ());
tree.put ("representative", representative ().to_account ());
tree.put ("representative", hashables.representative.to_account ());
tree.put ("balance", hashables.balance.to_string_dec ());
tree.put ("link", hashables.link.to_string ());
tree.put ("link_as_account", hashables.link.to_account ());
@ -1363,17 +1482,17 @@ nano::root const & nano::state_block::root () const
}
}
nano::link const & nano::state_block::link () const
std::optional<nano::link> nano::state_block::link_field () const
{
return hashables.link;
}
nano::account const & nano::state_block::representative () const
std::optional<nano::account> nano::state_block::representative_field () const
{
return hashables.representative;
}
nano::amount const & nano::state_block::balance () const
std::optional<nano::amount> nano::state_block::balance_field () const
{
return hashables.balance;
}
@ -1695,12 +1814,12 @@ bool nano::receive_block::valid_predecessor (nano::block const & block_a) const
return result;
}
nano::block_hash const & nano::receive_block::previous () const
std::optional<nano::block_hash> nano::receive_block::previous_field () const
{
return hashables.previous;
}
nano::block_hash const & nano::receive_block::source () const
std::optional<nano::block_hash> nano::receive_block::source_field () const
{
return hashables.source;
}

View file

@ -33,21 +33,10 @@ public:
virtual void hash (blake2b_state &) const = 0;
virtual uint64_t block_work () const = 0;
virtual void block_work_set (uint64_t) = 0;
virtual nano::account const & account () const;
// Previous block in account's chain, zero for open block
virtual nano::block_hash const & previous () const = 0;
// Source block for open/receive blocks, zero otherwise.
virtual nano::block_hash const & source () const;
// Destination account for send blocks, zero otherwise.
virtual nano::account const & destination () const;
// Previous block or account number for open blocks
virtual nano::root const & root () const = 0;
// Qualified root value based on previous() and root()
virtual nano::qualified_root qualified_root () const;
// Link field for state blocks, zero otherwise.
virtual nano::link const & link () const;
virtual nano::account const & representative () const;
virtual nano::amount const & balance () const;
virtual void serialize (nano::stream &) const = 0;
virtual void serialize_json (std::string &, bool = false) const = 0;
virtual void serialize_json (boost::property_tree::ptree &) const = 0;
@ -63,6 +52,35 @@ public:
virtual nano::work_version work_version () const;
// If there are any changes to the hashables, call this to update the cached hash
void refresh ();
bool is_send () const noexcept;
bool is_receive () const noexcept;
bool is_change () const noexcept;
public: // Direct access to the block fields or nullopt if the block type does not have the specified field
// Returns account field or account from sideband
nano::account account () const noexcept;
// Account field for open/state blocks
virtual std::optional<nano::account> account_field () const;
// Returns the balance field or balance from sideband
nano::amount balance () const noexcept;
// Balance field for open/send/state blocks
virtual std::optional<nano::amount> balance_field () const;
// Returns the destination account for send/state blocks that are sends
nano::account destination () const noexcept;
// Destination account for send blocks
virtual std::optional<nano::account> destination_field () const;
// Link field for state blocks
virtual std::optional<nano::link> link_field () const;
// Previous block if field exists or 0
nano::block_hash previous () const noexcept;
// Previous block in chain if the field exists
virtual std::optional<nano::block_hash> previous_field () const = 0;
// Representative field for open/change blocks
virtual std::optional<nano::account> representative_field () const;
// Returns the source block hash for open/receive/state blocks that are receives
nano::block_hash source () const noexcept;
// Source block for open/receive blocks
virtual std::optional<nano::block_hash> source_field () const;
protected:
mutable nano::block_hash cached_hash{ 0 };
@ -106,10 +124,7 @@ public:
void hash (blake2b_state &) const override;
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash const & previous () const override;
nano::account const & destination () const override;
nano::root const & root () const override;
nano::amount const & balance () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &, bool = false) const override;
@ -128,6 +143,11 @@ public:
uint64_t work;
static std::size_t constexpr size = nano::send_hashables::size + sizeof (signature) + sizeof (work);
public: // Send block fields
std::optional<nano::amount> balance_field () const override;
std::optional<nano::account> destination_field () const override;
std::optional<nano::block_hash> previous_field () const override;
public: // Logging
void operator() (nano::object_stream &) const override;
};
@ -157,8 +177,6 @@ public:
void hash (blake2b_state &) const override;
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash const & previous () const override;
nano::block_hash const & source () const override;
nano::root const & root () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
@ -178,6 +196,10 @@ public:
uint64_t work;
static std::size_t constexpr size = nano::receive_hashables::size + sizeof (signature) + sizeof (work);
public: // Receive block fields
std::optional<nano::block_hash> previous_field () const override;
std::optional<nano::block_hash> source_field () const override;
public: // Logging
void operator() (nano::object_stream &) const override;
};
@ -209,11 +231,7 @@ public:
void hash (blake2b_state &) const override;
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash const & previous () const override;
nano::account const & account () const override;
nano::block_hash const & source () const override;
nano::root const & root () const override;
nano::account const & representative () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &, bool = false) const override;
@ -232,6 +250,12 @@ public:
uint64_t work;
static std::size_t constexpr size = nano::open_hashables::size + sizeof (signature) + sizeof (work);
public: // Open block fields
std::optional<nano::account> account_field () const override;
std::optional<nano::block_hash> previous_field () const override;
std::optional<nano::account> representative_field () const override;
std::optional<nano::block_hash> source_field () const override;
public: // Logging
void operator() (nano::object_stream &) const override;
};
@ -261,9 +285,7 @@ public:
void hash (blake2b_state &) const override;
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash const & previous () const override;
nano::root const & root () const override;
nano::account const & representative () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &, bool = false) const override;
@ -282,6 +304,10 @@ public:
uint64_t work;
static std::size_t constexpr size = nano::change_hashables::size + sizeof (signature) + sizeof (work);
public: // Change block fields
std::optional<nano::block_hash> previous_field () const override;
std::optional<nano::account> representative_field () const override;
public: // Logging
void operator() (nano::object_stream &) const override;
};
@ -324,12 +350,7 @@ public:
void hash (blake2b_state &) const override;
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash const & previous () const override;
nano::account const & account () const override;
nano::root const & root () const override;
nano::link const & link () const override;
nano::account const & representative () const override;
nano::amount const & balance () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &, bool = false) const override;
@ -348,6 +369,13 @@ public:
uint64_t work;
static std::size_t constexpr size = nano::state_hashables::size + sizeof (signature) + sizeof (work);
public: // State block fields
std::optional<nano::account> account_field () const override;
std::optional<nano::amount> balance_field () const override;
std::optional<nano::link> link_field () const override;
std::optional<nano::block_hash> previous_field () const override;
std::optional<nano::account> representative_field () const override;
public: // Logging
void operator() (nano::object_stream &) const override;
};

View file

@ -653,7 +653,7 @@ int main (int argc, char * const * argv)
}
// Send from genesis account to different accounts and receive the funds
auto send_receive = std::make_shared<send_receive_impl> (ioc, wallet, nano::dev::genesis->account ().to_account (), destination_account->as_string, send_calls_remaining, primary_node_results);
auto send_receive = std::make_shared<send_receive_impl> (ioc, wallet, nano::dev::genesis_key.pub.to_account (), destination_account->as_string, send_calls_remaining, primary_node_results);
boost::asio::strand<boost::asio::io_context::executor_type> strand{ ioc.get_executor () };
boost::asio::post (strand,
[send_receive] () {

View file

@ -1501,7 +1501,7 @@ int main (int argc, char * const * argv)
{
if ((state_block.hashables.balance == prev_balance && !error_or_pruned) || (node->ledger.pruning && error_or_pruned && block->sideband ().details.is_epoch))
{
invalid = validate_message (node->ledger.epoch_signer (block->link ()), hash, block->block_signature ());
invalid = validate_message (node->ledger.epoch_signer (block->link_field ().value ()), hash, block->block_signature ());
}
}
}
@ -1529,12 +1529,12 @@ int main (int argc, char * const * argv)
}
else
{
if (block->link ().is_zero ())
if (block->is_change ())
{
// State change
block_details_error = sideband.details.is_send || sideband.details.is_receive || sideband.details.is_epoch;
}
else if (block->balance () == prev_balance.value () && node->ledger.is_epoch_link (block->link ()))
else if (block->balance () == prev_balance.value () && node->ledger.is_epoch_link (block->link_field ().value ()))
{
// State epoch
block_details_error = !sideband.details.is_epoch || sideband.details.is_send || sideband.details.is_receive;
@ -1543,7 +1543,7 @@ int main (int argc, char * const * argv)
{
// State receive
block_details_error = !sideband.details.is_receive || sideband.details.is_send || sideband.details.is_epoch;
block_details_error |= !node->ledger.block_or_pruned_exists (transaction, block->link ().as_block_hash ());
block_details_error |= !node->ledger.block_or_pruned_exists (transaction, block->source ());
}
}
}
@ -1557,7 +1557,7 @@ int main (int argc, char * const * argv)
print_error_message (boost::str (boost::format ("Incorrect sideband block details for block %1%\n") % hash.to_string ()));
}
// Check link epoch version
if (sideband.details.is_receive && (!node->ledger.pruning || !node->store.pruned.exists (transaction, block->link ().as_block_hash ())))
if (sideband.details.is_receive && (!node->ledger.pruning || !node->store.pruned.exists (transaction, block->source ())))
{
if (sideband.source_epoch != node->ledger.version (*block))
{
@ -1584,7 +1584,7 @@ int main (int argc, char * const * argv)
// Calculate representative block
if (block->type () == nano::block_type::open || block->type () == nano::block_type::change || block->type () == nano::block_type::state)
{
calculated_representative = block->representative ();
calculated_representative = block->representative_field ().value ();
}
// Retrieving successor block hash
hash = node->store.block.successor (transaction, hash);
@ -1697,7 +1697,7 @@ int main (int argc, char * const * argv)
}
if (auto state = dynamic_cast<nano::state_block *> (block.get ()))
{
if (node->ledger.is_send (transaction, *state))
if (state->is_send ())
{
destination = state->hashables.link.as_account ();
}
@ -1809,7 +1809,7 @@ int main (int argc, char * const * argv)
std::cout << boost::str (boost::format ("%1% blocks retrieved") % count) << std::endl;
}
node.node->block_processor.add (block);
if (block->type () == nano::block_type::state && block->previous ().is_zero () && source_node->ledger.is_epoch_link (block->link ()))
if (block->type () == nano::block_type::state && block->previous ().is_zero () && source_node->ledger.is_epoch_link (block->link_field ().value ()))
{
// Epoch open blocks can be rejected without processed pending blocks to account, push it later again
epoch_open_blocks.push_back (block);

View file

@ -165,8 +165,10 @@ void nano::active_transactions::handle_confirmation (nano::store::read_transacti
void nano::active_transactions::handle_block_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr<nano::block> const & block, nano::block_hash const & hash, nano::account & account, nano::uint128_t & amount, bool & is_state_send, bool & is_state_epoch, nano::account & pending_account)
{
auto destination = block->link ().is_zero () ? block->destination () : block->link ().as_account ();
node.receive_confirmed (transaction, hash, destination);
if (block->is_send ())
{
node.receive_confirmed (transaction, hash, block->destination ());
}
node.process_confirmed_data (transaction, block, hash, account, amount, is_state_send, is_state_epoch, pending_account);
}
@ -186,7 +188,7 @@ void nano::active_transactions::notify_observers (nano::election_status const &
void nano::active_transactions::handle_final_votes_confirmation (std::shared_ptr<nano::block> const & block, nano::store::read_transaction const & transaction, nano::election_status_type status)
{
auto const & account = !block->account ().is_zero () ? block->account () : block->sideband ().account;
auto account = block->account ();
bool is_canary_not_set = !node.ledger.cache.final_votes_confirmation_canary.load ();
bool is_canary_account = account == node.network_params.ledger.final_votes_canary_account;

View file

@ -340,11 +340,11 @@ nano::block_status nano::block_processor::process_one (store::write_transaction
/* For send blocks check epoch open unchecked (gap pending).
For state blocks check only send subtype and only if block epoch is not last epoch.
If epoch is last, then pending entry shouldn't trigger same epoch open block for destination account. */
if (block->type () == nano::block_type::send || (block->type () == nano::block_type::state && block->sideband ().details.is_send && std::underlying_type_t<nano::epoch> (block->sideband ().details.epoch) < std::underlying_type_t<nano::epoch> (nano::epoch::max)))
if (block->type () == nano::block_type::send || (block->type () == nano::block_type::state && block->is_send () && std::underlying_type_t<nano::epoch> (block->sideband ().details.epoch) < std::underlying_type_t<nano::epoch> (nano::epoch::max)))
{
/* block->destination () for legacy send blocks
block->link () for state blocks (send subtype) */
queue_unchecked (transaction_a, block->destination ().is_zero () ? block->link () : block->destination ());
queue_unchecked (transaction_a, block->destination ());
}
break;
}
@ -356,13 +356,14 @@ nano::block_status nano::block_processor::process_one (store::write_transaction
}
case nano::block_status::gap_source:
{
node.unchecked.put (node.ledger.block_source (transaction_a, *block), block);
release_assert (block->source_field () || block->link_field ());
node.unchecked.put (block->source_field ().value_or (block->link_field ().value_or (0).as_block_hash ()), block);
node.stats.inc (nano::stat::type::ledger, nano::stat::detail::gap_source);
break;
}
case nano::block_status::gap_epoch_open_pending:
{
node.unchecked.put (block->account (), block); // Specific unchecked key starting with epoch open block account public key
node.unchecked.put (block->account_field ().value_or (0), block); // Specific unchecked key starting with epoch open block account public key
node.stats.inc (nano::stat::type::ledger, nano::stat::detail::gap_source);
break;
}

View file

@ -176,7 +176,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code ec, std::
// Is block expected?
bool block_expected (false);
// Unconfirmed head is used only for lazy destinations if legacy bootstrap is not available, see nano::bootstrap_attempt::lazy_destinations_increment (...)
bool unconfirmed_account_head = node->flags.disable_legacy_bootstrap && pull_blocks == 0 && pull.retry_limit <= node->network_params.bootstrap.lazy_retry_limit && (expected == pull.account_or_head.as_block_hash ()) && (block->account () == pull.account_or_head.as_account ());
bool unconfirmed_account_head = node->flags.disable_legacy_bootstrap && pull_blocks == 0 && pull.retry_limit <= node->network_params.bootstrap.lazy_retry_limit && (expected == pull.account_or_head.as_block_hash ()) && (block->account_field () == pull.account_or_head.as_account ());
if (hash == expected || unconfirmed_account_head)
{
expected = block->previous ();
@ -188,7 +188,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code ec, std::
}
if (pull_blocks == 0 && block_expected)
{
known_account = block->account ();
known_account = block->account_field ().value_or (0);
}
if (connection->block_count++ == 0)
{

View file

@ -291,9 +291,9 @@ bool nano::bootstrap_attempt_lazy::process_block_lazy (std::shared_ptr<nano::blo
if (!lazy_blocks_processed (hash))
{
// Search for new dependencies
if (!block_a->source ().is_zero () && !node->ledger.block_or_pruned_exists (block_a->source ()) && block_a->source () != node->network_params.ledger.genesis->account ())
if (block_a->source_field () && !node->ledger.block_or_pruned_exists (block_a->source_field ().value ()) && block_a->source_field ().value () != node->network_params.ledger.genesis->account ())
{
lazy_add (block_a->source (), retry_limit);
lazy_add (block_a->source_field ().value (), retry_limit);
}
else if (block_a->type () == nano::block_type::state)
{
@ -303,7 +303,7 @@ bool nano::bootstrap_attempt_lazy::process_block_lazy (std::shared_ptr<nano::blo
// Adding lazy balances for first processed block in pull
if (pull_blocks_processed == 1 && (block_a->type () == nano::block_type::state || block_a->type () == nano::block_type::send))
{
lazy_balances.emplace (hash, block_a->balance ().number ());
lazy_balances.emplace (hash, block_a->balance_field ().value ().number ());
}
// Clearing lazy balances for previous block
if (!block_a->previous ().is_zero () && lazy_balances.find (block_a->previous ()) != lazy_balances.end ())
@ -394,7 +394,7 @@ void nano::bootstrap_attempt_lazy::lazy_block_state_backlog_check (std::shared_p
// Retrieve balance for previous state & send blocks
if (block_a->type () == nano::block_type::state || block_a->type () == nano::block_type::send)
{
if (block_a->balance ().number () <= next_block.balance) // balance
if (block_a->balance_field ().value ().number () <= next_block.balance) // balance
{
lazy_add (next_block.link, next_block.retry_limit); // link
}

View file

@ -133,42 +133,25 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx,
{
case nano::block_status::progress:
{
const auto account = ledger.account (block);
const auto is_send = ledger.is_send (tx, block);
const auto account = block.account ();
// If we've inserted any block in to an account, unmark it as blocked
accounts.unblock (account);
accounts.priority_up (account);
accounts.timestamp (account, /* reset timestamp */ true);
if (is_send)
if (block.is_send ())
{
// TODO: Encapsulate this as a helper somewhere
nano::account destination{ 0 };
switch (block.type ())
{
case nano::block_type::send:
destination = block.destination ();
break;
case nano::block_type::state:
destination = block.link ().as_account ();
break;
default:
debug_assert (false, "unexpected block type");
break;
}
if (!destination.is_zero ())
{
accounts.unblock (destination, hash); // Unblocking automatically inserts account into priority set
accounts.priority_up (destination);
}
auto destination = block.destination ();
accounts.unblock (destination, hash); // Unblocking automatically inserts account into priority set
accounts.priority_up (destination);
}
}
break;
case nano::block_status::gap_source:
{
const auto account = block.previous ().is_zero () ? block.account () : ledger.account (tx, block.previous ()).value ();
const auto source = block.source ().is_zero () ? block.link ().as_block_hash () : block.source ();
const auto account = block.previous ().is_zero () ? block.account_field ().value () : ledger.account (tx, block.previous ()).value ();
const auto source = block.source_field ().value_or (block.link_field ().value_or (0).as_block_hash ());
// Mark account as blocked because it is missing the source block
accounts.block (account, source);
@ -456,7 +439,7 @@ nano::bootstrap_ascending::service::verify_result nano::bootstrap_ascending::ser
case async_tag::query_type::blocks_by_account:
{
// Open & state blocks always contain account field
if (first->account () != tag.start.as_account ())
if (first->account_field () != tag.start.as_account ())
{
// TODO: Stat & log
return verify_result::invalid;

View file

@ -104,11 +104,7 @@ void nano::confirmation_height_bounded::process (std::shared_ptr<nano::block> or
release_assert (block);
}
}
nano::account account (block->account ());
if (account.is_zero ())
{
account = block->sideband ().account;
}
auto account = block->account ();
// Checks if we have encountered this account before but not commited changes yet, if so then update the cached confirmation height
nano::confirmation_height_info confirmation_height_info;
@ -257,19 +253,13 @@ bool nano::confirmation_height_bounded::iterate (store::read_transaction const &
// Once a receive is cemented, we can cement all blocks above it until the next receive, so store those details for later.
++num_blocks;
auto block = ledger.block (transaction_a, hash);
auto source (block->source ());
if (source.is_zero ())
{
source = block->link ().as_block_hash ();
}
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source))
if (block->is_receive () && ledger.block_exists (transaction_a, block->source ()))
{
hit_receive = true;
reached_target = true;
auto const & sideband (block->sideband ());
auto next = !sideband.successor.is_zero () && sideband.successor != top_level_hash_a ? boost::optional<nano::block_hash> (sideband.successor) : boost::none;
receive_source_pairs_a.push_back ({ receive_chain_details{ account_a, sideband.height, hash, top_level_hash_a, next, bottom_height_a, bottom_hash_a }, source });
receive_source_pairs_a.push_back ({ receive_chain_details{ account_a, sideband.height, hash, top_level_hash_a, next, bottom_height_a, bottom_hash_a }, block->source () });
// Store a checkpoint every max_items so that we can always traverse a long number of accounts to genesis
if (receive_source_pairs_a.size () % max_items == 0)
{

View file

@ -79,11 +79,7 @@ void nano::confirmation_height_unbounded::process (std::shared_ptr<nano::block>
}
release_assert (block);
nano::account account (block->account ());
if (account.is_zero ())
{
account = block->sideband ().account;
}
auto account = block->account ();
auto block_height = block->sideband ().height;
uint64_t confirmation_height = 0;
@ -216,13 +212,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source
if (block)
{
auto source (block->source ());
if (source.is_zero ())
{
source = block->link ().as_block_hash ();
}
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source))
if (block->is_receive () && ledger.block_exists (transaction_a, block->source ()))
{
if (!hit_receive && !block_callback_data_a.empty ())
{
@ -237,7 +227,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source
hit_receive = true;
auto block_height = confirmation_height_a + num_to_confirm;
receive_source_pairs_a.emplace_back (std::make_shared<conf_height_details> (account_a, hash, block_height, 1, std::vector<nano::block_hash>{ hash }), source);
receive_source_pairs_a.emplace_back (std::make_shared<conf_height_details> (account_a, hash, block_height, 1, std::vector<nano::block_hash>{ hash }), block->source ());
}
else if (is_original_block)
{

View file

@ -68,7 +68,7 @@ void nano::distributed_work::start ()
else if (need_resolve.empty () && request.callback)
{
status = work_generation_status::failure_local;
request.callback (boost::none);
request.callback (std::nullopt);
}
for (auto const & peer : need_resolve)
{
@ -117,7 +117,7 @@ void nano::distributed_work::start_local ()
this_l->status = work_generation_status::failure_local;
if (this_l->request.callback)
{
this_l->request.callback (boost::none);
this_l->request.callback (std::nullopt);
}
}
this_l->stop_once (false);
@ -143,9 +143,9 @@ void nano::distributed_work::do_request (nano::tcp_endpoint const & endpoint_a)
rpc_request.put ("action", "work_generate");
rpc_request.put ("hash", this_l->request.root.to_string ());
rpc_request.put ("difficulty", nano::to_string_hex (this_l->request.difficulty));
if (this_l->request.account.is_initialized ())
if (this_l->request.account.has_value ())
{
rpc_request.put ("account", this_l->request.account.get ().to_account ());
rpc_request.put ("account", this_l->request.account.value ().to_account ());
}
std::stringstream ostream;
boost::property_tree::write_json (ostream, rpc_request);
@ -373,7 +373,7 @@ void nano::distributed_work::cancel ()
status = work_generation_status::cancelled;
if (request.callback)
{
request.callback (boost::none);
request.callback (std::nullopt);
}
stop_once (true);
}
@ -411,7 +411,7 @@ void nano::distributed_work::handle_failure ()
}
if (error_l && request_l.callback)
{
request_l.callback (boost::none);
request_l.callback (std::nullopt);
}
});
}

View file

@ -9,6 +9,8 @@
#include <nano/lib/work.hpp>
#include <nano/node/common.hpp>
#include <optional>
using request_type = boost::beast::http::request<boost::beast::http::string_body>;
namespace boost
@ -28,8 +30,8 @@ struct work_request final
nano::work_version version;
nano::root root;
uint64_t difficulty;
boost::optional<nano::account> const account;
std::function<void (boost::optional<uint64_t>)> callback;
std::optional<nano::account> const account;
std::function<void (std::optional<uint64_t>)> callback;
std::vector<std::pair<std::string, uint16_t>> const peers;
};
@ -107,4 +109,4 @@ private:
std::atomic<bool> stopped{ false };
std::atomic<bool> local_generation_started{ false };
};
}
}

View file

@ -12,7 +12,7 @@ nano::distributed_work_factory::~distributed_work_factory ()
stop ();
}
bool nano::distributed_work_factory::make (nano::work_version const version_a, nano::root const & root_a, std::vector<std::pair<std::string, uint16_t>> const & peers_a, uint64_t difficulty_a, std::function<void (boost::optional<uint64_t>)> const & callback_a, boost::optional<nano::account> const & account_a)
bool nano::distributed_work_factory::make (nano::work_version const version_a, nano::root const & root_a, std::vector<std::pair<std::string, uint16_t>> const & peers_a, uint64_t difficulty_a, std::function<void (std::optional<uint64_t>)> const & callback_a, std::optional<nano::account> const & account_a)
{
return make (std::chrono::seconds (1), nano::work_request{ version_a, root_a, difficulty_a, account_a, callback_a, peers_a });
}

View file

@ -4,6 +4,7 @@
#include <atomic>
#include <functional>
#include <optional>
#include <unordered_map>
#include <vector>
@ -20,7 +21,7 @@ class distributed_work_factory final
public:
distributed_work_factory (nano::node &);
~distributed_work_factory ();
bool make (nano::work_version const, nano::root const &, std::vector<std::pair<std::string, uint16_t>> const &, uint64_t, std::function<void (boost::optional<uint64_t>)> const &, boost::optional<nano::account> const & = boost::none);
bool make (nano::work_version const, nano::root const &, std::vector<std::pair<std::string, uint16_t>> const &, uint64_t, std::function<void (std::optional<uint64_t>)> const &, std::optional<nano::account> const & = std::nullopt);
bool make (std::chrono::seconds const &, nano::work_request const &);
void cancel (nano::root const &);
void cleanup_finished ();

View file

@ -9,10 +9,10 @@ std::unique_ptr<nanoapi::BlockStateT> nano::ipc::flatbuffers_builder::from (nano
block->account = block_a.account ().to_account ();
block->hash = block_a.hash ().to_string ();
block->previous = block_a.previous ().to_string ();
block->representative = block_a.representative ().to_account ();
block->representative = block_a.representative_field ().value ().to_account ();
block->balance = block_a.balance ().to_string_dec ();
block->link = block_a.link ().to_string ();
block->link_as_account = block_a.link ().to_account ();
block->link = block_a.link_field ().value ().to_string ();
block->link_as_account = block_a.link_field ().value ().to_account ();
block_a.signature.encode_hex (block->signature);
block->work = nano::to_string_hex (block_a.work);
@ -20,7 +20,7 @@ std::unique_ptr<nanoapi::BlockStateT> nano::ipc::flatbuffers_builder::from (nano
{
block->subtype = nanoapi::BlockSubType::BlockSubType_send;
}
else if (block_a.link ().is_zero ())
else if (block_a.is_change ())
{
block->subtype = nanoapi::BlockSubType::BlockSubType_change;
}
@ -51,7 +51,7 @@ std::unique_ptr<nanoapi::BlockReceiveT> nano::ipc::flatbuffers_builder::from (na
{
auto block (std::make_unique<nanoapi::BlockReceiveT> ());
block->hash = block_a.hash ().to_string ();
block->source = block_a.source ().to_string ();
block->source = block_a.source_field ().value ().to_string ();
block->previous = block_a.previous ().to_string ();
block_a.signature.encode_hex (block->signature);
block->work = nano::to_string_hex (block_a.work);
@ -62,9 +62,9 @@ std::unique_ptr<nanoapi::BlockOpenT> nano::ipc::flatbuffers_builder::from (nano:
{
auto block (std::make_unique<nanoapi::BlockOpenT> ());
block->hash = block_a.hash ().to_string ();
block->source = block_a.source ().to_string ();
block->source = block_a.source_field ().value ().to_string ();
block->account = block_a.account ().to_account ();
block->representative = block_a.representative ().to_account ();
block->representative = block_a.representative_field ().value ().to_account ();
block_a.signature.encode_hex (block->signature);
block->work = nano::to_string_hex (block_a.work);
return block;
@ -75,7 +75,7 @@ std::unique_ptr<nanoapi::BlockChangeT> nano::ipc::flatbuffers_builder::from (nan
auto block (std::make_unique<nanoapi::BlockChangeT> ());
block->hash = block_a.hash ().to_string ();
block->previous = block_a.previous ().to_string ();
block->representative = block_a.representative ().to_account ();
block->representative = block_a.representative_field ().value ().to_account ();
block_a.signature.encode_hex (block->signature);
block->work = nano::to_string_hex (block_a.work);
return block;

View file

@ -403,7 +403,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a)
// Send check
if (block_previous != nullptr)
{
details.is_send = node.ledger.balance (transaction, previous) > block_a.balance ().number ();
details.is_send = node.ledger.balance (transaction, previous) > block_a.balance_field ().value ().number ();
details_found = true;
}
// Epoch check
@ -411,11 +411,12 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a)
{
details.epoch = block_previous->sideband ().details.epoch;
}
auto link (block_a.link ());
if (!link.is_zero () && !details.is_send)
auto link = block_a.link_field ();
if (link && !link.value ().is_zero () && !details.is_send)
{
auto block_link = node.ledger.block (transaction, link.as_block_hash ());
if (block_link != nullptr && node.store.pending.exists (transaction, nano::pending_key (block_a.account (), link.as_block_hash ())))
auto block_link = node.ledger.block (transaction, link.value ().as_block_hash ());
auto account = block_a.account_field ().value (); // Link is non-zero therefore it's a state block and has an account field;
if (block_link != nullptr && node.store.pending.exists (transaction, nano::pending_key (account, link.value ().as_block_hash ())))
{
details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch);
details.is_receive = true;
@ -684,10 +685,10 @@ void nano::json_handler::account_info ()
nano::account confirmed_representative{};
if (confirmed_frontier_block)
{
confirmed_representative = confirmed_frontier_block->representative ();
confirmed_representative = confirmed_frontier_block->representative_field ().value_or (0);
if (confirmed_representative.is_zero ())
{
confirmed_representative = node.ledger.block (transaction, node.ledger.representative (transaction, confirmation_height_info.frontier))->representative ();
confirmed_representative = node.ledger.block (transaction, node.ledger.representative (transaction, confirmation_height_info.frontier))->representative_field ().value ();
}
}
@ -1149,15 +1150,15 @@ void nano::json_handler::block_info ()
auto block = node.ledger.block (transaction, hash);
if (block != nullptr)
{
nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ());
auto account = block->account ();
response_l.put ("block_account", account.to_account ());
auto amount = node.ledger.amount (transaction, hash);
if (amount)
{
response_l.put ("amount", amount.value ().convert_to<std::string> ());
}
auto balance = node.ledger.balance (*block);
response_l.put ("balance", balance.convert_to<std::string> ());
auto balance = block->balance ();
response_l.put ("balance", balance.number ().convert_to<std::string> ());
response_l.put ("height", std::to_string (block->sideband ().height));
response_l.put ("local_timestamp", std::to_string (block->sideband ().timestamp));
response_l.put ("successor", block->sideband ().successor.to_string ());
@ -1214,7 +1215,7 @@ void nano::json_handler::block_confirm ()
nano::election_status status{ block_l, 0, 0, std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values<std::chrono::milliseconds>::zero (), 0, 1, 0, nano::election_status_type::active_confirmation_height };
node.active.recently_cemented.put (status);
// Trigger callback for confirmed block
auto account = node.ledger.account (*block_l);
auto account = block_l->account ();
auto amount = node.ledger.amount (transaction, hash);
bool is_state_send (false);
bool is_state_epoch (false);
@ -1222,8 +1223,8 @@ void nano::json_handler::block_confirm ()
{
if (auto state = dynamic_cast<nano::state_block *> (block_l.get ()))
{
is_state_send = node.ledger.is_send (transaction, *state);
is_state_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link ());
is_state_send = state->is_send ();
is_state_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link_field ().value ());
}
}
node.observers.blocks.notify (status, {}, account, amount ? amount.value () : 0, is_state_send, is_state_epoch);
@ -1306,15 +1307,15 @@ void nano::json_handler::blocks_info ()
if (block != nullptr)
{
boost::property_tree::ptree entry;
nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ());
auto account = block->account ();
entry.put ("block_account", account.to_account ());
auto amount = node.ledger.amount (transaction, hash);
if (amount)
{
entry.put ("amount", amount.value ().convert_to<std::string> ());
}
auto balance = node.ledger.balance (*block);
entry.put ("balance", balance.convert_to<std::string> ());
auto balance = block->balance ();
entry.put ("balance", balance.number ().convert_to<std::string> ());
entry.put ("height", std::to_string (block->sideband ().height));
entry.put ("local_timestamp", std::to_string (block->sideband ().timestamp));
entry.put ("successor", block->sideband ().successor.to_string ());
@ -1382,16 +1383,15 @@ void nano::json_handler::blocks_info ()
}
if (source)
{
nano::block_hash source_hash (node.ledger.block_source (transaction, *block));
auto block_a = node.ledger.block (transaction, source_hash);
if (block_a != nullptr)
if (!block->is_receive () || !node.ledger.block_exists (transaction, block->source ()))
{
auto source_account (node.ledger.account (*block_a));
entry.put ("source_account", source_account.to_account ());
entry.put ("source_account", "0");
}
else
{
entry.put ("source_account", "0");
auto block_a = node.ledger.block (transaction, block->source ());
release_assert (block_a);
entry.put ("source_account", block_a->account ().to_account ());
}
}
blocks.push_back (std::make_pair (hash_text, entry));
@ -1433,7 +1433,7 @@ void nano::json_handler::block_account ()
auto block = node.ledger.block (transaction, hash);
if (block)
{
response_l.put ("account", node.ledger.account (*block).to_account ());
response_l.put ("account", block->account ().to_account ());
}
else
{
@ -1613,10 +1613,10 @@ void nano::json_handler::block_create ()
// Wrapper from argument to lambda capture, to extend the block's scope
auto get_callback_l = [rpc_l, block_response_put_l] (std::shared_ptr<nano::block> const & block_a) {
// Callback upon work generation success or failure
return [block_a, rpc_l, block_response_put_l] (boost::optional<uint64_t> const & work_a) {
return [block_a, rpc_l, block_response_put_l] (std::optional<uint64_t> const & work_a) {
if (block_a != nullptr)
{
if (work_a.is_initialized ())
if (work_a.has_value ())
{
block_a->block_work_set (*work_a);
block_response_put_l (*block_a);
@ -2522,7 +2522,7 @@ public:
if (raw && accounts_filter.empty ())
{
tree.put ("subtype", "epoch");
tree.put ("account", handler.node.ledger.epoch_signer (block_a.link ()).to_account ());
tree.put ("account", handler.node.ledger.epoch_signer (block_a.link_field ().value ()).to_account ());
}
}
else
@ -3641,7 +3641,7 @@ void nano::json_handler::republish ()
block = node.ledger.block (transaction, hash);
if (sources != 0) // Republish source chain
{
nano::block_hash source (node.ledger.block_source (transaction, *block));
nano::block_hash source = block->source_field ().value_or (block->link_field ().value_or (0).as_block_hash ());
auto block_a = node.ledger.block (transaction, source);
std::vector<nano::block_hash> hashes;
while (block_a != nullptr && hashes.size () < sources)
@ -3679,7 +3679,7 @@ void nano::json_handler::republish ()
while (block_d != nullptr && hash != source)
{
hashes.push_back (previous);
source = node.ledger.block_source (transaction, *block_d);
source = block_d->source_field ().value_or (block_d->is_send () ? 0 : block_d->link_field ().value_or (0).as_block_hash ());
previous = block_d->previous ();
block_d = node.ledger.block (transaction, previous);
}
@ -4994,7 +4994,7 @@ void nano::json_handler::wallet_work_get ()
void nano::json_handler::work_generate ()
{
boost::optional<nano::account> account;
std::optional<nano::account> account;
auto account_opt (request.get_optional<std::string> ("account"));
// Default to work_1 if not specified
auto work_version (work_version_optional_impl (nano::work_version::work_1));
@ -5046,7 +5046,7 @@ void nano::json_handler::work_generate ()
{
auto use_peers (request.get<bool> ("use_peers", false));
auto rpc_l (shared_from_this ());
auto callback = [rpc_l, hash, work_version, this] (boost::optional<uint64_t> const & work_a) {
auto callback = [rpc_l, hash, work_version, this] (std::optional<uint64_t> const & work_a) {
if (work_a)
{
boost::property_tree::ptree response_l;

View file

@ -246,13 +246,13 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons
// Subtype field
else if (block_a->type () == nano::block_type::state)
{
if (block_a->link ().is_zero ())
if (block_a->is_change ())
{
event.add ("subtype", "change");
}
else if (is_state_epoch_a)
{
debug_assert (amount_a == 0 && node_l->ledger.is_epoch_link (block_a->link ()));
debug_assert (amount_a == 0 && node_l->ledger.is_epoch_link (block_a->link_field ().value ()));
event.add ("subtype", "epoch");
}
else
@ -1066,50 +1066,50 @@ bool nano::node::work_generation_enabled (std::vector<std::pair<std::string, uin
return !peers_a.empty () || local_work_generation_enabled ();
}
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::block & block_a, uint64_t difficulty_a)
std::optional<uint64_t> nano::node::work_generate_blocking (nano::block & block_a, uint64_t difficulty_a)
{
auto opt_work_l (work_generate_blocking (block_a.work_version (), block_a.root (), difficulty_a, block_a.account ()));
if (opt_work_l.is_initialized ())
auto opt_work_l (work_generate_blocking (block_a.work_version (), block_a.root (), difficulty_a, block_a.account_field ()));
if (opt_work_l.has_value ())
{
block_a.block_work_set (*opt_work_l);
block_a.block_work_set (opt_work_l.value ());
}
return opt_work_l;
}
void nano::node::work_generate (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::function<void (boost::optional<uint64_t>)> callback_a, boost::optional<nano::account> const & account_a, bool secondary_work_peers_a)
void nano::node::work_generate (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::function<void (std::optional<uint64_t>)> callback_a, std::optional<nano::account> const & account_a, bool secondary_work_peers_a)
{
auto const & peers_l (secondary_work_peers_a ? config.secondary_work_peers : config.work_peers);
if (distributed_work.make (version_a, root_a, peers_l, difficulty_a, callback_a, account_a))
{
// Error in creating the job (either stopped or work generation is not possible)
callback_a (boost::none);
callback_a (std::nullopt);
}
}
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
std::optional<uint64_t> nano::node::work_generate_blocking (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::optional<nano::account> const & account_a)
{
std::promise<boost::optional<uint64_t>> promise;
std::promise<std::optional<uint64_t>> promise;
work_generate (
version_a, root_a, difficulty_a, [&promise] (boost::optional<uint64_t> opt_work_a) {
version_a, root_a, difficulty_a, [&promise] (std::optional<uint64_t> opt_work_a) {
promise.set_value (opt_work_a);
},
account_a);
return promise.get_future ().get ();
}
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::block & block_a)
std::optional<uint64_t> nano::node::work_generate_blocking (nano::block & block_a)
{
debug_assert (network_params.network.is_dev_network ());
return work_generate_blocking (block_a, default_difficulty (nano::work_version::work_1));
}
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::root const & root_a)
std::optional<uint64_t> nano::node::work_generate_blocking (nano::root const & root_a)
{
debug_assert (network_params.network.is_dev_network ());
return work_generate_blocking (root_a, default_difficulty (nano::work_version::work_1));
}
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::root const & root_a, uint64_t difficulty_a)
std::optional<uint64_t> nano::node::work_generate_blocking (nano::root const & root_a, uint64_t difficulty_a)
{
debug_assert (network_params.network.is_dev_network ());
return work_generate_blocking (nano::work_version::work_1, root_a, difficulty_a);
@ -1215,19 +1215,15 @@ void nano::node::process_confirmed_data (store::transaction const & transaction_
{
// Faster account calculation
account_a = block_a->account ();
if (account_a.is_zero ())
{
account_a = block_a->sideband ().account;
}
// Faster amount calculation
auto previous (block_a->previous ());
auto previous_balance = ledger.balance (transaction_a, previous);
auto block_balance = ledger.balance (*block_a);
auto block_balance = block_a->balance ();
if (hash_a != ledger.constants.genesis->account ())
{
if (previous_balance)
{
amount_a = block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance;
amount_a = block_balance > previous_balance.value () ? block_balance.number () - previous_balance.value () : previous_balance.value () - block_balance.number ();
}
else
{
@ -1244,7 +1240,7 @@ void nano::node::process_confirmed_data (store::transaction const & transaction_
{
is_state_send_a = true;
}
if (amount_a == 0 && network_params.ledger.epochs.is_epoch_link (state->link ()))
if (amount_a == 0 && network_params.ledger.epochs.is_epoch_link (state->link_field ().value ()))
{
is_state_epoch_a = true;
}

View file

@ -43,6 +43,7 @@
#include <atomic>
#include <memory>
#include <optional>
#include <vector>
namespace nano
@ -109,9 +110,9 @@ public:
bool local_work_generation_enabled () const;
bool work_generation_enabled () const;
bool work_generation_enabled (std::vector<std::pair<std::string, uint16_t>> const &) const;
boost::optional<uint64_t> work_generate_blocking (nano::block &, uint64_t);
boost::optional<uint64_t> work_generate_blocking (nano::work_version const, nano::root const &, uint64_t, boost::optional<nano::account> const & = boost::none);
void work_generate (nano::work_version const, nano::root const &, uint64_t, std::function<void (boost::optional<uint64_t>)>, boost::optional<nano::account> const & = boost::none, bool const = false);
std::optional<uint64_t> work_generate_blocking (nano::block &, uint64_t);
std::optional<uint64_t> work_generate_blocking (nano::work_version const, nano::root const &, uint64_t, std::optional<nano::account> const & = std::nullopt);
void work_generate (nano::work_version const, nano::root const &, uint64_t, std::function<void (std::optional<uint64_t>)>, std::optional<nano::account> const & = std::nullopt, bool const = false);
void add_initial_peers ();
void start_election (std::shared_ptr<nano::block> const & block);
bool block_confirmed (nano::block_hash const &);
@ -197,11 +198,11 @@ public:
// For tests only
unsigned node_seq;
// For tests only
boost::optional<uint64_t> work_generate_blocking (nano::block &);
std::optional<uint64_t> work_generate_blocking (nano::block &);
// For tests only
boost::optional<uint64_t> work_generate_blocking (nano::root const &, uint64_t);
std::optional<uint64_t> work_generate_blocking (nano::root const &, uint64_t);
// For tests only
boost::optional<uint64_t> work_generate_blocking (nano::root const &);
std::optional<uint64_t> work_generate_blocking (nano::root const &);
public: // Testing convenience functions
/**

View file

@ -45,8 +45,7 @@ void nano::process_live_dispatcher::process_live (nano::block const & block, sto
// Start collecting quorum on block
if (ledger.dependents_confirmed (transaction, block))
{
auto account = block.account ().is_zero () ? block.sideband ().account : block.account ();
scheduler.activate (account, transaction);
scheduler.activate (block.account (), transaction);
}
if (websocket.server && websocket.server->any_subscriber (nano::websocket::topic::new_unconfirmed_block))

View file

@ -229,7 +229,7 @@ std::pair<std::vector<std::shared_ptr<nano::block>>, std::vector<std::shared_ptr
if (block != nullptr)
{
nano::confirmation_height_info confirmation_height_info;
ledger.store.confirmation_height.get (transaction, block->account ().is_zero () ? block->sideband ().account : block->account (), confirmation_height_info);
ledger.store.confirmation_height.get (transaction, block->account (), confirmation_height_info);
generate_final_vote = (confirmation_height_info.height >= block->sideband ().height);
}
}
@ -265,7 +265,7 @@ std::pair<std::vector<std::shared_ptr<nano::block>>, std::vector<std::shared_ptr
if (block != nullptr && generate_vote)
{
nano::confirmation_height_info confirmation_height_info;
ledger.store.confirmation_height.get (transaction, block->account ().is_zero () ? block->sideband ().account : block->account (), confirmation_height_info);
ledger.store.confirmation_height.get (transaction, block->account (), confirmation_height_info);
generate_final_vote = (confirmation_height_info.height >= block->sideband ().height);
}
}

View file

@ -1050,7 +1050,7 @@ bool nano::wallet::action_complete (std::shared_ptr<nano::block> const & block_a
account_a.to_account ());
debug_assert (required_difficulty <= wallets.node.max_work_generate_difficulty (block_a->work_version ()));
error = !wallets.node.work_generate_blocking (*block_a, required_difficulty).is_initialized ();
error = !wallets.node.work_generate_blocking (*block_a, required_difficulty).has_value ();
}
if (!error)
{
@ -1092,9 +1092,8 @@ bool nano::wallet::receive_sync (std::shared_ptr<nano::block> const & block_a, n
{
std::promise<bool> result;
std::future<bool> future = result.get_future ();
auto destination (block_a->link ().is_zero () ? block_a->destination () : block_a->link ().as_account ());
receive_async (
block_a->hash (), representative_a, amount_a, destination, [&result] (std::shared_ptr<nano::block> const & block_a) {
block_a->hash (), representative_a, amount_a, block_a->destination (), [&result] (std::shared_ptr<nano::block> const & block_a) {
result.set_value (block_a == nullptr);
},
true);
@ -1298,12 +1297,12 @@ void nano::wallet::work_cache_blocking (nano::account const & account_a, nano::r
{
auto difficulty (wallets.node.default_difficulty (nano::work_version::work_1));
auto opt_work_l (wallets.node.work_generate_blocking (nano::work_version::work_1, root_a, difficulty, account_a));
if (opt_work_l.is_initialized ())
if (opt_work_l.has_value ())
{
auto transaction_l (wallets.tx_begin_write ());
if (live () && store.exists (transaction_l, account_a))
{
work_update (transaction_l, account_a, root_a, *opt_work_l);
work_update (transaction_l, account_a, root_a, opt_work_l.value ());
}
}
else if (!wallets.node.stopped)

View file

@ -1012,13 +1012,13 @@ nano::websocket_server::websocket_server (nano::websocket::config & config_a, na
}
else if (block_a->type () == nano::block_type::state)
{
if (block_a->link ().is_zero ())
if (block_a->is_change ())
{
subtype = "change";
}
else if (is_state_epoch_a)
{
debug_assert (amount_a == 0 && ledger.is_epoch_link (block_a->link ()));
debug_assert (amount_a == 0 && ledger.is_epoch_link (block_a->link_field ().value ()));
subtype = "epoch";
}
else

View file

@ -2253,7 +2253,7 @@ void nano_qt::block_creation::create_send ()
details.is_send = true;
details.epoch = info.epoch ();
auto const required_difficulty{ wallet.node.network_params.work.threshold (send.work_version (), details) };
if (wallet.node.work_generate_blocking (send, required_difficulty).is_initialized ())
if (wallet.node.work_generate_blocking (send, required_difficulty).has_value ())
{
std::string block_l;
send.serialize_json (block_l);
@ -2337,7 +2337,7 @@ void nano_qt::block_creation::create_receive ()
details.is_receive = true;
details.epoch = std::max (info.epoch (), pending.epoch);
auto required_difficulty{ wallet.node.network_params.work.threshold (receive.work_version (), details) };
if (wallet.node.work_generate_blocking (receive, required_difficulty).is_initialized ())
if (wallet.node.work_generate_blocking (receive, required_difficulty).has_value ())
{
std::string block_l;
receive.serialize_json (block_l);
@ -2420,7 +2420,7 @@ void nano_qt::block_creation::create_change ()
nano::block_details details;
details.epoch = info.epoch ();
auto const required_difficulty{ wallet.node.network_params.work.threshold (change.work_version (), details) };
if (wallet.node.work_generate_blocking (change, required_difficulty).is_initialized ())
if (wallet.node.work_generate_blocking (change, required_difficulty).has_value ())
{
std::string block_l;
change.serialize_json (block_l);
@ -2502,7 +2502,7 @@ void nano_qt::block_creation::create_open ()
details.is_receive = true;
details.epoch = pending.epoch;
auto const required_difficulty{ wallet.node.network_params.work.threshold (open.work_version (), details) };
if (wallet.node.work_generate_blocking (open, required_difficulty).is_initialized ())
if (wallet.node.work_generate_blocking (open, required_difficulty).has_value ())
{
std::string block_l;
open.serialize_json (block_l);

View file

@ -360,7 +360,7 @@ TEST (wallet, DISABLED_process_block)
nano_qt::eventloop_processor processor;
nano::test::system system (1);
nano::account account;
nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis->account ()));
nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis_key.pub));
system.wallet (0)->insert_adhoc (nano::keypair ().prv);
{
auto transaction (system.nodes[0]->wallets.tx_begin_read ());
@ -665,7 +665,7 @@ TEST (wallet, block_viewer)
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 ());
nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis->account ()));
nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis_key.pub));
QTest::keyClicks (wallet->block_viewer.hash, latest.to_string ().c_str ());
QTest::mouseClick (wallet->block_viewer.retrieve, Qt::LeftButton);
ASSERT_FALSE (wallet->block_viewer.block->toPlainText ().toStdString ().empty ());
@ -916,7 +916,7 @@ TEST (wallet, DISABLED_synchronizing)
wallet->start ();
{
auto transaction (system1.nodes[0]->store.tx_begin_write ());
auto latest (system1.nodes[0]->ledger.latest (transaction, nano::dev::genesis->account ()));
auto latest (system1.nodes[0]->ledger.latest (transaction, nano::dev::genesis_key.pub));
auto send = std::make_shared<nano::send_block> (latest, key1, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system1.work.generate (latest));
system1.nodes[0]->ledger.process (transaction, send);
}

View file

@ -21,7 +21,7 @@ TEST (rpc, receivable)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "receivable");
request.put ("account", block1->link ().to_account ());
request.put ("account", block1->destination ().to_account ());
auto response = wait_response (system, rpc_ctx, request);
auto & blocks_node = response.get_child ("blocks");
ASSERT_EQ (1, blocks_node.size ());
@ -39,7 +39,7 @@ TEST (rpc, receivable_sorting)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "receivable");
request.put ("account", block1->link ().to_account ());
request.put ("account", block1->destination ().to_account ());
request.put ("sorting", "true"); // Sorting test
auto response = wait_response (system, rpc_ctx, request);
auto & blocks_node = response.get_child ("blocks");
@ -60,7 +60,7 @@ TEST (rpc, receivable_threshold_sufficient)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "receivable");
request.put ("account", block1->link ().to_account ());
request.put ("account", block1->destination ().to_account ());
request.put ("threshold", "1"); // Threshold test
auto response = wait_response (system, rpc_ctx, request);
auto & blocks_node = response.get_child ("blocks");
@ -91,7 +91,7 @@ TEST (rpc, receivable_threshold_insufficient)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "receivable");
request.put ("account", block1->link ().to_account ());
request.put ("account", block1->destination ().to_account ());
request.put ("threshold", "2"); // Chains are set up with 1 raw transfers therefore all blocks are less than 2 raw.
auto response = wait_response (system, rpc_ctx, request, 10s);
auto & blocks_node = response.get_child ("blocks");
@ -108,7 +108,7 @@ TEST (rpc, receivable_source_min_version)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "receivable");
request.put ("account", block1->link ().to_account ());
request.put ("account", block1->destination ().to_account ());
request.put ("source", "true");
request.put ("min_version", "true");
auto response (wait_response (system, rpc_ctx, request));
@ -140,7 +140,7 @@ TEST (rpc, receivable_unconfirmed)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "receivable");
request.put ("account", block1->link ().to_account ());
request.put ("account", block1->destination ().to_account ());
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0));
request.put ("include_only_confirmed", "true");
ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0));
@ -197,7 +197,7 @@ TEST (rpc, receivable_offset_and_sorting)
// check confirmation height is as expected, there is no perfect clarity yet when confirmation height updates after a block get confirmed
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (node->store.confirmation_height.get (node->store.tx_begin_read (), nano::dev::genesis->account (), confirmation_height_info));
ASSERT_FALSE (node->store.confirmation_height.get (node->store.tx_begin_read (), nano::dev::genesis_key.pub, confirmation_height_info));
ASSERT_EQ (confirmation_height_info.height, 7);
ASSERT_EQ (confirmation_height_info.frontier, block6->hash ());
@ -410,14 +410,14 @@ TEST (rpc, accounts_receivable_blocks)
request.put ("action", "accounts_receivable");
boost::property_tree::ptree entry;
boost::property_tree::ptree peers_l;
entry.put ("", block1->link ().to_account ());
entry.put ("", block1->destination ().to_account ());
peers_l.push_back (std::make_pair ("", entry));
request.add_child ("accounts", peers_l);
auto response = wait_response (system, rpc_ctx, request);
for (auto & blocks : response.get_child ("blocks"))
{
std::string account_text{ blocks.first };
ASSERT_EQ (block1->link ().to_account (), account_text);
ASSERT_EQ (block1->destination ().to_account (), account_text);
nano::block_hash hash1{ blocks.second.begin ()->second.get<std::string> ("") };
ASSERT_EQ (block1->hash (), hash1);
}
@ -436,7 +436,7 @@ TEST (rpc, accounts_receivable_sorting)
request.put ("action", "accounts_receivable");
boost::property_tree::ptree entry;
boost::property_tree::ptree peers_l;
entry.put ("", block1->link ().to_account ());
entry.put ("", block1->destination ().to_account ());
peers_l.push_back (std::make_pair ("", entry));
request.add_child ("accounts", peers_l);
request.put ("sorting", "true"); // Sorting test
@ -444,7 +444,7 @@ TEST (rpc, accounts_receivable_sorting)
for (auto & blocks : response.get_child ("blocks"))
{
std::string account_text{ blocks.first };
ASSERT_EQ (block1->link ().to_account (), account_text);
ASSERT_EQ (block1->destination ().to_account (), account_text);
nano::block_hash hash1{ blocks.second.begin ()->first };
ASSERT_EQ (block1->hash (), hash1);
std::string amount{ blocks.second.begin ()->second.get<std::string> ("") };
@ -465,7 +465,7 @@ TEST (rpc, accounts_receivable_threshold)
request.put ("action", "accounts_receivable");
boost::property_tree::ptree entry;
boost::property_tree::ptree peers_l;
entry.put ("", block1->link ().to_account ());
entry.put ("", block1->destination ().to_account ());
peers_l.push_back (std::make_pair ("", entry));
request.add_child ("accounts", peers_l);
request.put ("threshold", "1"); // Threshold test
@ -474,7 +474,7 @@ TEST (rpc, accounts_receivable_threshold)
for (auto & pending : response.get_child ("blocks"))
{
std::string account_text{ pending.first };
ASSERT_EQ (block1->link ().to_account (), account_text);
ASSERT_EQ (block1->destination ().to_account (), account_text);
for (auto i (pending.second.begin ()), j (pending.second.end ()); i != j; ++i)
{
nano::block_hash hash;
@ -501,7 +501,7 @@ TEST (rpc, accounts_receivable_source)
request.put ("action", "accounts_receivable");
boost::property_tree::ptree entry;
boost::property_tree::ptree peers_l;
entry.put ("", block1->link ().to_account ());
entry.put ("", block1->destination ().to_account ());
peers_l.push_back (std::make_pair ("", entry));
request.add_child ("accounts", peers_l);
request.put ("source", "true");
@ -512,7 +512,7 @@ TEST (rpc, accounts_receivable_source)
for (auto & pending : response.get_child ("blocks"))
{
std::string account_text (pending.first);
ASSERT_EQ (block1->link ().to_account (), account_text);
ASSERT_EQ (block1->destination ().to_account (), account_text);
for (auto i (pending.second.begin ()), j (pending.second.end ()); i != j; ++i)
{
nano::block_hash hash;
@ -540,7 +540,7 @@ TEST (rpc, accounts_receivable_confirmed)
request.put ("action", "accounts_receivable");
boost::property_tree::ptree entry;
boost::property_tree::ptree peers_l;
entry.put ("", block1->link ().to_account ());
entry.put ("", block1->destination ().to_account ());
peers_l.push_back (std::make_pair ("", entry));
request.add_child ("accounts", peers_l);

View file

@ -505,7 +505,7 @@ TEST (rpc, wallet_representative)
request.put ("action", "wallet_representative");
auto response (wait_response (system, rpc_ctx, request));
std::string account_text1 (response.get<std::string> ("representative"));
ASSERT_EQ (account_text1, nano::dev::genesis->account ().to_account ());
ASSERT_EQ (account_text1, nano::dev::genesis_key.pub.to_account ());
}
TEST (rpc, wallet_representative_set)
@ -663,7 +663,7 @@ TEST (rpc, wallet_export)
bool error (false);
auto transaction (node->wallets.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
nano::wallet_store store (error, kdf, transaction, node->wallets.env, nano::dev::genesis->account (), 1, "0", wallet_json);
nano::wallet_store store (error, kdf, transaction, node->wallets.env, nano::dev::genesis_key.pub, 1, "0", wallet_json);
ASSERT_FALSE (error);
ASSERT_TRUE (store.exists (transaction, nano::dev::genesis_key.pub));
}
@ -718,7 +718,7 @@ TEST (rpc, block)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "block");
request.put ("hash", node->latest (nano::dev::genesis->account ()).to_string ());
request.put ("hash", node->latest (nano::dev::genesis_key.pub).to_string ());
auto response (wait_response (system, rpc_ctx, request));
auto contents (response.get<std::string> ("contents"));
ASSERT_FALSE (contents.empty ());
@ -923,24 +923,24 @@ TEST (rpc, history)
ASSERT_NE (nullptr, change);
auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node0->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send);
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->link ().as_account ()));
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->destination ()));
ASSERT_NE (nullptr, receive);
nano::block_builder builder;
auto usend = builder
.state ()
.account (nano::dev::genesis->account ())
.previous (node0->latest (nano::dev::genesis->account ()))
.representative (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (node0->latest (nano::dev::genesis_key.pub))
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (nano::dev::genesis->account ())
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis->account ())))
.work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis_key.pub)))
.build ();
auto ureceive = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (usend->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount)
.link (usend->hash ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -948,7 +948,7 @@ TEST (rpc, history)
.build ();
auto uchange = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (ureceive->hash ())
.representative (nano::keypair ().pub)
.balance (nano::dev::constants.genesis_amount)
@ -1007,24 +1007,24 @@ TEST (rpc, account_history)
ASSERT_NE (nullptr, change);
auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node0->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send);
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->link ().as_account ()));
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->destination ()));
ASSERT_NE (nullptr, receive);
nano::block_builder builder;
auto usend = builder
.state ()
.account (nano::dev::genesis->account ())
.previous (node0->latest (nano::dev::genesis->account ()))
.representative (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (node0->latest (nano::dev::genesis_key.pub))
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (nano::dev::genesis->account ())
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis->account ())))
.work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis_key.pub)))
.build ();
auto ureceive = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (usend->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount)
.link (usend->hash ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -1032,7 +1032,7 @@ TEST (rpc, account_history)
.build ();
auto uchange = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (ureceive->hash ())
.representative (nano::keypair ().pub)
.balance (nano::dev::constants.genesis_amount)
@ -1050,7 +1050,7 @@ TEST (rpc, account_history)
{
boost::property_tree::ptree request;
request.put ("action", "account_history");
request.put ("account", nano::dev::genesis->account ().to_account ());
request.put ("account", nano::dev::genesis_key.pub.to_account ());
request.put ("count", 100);
auto response (wait_response (system, rpc_ctx, request, 10s));
std::vector<std::tuple<std::string, std::string, std::string, std::string, std::string, bool>> history_l;
@ -1096,7 +1096,7 @@ TEST (rpc, account_history)
{
boost::property_tree::ptree request;
request.put ("action", "account_history");
request.put ("account", nano::dev::genesis->account ().to_account ());
request.put ("account", nano::dev::genesis_key.pub.to_account ());
request.put ("reverse", true);
request.put ("count", 1);
auto response (wait_response (system, rpc_ctx, request, 10s));
@ -1110,7 +1110,7 @@ TEST (rpc, account_history)
auto account2 (system.wallet (0)->deterministic_insert ());
auto send2 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, account2, node0->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send2);
auto receive2 (system.wallet (0)->receive_action (send2->hash (), account2, node0->config.receive_minimum.number (), send2->link ().as_account ()));
auto receive2 (system.wallet (0)->receive_action (send2->hash (), account2, node0->config.receive_minimum.number (), send2->destination ()));
// Test filter for send state blocks
ASSERT_NE (nullptr, receive2);
{
@ -1153,7 +1153,7 @@ TEST (rpc, history_count)
ASSERT_NE (nullptr, change);
auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send);
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->link ().as_account ()));
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->destination ()));
ASSERT_NE (nullptr, receive);
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
@ -1211,11 +1211,11 @@ TEST (rpc, history_pruning)
// non legacy self send
auto usend = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (receive->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (nano::dev::genesis->account ())
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*node0->work_generate_blocking (receive->hash ()))
.build ();
@ -1224,9 +1224,9 @@ TEST (rpc, history_pruning)
// non legacy receive of the non legacy self send
auto ureceive = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (usend->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount)
.link (usend->hash ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -1237,7 +1237,7 @@ TEST (rpc, history_pruning)
// change genesis to a random rep
auto uchange = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (ureceive->hash ())
.representative (nano::keypair ().pub)
.balance (nano::dev::constants.genesis_amount)
@ -1514,9 +1514,9 @@ TEST (rpc, process_subtype_send)
nano::block_builder builder;
auto send = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (latest)
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -1550,9 +1550,9 @@ TEST (rpc, process_subtype_open)
nano::block_builder builder;
auto send = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (latest)
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -1599,9 +1599,9 @@ TEST (rpc, process_subtype_receive)
nano::block_builder builder;
auto send = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (latest)
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -1652,9 +1652,9 @@ TEST (rpc, process_ledger_insufficient_work)
nano::block_builder builder;
auto send = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (latest)
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -2088,9 +2088,9 @@ TEST (rpc, work_peer_bad)
auto const rpc_ctx = add_rpc (system, node1);
nano::block_hash hash1 (1);
std::atomic<uint64_t> work (0);
node2.work_generate (nano::work_version::work_1, hash1, node2.network_params.work.base, [&work] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
work = *work_a;
node2.work_generate (nano::work_version::work_1, hash1, node2.network_params.work.base, [&work] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
work = work_a.value ();
});
ASSERT_TIMELY (5s, nano::dev::network_params.work.difficulty (nano::work_version::work_1, hash1, work) >= nano::dev::network_params.work.threshold_base (nano::work_version::work_1));
}
@ -2107,9 +2107,9 @@ TEST (rpc, DISABLED_work_peer_one)
node2.config.work_peers.emplace_back (node1->network.endpoint ().address ().to_string (), rpc_ctx.rpc->listening_port ());
nano::keypair key1;
std::atomic<uint64_t> work (0);
node2.work_generate (nano::work_version::work_1, key1.pub, node1->network_params.work.base, [&work] (boost::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.is_initialized ());
work = *work_a;
node2.work_generate (nano::work_version::work_1, key1.pub, node1->network_params.work.base, [&work] (std::optional<uint64_t> work_a) {
ASSERT_TRUE (work_a.has_value ());
work = work_a.value ();
});
ASSERT_TIMELY (5s, nano::dev::network_params.work.difficulty (nano::work_version::work_1, key1.pub, work) >= nano::dev::network_params.work.threshold_base (nano::work_version::work_1));
}
@ -2138,7 +2138,7 @@ TEST (rpc, DISABLED_work_peer_many)
for (auto & work : works)
{
nano::keypair key1;
node1.work_generate (nano::work_version::work_1, key1.pub, node1.network_params.work.base, [&work] (boost::optional<uint64_t> work_a) {
node1.work_generate (nano::work_version::work_1, key1.pub, node1.network_params.work.base, [&work] (std::optional<uint64_t> work_a) {
work = *work_a;
});
while (nano::dev::network_params.work.difficulty (nano::work_version::work_1, key1.pub, work) < nano::dev::network_params.work.threshold_base (nano::work_version::work_1))
@ -2377,11 +2377,11 @@ TEST (rpc, account_representative)
auto node = add_ipc_enabled_node (system);
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("account", nano::dev::genesis->account ().to_account ());
request.put ("account", nano::dev::genesis_key.pub.to_account ());
request.put ("action", "account_representative");
auto response (wait_response (system, rpc_ctx, request));
std::string account_text1 (response.get<std::string> ("representative"));
ASSERT_EQ (account_text1, nano::dev::genesis->account ().to_account ());
ASSERT_EQ (account_text1, nano::dev::genesis_key.pub.to_account ());
}
TEST (rpc, account_representative_set)
@ -2397,7 +2397,7 @@ TEST (rpc, account_representative_set)
auto key2_open_block_hash = wallet.send_sync (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ());
ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), key2_open_block_hash));
auto key2_open_block = node->ledger.block (node->store.tx_begin_read (), key2_open_block_hash);
ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative ());
ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative_field ().value ());
// now change the representative of key2 to be genesis
auto const rpc_ctx = add_rpc (system, node);
@ -2416,7 +2416,7 @@ TEST (rpc, account_representative_set)
auto block = node->ledger.block (node->store.tx_begin_read (), hash);
ASSERT_NE (block, nullptr);
ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), hash));
ASSERT_EQ (key2.pub, block->representative ());
ASSERT_EQ (key2.pub, block->representative_field ().value ());
}
TEST (rpc, account_representative_set_work_disabled)
@ -2429,7 +2429,7 @@ TEST (rpc, account_representative_set_work_disabled)
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
nano::keypair rep;
request.put ("account", nano::dev::genesis->account ().to_account ());
request.put ("account", nano::dev::genesis_key.pub.to_account ());
request.put ("representative", rep.pub.to_account ());
request.put ("wallet", node->wallets.items.begin ()->first.to_string ());
request.put ("action", "account_representative_set");
@ -2491,7 +2491,7 @@ TEST (rpc, bootstrap)
auto send = builder
.send ()
.previous (latest)
.destination (nano::dev::genesis->account ())
.destination (nano::dev::genesis_key.pub)
.balance (100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*node1->work_generate_blocking (latest))
@ -2511,7 +2511,7 @@ TEST (rpc, bootstrap)
system0.poll ();
}
system1.deadline_set (10s);
while (node->latest (nano::dev::genesis->account ()) != node1->latest (nano::dev::genesis->account ()))
while (node->latest (nano::dev::genesis_key.pub) != node1->latest (nano::dev::genesis_key.pub))
{
ASSERT_NO_ERROR (system0.poll ());
ASSERT_NO_ERROR (system1.poll ());
@ -2550,7 +2550,7 @@ TEST (rpc, representatives)
representatives.push_back (account);
}
ASSERT_EQ (1, representatives.size ());
ASSERT_EQ (nano::dev::genesis->account (), representatives[0]);
ASSERT_EQ (nano::dev::genesis_key.pub, representatives[0]);
}
// wallet_seed is only available over IPC's unsafe encoding, and when running on test network
@ -2626,7 +2626,7 @@ TEST (rpc, wallet_frontiers)
frontiers.push_back (nano::account (i->second.get<std::string> ("")));
}
ASSERT_EQ (1, frontiers.size ());
ASSERT_EQ (node->latest (nano::dev::genesis->account ()), frontiers[0]);
ASSERT_EQ (node->latest (nano::dev::genesis_key.pub), frontiers[0]);
}
TEST (rpc, work_validate)
@ -2776,7 +2776,7 @@ TEST (rpc, bootstrap_any)
auto send = builder
.send ()
.previous (latest)
.destination (nano::dev::genesis->account ())
.destination (nano::dev::genesis_key.pub)
.balance (100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system1.nodes[0]->work_generate_blocking (latest))
@ -3051,8 +3051,8 @@ TEST (rpc, accounts_representatives)
request.add_child ("accounts", accounts);
auto response (wait_response (system, rpc_ctx, request));
// Ensures the response is correct.
auto response_representative (response.get_child ("representatives").get<std::string> (nano::dev::genesis->account ().to_account ()));
ASSERT_EQ (response_representative, nano::dev::genesis->account ().to_account ());
auto response_representative (response.get_child ("representatives").get<std::string> (nano::dev::genesis_key.pub.to_account ()));
ASSERT_EQ (response_representative, nano::dev::genesis_key.pub.to_account ());
ASSERT_EQ (response.count ("errors"), 0);
}
@ -3093,7 +3093,7 @@ TEST (rpc, accounts_representatives_with_errors)
ASSERT_EQ (response.get_child ("representatives").size (), 1);
ASSERT_EQ (response.get_child ("representatives").count (nano::dev::genesis_key.pub.to_account ()), 1);
auto rep_text = response.get_child ("representatives").get<std::string> (nano::dev::genesis_key.pub.to_account ());
ASSERT_EQ (rep_text, nano::dev::genesis->account ().to_account ());
ASSERT_EQ (rep_text, nano::dev::genesis_key.pub.to_account ());
ASSERT_EQ (response.count ("errors"), 1);
ASSERT_EQ (response.get_child ("errors").size (), 2);
@ -3126,7 +3126,7 @@ TEST (rpc, accounts_frontiers)
ASSERT_EQ (response.get_child ("frontiers").size (), 1);
ASSERT_EQ (response.get_child ("frontiers").count (nano::dev::genesis_key.pub.to_account ()), 1);
auto frontier_text = response.get_child ("frontiers").get<std::string> (nano::dev::genesis_key.pub.to_account ());
ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis->account ()));
ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis_key.pub));
ASSERT_EQ (response.count ("errors"), 0);
}
@ -3166,7 +3166,7 @@ TEST (rpc, accounts_frontiers_with_errors)
ASSERT_EQ (response.get_child ("frontiers").size (), 1);
ASSERT_EQ (response.get_child ("frontiers").count (nano::dev::genesis_key.pub.to_account ()), 1);
auto frontier_text = response.get_child ("frontiers").get<std::string> (nano::dev::genesis_key.pub.to_account ());
ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis->account ()));
ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis_key.pub));
ASSERT_EQ (response.count ("errors"), 1);
ASSERT_EQ (response.get_child ("errors").size (), 2);
@ -3185,14 +3185,14 @@ TEST (rpc, blocks)
request.put ("action", "blocks");
boost::property_tree::ptree entry;
boost::property_tree::ptree peers_l;
entry.put ("", node->latest (nano::dev::genesis->account ()).to_string ());
entry.put ("", node->latest (nano::dev::genesis_key.pub).to_string ());
peers_l.push_back (std::make_pair ("", entry));
request.add_child ("hashes", peers_l);
auto response (wait_response (system, rpc_ctx, request));
for (auto & blocks : response.get_child ("blocks"))
{
std::string hash_text (blocks.first);
ASSERT_EQ (node->latest (nano::dev::genesis->account ()).to_string (), hash_text);
ASSERT_EQ (node->latest (nano::dev::genesis_key.pub).to_string (), hash_text);
std::string blocks_text (blocks.second.get<std::string> (""));
ASSERT_FALSE (blocks_text.empty ());
}
@ -3291,7 +3291,7 @@ TEST (rpc, pending_exists)
auto node = add_ipc_enabled_node (system, config);
nano::keypair key1;
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
auto hash0 (node->latest (nano::dev::genesis->account ()));
auto hash0 (node->latest (nano::dev::genesis_key.pub));
auto block1 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 100));
ASSERT_TIMELY (5s, node->block_confirmed (block1->hash ()));
ASSERT_TIMELY (5s, !node->active.active (*block1));
@ -3467,7 +3467,7 @@ TEST (rpc, work_get)
std::string work_text (response.get<std::string> ("work"));
uint64_t work (1);
auto transaction (node->wallets.tx_begin_read ());
node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis->account (), work);
node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis_key.pub, work);
ASSERT_EQ (nano::to_string_hex (work), work_text);
}
@ -3489,7 +3489,7 @@ TEST (rpc, wallet_work_get)
ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), account_text);
std::string work_text (works.second.get<std::string> (""));
uint64_t work (1);
node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis->account (), work);
node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis_key.pub, work);
ASSERT_EQ (nano::to_string_hex (work), work_text);
}
}
@ -3511,7 +3511,7 @@ TEST (rpc, work_set)
ASSERT_TRUE (success.empty ());
uint64_t work1 (1);
auto transaction (node->wallets.tx_begin_read ());
node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis->account (), work1);
node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis_key.pub, work1);
ASSERT_EQ (work1, work0);
}
@ -3973,9 +3973,9 @@ TEST (rpc, json_block_input)
nano::block_builder builder;
auto send = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (node1->latest (nano::dev::genesis_key.pub))
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -4042,7 +4042,7 @@ TEST (rpc, blocks_info)
for (auto & blocks : response.get_child ("blocks"))
{
std::string hash_text (blocks.first);
ASSERT_EQ (node->latest (nano::dev::genesis->account ()).to_string (), hash_text);
ASSERT_EQ (node->latest (nano::dev::genesis_key.pub).to_string (), hash_text);
std::string account_text (blocks.second.get<std::string> ("block_account"));
ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), account_text);
std::string amount_text (blocks.second.get<std::string> ("amount"));
@ -4066,7 +4066,7 @@ TEST (rpc, blocks_info)
request.put ("action", "blocks_info");
boost::property_tree::ptree entry;
boost::property_tree::ptree hashes;
entry.put ("", node->latest (nano::dev::genesis->account ()).to_string ());
entry.put ("", node->latest (nano::dev::genesis_key.pub).to_string ());
hashes.push_back (std::make_pair ("", entry));
request.add_child ("hashes", hashes);
{
@ -4126,10 +4126,10 @@ TEST (rpc, blocks_info_receive_hash)
auto send4 = system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 4);
// do 4 receives, mix up the ordering a little
auto recv1 (system.wallet (0)->receive_action (send1->hash (), key1.pub, node->config.receive_minimum.number (), send1->link ().as_account ()));
auto recv4 (system.wallet (0)->receive_action (send4->hash (), key1.pub, node->config.receive_minimum.number (), send4->link ().as_account ()));
auto recv3 (system.wallet (0)->receive_action (send3->hash (), key1.pub, node->config.receive_minimum.number (), send3->link ().as_account ()));
auto recv2 (system.wallet (0)->receive_action (send2->hash (), key1.pub, node->config.receive_minimum.number (), send2->link ().as_account ()));
auto recv1 (system.wallet (0)->receive_action (send1->hash (), key1.pub, node->config.receive_minimum.number (), send1->destination ()));
auto recv4 (system.wallet (0)->receive_action (send4->hash (), key1.pub, node->config.receive_minimum.number (), send4->destination ()));
auto recv3 (system.wallet (0)->receive_action (send3->hash (), key1.pub, node->config.receive_minimum.number (), send3->destination ()));
auto recv2 (system.wallet (0)->receive_action (send2->hash (), key1.pub, node->config.receive_minimum.number (), send2->destination ()));
// function to check that all 4 receive blocks are cemented
auto all_blocks_cemented = [node, &key1] () -> bool {
@ -4192,7 +4192,7 @@ TEST (rpc, blocks_info_subtype)
system.wallet (0)->insert_adhoc (key.prv);
auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, nano::Gxrb_ratio));
ASSERT_NE (nullptr, send);
auto receive (system.wallet (0)->receive_action (send->hash (), key.pub, nano::Gxrb_ratio, send->link ().as_account ()));
auto receive (system.wallet (0)->receive_action (send->hash (), key.pub, nano::Gxrb_ratio, send->destination ()));
ASSERT_NE (nullptr, receive);
auto change (system.wallet (0)->change_action (nano::dev::genesis_key.pub, key.pub));
ASSERT_NE (nullptr, change);
@ -4769,7 +4769,7 @@ TEST (rpc, block_create_state_open)
auto process_result (node->process (state_block));
ASSERT_EQ (nano::block_status::progress, process_result);
ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_0);
ASSERT_TRUE (state_block->sideband ().details.is_receive);
ASSERT_TRUE (state_block->is_receive ());
ASSERT_FALSE (node->latest (key.pub).is_zero ());
}
@ -4848,7 +4848,7 @@ TEST (rpc, block_create_open_epoch_v2)
auto process_result (node->process (state_block));
ASSERT_EQ (nano::block_status::progress, process_result);
ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_2);
ASSERT_TRUE (state_block->sideband ().details.is_receive);
ASSERT_TRUE (state_block->is_receive ());
ASSERT_FALSE (node->latest (key.pub).is_zero ());
}
@ -4900,7 +4900,7 @@ TEST (rpc, block_create_receive_epoch_v2)
auto process_result (node->process (state_block));
ASSERT_EQ (nano::block_status::progress, process_result);
ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_2);
ASSERT_TRUE (state_block->sideband ().details.is_receive);
ASSERT_TRUE (state_block->is_receive ());
ASSERT_FALSE (node->latest (key.pub).is_zero ());
}
@ -4951,7 +4951,7 @@ TEST (rpc, block_create_send_epoch_v2)
auto process_result (node->process (state_block));
ASSERT_EQ (nano::block_status::progress, process_result);
ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_2);
ASSERT_TRUE (state_block->sideband ().details.is_send);
ASSERT_TRUE (state_block->is_send ());
ASSERT_FALSE (node->latest (key.pub).is_zero ());
}
@ -5177,7 +5177,7 @@ TEST (rpc, online_reps)
auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, new_rep, node1->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send);
ASSERT_TIMELY (10s, node2->block (send->hash ()));
auto receive (system.wallet (1)->receive_action (send->hash (), new_rep, node1->config.receive_minimum.number (), send->link ().as_account ()));
auto receive (system.wallet (1)->receive_action (send->hash (), new_rep, node1->config.receive_minimum.number (), send->destination ()));
ASSERT_NE (nullptr, receive);
ASSERT_TIMELY (5s, node2->block (receive->hash ()));
auto change (system.wallet (0)->change_action (nano::dev::genesis_key.pub, new_rep));
@ -5666,7 +5666,7 @@ TEST (rpc, DISABLED_wallet_history)
auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send);
auto timestamp2 = nano::seconds_since_epoch ();
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->link ().as_account ()));
auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->destination ()));
ASSERT_NE (nullptr, receive);
nano::keypair key;
auto timestamp3 = nano::seconds_since_epoch ();
@ -5719,9 +5719,9 @@ TEST (rpc, sign_hash)
nano::block_builder builder;
auto send = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (node1->latest (nano::dev::genesis_key.pub))
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -5752,9 +5752,9 @@ TEST (rpc, sign_block)
nano::block_builder builder;
auto send = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (node1->latest (nano::dev::genesis_key.pub))
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -5855,7 +5855,7 @@ TEST (rpc, block_confirmed)
auto open1 = builder
.open ()
.source (send1->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key.pub)
.sign (key.prv, key.pub)
.work (*system.work.generate (key.pub))

View file

@ -127,10 +127,10 @@ nano::ledger_constants::ledger_constants (nano::work_thresholds & work, nano::ne
: network_a == nano::networks::nano_test_network ? nano_test_final_votes_canary_height
: nano_live_final_votes_canary_height)
{
nano_beta_genesis->sideband_set (nano::block_sideband (nano_beta_genesis->account (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano_dev_genesis->sideband_set (nano::block_sideband (nano_dev_genesis->account (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano_live_genesis->sideband_set (nano::block_sideband (nano_live_genesis->account (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano_test_genesis->sideband_set (nano::block_sideband (nano_test_genesis->account (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano_beta_genesis->sideband_set (nano::block_sideband (nano_beta_genesis->account_field ().value (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano_dev_genesis->sideband_set (nano::block_sideband (nano_dev_genesis->account_field ().value (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano_live_genesis->sideband_set (nano::block_sideband (nano_live_genesis->account_field ().value (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano_test_genesis->sideband_set (nano::block_sideband (nano_test_genesis->account_field ().value (), 0, std::numeric_limits<nano::uint128_t>::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
nano::link epoch_link_v1;
char const * epoch_message_v1 ("epoch v1 block");

View file

@ -64,7 +64,7 @@ public:
{
auto hash (block_a.hash ());
auto amount = ledger.amount (transaction, hash).value ();
auto destination_account = ledger.account (block_a);
auto destination_account = block_a.account ();
// Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing
auto source_account = ledger.account (transaction, block_a.hashables.source);
auto info = ledger.account_info (transaction, destination_account);
@ -83,9 +83,9 @@ public:
{
auto hash (block_a.hash ());
auto amount = ledger.amount (transaction, hash).value ();
auto destination_account = ledger.account (block_a);
auto destination_account = block_a.account ();
auto source_account = ledger.account (transaction, block_a.hashables.source);
ledger.cache.rep_weights.representation_add (block_a.representative (), 0 - amount);
ledger.cache.rep_weights.representation_add (block_a.representative_field ().value (), 0 - amount);
nano::account_info new_info;
ledger.update_account (transaction, destination_account, new_info, new_info);
ledger.store.block.del (transaction, hash);
@ -97,14 +97,14 @@ public:
{
auto hash (block_a.hash ());
auto rep_block (ledger.representative (transaction, block_a.hashables.previous));
auto account = ledger.account (block_a);
auto account = block_a.account ();
auto info = ledger.account_info (transaction, account);
debug_assert (info);
auto balance = ledger.balance (transaction, block_a.hashables.previous).value ();
auto block = ledger.store.block.get (transaction, rep_block);
release_assert (block != nullptr);
auto representative = block->representative ();
ledger.cache.rep_weights.representation_add_dual (block_a.representative (), 0 - balance, representative, balance);
auto representative = block->representative_field ().value ();
ledger.cache.rep_weights.representation_add_dual (block_a.hashables.representative, 0 - balance, representative, balance);
ledger.store.block.del (transaction, hash);
nano::account_info new_info (block_a.hashables.previous, representative, info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0);
ledger.update_account (transaction, account, *info, new_info);
@ -129,13 +129,13 @@ public:
// Move existing representation & add in amount delta
auto block (ledger.store.block.get (transaction, rep_block_hash));
debug_assert (block != nullptr);
representative = block->representative ();
ledger.cache.rep_weights.representation_add_dual (representative, balance, block_a.representative (), 0 - block_a.hashables.balance.number ());
representative = block->representative_field ().value ();
ledger.cache.rep_weights.representation_add_dual (representative, balance, block_a.hashables.representative, 0 - block_a.hashables.balance.number ());
}
else
{
// Add in amount delta only
ledger.cache.rep_weights.representation_add (block_a.representative (), 0 - block_a.hashables.balance.number ());
ledger.cache.rep_weights.representation_add (block_a.hashables.representative, 0 - block_a.hashables.balance.number ());
}
auto info = ledger.account_info (transaction, block_a.hashables.account);
@ -224,7 +224,7 @@ bool ledger_processor::validate_epoch_block (nano::state_block const & block_a)
if (validate_message (block_a.hashables.account, block_a.hash (), block_a.signature))
{
// Is epoch block signed correctly
if (validate_message (ledger.epoch_signer (block_a.link ()), block_a.hash (), block_a.signature))
if (validate_message (ledger.epoch_signer (block_a.link_field ().value ()), block_a.hash (), block_a.signature))
{
result = nano::block_status::bad_signature;
}
@ -345,12 +345,12 @@ void ledger_processor::state_block_impl (nano::state_block & block_a)
if (!info.head.is_zero ())
{
// Move existing representation & add in amount delta
ledger.cache.rep_weights.representation_add_dual (info.representative, 0 - info.balance.number (), block_a.representative (), block_a.hashables.balance.number ());
ledger.cache.rep_weights.representation_add_dual (info.representative, 0 - info.balance.number (), block_a.hashables.representative, block_a.hashables.balance.number ());
}
else
{
// Add in amount delta only
ledger.cache.rep_weights.representation_add (block_a.representative (), block_a.hashables.balance.number ());
ledger.cache.rep_weights.representation_add (block_a.hashables.representative, block_a.hashables.balance.number ());
}
if (is_send)
@ -364,7 +364,7 @@ void ledger_processor::state_block_impl (nano::state_block & block_a)
ledger.store.pending.del (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link.as_block_hash ()));
}
nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch);
nano::account_info new_info (hash, block_a.hashables.representative, info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch);
ledger.update_account (transaction, block_a.hashables.account, info, new_info);
if (!ledger.store.frontier.get (transaction, info.head).is_zero ())
{
@ -434,7 +434,7 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a)
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::epoch_block);
block_a.sideband_set (nano::block_sideband (block_a.hashables.account /* unused */, 0, 0 /* unused */, info.block_count + 1, nano::seconds_since_epoch (), block_details, nano::epoch::epoch_0 /* unused */));
ledger.store.block.put (transaction, hash, block_a);
nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch);
nano::account_info new_info (hash, block_a.hashables.representative, info.open_block.is_zero () ? hash : info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch);
ledger.update_account (transaction, block_a.hashables.account, info, new_info);
if (!ledger.store.frontier.get (transaction, info.head).is_zero ())
{
@ -480,9 +480,9 @@ void ledger_processor::change_block (nano::change_block & block_a)
debug_assert (!validate_message (account, hash, block_a.signature));
block_a.sideband_set (nano::block_sideband (account, 0, info->balance, info->block_count + 1, nano::seconds_since_epoch (), block_details, nano::epoch::epoch_0 /* unused */));
ledger.store.block.put (transaction, hash, block_a);
auto balance = ledger.balance (*previous);
ledger.cache.rep_weights.representation_add_dual (block_a.representative (), balance, info->representative, 0 - balance);
nano::account_info new_info (hash, block_a.representative (), info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0);
auto balance = previous->balance ();
ledger.cache.rep_weights.representation_add_dual (block_a.hashables.representative, balance.number (), info->representative, 0 - balance.number ());
nano::account_info new_info (hash, block_a.hashables.representative, info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0);
ledger.update_account (transaction, account, *info, new_info);
ledger.store.frontier.del (transaction, block_a.hashables.previous);
ledger.store.frontier.put (transaction, hash, account);
@ -665,9 +665,9 @@ void ledger_processor::open_block (nano::open_block & block_a)
ledger.store.pending.del (transaction, key);
block_a.sideband_set (nano::block_sideband (block_a.hashables.account, 0, pending.amount, 1, nano::seconds_since_epoch (), block_details, nano::epoch::epoch_0 /* unused */));
ledger.store.block.put (transaction, hash, block_a);
nano::account_info new_info (hash, block_a.representative (), hash, pending.amount.number (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0);
nano::account_info new_info (hash, block_a.representative_field ().value (), hash, pending.amount.number (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0);
ledger.update_account (transaction, block_a.hashables.account, info, new_info);
ledger.cache.rep_weights.representation_add (block_a.representative (), pending.amount.number ());
ledger.cache.rep_weights.representation_add (block_a.representative_field ().value (), pending.amount.number ());
ledger.store.frontier.put (transaction, hash, block_a.hashables.account);
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::open);
}
@ -808,28 +808,6 @@ void nano::ledger::initialize (nano::generate_cache const & generate_cache_a)
}
}
nano::uint128_t nano::ledger::balance (nano::block const & block)
{
nano::uint128_t result;
switch (block.type ())
{
case nano::block_type::open:
case nano::block_type::receive:
case nano::block_type::change:
result = block.sideband ().balance.number ();
break;
case nano::block_type::send:
case nano::block_type::state:
result = block.balance ().number ();
break;
case nano::block_type::invalid:
case nano::block_type::not_a_block:
release_assert (false);
break;
}
return result;
}
// Balance for account containing hash
std::optional<nano::uint128_t> nano::ledger::balance (store::transaction const & transaction, nano::block_hash const & hash) const
{
@ -842,7 +820,7 @@ std::optional<nano::uint128_t> nano::ledger::balance (store::transaction const &
{
return std::nullopt;
}
return balance (*block);
return block->balance ().number ();
}
std::shared_ptr<nano::block> nano::ledger::block (store::transaction const & transaction, nano::block_hash const & hash) const
@ -972,38 +950,6 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a)
return result;
}
bool nano::ledger::is_send (store::transaction const & transaction_a, nano::block const & block_a) const
{
if (block_a.type () != nano::block_type::state)
{
return block_a.type () == nano::block_type::send;
}
nano::block_hash previous = block_a.previous ();
/*
* if block_a does not have a sideband, then is_send()
* requires that the previous block exists in the database.
* This is because it must retrieve the balance of the previous block.
*/
debug_assert (block_a.has_sideband () || previous.is_zero () || block_exists (transaction_a, previous));
bool result (false);
if (block_a.has_sideband ())
{
result = block_a.sideband ().details.is_send;
}
else
{
if (!previous.is_zero ())
{
if (block_a.balance () < balance (transaction_a, previous))
{
result = true;
}
}
}
return result;
}
nano::account const & nano::ledger::block_destination (store::transaction const & transaction_a, nano::block const & block_a)
{
nano::send_block const * send_block (dynamic_cast<nano::send_block const *> (&block_a));
@ -1012,7 +958,7 @@ nano::account const & nano::ledger::block_destination (store::transaction const
{
return send_block->hashables.destination;
}
else if (state_block != nullptr && is_send (transaction_a, *state_block))
else if (state_block != nullptr && block_a.is_send ())
{
return state_block->hashables.link.as_account ();
}
@ -1020,26 +966,6 @@ nano::account const & nano::ledger::block_destination (store::transaction const
return nano::account::null ();
}
nano::block_hash nano::ledger::block_source (store::transaction const & transaction_a, nano::block const & block_a)
{
/*
* block_source() requires that the previous block of the block
* passed in exist in the database. This is because it will try
* to check account balances to determine if it is a send block.
*/
debug_assert (block_a.previous ().is_zero () || block_exists (transaction_a, block_a.previous ()));
// If block_a.source () is nonzero, then we have our source.
// However, universal blocks will always return zero.
nano::block_hash result (block_a.source ());
nano::state_block const * state_block (dynamic_cast<nano::state_block const *> (&block_a));
if (state_block != nullptr && !is_send (transaction_a, *state_block))
{
result = state_block->hashables.link.as_block_hash ();
}
return result;
}
std::pair<nano::block_hash, nano::block_hash> nano::ledger::hash_root_random (store::transaction const & transaction_a) const
{
nano::block_hash hash (0);
@ -1129,18 +1055,6 @@ bool nano::ledger::rollback (store::write_transaction const & transaction_a, nan
return rollback (transaction_a, block_a, rollback_list);
}
nano::account nano::ledger::account (nano::block const & block)
{
debug_assert (block.has_sideband ());
nano::account result (block.account ());
if (result.is_zero ())
{
result = block.sideband ().account;
}
debug_assert (!result.is_zero ());
return result;
}
std::optional<nano::account> nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const
{
auto block_l = block (transaction, hash);
@ -1148,7 +1062,7 @@ std::optional<nano::account> nano::ledger::account (store::transaction const & t
{
return std::nullopt;
}
return account (*block_l);
return block_l->account ();
}
std::optional<nano::account_info> nano::ledger::account_info (store::transaction const & transaction, nano::account const & account) const
@ -1163,17 +1077,17 @@ std::optional<nano::uint128_t> nano::ledger::amount (store::transaction const &
{
return std::nullopt;
}
auto block_balance = balance (*block_l);
auto block_balance = block_l->balance ();
if (block_l->previous ().is_zero ())
{
return block_balance;
return block_balance.number ();
}
auto previous_balance = balance (transaction_a, block_l->previous ());
if (!previous_balance)
{
return std::nullopt;
}
return block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance;
return block_balance > previous_balance.value () ? block_balance.number () - previous_balance.value () : previous_balance.value () - block_balance.number ();
}
// Return latest block for account
@ -1244,13 +1158,13 @@ public:
void receive_block (nano::receive_block const & block_a) override
{
result[0] = block_a.previous ();
result[1] = block_a.source ();
result[1] = block_a.source_field ().value ();
}
void open_block (nano::open_block const & block_a) override
{
if (block_a.source () != ledger.constants.genesis->account ())
if (block_a.source_field ().value () != ledger.constants.genesis->account ())
{
result[0] = block_a.source ();
result[0] = block_a.source_field ().value ();
}
}
void change_block (nano::change_block const & block_a) override
@ -1262,11 +1176,25 @@ public:
result[0] = block_a.hashables.previous;
result[1] = block_a.hashables.link.as_block_hash ();
// ledger.is_send will check the sideband first, if block_a has a loaded sideband the check that previous block exists can be skipped
if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.block_exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a)))
if (ledger.is_epoch_link (block_a.hashables.link) || is_send (transaction, block_a))
{
result[1].clear ();
}
}
// This function is used in place of block->is_send () as it is tolerant to the block not having the sideband information loaded
// This is needed for instance in vote generation on forks which have not yet had sideband information attached
bool is_send (nano::store::transaction const & transaction, nano::state_block const & block) const
{
if (block.previous ().is_zero ())
{
return false;
}
if (block.has_sideband ())
{
return block.sideband ().details.is_send;
}
return block.balance_field ().value () < ledger.balance (transaction, block.previous ());
}
nano::ledger const & ledger;
nano::store::transaction const & transaction;
std::array<nano::block_hash, 2> result;
@ -1299,22 +1227,7 @@ std::shared_ptr<nano::block> nano::ledger::find_receive_block_by_send_hash (stor
// walk down the chain until the source field of a receive block matches the send block hash
while (possible_receive_block != nullptr)
{
// if source is non-zero then it is a legacy receive or open block
nano::block_hash source = possible_receive_block->source ();
// if source is zero then it could be a state block, which needs a different kind of access
auto state_block = dynamic_cast<nano::state_block const *> (possible_receive_block.get ());
if (state_block != nullptr)
{
// we read the block from the database, so we expect it to have sideband
debug_assert (state_block->has_sideband ());
if (state_block->sideband ().details.is_receive)
{
source = state_block->hashables.link.as_block_hash ();
}
}
if (send_block_hash == source)
if (possible_receive_block->is_receive () && send_block_hash == possible_receive_block->source ())
{
// we have a match
result = possible_receive_block;
@ -1431,7 +1344,7 @@ bool nano::ledger::block_confirmed (store::transaction const & transaction_a, na
if (block_l)
{
nano::confirmation_height_info confirmation_height_info;
store.confirmation_height.get (transaction_a, block_l->account ().is_zero () ? block_l->sideband ().account : block_l->account (), confirmation_height_info);
store.confirmation_height.get (transaction_a, block_l->account (), confirmation_height_info);
auto confirmed (confirmation_height_info.height >= block_l->sideband ().height);
return confirmed;
}
@ -1616,7 +1529,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
auto random_block (store.block.random (lmdb_transaction));
error |= rocksdb_store->block.get (rocksdb_transaction, random_block->hash ()) == nullptr;
auto account = random_block->account ().is_zero () ? random_block->sideband ().account : random_block->account ();
auto account = random_block->account ();
nano::account_info account_info;
error |= rocksdb_store->account.get (rocksdb_transaction, account, account_info);

View file

@ -30,10 +30,6 @@ class ledger final
{
public:
ledger (nano::store::component &, nano::stats &, nano::ledger_constants & constants, nano::generate_cache const & = nano::generate_cache ());
/**
* Return account containing hash, expects that block hash exists in ledger
*/
static nano::account account (nano::block const & block);
/**
* Returns the account for a given hash
* Returns std::nullopt if the block doesn't exist or has been pruned
@ -41,7 +37,6 @@ public:
std::optional<nano::account> account (store::transaction const &, nano::block_hash const &) const;
std::optional<nano::account_info> account_info (store::transaction const & transaction, nano::account const & account) const;
std::optional<nano::uint128_t> amount (store::transaction const &, nano::block_hash const &);
static nano::uint128_t balance (nano::block const & block);
std::optional<nano::uint128_t> balance (store::transaction const &, nano::block_hash const &) const;
std::shared_ptr<nano::block> block (store::transaction const & transaction, nano::block_hash const & hash) const;
bool block_exists (store::transaction const & transaction, nano::block_hash const & hash) const;
@ -61,9 +56,7 @@ public:
bool root_exists (store::transaction const &, nano::root const &);
std::string block_text (char const *);
std::string block_text (nano::block_hash const &);
bool is_send (store::transaction const &, nano::block const &) const;
nano::account const & block_destination (store::transaction const &, nano::block const &);
nano::block_hash block_source (store::transaction const &, nano::block const &);
std::pair<nano::block_hash, nano::block_hash> hash_root_random (store::transaction const &) const;
std::optional<nano::pending_info> pending_info (store::transaction const & transaction, nano::pending_key const & key) const;
nano::block_status process (store::write_transaction const & transaction, std::shared_ptr<nano::block> block);

View file

@ -820,7 +820,7 @@ TEST (confirmation_height, long_chains)
auto open = builder
.open ()
.source (send->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.account (key1.pub)
.sign (key1.prv, key1.pub)
.work (*system.work.generate (key1.pub))
@ -874,7 +874,7 @@ TEST (confirmation_height, long_chains)
.state ()
.account (nano::dev::genesis_key.pub)
.previous (previous_genesis_chain_hash)
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio + 1)
.link (send1->hash ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
@ -885,9 +885,9 @@ TEST (confirmation_height, long_chains)
nano::keypair key2;
auto send2 = builder
.state ()
.account (nano::dev::genesis->account ())
.account (nano::dev::genesis_key.pub)
.previous (receive1->hash ())
.representative (nano::dev::genesis->account ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (key2.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)

View file

@ -424,7 +424,7 @@ void nano::test::system::generate_receive (nano::node & node_a)
}
if (send_block != nullptr)
{
auto receive_error (wallet (0)->receive_sync (send_block, nano::dev::genesis->account (), std::numeric_limits<nano::uint128_t>::max ()));
auto receive_error (wallet (0)->receive_sync (send_block, nano::dev::genesis_key.pub, std::numeric_limits<nano::uint128_t>::max ()));
(void)receive_error;
}
}