Skip to content

Commit

Permalink
fix(derive): fix span batch utils read_tx_data() (#170)
Browse files Browse the repository at this point in the history
instead of copying the entire buffer, de-reference twice to make a new
mutable reference of the input u8 array
  • Loading branch information
N0xMare authored Apr 29, 2024
1 parent eba5b50 commit bd7ac13
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions crates/derive/src/types/batch/span_batch/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ pub(crate) fn read_tx_data(r: &mut &[u8]) -> Result<(Vec<u8>, TxType), SpanBatch
r.advance(1);
}

// Copy the reader, as we need to read the header to determine if the payload is a list.
// TODO(clabby): This is horribly inefficient. It'd be nice if we could peek at this rather than
// forcibly having to advance the buffer passed, should read more into the alloy rlp docs to
// see if this is possible.
let r_copy = Vec::from(*r);
let rlp_header = Header::decode(&mut r_copy.as_slice())
// Read the RLP header with a different reader pointer. This prevents the initial pointer from
// being advanced in the case that what we read is invalid.
let rlp_header = Header::decode(&mut (**r).as_ref())
.map_err(|_| SpanBatchError::Decoding(SpanDecodingError::InvalidTransactionData))?;

let tx_payload = if rlp_header.list {
Expand Down

0 comments on commit bd7ac13

Please sign in to comment.