Moving ::balance off of nano::store on to nano::ledger
This commit is contained in:
parent
ac56df90d2
commit
63d3c3cad6
8 changed files with 38 additions and 48 deletions
|
@ -402,7 +402,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a)
|
|||
// Send check
|
||||
if (block_previous != nullptr)
|
||||
{
|
||||
details.is_send = node.store.block.balance (transaction, previous) > block_a.balance ().number ();
|
||||
details.is_send = node.ledger.balance (transaction, previous) > block_a.balance ().number ();
|
||||
details_found = true;
|
||||
}
|
||||
// Epoch check
|
||||
|
@ -1653,7 +1653,7 @@ void nano::json_handler::block_create ()
|
|||
else if (previous_text.is_initialized () && balance_text.is_initialized () && type == "send")
|
||||
{
|
||||
auto transaction (node.store.tx_begin_read ());
|
||||
if (node.store.block.exists (transaction, previous) && node.store.block.balance (transaction, previous) != balance.number ())
|
||||
if (node.store.block.exists (transaction, previous) && node.ledger.balance (transaction, previous) != balance.number ())
|
||||
{
|
||||
ec = nano::error_rpc::block_create_balance_mismatch;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <nano/node/lmdb/lmdb_iterator.hpp>
|
||||
#include <nano/node/lmdb/wallet_value.hpp>
|
||||
#include <nano/secure/buffer.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/secure/versioning.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
@ -545,7 +546,8 @@ void nano::lmdb::store::upgrade_v17_to_v18 (nano::write_transaction const & tran
|
|||
nano::amount prev_balance (0);
|
||||
if (!block->hashables.previous.is_zero ())
|
||||
{
|
||||
prev_balance = block_balance_v18 (transaction_a, block->hashables.previous);
|
||||
auto prev = block_get_v18 (transaction_a, block->hashables.previous);
|
||||
prev_balance = nano::ledger::balance (*prev);
|
||||
}
|
||||
if (block->hashables.balance == prev_balance && constants.epochs.is_epoch_link (block->hashables.link))
|
||||
{
|
||||
|
@ -1061,14 +1063,6 @@ boost::optional<nano::mdb_val> nano::lmdb::store::block_raw_get_by_type_v18 (nan
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::uint128_t nano::lmdb::store::block_balance_v18 (nano::transaction const & transaction, nano::block_hash const & hash) const
|
||||
{
|
||||
auto block_l = block_get_v18 (transaction, hash);
|
||||
release_assert (block_l);
|
||||
nano::uint128_t result = block.balance (*block_l);
|
||||
return result;
|
||||
}
|
||||
|
||||
// All the v14 functions below are only needed during upgrades
|
||||
std::size_t nano::lmdb::store::block_successor_offset_v14 (nano::transaction const & transaction_a, std::size_t entry_size_a, nano::block_type type_a) const
|
||||
{
|
||||
|
|
|
@ -138,7 +138,6 @@ namespace lmdb
|
|||
std::shared_ptr<nano::block> block_get_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const;
|
||||
nano::mdb_val block_raw_get_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const;
|
||||
boost::optional<nano::mdb_val> block_raw_get_by_type_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const;
|
||||
nano::uint128_t block_balance_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const;
|
||||
|
||||
void open_databases (bool &, nano::transaction const &, unsigned);
|
||||
|
||||
|
|
|
@ -1344,7 +1344,7 @@ void nano::node::process_confirmed_data (nano::transaction const & transaction_a
|
|||
auto previous (block_a->previous ());
|
||||
bool error (false);
|
||||
auto previous_balance (ledger.balance_safe (transaction_a, previous, error));
|
||||
auto block_balance = store.block.balance (*block_a);
|
||||
auto block_balance = ledger.balance (*block_a);
|
||||
if (hash_a != ledger.constants.genesis->account ())
|
||||
{
|
||||
if (!error)
|
||||
|
|
|
@ -736,10 +736,38 @@ void nano::ledger::initialize (nano::generate_cache const & generate_cache_a)
|
|||
}
|
||||
}
|
||||
|
||||
// Balance for account containing hash
|
||||
nano::uint128_t nano::ledger::balance (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const
|
||||
nano::uint128_t nano::ledger::balance (nano::block const & block)
|
||||
{
|
||||
return hash_a.is_zero () ? 0 : store.block.balance (transaction_a, hash_a);
|
||||
nano::uint128_t result;
|
||||
switch (block.type ())
|
||||
{
|
||||
case nano::block_type::open:
|
||||
case nano::block_type::receive:
|
||||
case nano::block_type::change:
|
||||
result = block.sideband ().balance.number ();
|
||||
break;
|
||||
case nano::block_type::send:
|
||||
case nano::block_type::state:
|
||||
result = block.balance ().number ();
|
||||
break;
|
||||
case nano::block_type::invalid:
|
||||
case nano::block_type::not_a_block:
|
||||
release_assert (false);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Balance for account containing hash
|
||||
nano::uint128_t nano::ledger::balance (nano::transaction const & transaction, nano::block_hash const & hash) const
|
||||
{
|
||||
if (hash.is_zero ())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
auto block = store.block.get (transaction, hash);
|
||||
debug_assert (block != nullptr);
|
||||
return balance (*block);
|
||||
}
|
||||
|
||||
nano::uint128_t nano::ledger::balance_safe (nano::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
nano::uint128_t amount (nano::transaction const &, nano::block_hash const &);
|
||||
/** Safe for previous block, but block hash_a must exist */
|
||||
nano::uint128_t amount_safe (nano::transaction const &, nano::block_hash const & hash_a, bool &) const;
|
||||
static nano::uint128_t balance (nano::block const & block);
|
||||
nano::uint128_t balance (nano::transaction const &, nano::block_hash const &) const;
|
||||
nano::uint128_t balance_safe (nano::transaction const &, nano::block_hash const &, bool &) const;
|
||||
nano::uint128_t account_balance (nano::transaction const &, nano::account const &, bool = false);
|
||||
|
|
|
@ -106,36 +106,6 @@ bool nano::write_transaction::contains (nano::tables table_a) const
|
|||
return impl->contains (table_a);
|
||||
}
|
||||
|
||||
|
||||
nano::uint128_t nano::block_store::balance (nano::block const & block) const
|
||||
{
|
||||
nano::uint128_t result;
|
||||
switch (block.type ())
|
||||
{
|
||||
case nano::block_type::open:
|
||||
case nano::block_type::receive:
|
||||
case nano::block_type::change:
|
||||
result = block.sideband ().balance.number ();
|
||||
break;
|
||||
case nano::block_type::send:
|
||||
case nano::block_type::state:
|
||||
result = block.balance ().number ();
|
||||
break;
|
||||
case nano::block_type::invalid:
|
||||
case nano::block_type::not_a_block:
|
||||
release_assert (false);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nano::uint128_t nano::block_store::balance (nano::transaction const & transaction, nano::block_hash const & hash) const
|
||||
{
|
||||
auto block = get (transaction, hash);
|
||||
debug_assert (block != nullptr);
|
||||
return balance (*block);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
nano::store::store (
|
||||
nano::block_store & block_store_a,
|
||||
|
|
|
@ -755,8 +755,6 @@ public:
|
|||
virtual nano::store_iterator<nano::block_hash, block_w_sideband> begin (nano::transaction const &, nano::block_hash const &) const = 0;
|
||||
virtual nano::store_iterator<nano::block_hash, block_w_sideband> begin (nano::transaction const &) const = 0;
|
||||
virtual nano::store_iterator<nano::block_hash, block_w_sideband> end () const = 0;
|
||||
nano::uint128_t balance (nano::block const & block) const;
|
||||
nano::uint128_t balance (nano::transaction const & transaction, nano::block_hash const & hash) const;
|
||||
virtual nano::epoch version (nano::transaction const &, nano::block_hash const &) = 0;
|
||||
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::block_hash, block_w_sideband>, nano::store_iterator<nano::block_hash, block_w_sideband>)> const & action_a) const = 0;
|
||||
virtual uint64_t account_height (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue