Skip to content

Commit

Permalink
Remove ledger::block_destination and use block::destination (#4478)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu authored Mar 11, 2024
1 parent d595655 commit 47e7c81
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 36 deletions.
12 changes: 6 additions & 6 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2328,17 +2328,17 @@ TEST (ledger, block_destination_source)
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, block5));
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, block6));
ASSERT_EQ (balance, ledger.balance (transaction, block6->hash ()));
ASSERT_EQ (dest.pub, ledger.block_destination (transaction, *block1));
ASSERT_EQ (dest.pub, block1->destination ());
ASSERT_FALSE (block1->source_field ());
ASSERT_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block2));
ASSERT_EQ (nano::dev::genesis_key.pub, block2->destination ());
ASSERT_FALSE (block2->source_field ());
ASSERT_EQ (ledger.block_destination (transaction, *block3), nullptr);
ASSERT_FALSE (block3->destination_field ());
ASSERT_EQ (block2->hash (), block3->source ());
ASSERT_EQ (dest.pub, ledger.block_destination (transaction, *block4));
ASSERT_EQ (dest.pub, block4->destination ());
ASSERT_FALSE (block4->source_field ());
ASSERT_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block5));
ASSERT_EQ (nano::dev::genesis_key.pub, block5->destination ());
ASSERT_FALSE (block5->source_field ());
ASSERT_EQ (ledger.block_destination (transaction, *block6), nullptr);
ASSERT_FALSE (block6->destination_field ());
ASSERT_EQ (block5->hash (), block6->source ());
}

Expand Down
5 changes: 2 additions & 3 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,11 @@ void nano::active_transactions::handle_final_votes_confirmation (std::shared_ptr
void nano::active_transactions::activate_successors (const nano::account & account, std::shared_ptr<nano::block> const & block, nano::store::read_transaction const & transaction)
{
node.scheduler.priority.activate (account, transaction);
auto const & destination = node.ledger.block_destination (transaction, *block);

// Start or vote for the next unconfirmed block in the destination account
if (!destination.is_zero () && destination != account)
if (block->is_send () && !block->destination ().is_zero () && block->destination () != account)
{
node.scheduler.priority.activate (destination, transaction);
node.scheduler.priority.activate (block->destination (), transaction);
}
}

Expand Down
14 changes: 6 additions & 8 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,7 @@ void nano::json_handler::blocks_info ()
}
if (receivable || receive_hash)
{
auto destination (node.ledger.block_destination (transaction, *block));
if (destination.is_zero ())
if (!block->is_send ())
{
if (receivable)
{
Expand All @@ -1355,7 +1354,7 @@ void nano::json_handler::blocks_info ()
entry.put ("receive_hash", nano::block_hash (0).to_string ());
}
}
else if (node.store.pending.exists (transaction, nano::pending_key (destination, hash)))
else if (node.store.pending.exists (transaction, nano::pending_key (block->destination (), hash)))
{
if (receivable)
{
Expand All @@ -1376,7 +1375,7 @@ void nano::json_handler::blocks_info ()
}
if (receive_hash)
{
std::shared_ptr<nano::block> receive_block = node.ledger.find_receive_block_by_send_hash (transaction, destination, hash);
std::shared_ptr<nano::block> receive_block = node.ledger.find_receive_block_by_send_hash (transaction, block->destination (), hash);
std::string receive_hash = receive_block ? receive_block->hash ().to_string () : nano::block_hash (0).to_string ();
entry.put ("receive_hash", receive_hash);
}
Expand Down Expand Up @@ -3163,10 +3162,9 @@ void nano::json_handler::receivable_exists ()
if (block != nullptr)
{
auto exists (false);
auto destination (node.ledger.block_destination (transaction, *block));
if (!destination.is_zero ())
if (block->is_send ())
{
exists = node.store.pending.exists (transaction, nano::pending_key (destination, hash));
exists = node.store.pending.exists (transaction, nano::pending_key (block->destination (), hash));
}
exists = exists && (block_confirmed (node, transaction, block->hash (), include_active, include_only_confirmed));
response_l.put ("exists", exists ? "1" : "0");
Expand Down Expand Up @@ -3668,7 +3666,7 @@ void nano::json_handler::republish ()
if (destinations != 0) // Republish destination chain
{
auto block_b = node.ledger.block (transaction, hash);
auto destination (node.ledger.block_destination (transaction, *block_b));
auto destination = block_b->destination ();
if (!destination.is_zero ())
{
if (!node.store.pending.exists (transaction, nano::pending_key (destination, hash)))
Expand Down
4 changes: 2 additions & 2 deletions nano/qt/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ void nano_qt::block_creation::create_receive ()
auto block_l (wallet.node.ledger.block (block_transaction, source_l));
if (block_l != nullptr)
{
auto const & destination (wallet.node.ledger.block_destination (block_transaction, *block_l));
auto destination = block_l->destination ();
if (!destination.is_zero ())
{
nano::pending_key pending_key (destination, source_l);
Expand Down Expand Up @@ -2483,7 +2483,7 @@ void nano_qt::block_creation::create_open ()
auto block_l (wallet.node.ledger.block (block_transaction, source_l));
if (block_l != nullptr)
{
auto const & destination (wallet.node.ledger.block_destination (block_transaction, *block_l));
auto destination = block_l->destination ();
if (!destination.is_zero ())
{
nano::pending_key pending_key (destination, source_l);
Expand Down
16 changes: 0 additions & 16 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,22 +950,6 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a)
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));
nano::state_block const * state_block (dynamic_cast<nano::state_block const *> (&block_a));
if (send_block != nullptr)
{
return send_block->hashables.destination;
}
else if (state_block != nullptr && block_a.is_send ())
{
return state_block->hashables.link.as_account ();
}

return nano::account::null ();
}

std::pair<nano::block_hash, nano::block_hash> nano::ledger::hash_root_random (store::transaction const & transaction_a) const
{
nano::block_hash hash (0);
Expand Down
1 change: 0 additions & 1 deletion nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class ledger final
bool root_exists (store::transaction const &, nano::root const &);
std::string block_text (char const *);
std::string block_text (nano::block_hash const &);
nano::account const & block_destination (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);
Expand Down

0 comments on commit 47e7c81

Please sign in to comment.