mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat: block level indexing (#2275)
Co-authored-by: rakita <dragan0rakita@gmail.com> Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
@ -25,7 +25,7 @@ use crate::{
|
||||
tables::{
|
||||
codecs::CompactU256,
|
||||
models::{
|
||||
accounts::{AccountBeforeTx, TransitionIdAddress},
|
||||
accounts::{AccountBeforeTx, BlockNumberAddress},
|
||||
blocks::{HeaderHash, StoredBlockOmmers},
|
||||
storage_sharded_key::StorageShardedKey,
|
||||
ShardedKey, StoredBlockBodyIndices, StoredBlockWithdrawals,
|
||||
@ -35,7 +35,7 @@ use crate::{
|
||||
use reth_primitives::{
|
||||
trie::{BranchNodeCompact, StorageTrieEntry, StoredNibbles, StoredNibblesSubKey},
|
||||
Account, Address, BlockHash, BlockNumber, Bytecode, Header, IntegerList, Receipt, StorageEntry,
|
||||
TransactionSigned, TransitionId, TxHash, TxNumber, H256,
|
||||
TransactionSigned, TxHash, TxNumber, H256,
|
||||
};
|
||||
|
||||
/// Enum for the types of tables present in libmdbx.
|
||||
@ -151,8 +151,7 @@ table!(
|
||||
);
|
||||
|
||||
table!(
|
||||
/// Stores block indices that contains indexes of transaction and transitions,
|
||||
/// number of transactions and if block has a block change (block reward or withdrawals).
|
||||
/// Stores block indices that contains indexes of transaction and the count of them.
|
||||
///
|
||||
/// More information about stored indices can be found in the [`StoredBlockBodyIndices`] struct.
|
||||
( BlockBodyIndices ) BlockNumber | StoredBlockBodyIndices
|
||||
@ -209,61 +208,61 @@ dupsort!(
|
||||
);
|
||||
|
||||
table!(
|
||||
/// Stores pointers to transition changeset with changes for each account key.
|
||||
/// Stores pointers to block changeset with changes for each account key.
|
||||
///
|
||||
/// Last shard key of the storage will contains `u64::MAX` `TransitionId`,
|
||||
/// Last shard key of the storage will contains `u64::MAX` `BlockNumber`,
|
||||
/// this would allows us small optimization on db access when change is in plain state.
|
||||
///
|
||||
/// Imagine having shards as:
|
||||
/// * `Address | 100`
|
||||
/// * `Address | u64::MAX`
|
||||
///
|
||||
/// What we need to find is id that is one greater than N. Db `seek` function allows us to fetch
|
||||
/// What we need to find is number that is one greater than N. Db `seek` function allows us to fetch
|
||||
/// the shard that equal or more than asked. For example:
|
||||
/// * For N=50 we would get first shard.
|
||||
/// * for N=150 we would get second shard.
|
||||
/// * If max transition id is 200 and we ask for N=250 we would fetch last shard and
|
||||
/// * If max block number is 200 and we ask for N=250 we would fetch last shard and
|
||||
/// know that needed entry is in `AccountPlainState`.
|
||||
/// * If there were no shard we would get `None` entry or entry of different storage key.
|
||||
///
|
||||
/// Code example can be found in `reth_provider::HistoricalStateProviderRef`
|
||||
( AccountHistory ) ShardedKey<Address> | TransitionList
|
||||
( AccountHistory ) ShardedKey<Address> | BlockNumberList
|
||||
);
|
||||
|
||||
table!(
|
||||
/// Stores pointers to transition changeset with changes for each storage key.
|
||||
/// Stores pointers to block number changeset with changes for each storage key.
|
||||
///
|
||||
/// Last shard key of the storage will contains `u64::MAX` `TransitionId`,
|
||||
/// Last shard key of the storage will contains `u64::MAX` `BlockNumber`,
|
||||
/// this would allows us small optimization on db access when change is in plain state.
|
||||
///
|
||||
/// Imagine having shards as:
|
||||
/// * `Address | StorageKey | 100`
|
||||
/// * `Address | StorageKey | u64::MAX`
|
||||
///
|
||||
/// What we need to find is id that is one greater than N. Db `seek` function allows us to fetch
|
||||
/// What we need to find is number that is one greater than N. Db `seek` function allows us to fetch
|
||||
/// the shard that equal or more than asked. For example:
|
||||
/// * For N=50 we would get first shard.
|
||||
/// * for N=150 we would get second shard.
|
||||
/// * If max transition id is 200 and we ask for N=250 we would fetch last shard and
|
||||
/// * If max block number is 200 and we ask for N=250 we would fetch last shard and
|
||||
/// know that needed entry is in `StoragePlainState`.
|
||||
/// * If there were no shard we would get `None` entry or entry of different storage key.
|
||||
///
|
||||
/// Code example can be found in `reth_provider::HistoricalStateProviderRef`
|
||||
( StorageHistory ) StorageShardedKey | TransitionList
|
||||
( StorageHistory ) StorageShardedKey | BlockNumberList
|
||||
);
|
||||
|
||||
dupsort!(
|
||||
/// Stores the state of an account before a certain transaction changed it.
|
||||
/// Change on state can be: account is created, selfdestructed, touched while empty
|
||||
/// or changed (balance,nonce).
|
||||
( AccountChangeSet ) TransitionId | [Address] AccountBeforeTx
|
||||
( AccountChangeSet ) BlockNumber | [Address] AccountBeforeTx
|
||||
);
|
||||
|
||||
dupsort!(
|
||||
/// Stores the state of a storage key before a certain transaction changed it.
|
||||
/// If [`StorageEntry::value`] is zero, this means storage was not existing
|
||||
/// and needs to be removed.
|
||||
( StorageChangeSet ) TransitionIdAddress | [H256] StorageEntry
|
||||
( StorageChangeSet ) BlockNumberAddress | [H256] StorageEntry
|
||||
);
|
||||
|
||||
table!(
|
||||
@ -309,14 +308,9 @@ table!(
|
||||
( SyncStageProgress ) StageId | Vec<u8>
|
||||
);
|
||||
|
||||
///
|
||||
/// Alias Types
|
||||
|
||||
/// List with transaction numbers.
|
||||
pub type TransitionList = IntegerList;
|
||||
pub type BlockNumberList = IntegerList;
|
||||
/// Encoded stage id.
|
||||
pub type StageId = String;
|
||||
|
||||
//
|
||||
// TODO: Temporary types, until they're properly defined alongside with the Encode and Decode Trait
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user