Fix Uint256 deserialization (#2786)

* Change base_fee_per_gas to Uint256

* Add custom (de)serialization to ExecutionPayload

* Fix errors

* Add a quoted_u256 module

* Remove unused function

* lint

* Add test

* Remove extra line

Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
Pawan Dhananjay
2021-11-10 15:57:44 -08:00
committed by Paul Hauner
parent de49c7ddaa
commit 24966c059d
10 changed files with 90 additions and 24 deletions

View File

@@ -326,7 +326,7 @@ impl<T: EthSpec> From<ExecutionPayload<T>> for JsonExecutionPayload<T> {
gas_used: e.gas_used,
timestamp: e.timestamp,
extra_data: e.extra_data,
base_fee_per_gas: Uint256::from_little_endian(e.base_fee_per_gas.as_bytes()),
base_fee_per_gas: e.base_fee_per_gas,
block_hash: e.block_hash,
transactions: e.transactions,
}
@@ -347,19 +347,13 @@ impl<T: EthSpec> From<JsonExecutionPayload<T>> for ExecutionPayload<T> {
gas_used: e.gas_used,
timestamp: e.timestamp,
extra_data: e.extra_data,
base_fee_per_gas: uint256_to_hash256(e.base_fee_per_gas),
base_fee_per_gas: e.base_fee_per_gas,
block_hash: e.block_hash,
transactions: e.transactions,
}
}
}
fn uint256_to_hash256(u: Uint256) -> Hash256 {
let mut bytes = [0; 32];
u.to_little_endian(&mut bytes);
Hash256::from_slice(&bytes)
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonConsensusValidatedRequest {
@@ -797,7 +791,7 @@ mod test {
gas_used: 2,
timestamp: 42,
extra_data: vec![].into(),
base_fee_per_gas: uint256_to_hash256(Uint256::from(1)),
base_fee_per_gas: Uint256::from(1),
block_hash: Hash256::repeat_byte(1),
transactions: vec![].into(),
})
@@ -960,7 +954,7 @@ mod test {
gas_used: 0,
timestamp: 5,
extra_data: vec![].into(),
base_fee_per_gas: uint256_to_hash256(Uint256::from(0)),
base_fee_per_gas: Uint256::from(0),
block_hash: Hash256::from_str("0xb084c10440f05f5a23a55d1d7ebcb1b3892935fb56f23cdc9a7f42c348eed174").unwrap(),
transactions: vec![].into(),
};
@@ -984,7 +978,7 @@ mod test {
gas_used: 0,
timestamp: 5,
extra_data: vec![].into(),
base_fee_per_gas: uint256_to_hash256(Uint256::from(0)),
base_fee_per_gas: Uint256::from(0),
block_hash: Hash256::from_str("0xb084c10440f05f5a23a55d1d7ebcb1b3892935fb56f23cdc9a7f42c348eed174").unwrap(),
transactions: vec![].into(),
})

View File

@@ -250,7 +250,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
gas_used: GAS_USED,
timestamp: payload.timestamp,
extra_data: "block gen was here".as_bytes().to_vec().into(),
base_fee_per_gas: Hash256::from_low_u64_le(1),
base_fee_per_gas: Uint256::one(),
block_hash: Hash256::zero(),
transactions: vec![].into(),
};