-
Notifications
You must be signed in to change notification settings - Fork 114
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
- Loading branch information
Showing
7 changed files
with
448 additions
and
217 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 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,47 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::anyhow; | ||
use eth_trie::DB; | ||
use hashbrown::HashMap; | ||
use parking_lot::Mutex; | ||
use revm_primitives::B256; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum ReadOnlyMemoryDBError { | ||
#[error("read only memory db error {0}")] | ||
ANYHOW(#[from] anyhow::Error), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ReadOnlyMemoryDB { | ||
storage: Arc<Mutex<HashMap<B256, Vec<u8>>>>, | ||
} | ||
|
||
impl ReadOnlyMemoryDB { | ||
pub fn new(storage: HashMap<B256, Vec<u8>>) -> Self { | ||
ReadOnlyMemoryDB { | ||
storage: Arc::new(Mutex::new(storage)), | ||
} | ||
} | ||
} | ||
|
||
impl DB for ReadOnlyMemoryDB { | ||
type Error = ReadOnlyMemoryDBError; | ||
|
||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> { | ||
Ok(self.storage.lock().get(key).cloned()) | ||
} | ||
|
||
fn insert(&self, _key: &[u8], _value: Vec<u8>) -> Result<(), Self::Error> { | ||
Err(anyhow!("Cannot insert into read only memory db").into()) | ||
} | ||
|
||
fn remove(&self, _key: &[u8]) -> Result<(), Self::Error> { | ||
Err(anyhow!("Cannot remove from read only memory db").into()) | ||
} | ||
|
||
fn flush(&self) -> Result<(), Self::Error> { | ||
Err(anyhow!("Cannot flush read only memory db").into()) | ||
} | ||
} |
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,2 @@ | ||
pub mod memory_db; | ||
pub mod trie_walker; |
Oops, something went wrong.