Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.27.1"
version = "0.27.2"
rust-version = "1.83.0"
edition = "2021"
authors = ["init4"]
Expand Down
11 changes: 5 additions & 6 deletions src/journal/coder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::journal::{AcctDiff, BundleStateIndex, InfoOutcome};
use alloy::{
consensus::Header,
primitives::{Address, Bytes, B256, U256},
rlp::{Buf, BufMut},
rlp::{Buf, BufMut, BytesMut},
};
use revm::{
bytecode::eip7702::{Eip7702Bytecode, Eip7702DecodeError},
Expand All @@ -13,7 +13,6 @@ use std::{
borrow::{Cow, ToOwned},
collections::BTreeMap,
fmt::Debug,
vec::Vec,
};

type Result<T, E = JournalDecodeError> = core::result::Result<T, E>;
Expand Down Expand Up @@ -156,10 +155,10 @@ pub trait JournalEncode: Debug {
fn encode(&self, buf: &mut dyn BufMut);

/// Shortcut to encode the type into a new vec.
fn encoded(&self) -> Vec<u8> {
let mut buf = Vec::new();
fn encoded(&self) -> Bytes {
let mut buf = BytesMut::with_capacity(self.serialized_size());
self.encode(&mut buf);
buf
buf.freeze().into()
}
}

Expand Down Expand Up @@ -641,7 +640,7 @@ mod test {
let enc = JournalEncode::encoded(expected);
let ty_name = core::any::type_name::<T>();
assert_eq!(enc.len(), expected.serialized_size(), "{ty_name}");
let dec = T::decode(&mut enc.as_slice()).expect("decoding failed");
let dec = T::decode(&mut enc.as_ref()).expect("decoding failed");
assert_eq!(&dec, expected, "{ty_name}");
}

Expand Down
2 changes: 1 addition & 1 deletion src/journal/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl From<AcctDiff<'_>> for BundleAccount {
/// # fn make_index(bundle_state: &BundleState) -> Result<(), JournalDecodeError> {
/// let index = BundleStateIndex::from(bundle_state);
/// let serialized_index = index.encoded();
/// let decoded = BundleStateIndex::decode(&mut serialized_index.as_slice())?;
/// let decoded = BundleStateIndex::decode(&mut serialized_index.as_ref())?;
/// assert_eq!(index, decoded);
/// # Ok(())
/// # }
Expand Down
2 changes: 1 addition & 1 deletion src/journal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//!
//! // We can serialize it and deserialize it :)
//! let serialized_index = index.encoded();
//! let decoded = BundleStateIndex::decode(&mut serialized_index.as_slice())?;
//! let decoded = BundleStateIndex::decode(&mut serialized_index.as_ref())?;
//! assert_eq!(index, decoded);
//!
//! // It contains information about accounts
Expand Down
8 changes: 4 additions & 4 deletions src/journal/update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::journal::{BundleStateIndex, JournalDecode, JournalDecodeError, JournalEncode};
use alloy::primitives::{keccak256, B256};
use alloy::primitives::{keccak256, Bytes, B256};
use std::sync::OnceLock;

/// Journal associated with a block
Expand All @@ -15,7 +15,7 @@ pub struct BlockUpdate<'a> {
journal: BundleStateIndex<'a>,

/// The serialized journal
serialized: OnceLock<Vec<u8>>,
serialized: OnceLock<Bytes>,

/// The hash of the serialized journal
hash: OnceLock<B256>,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<'a> BlockUpdate<'a> {

/// Serialize the block update.
pub fn serialized(&self) -> &[u8] {
self.serialized.get_or_init(|| JournalEncode::encoded(self)).as_slice()
self.serialized.get_or_init(|| JournalEncode::encoded(self)).as_ref()
}

/// Serialize and hash the block update.
Expand Down Expand Up @@ -78,7 +78,7 @@ impl JournalDecode for BlockUpdate<'static> {
height: JournalDecode::decode(buf)?,
prev_journal_hash: JournalDecode::decode(buf)?,
journal: JournalDecode::decode(buf)?,
serialized: OnceLock::from(original.to_vec()),
serialized: OnceLock::from(Bytes::copy_from_slice(original)),
hash: OnceLock::from(keccak256(original)),
})
}
Expand Down