Skip to content

Commit

Permalink
Merge pull request #4760 from clemahieu/store_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu authored Oct 21, 2024
2 parents 0b6a5cc + c659c8b commit e11ffcf
Show file tree
Hide file tree
Showing 56 changed files with 293 additions and 256 deletions.
4 changes: 2 additions & 2 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ int main (int argc, char * const * argv)
nano::locked<std::vector<boost::unordered_set<nano::account>>> opened_account_versions_shared (epoch_count);
using opened_account_versions_t = decltype (opened_account_versions_shared)::value_type;
node->store.account.for_each_par (
[&opened_account_versions_shared, epoch_count] (nano::store::read_transaction const & /*unused*/, nano::store::iterator<nano::account, nano::account_info> i, nano::store::iterator<nano::account, nano::account_info> n) {
[&opened_account_versions_shared, epoch_count] (nano::store::read_transaction const & /*unused*/, auto i, auto n) {
// First cache locally
opened_account_versions_t opened_account_versions_l (epoch_count);
for (; i != n; ++i)
Expand Down Expand Up @@ -1979,7 +1979,7 @@ int main (int argc, char * const * argv)
nano::locked<boost::unordered_map<nano::account, std::underlying_type_t<nano::epoch>>> unopened_highest_pending_shared;
using unopened_highest_pending_t = decltype (unopened_highest_pending_shared)::value_type;
node->store.pending.for_each_par (
[&unopened_highest_pending_shared, &opened_accounts] (nano::store::read_transaction const & /*unused*/, nano::store::iterator<nano::pending_key, nano::pending_info> i, nano::store::iterator<nano::pending_key, nano::pending_info> n) {
[&unopened_highest_pending_shared, &opened_accounts] (nano::store::read_transaction const & /*unused*/, auto i, auto n) {
// First cache locally
unopened_highest_pending_t unopened_highest_pending_l;
for (; i != n; ++i)
Expand Down
17 changes: 9 additions & 8 deletions nano/node/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,22 +1753,22 @@ std::unordered_map<nano::wallet_id, std::shared_ptr<nano::wallet>> nano::wallets
nano::uint128_t const nano::wallets::generate_priority = std::numeric_limits<nano::uint128_t>::max ();
nano::uint128_t const nano::wallets::high_priority = std::numeric_limits<nano::uint128_t>::max () - 1;

nano::store::iterator<nano::account, nano::wallet_value> nano::wallet_store::begin (store::transaction const & transaction_a)
auto nano::wallet_store::begin (store::transaction const & transaction_a) -> iterator
{
store::iterator<nano::account, nano::wallet_value> result (std::make_unique<nano::store::lmdb::iterator<nano::account, nano::wallet_value>> (transaction_a, env, handle, nano::store::lmdb::db_val (nano::account (special_count))));
iterator result (std::make_unique<nano::store::lmdb::iterator<nano::account, nano::wallet_value>> (transaction_a, env, handle, nano::store::lmdb::db_val (nano::account (special_count))));
return result;
}

nano::store::iterator<nano::account, nano::wallet_value> nano::wallet_store::begin (store::transaction const & transaction_a, nano::account const & key)
auto nano::wallet_store::begin (store::transaction const & transaction_a, nano::account const & key) -> iterator
{
store::iterator<nano::account, nano::wallet_value> result (std::make_unique<nano::store::lmdb::iterator<nano::account, nano::wallet_value>> (transaction_a, env, handle, nano::store::lmdb::db_val (key)));
iterator result (std::make_unique<nano::store::lmdb::iterator<nano::account, nano::wallet_value>> (transaction_a, env, handle, nano::store::lmdb::db_val (key)));
return result;
}

nano::store::iterator<nano::account, nano::wallet_value> nano::wallet_store::find (store::transaction const & transaction_a, nano::account const & key)
auto nano::wallet_store::find (store::transaction const & transaction_a, nano::account const & key) -> iterator
{
auto result (begin (transaction_a, key));
store::iterator<nano::account, nano::wallet_value> end (nullptr);
iterator end{ nullptr };
if (result != end)
{
if (result->first == key)
Expand All @@ -1787,10 +1787,11 @@ nano::store::iterator<nano::account, nano::wallet_value> nano::wallet_store::fin
return result;
}

nano::store::iterator<nano::account, nano::wallet_value> nano::wallet_store::end ()
auto nano::wallet_store::end () -> iterator
{
return store::iterator<nano::account, nano::wallet_value> (nullptr);
return iterator{ nullptr };
}

nano::mdb_wallets_store::mdb_wallets_store (std::filesystem::path const & path_a, nano::lmdb_config const & lmdb_config_a) :
environment (error, path_a, nano::store::lmdb::env::options::make ().set_config (lmdb_config_a).override_config_sync (nano::lmdb_config::sync_strategy::always).override_config_map_size (1ULL * 1024 * 1024 * 1024))
{
Expand Down
11 changes: 7 additions & 4 deletions nano/node/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ enum class key_type

class wallet_store final
{
public:
using iterator = store::iterator<nano::account, nano::wallet_value>;

public:
wallet_store (bool &, nano::kdf &, store::transaction &, store::lmdb::env &, nano::account, unsigned, std::string const &);
wallet_store (bool &, nano::kdf &, store::transaction &, store::lmdb::env &, nano::account, unsigned, std::string const &, std::string const &);
Expand Down Expand Up @@ -89,10 +92,10 @@ class wallet_store final
bool fetch (store::transaction const &, nano::account const &, nano::raw_key &);
bool exists (store::transaction const &, nano::account const &);
void destroy (store::transaction const &);
store::iterator<nano::account, nano::wallet_value> find (store::transaction const &, nano::account const &);
store::iterator<nano::account, nano::wallet_value> begin (store::transaction const &, nano::account const &);
store::iterator<nano::account, nano::wallet_value> begin (store::transaction const &);
store::iterator<nano::account, nano::wallet_value> end ();
iterator find (store::transaction const &, nano::account const &);
iterator begin (store::transaction const &, nano::account const &);
iterator begin (store::transaction const &);
iterator end ();
void derive_key (nano::raw_key &, store::transaction const &, std::string const &);
void serialize_json (store::transaction const &, std::string &);
void write_backup (store::transaction const &, std::filesystem::path const &);
Expand Down
10 changes: 5 additions & 5 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>
#include <nano/store/final.hpp>
#include <nano/store/final_vote.hpp>
#include <nano/store/online_weight.hpp>
#include <nano/store/peer.hpp>
#include <nano/store/pending.hpp>
Expand Down Expand Up @@ -749,7 +749,7 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache
if (generate_cache_flags_a.reps || generate_cache_flags_a.account_count || generate_cache_flags_a.block_count)
{
store.account.for_each_par (
[this] (store::read_transaction const & /*unused*/, store::iterator<nano::account, nano::account_info> i, store::iterator<nano::account, nano::account_info> n) {
[this] (store::read_transaction const & /*unused*/, auto i, auto n) {
uint64_t block_count_l{ 0 };
uint64_t account_count_l{ 0 };
for (; i != n; ++i)
Expand All @@ -763,7 +763,7 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache
});

store.rep_weight.for_each_par (
[this] (store::read_transaction const & /*unused*/, store::iterator<nano::account, nano::uint128_union> i, store::iterator<nano::account, nano::uint128_union> n) {
[this] (store::read_transaction const & /*unused*/, auto i, auto n) {
nano::rep_weights rep_weights_l{ this->store.rep_weight };
for (; i != n; ++i)
{
Expand All @@ -776,7 +776,7 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache
if (generate_cache_flags_a.cemented_count)
{
store.confirmation_height.for_each_par (
[this] (store::read_transaction const & /*unused*/, store::iterator<nano::account, nano::confirmation_height_info> i, store::iterator<nano::account, nano::confirmation_height_info> n) {
[this] (store::read_transaction const & /*unused*/, auto i, auto n) {
uint64_t cemented_count_l (0);
for (; i != n; ++i)
{
Expand Down Expand Up @@ -1523,4 +1523,4 @@ nano::container_info nano::ledger::container_info () const
info.put ("bootstrap_weights", bootstrap_weights);
info.add ("rep_weights", cache.rep_weights.container_info ());
return info;
}
}
5 changes: 3 additions & 2 deletions nano/store/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_library(
db_val_impl.hpp
iterator.hpp
iterator_impl.hpp
final.hpp
final_vote.hpp
lmdb/account.hpp
lmdb/block.hpp
lmdb/confirmation_height.hpp
Expand All @@ -32,6 +32,7 @@ add_library(
peer.hpp
pending.hpp
pruned.hpp
rep_weight.hpp
rocksdb/account.hpp
rocksdb/block.hpp
rocksdb/confirmation_height.hpp
Expand All @@ -58,7 +59,7 @@ add_library(
db_val.cpp
iterator.cpp
iterator_impl.cpp
final.cpp
final_vote.cpp
lmdb/account.cpp
lmdb/block.cpp
lmdb/confirmation_height.cpp
Expand Down
13 changes: 8 additions & 5 deletions nano/store/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ namespace nano::store
*/
class account
{
public:
using iterator = store::iterator<nano::account, nano::account_info>;

public:
virtual void put (store::write_transaction const &, nano::account const &, nano::account_info const &) = 0;
virtual bool get (store::transaction const &, nano::account const &, nano::account_info &) = 0;
std::optional<nano::account_info> get (store::transaction const &, nano::account const &);
virtual void del (store::write_transaction const &, nano::account const &) = 0;
virtual bool exists (store::transaction const &, nano::account const &) = 0;
virtual size_t count (store::transaction const &) = 0;
virtual iterator<nano::account, nano::account_info> begin (store::transaction const &, nano::account const &) const = 0;
virtual iterator<nano::account, nano::account_info> begin (store::transaction const &) const = 0;
virtual iterator<nano::account, nano::account_info> rbegin (store::transaction const &) const = 0;
virtual iterator<nano::account, nano::account_info> end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, iterator<nano::account, nano::account_info>, iterator<nano::account, nano::account_info>)> const &) const = 0;
virtual iterator begin (store::transaction const &, nano::account const &) const = 0;
virtual iterator begin (store::transaction const &) const = 0;
virtual iterator rbegin (store::transaction const &) const = 0;
virtual iterator end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, iterator, iterator)> const &) const = 0;
};
} // namespace nano::store
11 changes: 7 additions & 4 deletions nano/store/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace nano::store
*/
class block
{
public:
using iterator = store::iterator<nano::block_hash, block_w_sideband>;

public:
virtual void put (store::write_transaction const &, nano::block_hash const &, nano::block const &) = 0;
virtual void raw_put (store::write_transaction const &, std::vector<uint8_t> const &, nano::block_hash const &) = 0;
Expand All @@ -31,9 +34,9 @@ class block
virtual void del (store::write_transaction const &, nano::block_hash const &) = 0;
virtual bool exists (store::transaction const &, nano::block_hash const &) = 0;
virtual uint64_t count (store::transaction const &) = 0;
virtual iterator<nano::block_hash, block_w_sideband> begin (store::transaction const &, nano::block_hash const &) const = 0;
virtual iterator<nano::block_hash, block_w_sideband> begin (store::transaction const &) const = 0;
virtual iterator<nano::block_hash, block_w_sideband> end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, iterator<nano::block_hash, block_w_sideband>, iterator<nano::block_hash, block_w_sideband>)> const & action_a) const = 0;
virtual iterator begin (store::transaction const &, nano::block_hash const &) const = 0;
virtual iterator begin (store::transaction const &) const = 0;
virtual iterator end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, iterator, iterator)> const & action_a) const = 0;
};
} // namespace nano::store
11 changes: 7 additions & 4 deletions nano/store/confirmation_height.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace nano::store
*/
class confirmation_height
{
public:
using iterator = store::iterator<nano::account, nano::confirmation_height_info>;

public:
virtual void put (store::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) = 0;

Expand All @@ -32,9 +35,9 @@ class confirmation_height
virtual uint64_t count (store::transaction const & transaction_a) = 0;
virtual void clear (store::write_transaction const &, nano::account const &) = 0;
virtual void clear (store::write_transaction const &) = 0;
virtual iterator<nano::account, nano::confirmation_height_info> begin (store::transaction const & transaction_a, nano::account const & account_a) const = 0;
virtual iterator<nano::account, nano::confirmation_height_info> begin (store::transaction const & transaction_a) const = 0;
virtual iterator<nano::account, nano::confirmation_height_info> end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, iterator<nano::account, nano::confirmation_height_info>, iterator<nano::account, nano::confirmation_height_info>)> const &) const = 0;
virtual iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const = 0;
virtual iterator begin (store::transaction const & transaction_a) const = 0;
virtual iterator end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, iterator, iterator)> const &) const = 0;
};
} // namespace nano::store
1 change: 0 additions & 1 deletion nano/store/final.cpp

This file was deleted.

1 change: 1 addition & 0 deletions nano/store/final_vote.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <nano/store/final_vote.hpp>
11 changes: 7 additions & 4 deletions nano/store/final.hpp → nano/store/final_vote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ namespace nano::store
*/
class final_vote
{
public:
using iterator = store::iterator<nano::qualified_root, nano::block_hash>;

public:
virtual bool put (store::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) = 0;
virtual std::vector<nano::block_hash> get (store::transaction const & transaction_a, nano::root const & root_a) = 0;
virtual void del (store::write_transaction const & transaction_a, nano::root const & root_a) = 0;
virtual size_t count (store::transaction const & transaction_a) const = 0;
virtual void clear (store::write_transaction const &, nano::root const &) = 0;
virtual void clear (store::write_transaction const &) = 0;
virtual store::iterator<nano::qualified_root, nano::block_hash> begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0;
virtual store::iterator<nano::qualified_root, nano::block_hash> begin (store::transaction const & transaction_a) const = 0;
virtual store::iterator<nano::qualified_root, nano::block_hash> end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, store::iterator<nano::qualified_root, nano::block_hash>, store::iterator<nano::qualified_root, nano::block_hash>)> const & action_a) const = 0;
virtual iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0;
virtual iterator begin (store::transaction const & transaction_a) const = 0;
virtual iterator end () const = 0;
virtual void for_each_par (std::function<void (store::read_transaction const &, iterator, iterator)> const & action_a) const = 0;
};
} // namespace nano::store
10 changes: 5 additions & 5 deletions nano/store/iterator_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ template <typename T, typename U>
class iterator_impl
{
public:
explicit iterator_impl (nano::store::transaction const & transaction_a) :
transaction{ transaction_a },
explicit iterator_impl (transaction const & transaction_a) :
txn{ transaction_a },
transaction_epoch{ transaction_a.epoch () }
{
}
virtual ~iterator_impl ()
{
debug_assert (transaction_epoch == transaction.epoch (), "invalid iterator-transaction lifetime detected");
debug_assert (transaction_epoch == txn.epoch (), "invalid iterator-transaction lifetime detected");
}

virtual iterator_impl<T, U> & operator++ () = 0;
Expand All @@ -37,7 +37,7 @@ class iterator_impl
}

protected:
nano::store::transaction const & transaction;
nano::store::transaction::epoch_t const transaction_epoch;
transaction const & txn;
transaction::epoch_t const transaction_epoch;
};
}
12 changes: 6 additions & 6 deletions nano/store/lmdb/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ size_t nano::store::lmdb::account::count (store::transaction const & transaction
return store.count (transaction_a, tables::accounts);
}

nano::store::iterator<nano::account, nano::account_info> nano::store::lmdb::account::begin (store::transaction const & transaction, nano::account const & account) const
auto nano::store::lmdb::account::begin (store::transaction const & transaction, nano::account const & account) const -> iterator
{
return store.make_iterator<nano::account, nano::account_info> (transaction, tables::accounts, account);
}

nano::store::iterator<nano::account, nano::account_info> nano::store::lmdb::account::begin (store::transaction const & transaction) const
auto nano::store::lmdb::account::begin (store::transaction const & transaction) const -> iterator
{
return store.make_iterator<nano::account, nano::account_info> (transaction, tables::accounts);
}

nano::store::iterator<nano::account, nano::account_info> nano::store::lmdb::account::rbegin (store::transaction const & transaction_a) const
auto nano::store::lmdb::account::rbegin (store::transaction const & transaction_a) const -> iterator
{
return store.make_iterator<nano::account, nano::account_info> (transaction_a, tables::accounts, false);
}

nano::store::iterator<nano::account, nano::account_info> nano::store::lmdb::account::end () const
auto nano::store::lmdb::account::end () const -> iterator
{
return store::iterator<nano::account, nano::account_info> (nullptr);
return iterator{ nullptr };
}

void nano::store::lmdb::account::for_each_par (std::function<void (store::read_transaction const &, store::iterator<nano::account, nano::account_info>, store::iterator<nano::account, nano::account_info>)> const & action_a) const
void nano::store::lmdb::account::for_each_par (std::function<void (store::read_transaction const &, iterator, iterator)> const & action_a) const
{
parallel_traversal<nano::uint256_t> (
[&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) {
Expand Down
10 changes: 5 additions & 5 deletions nano/store/lmdb/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class account : public nano::store::account
void del (store::write_transaction const & transaction_a, nano::account const & account_a) override;
bool exists (store::transaction const & transaction_a, nano::account const & account_a) override;
size_t count (store::transaction const & transaction_a) override;
store::iterator<nano::account, nano::account_info> begin (store::transaction const & transaction_a, nano::account const & account_a) const override;
store::iterator<nano::account, nano::account_info> begin (store::transaction const & transaction_a) const override;
store::iterator<nano::account, nano::account_info> rbegin (store::transaction const & transaction_a) const override;
store::iterator<nano::account, nano::account_info> end () const override;
void for_each_par (std::function<void (store::read_transaction const &, store::iterator<nano::account, nano::account_info>, store::iterator<nano::account, nano::account_info>)> const & action_a) const override;
iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override;
iterator begin (store::transaction const & transaction_a) const override;
iterator rbegin (store::transaction const & transaction_a) const override;
iterator end () const override;
void for_each_par (std::function<void (store::read_transaction const &, iterator, iterator)> const & action_a) const override;

/**
* Maps account v1 to account information, head, rep, open, balance, timestamp and block count. (Removed)
Expand Down
Loading

0 comments on commit e11ffcf

Please sign in to comment.