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 cd3ca85
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 67 deletions.
2 changes: 1 addition & 1 deletion light-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ mod test {
fn test_error_create_client() {
let client_state = hex!("0a272f6962632e6c69676874636c69656e74732e7061726c69612e76312e436c69656e745374617465124d08381214151f3951fa218cac426edfe078fa9e5c6dcea5001a2000000000000000000000000000000000000000000000000000000000000000002205109b9ea90f2a040880a305320410c0843d").to_vec();
let consensus_state = hex!("0a2a2f6962632e6c69676874636c69656e74732e7061726c69612e76312e436f6e73656e7375735374617465126c0a2056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b42110de82d5a8061a209c59cf0b5717cb6e2bd8620b7f3481605c8abcd45636bdf45c86db06338f0c5e22207a1dede35f5c835fecdc768324928cd0d9d9161e8529e1ba1e60451f3a9d088a").to_vec();
let client = ParliaLightClient::default();
let client = ParliaLightClient;
let mock_consensus_state = BTreeMap::new();
let ctx = MockClientReader {
client_state: None,
Expand Down
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());

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 cd3ca85

Please sign in to comment.