From a6d782809f6795b1659c6bf0fdda051879898b53 Mon Sep 17 00:00:00 2001 From: shu-unifra Date: Sun, 7 Dec 2025 14:30:35 +0900 Subject: [PATCH] trying to fix decode --- crates/codec/src/decoding/v7/mod.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/codec/src/decoding/v7/mod.rs b/crates/codec/src/decoding/v7/mod.rs index 684ac2b1..13df3afc 100644 --- a/crates/codec/src/decoding/v7/mod.rs +++ b/crates/codec/src/decoding/v7/mod.rs @@ -56,11 +56,11 @@ pub fn decode_v7(blob: &[u8]) -> Result { }; // decode the payload. - decode_v7_payload(buf) + decode_v7_payload(version, buf) } /// Decode the blob data into a [`Batch`]. -pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result { +pub(crate) fn decode_v7_payload(version: u8, blob: &[u8]) -> Result { let buf = &mut (&*blob); // check buf len. @@ -103,7 +103,7 @@ pub(crate) fn decode_v7_payload(blob: &[u8]) -> Result { skipped_l1_message_bitmap: None, }; - Ok(Batch::new(7, None, payload)) + Ok(Batch::new(version, None, payload)) } #[cfg(test)] @@ -292,6 +292,26 @@ mod tests { assert_eq!(last_block, &expected_block); + + + Ok(()) + } + + #[test] + fn test_should_decode_v8_mock() -> eyre::Result<()> { + let blob = read_to_bytes("./testdata/blob_v7_uncompressed.bin")?; + let mut blob = blob.to_vec(); + // Manually patch the version byte to 8 to simulate a v8 blob. + // BlobSliceIter skips the first byte (index 0) of every 32-byte chunk. + // So the first data byte (version) is at index 1. + blob[1] = 8; + + let batch = decode_v7(&blob)?; + assert_eq!(batch.version, 8); + + let blocks = batch.data.l2_blocks(); + assert_eq!(blocks.len(), 4); + Ok(()) } }