Skip to content

Commit

Permalink
Move ledger::receivable_any on to ledger set
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Apr 7, 2024
1 parent 282f27a commit 7af4851
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5625,7 +5625,7 @@ 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));
ASSERT_FALSE (ctx.ledger ().any.receivable_any (ctx.store ().tx_begin_read (), nano::dev::genesis_key.pub));
}

TEST (ledger_receivable, any_one)
Expand All @@ -5644,6 +5644,6 @@ 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));
ASSERT_TRUE (ctx.ledger ().any.receivable_any (ctx.store ().tx_begin_read (), nano::dev::genesis_key.pub));
ASSERT_FALSE (ctx.ledger ().any.receivable_any (ctx.store ().tx_begin_read (), key.pub));
}
8 changes: 1 addition & 7 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,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 = ledger.any.receivable_any (transaction, block_a.hashables.account);
result = pending_exists ? nano::block_status::progress : nano::block_status::gap_epoch_open_pending;
}
}
Expand Down Expand Up @@ -1376,12 +1376,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 next = any.receivable_upper_bound (tx, account, 0);
return next != any.receivable_end ();
}

uint64_t nano::ledger::cemented_count () const
{
return cache.cemented_count;
Expand Down
2 changes: 0 additions & 2 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,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;
std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const;
uint64_t cemented_count () const;
uint64_t block_count () const;
Expand Down
6 changes: 6 additions & 0 deletions nano/secure/ledger_set_any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ uint64_t nano::ledger_set_any::height (store::transaction const & transaction, n
return block->sideband ().height;
}

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

std::optional<std::pair<nano::pending_key, nano::pending_info>> nano::ledger_set_any::receivable_lower_bound (store::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const
{
auto result = ledger.store.pending.begin (transaction, { account, hash });
Expand Down
2 changes: 2 additions & 0 deletions nano/secure/ledger_set_any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ledger_set_any
nano::block_hash head (store::transaction const & transaction, nano::account const & account) const;
uint64_t height (store::transaction const & transaction, nano::account const & account) const;
uint64_t height (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 & transaction, nano::account const & account) const;
receivable_iterator receivable_end () const;
// Returns the next receivable entry equal or greater than 'key'
std::optional<std::pair<nano::pending_key, nano::pending_info>> receivable_lower_bound (store::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const;
Expand Down

0 comments on commit 7af4851

Please sign in to comment.