Skip to content

Commit 40e7350

Browse files
authored
fix: codec v7 version field (#459)
* fix: codec v7 version field * fix: comment
1 parent 8c1f7d1 commit 40e7350

File tree

1 file changed

+27
-6
lines changed
  • crates/codec/src/decoding/v7

1 file changed

+27
-6
lines changed

crates/codec/src/decoding/v7/mod.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ pub fn decode_v7(blob: &[u8]) -> Result<Batch, DecodingError> {
5656
};
5757

5858
// decode the payload.
59-
decode_v7_payload(buf)
59+
decode_payload(version, buf)
60+
}
61+
62+
pub(crate) fn decode_payload(version: u8, blob: &[u8]) -> Result<Batch, DecodingError> {
63+
let payload = decode_v7_payload(blob)?;
64+
Ok(Batch::new(version, None, payload))
6065
}
6166

6267
/// Decode the blob data into a [`Batch`].
63-
pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result<Batch, DecodingError> {
68+
pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result<PayloadData, DecodingError> {
6469
let buf = &mut (&*blob);
6570

6671
// check buf len.
@@ -97,13 +102,11 @@ pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result<Batch, DecodingError> {
97102
.push(L2Block::new(transactions, (context, initial_block_number + i as u64).into()));
98103
}
99104

100-
let payload = PayloadData {
105+
Ok(PayloadData {
101106
blocks: l2_blocks,
102107
l1_message_queue_info: (prev_message_queue_hash, post_message_queue_hash).into(),
103108
skipped_l1_message_bitmap: None,
104-
};
105-
106-
Ok(Batch::new(7, None, payload))
109+
})
107110
}
108111

109112
#[cfg(test)]
@@ -294,4 +297,22 @@ mod tests {
294297

295298
Ok(())
296299
}
300+
301+
#[test]
302+
fn test_should_decode_v8_mock() -> eyre::Result<()> {
303+
let blob = read_to_bytes("./testdata/blob_v7_uncompressed.bin")?;
304+
let mut blob = blob.to_vec();
305+
// Manually patch the version byte to 8 to simulate a v8 blob.
306+
// BlobSliceIter skips the first byte (index 0) of every 32-byte chunk.
307+
// So the first data byte (version) is at index 1.
308+
blob[1] = 8;
309+
310+
let batch = decode_v7(&blob)?;
311+
assert_eq!(batch.version, 8);
312+
313+
let blocks = batch.data.l2_blocks();
314+
assert_eq!(blocks.len(), 4);
315+
316+
Ok(())
317+
}
297318
}

0 commit comments

Comments
 (0)