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

feat: l1_fee field on Receipt #42

Merged
merged 1 commit into from
Nov 28, 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
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 @@ -817,6 +817,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 @@ -825,6 +827,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 @@ -7,6 +7,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 @@ -50,6 +52,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 @@ -247,6 +255,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: U256::arbitrary(u)?,
})
}
}
Expand Down Expand Up @@ -334,6 +344,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 @@ -571,10 +583,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 @@ -604,6 +620,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 @@ -638,6 +656,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 @@ -720,6 +740,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 @@ -740,6 +762,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 @@ -762,6 +786,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 @@ -335,7 +335,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!(StageCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(StageUnitCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(StoredBlockBodyIndices::bitflag_encoded_bytes(), 1);
Expand All @@ -356,7 +359,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!(StageCheckpoint, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(StageUnitCheckpoint, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StoredBlockBodyIndices, UnusedBits::Zero);
Expand Down
Loading