Skip to content

Commit

Permalink
Loading full account_info object in to nano::context::state rather th…
Browse files Browse the repository at this point in the history
…an individual components.
  • Loading branch information
clemahieu committed Mar 3, 2022
1 parent d6ee843 commit afcac11
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
12 changes: 8 additions & 4 deletions nano/core_test/metastable_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ nano::block_pipeline::context pass_block ()
.work (0)
.build_shared ();
result.previous = nano::dev::genesis;
result.head = nano::dev::genesis->hash (); // <- Head block
result.state = nano::account_info{};
result.state->head = nano::dev::genesis->hash (); // <- Head block
return result;
}
nano::block_pipeline::context reject_open_block ()
Expand All @@ -53,7 +54,8 @@ nano::block_pipeline::context reject_open_block ()
.sign (4, 5)
.work (0)
.build_shared ();
result.head = 6; // Head block is initialized
result.state = nano::account_info{};
result.state->head = 6; // Head block is initialized
return result;
}
nano::block_pipeline::context reject_initial_block ()
Expand All @@ -69,7 +71,8 @@ nano::block_pipeline::context reject_initial_block ()
.sign (5, 6)
.work (0)
.build_shared ();
result.head = 6; // Head block is initialized
result.state = nano::account_info{};
result.state->head = 6; // Head block is initialized
return result;
}
nano::block_pipeline::context reject_state_block ()
Expand All @@ -94,7 +97,8 @@ nano::block_pipeline::context reject_state_block ()
.sign (5, 6)
.work (0)
.build_shared ();
result.head = 1; // Assuming precondition that previous exists in the ledger, head block is different therefore it's metastable
result.state = nano::account_info{};
result.state->head = 1; // Assuming precondition that previous exists in the ledger, head block is different therefore it's metastable
return result;
}
}
Expand Down
8 changes: 1 addition & 7 deletions nano/node/block_pipeline/account_state_decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ nano::block_pipeline::account_state_decorator::account_state_decorator (nano::le
{
}

void nano::block_pipeline::account_state_decorator::head_decorate (context & context) const
{
context.head = ledger.latest (ledger.store.tx_begin_read (), context.account ());
debug_assert (context.head.has_value ());
}

void nano::block_pipeline::account_state_decorator::sink (context & context) const
{
head_decorate (context);
context.info = ledger.account_info (ledger.store.tx_begin_read (), context.account ());
output (context);
}
1 change: 0 additions & 1 deletion nano/node/block_pipeline/account_state_decorator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace block_pipeline

private:
void previous_balance_decorate (context & context) const;
void head_decorate (context & context) const;
nano::ledger & ledger;
};
} // namespace pipeline
Expand Down
2 changes: 1 addition & 1 deletion nano/node/block_pipeline/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nano::amount nano::block_pipeline::context::previous_balance () const
case nano::block_type::not_a_block:
case nano::block_type::invalid:
debug_assert (false);
return;
return 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion nano/node/block_pipeline/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace block_pipeline
std::shared_ptr<nano::block> block;
std::shared_ptr<nano::block> previous;
std::optional<nano::account> signer;
std::optional<nano::block_hash> head;
std::optional<nano::account_info> state;
nano::signature_verification verification{ nano::signature_verification::unknown };
};
}
Expand Down
4 changes: 2 additions & 2 deletions nano/node/block_pipeline/metastable_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

void nano::block_pipeline::metastable_filter::sink (context & context)
{
debug_assert (context.head.has_value ());
if (context.block->previous () == *context.head)
debug_assert (context.state.has_value ());
if (context.block->previous () == context.state->head)
{
pass (context);
}
Expand Down
7 changes: 7 additions & 0 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,13 @@ nano::account nano::ledger::account_safe (nano::transaction const & transaction_
}
}

nano::account_info nano::ledger::account_info (nano::transaction const & transaction, nano::account const & account) const
{
nano::account_info result;
store.account.get (transaction, account, result);
return result;
}

// Return amount decrease or increase for block
nano::uint128_t nano::ledger::amount (nano::transaction const & transaction_a, nano::account const & account_a)
{
Expand Down
1 change: 1 addition & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ledger final
public:
ledger (nano::store &, nano::stat &, nano::ledger_constants & constants, nano::generate_cache const & = nano::generate_cache ());
nano::account account (nano::transaction const &, nano::block_hash const &) const;
nano::account_info account_info (nano::transaction const & transaction, nano::account const & account) const;
nano::account account_safe (nano::transaction const &, nano::block_hash const &, bool &) const;
nano::uint128_t amount (nano::transaction const &, nano::account const &);
nano::uint128_t amount (nano::transaction const &, nano::block_hash const &);
Expand Down

0 comments on commit afcac11

Please sign in to comment.