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

BEP466 #80

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
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
75 changes: 9 additions & 66 deletions light-client/src/header/eth_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct ETHHeader {
pub blob_gas_used: Option<u64>,
pub excess_blob_gas: Option<u64>,
pub parent_beacon_root: Option<Vec<u8>>,
pub requests_hash: Option<Vec<u8>>,

// calculated by RawETHHeader
pub hash: Hash,
Expand Down Expand Up @@ -133,6 +134,11 @@ impl ETHHeader {
stream.append_empty_data();
}
stream.append(parent_beacon_root);

// https://github.com/bnb-chain/bsc/blob/e2f2111a85fecabb4782099338aca21bf58bde09/core/types/block.go#L776
if let Some(value) = &self.requests_hash {
stream.append(value);
}
}
}
stream.finalize_unbounded_list();
Expand Down Expand Up @@ -378,6 +384,7 @@ impl TryFrom<RawETHHeader> for ETHHeader {
let blob_gas_used: Option<u64> = rlp.try_next_as_val().map(Some).unwrap_or(None);
let excess_blob_gas: Option<u64> = rlp.try_next_as_val().map(Some).unwrap_or(None);
let parent_beacon_root: Option<Vec<u8>> = rlp.try_next_as_val().map(Some).unwrap_or(None);
let requests_hash: Option<Vec<u8>> = rlp.try_next_as_val().map(Some).unwrap_or(None);

// Check that the extra-data contains the vanity, validators and signature
let extra_size = extra_data.len();
Expand Down Expand Up @@ -415,72 +422,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 Expand Up @@ -510,6 +452,7 @@ impl TryFrom<RawETHHeader> for ETHHeader {
withdrawals_hash,
blob_gas_used,
parent_beacon_root,
requests_hash,
hash,
epoch,
})
Expand Down
1 change: 1 addition & 0 deletions light-client/src/header/vote_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ mod test {
blob_gas_used: None,
excess_blob_gas: None,
parent_beacon_root: None,
requests_hash: None,
hash: [0u8; 32],
epoch: None,
};
Expand Down
Loading