Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement new trie_walker which can iterate full+partial tries #1567

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions portal-bridge/src/bridge/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ impl StateBridge {
.header
.hash();

let walk_diff = TrieWalker::new(root_with_trie_diff.root, root_with_trie_diff.trie_diff);
let walk_diff =
TrieWalker::new_partial_trie(root_with_trie_diff.root, root_with_trie_diff.trie_diff)?;

// gossip block's new state transitions
let mut content_idx = 0;
for node in walk_diff.nodes.keys() {
let account_proof = walk_diff.get_proof(*node);

for account_proof in walk_diff {
// gossip the account
self.gossip_account(&account_proof, block_hash, content_idx)
.await?;
Expand Down Expand Up @@ -213,10 +212,10 @@ impl StateBridge {
// gossip contract storage
let storage_changed_nodes = trin_execution.database.get_storage_trie_diff(address_hash);

let storage_walk_diff = TrieWalker::new(account.storage_root, storage_changed_nodes);
let storage_walk_diff =
TrieWalker::new_partial_trie(account.storage_root, storage_changed_nodes)?;

for storage_node in storage_walk_diff.nodes.keys() {
let storage_proof = storage_walk_diff.get_proof(*storage_node);
for storage_proof in storage_walk_diff {
self.gossip_storage(
&account_proof,
&storage_proof,
Expand Down
199 changes: 0 additions & 199 deletions trin-execution/src/trie_walker.rs

This file was deleted.

24 changes: 24 additions & 0 deletions trin-execution/src/trie_walker/db.rs
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}"))
}
}
Loading
Loading