Skip to content
Closed
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
17 changes: 13 additions & 4 deletions crates/common/types/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ pub struct Code {
}

impl Code {
// TODO: also add `from_hashed_bytecode` to optimize the download pipeline,
// where hash is already known and checked.
pub fn from_bytecode(code: Bytes) -> Self {
let jump_targets = Self::compute_jump_targets(&code);
Self {
Expand All @@ -43,6 +41,16 @@ impl Code {
}
}

pub fn from_hashed_bytecode(hash: H256, code: Bytes) -> Self {
let jump_targets = Self::compute_jump_targets(&code);
debug_assert_eq!(keccak(code.as_ref()), hash);
Self {
hash,
bytecode: code,
jump_targets,
}
}

fn compute_jump_targets(code: &[u8]) -> Vec<u32> {
debug_assert!(code.len() <= u32::MAX as usize);
let mut targets = Vec::new();
Expand Down Expand Up @@ -143,13 +151,14 @@ impl Default for Code {

impl From<GenesisAccount> for Account {
fn from(genesis: GenesisAccount) -> Self {
let hash = code_hash(&genesis.code);
Self {
info: AccountInfo {
code_hash: code_hash(&genesis.code),
code_hash: hash,
balance: genesis.balance,
nonce: genesis.nonce,
},
code: Code::from_bytecode(genesis.code),
code: Code::from_hashed_bytecode(hash, genesis.code),
storage: genesis
.storage
.iter()
Expand Down