-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement new trie_walker which can iterate full+partial tries (#…
…1567) * feat: implement new trie_walker which can iterate full+partial tries * fix: resolve PR concerns * fix: lint * fix: resolve PR concerns
- Loading branch information
Showing
5 changed files
with
310 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use alloy::primitives::{Bytes, B256}; | ||
use anyhow::anyhow; | ||
use eth_trie::DB; | ||
use hashbrown::HashMap; | ||
|
||
use crate::storage::trie_db::TrieRocksDB; | ||
|
||
pub trait TrieWalkerDb { | ||
fn get(&self, key: &[u8]) -> anyhow::Result<Option<Bytes>>; | ||
} | ||
|
||
impl TrieWalkerDb for HashMap<B256, Vec<u8>> { | ||
fn get(&self, key: &[u8]) -> anyhow::Result<Option<Bytes>> { | ||
Ok(self.get(key).map(|vec| Bytes::copy_from_slice(vec))) | ||
} | ||
} | ||
|
||
impl TrieWalkerDb for TrieRocksDB { | ||
fn get(&self, key: &[u8]) -> anyhow::Result<Option<Bytes>> { | ||
DB::get(self, key) | ||
.map(|result| result.map(Bytes::from)) | ||
.map_err(|err| anyhow!("Failed to read key value from TrieRocksDB {err}")) | ||
} | ||
} |
Oops, something went wrong.