Skip to content

Commit

Permalink
Merge pull request #3787 from nanocurrency/move_lmdb_handles_to_their…
Browse files Browse the repository at this point in the history
…_respective_store

Moves the LDMB table handles to their respective type of store class
  • Loading branch information
thsfs authored Apr 11, 2022
2 parents e4deda7 + 2670046 commit ce8c972
Show file tree
Hide file tree
Showing 13 changed files with 970 additions and 879 deletions.
1,327 changes: 692 additions & 635 deletions nano/core_test/block_store.cpp

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions nano/node/lmdb/account_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <nano/secure/store.hpp>

#include <lmdb/libraries/liblmdb/lmdb.h>

namespace nano
{
namespace lmdb
Expand All @@ -24,6 +26,30 @@ namespace lmdb
nano::store_iterator<nano::account, nano::account_info> rbegin (nano::transaction const & transaction_a) const override;
nano::store_iterator<nano::account, nano::account_info> end () const override;
void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::account, nano::account_info>, nano::store_iterator<nano::account, nano::account_info>)> const & action_a) const override;

/**
* Maps account v1 to account information, head, rep, open, balance, timestamp and block count. (Removed)
* nano::account -> nano::block_hash, nano::block_hash, nano::block_hash, nano::amount, uint64_t, uint64_t
*/
MDB_dbi accounts_v0_handle{ 0 };

/**
* Maps account v0 to account information, head, rep, open, balance, timestamp and block count. (Removed)
* nano::account -> nano::block_hash, nano::block_hash, nano::block_hash, nano::amount, uint64_t, uint64_t
*/
MDB_dbi accounts_v1_handle{ 0 };

/**
* Maps account v0 to account information, head, rep, open, balance, timestamp, block count and epoch
* nano::account -> nano::block_hash, nano::block_hash, nano::block_hash, nano::amount, uint64_t, uint64_t, nano::epoch
*/
MDB_dbi accounts_handle{ 0 };

/**
* Representative weights. (Removed)
* nano::account -> nano::uint128_t
*/
MDB_dbi representation_handle{ 0 };
};
}
}
56 changes: 56 additions & 0 deletions nano/node/lmdb/block_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <nano/secure/store.hpp>

#include <lmdb/libraries/liblmdb/lmdb.h>

namespace nano
{
using mdb_val = db_val<MDB_val>;
Expand Down Expand Up @@ -38,6 +40,60 @@ namespace lmdb
// Converts a block hash to a block height
uint64_t account_height (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override;

/**
* Maps block hash to send block. (Removed)
* nano::block_hash -> nano::send_block
*/
MDB_dbi send_blocks_handle{ 0 };

/**
* Maps block hash to receive block. (Removed)
* nano::block_hash -> nano::receive_block
*/
MDB_dbi receive_blocks_handle{ 0 };

/**
* Maps block hash to open block. (Removed)
* nano::block_hash -> nano::open_block
*/
MDB_dbi open_blocks_handle{ 0 };

/**
* Maps block hash to change block. (Removed)
* nano::block_hash -> nano::change_block
*/
MDB_dbi change_blocks_handle{ 0 };

/**
* Maps block hash to v0 state block. (Removed)
* nano::block_hash -> nano::state_block
*/
MDB_dbi state_blocks_v0_handle{ 0 };

/**
* Maps block hash to v1 state block. (Removed)
* nano::block_hash -> nano::state_block
*/
MDB_dbi state_blocks_v1_handle{ 0 };

/**
* Maps block hash to state block. (Removed)
* nano::block_hash -> nano::state_block
*/
MDB_dbi state_blocks_handle{ 0 };

/**
* Meta information about block store, such as versions.
* nano::uint256_union (arbitrary key) -> blob
*/
MDB_dbi meta_handle{ 0 };

/**
* Contains block_sideband and block for all block types (legacy send/change/open/receive & state blocks)
* nano::block_hash -> nano::block_sideband, nano::block
*/
MDB_dbi blocks_handle{ 0 };

protected:
void block_raw_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::mdb_val & value) const;
size_t block_successor_offset (nano::transaction const & transaction_a, size_t entry_size_a, nano::block_type type_a) const;
Expand Down
8 changes: 8 additions & 0 deletions nano/node/lmdb/confirmation_height_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <nano/secure/store.hpp>

#include <lmdb/libraries/liblmdb/lmdb.h>

namespace nano
{
namespace lmdb
Expand All @@ -24,6 +26,12 @@ namespace lmdb
nano::store_iterator<nano::account, nano::confirmation_height_info> begin (nano::transaction const & transaction_a) const override;
nano::store_iterator<nano::account, nano::confirmation_height_info> end () const override;
void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::account, nano::confirmation_height_info>, nano::store_iterator<nano::account, nano::confirmation_height_info>)> const & action_a) const override;

/*
* Confirmation height of an account, and the hash for the block at that height
* nano::account -> uint64_t, nano::block_hash
*/
MDB_dbi confirmation_height_handle{ 0 };
};
}
}
8 changes: 8 additions & 0 deletions nano/node/lmdb/final_vote_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <nano/secure/store.hpp>

#include <lmdb/libraries/liblmdb/lmdb.h>

namespace nano
{
namespace lmdb
Expand All @@ -24,6 +26,12 @@ namespace lmdb
nano::store_iterator<nano::qualified_root, nano::block_hash> begin (nano::transaction const & transaction_a) const override;
nano::store_iterator<nano::qualified_root, nano::block_hash> end () const override;
void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::qualified_root, nano::block_hash>, nano::store_iterator<nano::qualified_root, nano::block_hash>)> const & action_a) const override;

/**
* Maps root to block hash for generated final votes.
* nano::qualified_root -> nano::block_hash
*/
MDB_dbi final_votes_handle{ 0 };
};
}
}
12 changes: 10 additions & 2 deletions nano/node/lmdb/frontier_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

#include <nano/secure/store.hpp>

#include <lmdb/libraries/liblmdb/lmdb.h>

namespace nano
{
namespace lmdb
{
class store;
class frontier_store : public nano::frontier_store
{
private:
nano::lmdb::store & store;

public:
frontier_store (nano::lmdb::store & store);
void put (nano::write_transaction const &, nano::block_hash const &, nano::account const &) override;
Expand All @@ -19,8 +24,11 @@ namespace lmdb
nano::store_iterator<nano::block_hash, nano::account> end () const override;
void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::block_hash, nano::account>, nano::store_iterator<nano::block_hash, nano::account>)> const & action_a) const override;

private:
nano::lmdb::store & store;
/**
* Maps head block to owning account
* nano::block_hash -> nano::account
*/
MDB_dbi frontiers_handle{ 0 };
};
}
}
Loading

0 comments on commit ce8c972

Please sign in to comment.