Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve block field functions by accessing sideband information internally #4465

Merged
merged 17 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5678e8c
Directly use genesis_key.pub for obtaining the genesis account, rathe…
clemahieu Mar 6, 2024
76ebe9a
Convert boost::optional to std::optional for distributed work generat…
clemahieu Mar 6, 2024
122a935
Change block::account to return an std::optional if the block actuall…
clemahieu Mar 6, 2024
a7cab75
ledger::account is moved to block::account and block::account which a…
clemahieu Mar 6, 2024
deb5bf9
Change block::balance to return an std::optional if the block actuall…
clemahieu Mar 6, 2024
c6f506c
ledger::balance is moved to block::balance and block::balance which a…
clemahieu Mar 6, 2024
5dad3a2
Change block::destination to return an std::optional if the block act…
clemahieu Mar 7, 2024
61ad874
ledger::destination is moved to block::destination_field and block::d…
clemahieu Mar 7, 2024
fa81fc0
Change block::source to return an std::optional if the block actually…
clemahieu Mar 7, 2024
b66bfe2
ledger::source is moved to block::source_field and ledger::block_sour…
clemahieu Mar 7, 2024
4b2f574
Change block::link to return an std::optional if the block actually c…
clemahieu Mar 7, 2024
9bcb65c
Moving ledger::is_send to block::is_send.
clemahieu Mar 7, 2024
a60a16b
Creating block::is_receive function to determine if a block is a rece…
clemahieu Mar 8, 2024
dece1bc
Create block::is_change function which determines if a block is a cha…
clemahieu Mar 8, 2024
17e502d
Renaming block::link to block::link_field. Usages that converted this…
clemahieu Mar 8, 2024
e75fb68
Change block::representative to return an std::optional if the block …
clemahieu Mar 8, 2024
5332f2c
Change block::previous to block::previous_field and return std::optio…
clemahieu Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,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 ();
Expand Down
4 changes: 1 addition & 3 deletions nano/core_test/backlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());
Expand Down
30 changes: 15 additions & 15 deletions nano/core_test/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 ());
}
6 changes: 3 additions & 3 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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]));

Expand All @@ -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 ());
}

Expand All @@ -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 ());
Expand Down
56 changes: 28 additions & 28 deletions nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ 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))
.build ();
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))
.build ();
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))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -593,31 +593,31 @@ 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))
.build ();
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 ()))
.build ();
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 ()))
.build ();
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 ()))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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; });
Expand Down Expand Up @@ -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; });
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 () });
}

Expand Down
Loading
Loading