Skip to content

Commit

Permalink
reuse rlp to make hash
Browse files Browse the repository at this point in the history
Signed-off-by: Naohiro Yoshida <[email protected]>
  • Loading branch information
Naohiro Yoshida committed Nov 27, 2024
1 parent 432ef3d commit 19afe90
Showing 1 changed file with 1 addition and 66 deletions.
67 changes: 1 addition & 66 deletions light-client/src/header/eth_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,72 +415,7 @@ impl TryFrom<RawETHHeader> for ETHHeader {
return Err(Error::UnexpectedNonce(number));
}

// create block hash
let mut stream = RlpStream::new();
stream.begin_unbounded_list();
stream.append(&parent_hash);
stream.append(&uncle_hash);
stream.append(&coinbase);
stream.append(&root.to_vec());
stream.append(&tx_hash);
stream.append(&receipt_hash);
stream.append(&bloom);
stream.append(&difficulty);
stream.append(&number);
stream.append(&gas_limit);
stream.append(&gas_used);
stream.append(&timestamp);
stream.append(&extra_data);
stream.append(&mix_digest);
stream.append(&nonce);

if base_fee_per_gas.is_some()
|| withdrawals_hash.is_some()
|| blob_gas_used.is_some()
|| excess_blob_gas.is_some()
|| parent_beacon_root.is_some()
{
if let Some(v) = base_fee_per_gas {
stream.append(&v);
} else {
stream.append_empty_data();
}
}
if withdrawals_hash.is_some()
|| blob_gas_used.is_some()
|| excess_blob_gas.is_some()
|| parent_beacon_root.is_some()
{
if let Some(v) = &withdrawals_hash {
stream.append(v);
} else {
stream.append_empty_data();
}
}
if blob_gas_used.is_some() || excess_blob_gas.is_some() || parent_beacon_root.is_some() {
if let Some(v) = blob_gas_used {
stream.append(&v);
} else {
stream.append_empty_data();
}
}
if excess_blob_gas.is_some() || parent_beacon_root.is_some() {
if let Some(v) = excess_blob_gas {
stream.append(&v);
} else {
stream.append_empty_data();
}
}
if parent_beacon_root.is_some() {
if let Some(v) = &parent_beacon_root {
stream.append(v);
} else {
stream.append_empty_data();
}
}
stream.finalize_unbounded_list();
let buffer_vec: Vec<u8> = stream.out().to_vec();
let hash: Hash = keccak_256(&buffer_vec);
let hash: Hash = keccak_256(&value.header.as_slice());

Check failure on line 418 in light-client/src/header/eth_header.rs

View workflow job for this annotation

GitHub Actions / ci

this expression creates a reference which is immediately dereferenced by the compiler

let epoch = if number % BLOCKS_PER_EPOCH == 0 {
let (validators, turn_length) = get_validator_bytes_and_turn_length(&extra_data)?;
Expand Down

0 comments on commit 19afe90

Please sign in to comment.