Skip to content

Commit

Permalink
Move ledger::receivable_any on to ledger_view_base
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Mar 21, 2024
1 parent 075f5aa commit 0655adc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
10 changes: 7 additions & 3 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5675,7 +5675,9 @@ TEST (ledger_receivable, key_two)
TEST (ledger_receivable, any_none)
{
auto ctx = nano::test::context::ledger_empty ();
ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.store ().tx_begin_read (), nano::dev::genesis_key.pub));
auto tx = ctx.store ().tx_begin_read ();
auto view = ctx.ledger ().unconfirmed (tx);
ASSERT_FALSE (view.receivable_any (nano::dev::genesis_key.pub));
}

TEST (ledger_receivable, any_one)
Expand All @@ -5694,6 +5696,8 @@ TEST (ledger_receivable, any_one)
.work (*ctx.pool ().generate (nano::dev::genesis->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.store ().tx_begin_write (), send1));
ASSERT_TRUE (ctx.ledger ().receivable_any (ctx.store ().tx_begin_read (), nano::dev::genesis_key.pub));
ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.store ().tx_begin_read (), key.pub));
auto tx = ctx.store ().tx_begin_read ();
auto view = ctx.ledger ().unconfirmed (tx);
ASSERT_TRUE (view.receivable_any (nano::dev::genesis_key.pub));
ASSERT_FALSE (view.receivable_any (key.pub));
}
9 changes: 1 addition & 8 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a)
// Non-exisitng account should have pending entries
if (result == nano::block_status::progress)
{
bool pending_exists = ledger.receivable_any (transaction, block_a.hashables.account);
bool pending_exists = view.receivable_any (block_a.hashables.account);
result = pending_exists ? nano::block_status::progress : nano::block_status::gap_epoch_open_pending;
}
}
Expand Down Expand Up @@ -1356,13 +1356,6 @@ nano::epoch nano::ledger::version (store::transaction const & transaction, nano:
return version (*block_l);
}

bool nano::ledger::receivable_any (store::transaction const & tx, nano::account const & account) const
{
auto view = unconfirmed (tx);
auto next = view.receivable_upper_bound (account, 0);
return next != view.receivable_end ();
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (ledger & ledger, std::string const & name)
{
auto count = ledger.bootstrap_weights.size ();
Expand Down
2 changes: 0 additions & 2 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class ledger final
bool bootstrap_weight_reached () const;
static nano::epoch version (nano::block const & block);
nano::epoch version (store::transaction const & transaction, nano::block_hash const & hash) const;
// Returns whether there are any receivable entries for 'account'
bool receivable_any (store::transaction const & tx, nano::account const & account) const;
static nano::uint128_t const unit;
nano::ledger_constants & constants;
nano::store::component & store;
Expand Down
6 changes: 6 additions & 0 deletions nano/secure/ledger_view_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ uint64_t nano::ledger_view_base::height (nano::block_hash const & hash) const
return block->sideband ().height;
}

bool nano::ledger_view_base::receivable_any (nano::account const & account) const
{
auto next = receivable_upper_bound (account, 0);
return next != receivable_end ();
}

nano::receivable_iterator nano::ledger_view_base::receivable_end () const
{
return nano::receivable_iterator{};
Expand Down
2 changes: 2 additions & 0 deletions nano/secure/ledger_view_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class ledger_view_base
virtual std::optional<nano::pending_info> get (nano::pending_key const & key) const = 0;
virtual nano::block_hash head (nano::account const & account) const = 0;
uint64_t height (nano::block_hash const & hash) const;
// Returns whether there are any receivable entries for 'account'
bool receivable_any (nano::account const & account) const;
nano::receivable_iterator receivable_end () const;
// Returns the next receivable entry equal or greater than 'key'
virtual std::optional<std::pair<nano::pending_key, nano::pending_info>> receivable_lower_bound (nano::account const & account, nano::block_hash const & hash) const = 0;
Expand Down

0 comments on commit 0655adc

Please sign in to comment.