Skip to content

Commit

Permalink
add l1_fee field to Receipt
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
  • Loading branch information
greged93 committed Nov 23, 2024
1 parent 5b01075 commit 32844ae
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/evm/execution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ std = [
"serde?/std",
"reth-primitives-traits/std",
]
scroll = []
4 changes: 4 additions & 0 deletions crates/evm/execution-types/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "scroll")]
l1_fee: alloy_primitives::U256::ZERO,
};

// Create another random receipt object, receipt2
Expand All @@ -821,6 +823,8 @@ mod tests {
cumulative_gas_used: 1325345,
logs: vec![],
success: true,
#[cfg(feature = "scroll")]
l1_fee: alloy_primitives::U256::ZERO,
};

// Create a Receipts object with a vector of receipt vectors
Expand Down
18 changes: 18 additions & 0 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
})]],
};

Expand Down Expand Up @@ -460,6 +462,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
})]],
};

Expand Down Expand Up @@ -495,6 +499,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
})]],
};

Expand Down Expand Up @@ -527,6 +533,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
})]],
};

Expand All @@ -553,6 +561,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
})]
);
}
Expand All @@ -567,6 +577,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
})]],
};

Expand Down Expand Up @@ -615,6 +627,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
};

// Create a Receipts object with a vector of receipt vectors
Expand Down Expand Up @@ -664,6 +678,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
};

// Create a Receipts object containing the receipt.
Expand Down Expand Up @@ -708,6 +724,8 @@ mod tests {
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "scroll")]
l1_fee: U256::ZERO,
};

// Create a Receipts object with a vector of receipt vectors
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ mod tests {
success: true,
cumulative_gas_used: 102068,
logs,
#[cfg(feature = "scroll")]
l1_fee: U256::from(0xffffff),
},
bloom,
};
Expand Down
28 changes: 27 additions & 1 deletion crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use alloy_consensus::{
Eip658Value, TxReceipt,
};
use alloy_eips::eip2718::Encodable2718;
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
use alloy_primitives::U256;
use alloy_primitives::{Bloom, Log, B256};
use alloy_rlp::{length_of_length, Decodable, Encodable, RlpDecodable, RlpEncodable};
use bytes::{Buf, BufMut};
Expand Down Expand Up @@ -49,6 +51,12 @@ pub struct Receipt {
/// ensures this is only set for post-Canyon deposit transactions.
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
pub deposit_receipt_version: Option<u64>,
/// Additional fee to cover l1 data availability costs.
/// L1 fee is not part of the consensus encoding of a receipt.
/// <https://github.com/scroll-tech/go-ethereum/blob/9fff27e4f34fb5097100ed76ee725ce056267f4b/core/types/receipt.go#L96-L102>
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
#[rlp(skip)]
pub l1_fee: U256,
}

impl Receipt {
Expand Down Expand Up @@ -233,6 +241,8 @@ impl<'a> arbitrary::Arbitrary<'a> for Receipt {
deposit_nonce,
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
deposit_receipt_version,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
l1_fee: alloy_primitives::U256::arbitrary(u)?,
})
}
}
Expand Down Expand Up @@ -320,6 +330,8 @@ impl ReceiptWithBloom {
deposit_nonce: None,
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
deposit_receipt_version: None,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
l1_fee: U256::ZERO,
},
};

Expand Down Expand Up @@ -557,10 +569,14 @@ mod tests {

#[test]
fn test_decode_receipt() {
#[cfg(not(feature = "optimism"))]
#[cfg(all(not(feature = "optimism"), not(feature = "scroll")))]
reth_codecs::test_utils::test_decode::<Receipt>(&hex!(
"c428b52ffd23fc42696156b10200f034792b6a94c3850215c2fef7aea361a0c31b79d9a32652eefc0d4e2e730036061cff7344b6fc6132b50cda0ed810a991ae58ef013150c12b2522533cb3b3a8b19b7786a8b5ff1d3cdc84225e22b02def168c8858df"
));
#[cfg(feature = "scroll")]
reth_codecs::test_utils::test_decode::<Receipt>(&hex!(
"c42128b52ffd23fc42696159c90200f034792b6a94c3850215c2fef7aea361a0c31b79d9a32652eefc0d4e2e730036061cff7344b6fc6132b50cda0ed810a991ae58ef013150c12b2522533cb3b3a8b19b7786a8b5ff1d3cdc84225e22b02def168c8858dfffffff"
));
#[cfg(feature = "optimism")]
reth_codecs::test_utils::test_decode::<Receipt>(&hex!(
"c30328b52ffd23fc426961a00105007eb0042307705a97e503562eacf2b95060cce9de6de68386b6c155b73a9650021a49e2f8baad17f30faff5899d785c4c0873e45bc268bcf07560106424570d11f9a59e8f3db1efa4ceec680123712275f10d92c3411e1caaa11c7c5d591bc11487168e09934a9986848136da1b583babf3a7188e3aed007a1520f1cf4c1ca7d3482c6c28d37c298613c70a76940008816c4c95644579fd08471dc34732fd0f24"
Expand Down Expand Up @@ -590,6 +606,8 @@ mod tests {
deposit_nonce: None,
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
deposit_receipt_version: None,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
l1_fee: U256::ZERO,
},
bloom: [0; 256].into(),
};
Expand Down Expand Up @@ -624,6 +642,8 @@ mod tests {
deposit_nonce: None,
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
deposit_receipt_version: None,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
l1_fee: U256::ZERO,
},
bloom: [0; 256].into(),
};
Expand Down Expand Up @@ -706,6 +726,8 @@ mod tests {
deposit_nonce: None,
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
deposit_receipt_version: None,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
l1_fee: U256::from(0xffffff),
};

let mut data = vec![];
Expand All @@ -726,6 +748,8 @@ mod tests {
deposit_nonce: None,
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
deposit_receipt_version: None,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
l1_fee: U256::from(0xffffff),
},
bloom: Bloom::default(),
};
Expand All @@ -748,6 +772,8 @@ mod tests {
deposit_nonce: None,
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
deposit_receipt_version: None,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
l1_fee: U256::from(0xffffff),
},
bloom: Bloom::default(),
};
Expand Down
1 change: 1 addition & 0 deletions crates/storage/db-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ arbitrary = [
"alloy-consensus/arbitrary",
]
optimism = ["reth-primitives/optimism", "reth-codecs/optimism"]
scroll = ["reth-primitives/scroll"]
6 changes: 6 additions & 0 deletions crates/storage/db-api/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ mod tests {
assert_eq!(PruneCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(PruneMode::bitflag_encoded_bytes(), 1);
assert_eq!(PruneSegment::bitflag_encoded_bytes(), 1);
#[cfg(not(feature = "scroll"))]
assert_eq!(Receipt::bitflag_encoded_bytes(), 1);
#[cfg(feature = "scroll")]
assert_eq!(Receipt::bitflag_encoded_bytes(), 2);
assert_eq!(ReceiptWithBloom::bitflag_encoded_bytes(), 0);
assert_eq!(StageCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(StageUnitCheckpoint::bitflag_encoded_bytes(), 1);
Expand All @@ -354,7 +357,10 @@ mod tests {
validate_bitflag_backwards_compat!(PruneCheckpoint, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(PruneMode, UnusedBits::Zero);
validate_bitflag_backwards_compat!(PruneSegment, UnusedBits::Zero);
#[cfg(not(feature = "scroll"))]
validate_bitflag_backwards_compat!(Receipt, UnusedBits::Zero);
#[cfg(feature = "scroll")]
validate_bitflag_backwards_compat!(Receipt, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(ReceiptWithBloom, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StageCheckpoint, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(StageUnitCheckpoint, UnusedBits::Zero);
Expand Down

0 comments on commit 32844ae

Please sign in to comment.