Skip to content

Commit 75ee913

Browse files
authored
refactor: update receipt codec from HackReceipt to OpGethReceipt (#13738)
1 parent 2352664 commit 75ee913

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

book/cli/reth/import-receipts-op.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Database:
4949
[possible values: true, false]
5050

5151
<IMPORT_PATH>
52-
The path to a receipts file for import. File must use `HackReceiptFileCodec` (used for
52+
The path to a receipts file for import. File must use `OpGethReceiptFileCodec` (used for
5353
exporting OP chain segment below Bedrock block via testinprod/op-geth).
5454

5555
<https://github.com/testinprod-io/op-geth/pull/1>

crates/optimism/cli/src/commands/import_receipts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use reth_stages::{StageCheckpoint, StageId};
2626
use reth_static_file_types::StaticFileSegment;
2727
use tracing::{debug, info, trace, warn};
2828

29-
use crate::receipt_file_codec::HackReceiptFileCodec;
29+
use crate::receipt_file_codec::OpGethReceiptFileCodec;
3030

3131
/// Initializes the database with the genesis block.
3232
#[derive(Debug, Parser)]
@@ -38,7 +38,7 @@ pub struct ImportReceiptsOpCommand<C: ChainSpecParser> {
3838
#[arg(long, value_name = "CHUNK_LEN", verbatim_doc_comment)]
3939
chunk_len: Option<u64>,
4040

41-
/// The path to a receipts file for import. File must use `HackReceiptFileCodec` (used for
41+
/// The path to a receipts file for import. File must use `OpGethReceiptFileCodec` (used for
4242
/// exporting OP chain segment below Bedrock block via testinprod/op-geth).
4343
///
4444
/// <https://github.com/testinprod-io/op-geth/pull/1>
@@ -161,7 +161,7 @@ where
161161
.expect("transaction static files must exist before importing receipts");
162162

163163
while let Some(file_client) =
164-
reader.next_receipts_chunk::<ReceiptFileClient<HackReceiptFileCodec<OpReceipt>>>().await?
164+
reader.next_receipts_chunk::<ReceiptFileClient<OpGethReceiptFileCodec<OpReceipt>>>().await?
165165
{
166166
if highest_block_receipts == highest_block_transactions {
167167
warn!(target: "reth::cli", highest_block_receipts, highest_block_transactions, "Ignoring all other blocks in the file since we have reached the desired height");

crates/optimism/cli/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ pub mod chainspec;
1616
pub mod commands;
1717
/// Module with a codec for reading and encoding receipts in files.
1818
///
19-
/// Enables decoding and encoding `HackReceipt` type. See <https://github.com/testinprod-io/op-geth/pull/1>.
19+
/// Enables decoding and encoding `OpGethReceipt` type. See <https://github.com/testinprod-io/op-geth/pull/1>.
2020
///
21-
/// Currently configured to use codec [`HackReceipt`](receipt_file_codec::HackReceipt) based on
21+
/// Currently configured to use codec [`OpGethReceipt`](receipt_file_codec::OpGethReceipt) based on
2222
/// export of below Bedrock data using <https://github.com/testinprod-io/op-geth/pull/1>. Codec can
2323
/// be replaced with regular encoding of receipts for export.
2424
///
2525
/// NOTE: receipts can be exported using regular op-geth encoding for `Receipt` type, to fit
26-
/// reth's needs for importing. However, this would require patching the diff in <https://github.com/testinprod-io/op-geth/pull/1> to export the `Receipt` and not `HackReceipt` type (originally
26+
/// reth's needs for importing. However, this would require patching the diff in <https://github.com/testinprod-io/op-geth/pull/1> to export the `Receipt` and not `OpGethReceipt` type (originally
2727
/// made for op-erigon's import needs).
2828
pub mod receipt_file_codec;
2929

crates/optimism/cli/src/receipt_file_codec.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ use reth_downloaders::{file_client::FileClientError, receipt_file_client::Receip
2626
/// It's recommended to use [`with_capacity`](tokio_util::codec::FramedRead::with_capacity) to set
2727
/// the capacity of the framed reader to the size of the file.
2828
#[derive(Debug)]
29-
pub struct HackReceiptFileCodec<R = Receipt>(core::marker::PhantomData<R>);
29+
pub struct OpGethReceiptFileCodec<R = Receipt>(core::marker::PhantomData<R>);
3030

31-
impl<R> Default for HackReceiptFileCodec<R> {
31+
impl<R> Default for OpGethReceiptFileCodec<R> {
3232
fn default() -> Self {
3333
Self(Default::default())
3434
}
3535
}
3636

37-
impl<R> Decoder for HackReceiptFileCodec<R>
37+
impl<R> Decoder for OpGethReceiptFileCodec<R>
3838
where
39-
R: TryFrom<HackReceipt, Error: Into<FileClientError>>,
39+
R: TryFrom<OpGethReceipt, Error: Into<FileClientError>>,
4040
{
4141
type Item = Option<ReceiptWithBlockNumber<R>>;
4242
type Error = FileClientError;
@@ -47,7 +47,7 @@ where
4747
}
4848

4949
let buf_slice = &mut src.as_ref();
50-
let receipt = HackReceiptContainer::decode(buf_slice)
50+
let receipt = OpGethReceiptContainer::decode(buf_slice)
5151
.map_err(|err| Self::Error::Rlp(err, src.to_vec()))?
5252
.0;
5353
src.advance(src.len() - buf_slice.len());
@@ -68,7 +68,7 @@ where
6868

6969
/// See <https://github.com/testinprod-io/op-geth/pull/1>
7070
#[derive(Debug, PartialEq, Eq, RlpDecodable)]
71-
pub struct HackReceipt {
71+
pub struct OpGethReceipt {
7272
tx_type: u8,
7373
post_state: Bytes,
7474
status: u64,
@@ -90,13 +90,13 @@ pub struct HackReceipt {
9090

9191
#[derive(Debug, PartialEq, Eq, RlpDecodable)]
9292
#[rlp(trailing)]
93-
struct HackReceiptContainer(Option<HackReceipt>);
93+
struct OpGethReceiptContainer(Option<OpGethReceipt>);
9494

95-
impl TryFrom<HackReceipt> for Receipt {
95+
impl TryFrom<OpGethReceipt> for Receipt {
9696
type Error = &'static str;
9797

98-
fn try_from(exported_receipt: HackReceipt) -> Result<Self, Self::Error> {
99-
let HackReceipt { tx_type, status, cumulative_gas_used, logs, .. } = exported_receipt;
98+
fn try_from(exported_receipt: OpGethReceipt) -> Result<Self, Self::Error> {
99+
let OpGethReceipt { tx_type, status, cumulative_gas_used, logs, .. } = exported_receipt;
100100

101101
#[allow(clippy::needless_update)]
102102
Ok(Self {
@@ -109,10 +109,10 @@ impl TryFrom<HackReceipt> for Receipt {
109109
}
110110
}
111111

112-
impl TryFrom<HackReceipt> for OpReceipt {
112+
impl TryFrom<OpGethReceipt> for OpReceipt {
113113
type Error = &'static str;
114114

115-
fn try_from(exported_receipt: HackReceipt) -> Result<Self, Self::Error> {
115+
fn try_from(exported_receipt: OpGethReceipt) -> Result<Self, Self::Error> {
116116
let Receipt {
117117
tx_type,
118118
success,
@@ -152,10 +152,10 @@ pub(crate) mod test {
152152

153153
pub(crate) const HACK_RECEIPT_ENCODED_BLOCK_3: &[u8] = &hex!("f90271f9026e8080018301c60db9010000000000000000000000000000000000000000400000000000000000008000000000000000000000000000000000004000000000000000000000400004000000100000000000000000000000000000000000000000000000000000000000004000000000000000000000040000000000400080000400000000000000100000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000008100000000000000000000000000000000000004000000000000000000000000008000000000000000000010000000000000000000000000000400000000000000001000000000000000000000000002000f8faf89c948ce8c13d816fe6daf12d6fd9e4952e1fc88850aff884a092e98423f8adac6e64d0608e519fd1cefb861498385c6dee70d58fc926ddc68ca000000000000000000000000000000000000000000000000000000000d101e54ba00000000000000000000000000000000000000000000000000000000000014218a0000000000000000000000000fa011d8d6c26f13abe2cefed38226e401b2b8a9980f85a948ce8c13d816fe6daf12d6fd9e4952e1fc88850aff842a0fe25c73e3b9089fac37d55c4c7efcba6f04af04cebd2fc4d6d7dbb07e1e5234fa000000000000000000000000000000000000000000000007ed8842f062774800080a08fab01dcec1da547e90a77597999e9153ff788fa6451d1cc942064427bd995019400000000000000000000000000000000000000008301c60da0da4509fe0ca03202ddbe4f68692c132d689ee098433691040ece18c3a45d44c50380018212c2821c2383312e35");
154154

155-
fn hack_receipt_1() -> HackReceipt {
155+
fn hack_receipt_1() -> OpGethReceipt {
156156
let receipt = receipt_block_1();
157157

158-
HackReceipt {
158+
OpGethReceipt {
159159
tx_type: receipt.receipt.tx_type as u8,
160160
post_state: Bytes::default(),
161161
status: receipt.receipt.success as u64,
@@ -354,7 +354,7 @@ pub(crate) mod test {
354354
fn decode_hack_receipt() {
355355
let receipt = hack_receipt_1();
356356

357-
let decoded = HackReceiptContainer::decode(&mut &HACK_RECEIPT_ENCODED_BLOCK_1[..])
357+
let decoded = OpGethReceiptContainer::decode(&mut &HACK_RECEIPT_ENCODED_BLOCK_1[..])
358358
.unwrap()
359359
.0
360360
.unwrap();
@@ -373,7 +373,7 @@ pub(crate) mod test {
373373

374374
let encoded = &mut BytesMut::from(&receipt_1_to_3[..]);
375375

376-
let mut codec = HackReceiptFileCodec::default();
376+
let mut codec = OpGethReceiptFileCodec::default();
377377

378378
// test
379379

0 commit comments

Comments
 (0)