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

fix: update receipts type to work with pre-byzantium receipts #1112

Merged
merged 1 commit into from
Jan 25, 2024
Merged
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
30 changes: 23 additions & 7 deletions ethportal-api/src/types/execution/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ impl<'de> Deserialize<'de> for TransactionOutcome {
D: Deserializer<'de>,
{
let s: String = Deserialize::deserialize(deserializer)?;
let s = s.trim_start_matches("0x");
match s.len() {
1 => Ok(Self::StatusCode(
s.parse::<u8>().map_err(serde::de::Error::custom)?,
)),
64 => Ok(Self::StateRoot(H256::from_slice(
&hex_decode(s).map_err(serde::de::Error::custom)?,
3 => {
let s = s.trim_start_matches("0x");
Ok(Self::StatusCode(
s.parse::<u8>().map_err(serde::de::Error::custom)?,
))
}
66 => Ok(Self::StateRoot(H256::from_slice(
&hex_decode(&s).map_err(serde::de::Error::custom)?,
))),
_ => Err(serde::de::Error::custom("Invalid transaction outcome")),
}
Expand Down Expand Up @@ -244,7 +246,7 @@ struct LegacyReceiptHelper {
pub cumulative_gas_used: U256,
pub logs_bloom: Bloom,
pub logs: Vec<LogEntryHelper>,
#[serde(rename(deserialize = "status"))]
#[serde(alias = "root", alias = "status")]
pub outcome: TransactionOutcome,
}

Expand Down Expand Up @@ -745,6 +747,20 @@ mod tests {
assert_eq!(receipts.root().unwrap(), expected_receipts_root);
}

#[test_log::test]
fn pre_byzantium_receipts_batch() {
// batched group of pre-byzantium receipts, containing the "root" field instead of "status"
// sourced from infura.
let expected: String =
std::fs::read_to_string("../test_assets/infura_batch/receipts-1114271.json").unwrap();
let receipts: Receipts = serde_json::from_str(&expected).unwrap();
let expected_receipts_root: H256 = H256::from_slice(
&hex_decode("0xd262fe545cec9ec04f4246334d05437fac8d8dfe201a1f6476fab545878cb251")
.unwrap(),
);
assert_eq!(receipts.root().unwrap(), expected_receipts_root);
}

const EXPECTED_RECEIPTS_ROOT: &str =
"0x168a3827607627e781941dc777737fc4b6beb69a8b139240b881992b35b854ea";
const RECEIPT_0: &str = "0x02f90554018302e56fb9010000200000000000001000000080000000000000000000010000000000000000000000010000000000000090000001010002000000080008000000000000000000000000000000000000020008000000200000000000400000000004000000400000000000000000000000000000000000000000000000040000000010000000000000010000001100000000000000008000000000000000080020004000100000000000000000000000000080000000000000000000000000000000000000000001000002000000100004000000000000000000000000001000000002000000000024200000000000000000000000000000000000004000000000000000001000f90449f89b94dac17f958d2ee523a2206206994597c13d831ec7f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000dd19b32a084be0a318f11edb3f7034889c03c51fa000000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631a000000000000000000000000000000000000000000000000000000000979aedebf89b94dac17f958d2ee523a2206206994597c13d831ec7f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa000000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631a000000000000000000000000074c99f3f5331676f6aec2756e1f39b4fc029a83ea000000000000000000000000000000000000000000000000000000000979aedebf89b94c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa000000000000000000000000074c99f3f5331676f6aec2756e1f39b4fc029a83ea00000000000000000000000001111111254fb6c44bac0bed2854e76f90643097da000000000000000000000000000000000000000000000000011f8b9803bc57124f8799474c99f3f5331676f6aec2756e1f39b4fc029a83ee1a01c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1b8400000000000000000000000000000000000000000000000657acd23da825d7df70000000000000000000000000000000000000000000000000000035616e4172af8fc9474c99f3f5331676f6aec2756e1f39b4fc029a83ef863a0d78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822a00000000000000000000000001111111254fb6c44bac0bed2854e76f90643097da00000000000000000000000001111111254fb6c44bac0bed2854e76f90643097db880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000979aedeb00000000000000000000000000000000000000000000000011f8b9803bc571240000000000000000000000000000000000000000000000000000000000000000f87a94c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2f842a07fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65a00000000000000000000000001111111254fb6c44bac0bed2854e76f90643097da000000000000000000000000000000000000000000000000011f8b9803bc57124f87b94881d40237659c251811cec9c364ef91dc08d300cf863a0beee1e6e7fe307ddcf84b0a16137a4430ad5e2480fc4f4a8e250ab56ccd7630da0bd5c436f8c83379009c1962310b8347e561d1900906d3fe4075b1596f8955f88a0000000000000000000000000dd19b32a084be0a318f11edb3f7034889c03c51f80";
Expand Down
1 change: 1 addition & 0 deletions test_assets/infura_batch/receipts-1114271.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"jsonrpc":"2.0","id":0,"result":{"blockHash":"0xe533d4f90e456b728e2b661aab97985cab3895df339c3867b934c3e0f23748ad","blockNumber":"0x11009f","contractAddress":null,"cumulativeGasUsed":"0x5208","effectiveGasPrice":"0xba43b7400","from":"0x2a65aca4d5fc5b5c859090a6c34d164135398226","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0xe7ed69bdc3fbc644b525dfdc5258cacbd0514362d41ca39824c9ba95e901e359","to":"0x4ba17750802abcc34aa8b93a9fc48813368a86a6","transactionHash":"0xc3dd8d9fe8f4a06c97ca483fc08356ffdad2d43dd155fdb549bc252760fec068","transactionIndex":"0x0","type":"0x0"}},{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xe533d4f90e456b728e2b661aab97985cab3895df339c3867b934c3e0f23748ad","blockNumber":"0x11009f","contractAddress":null,"cumulativeGasUsed":"0xa410","effectiveGasPrice":"0x4a817c800","from":"0xbbb33ce61991cc4272d581b5cffa77f4be09f26c","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0xd231621c90fd9956ba02a39e5c95d191f075c667cfaff9e13d34fb8dcefd8c55","to":"0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98","transactionHash":"0xbdd848742eca5f0d64ee233ffdf95432db09367491dd0abda6abf5205eaff8c6","transactionIndex":"0x1","type":"0x0"}}]
Loading