Skip to content
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
12 changes: 4 additions & 8 deletions crates/common/trie/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ethereum_types::H256;
use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode, error::RLPDecodeError};
use ethrex_rlp::encode::RLPEncode;

use crate::{Nibbles, Node, NodeRLP, Trie, error::TrieError};
use crate::{Nibbles, Node, Trie, error::TrieError};
use std::{
collections::BTreeMap,
sync::{Arc, Mutex},
Expand Down Expand Up @@ -62,13 +62,9 @@ impl InMemoryTrieDB {
// Do not remove or make private as we use this in ethrex-replay
pub fn from_nodes(
root_hash: H256,
state_nodes: &BTreeMap<H256, NodeRLP>,
state_nodes: &BTreeMap<H256, Node>,
) -> Result<Self, TrieError> {
let state_nodes: BTreeMap<_, _> = state_nodes
.iter()
.map(|(h, b)| Ok((*h, Node::decode(b)?)))
.collect::<Result<_, RLPDecodeError>>()?;
let mut embedded_root = Trie::get_embedded_root(&state_nodes, root_hash)?;
let mut embedded_root = Trie::get_embedded_root(state_nodes, root_hash)?;
let mut hashed_nodes = vec![];
embedded_root.commit(Nibbles::default(), &mut hashed_nodes);

Expand Down
20 changes: 18 additions & 2 deletions crates/networking/rpc/debug/execution_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bytes::Bytes;
use ethrex_common::{
Address, H256, serde_utils,
types::{
AccountState, ChainConfig,
AccountState, BlockHeader, ChainConfig,
block_execution_witness::{ExecutionWitness, GuestProgramStateError},
},
utils::keccak,
Expand Down Expand Up @@ -70,8 +70,24 @@ pub fn execution_witness_from_rpc_chain_config(
rpc_witness: RpcExecutionWitness,
chain_config: ChainConfig,
first_block_number: u64,
initial_state_root: H256,
) -> Result<ExecutionWitness, GuestProgramStateError> {
let mut initial_state_root = None;

for h in &rpc_witness.headers {
let header = BlockHeader::decode(h)?;
if header.number == first_block_number - 1 {
initial_state_root = Some(header.state_root);
break;
}
}

let initial_state_root = initial_state_root.ok_or_else(|| {
GuestProgramStateError::Custom(format!(
"header for block {} not found",
first_block_number - 1
))
})?;

let nodes: BTreeMap<H256, Node> = rpc_witness
.state
.into_iter()
Expand Down