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
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.10.0"
version = "0.10.1"
edition = "2021"
rust-version = "1.81"
authors = ["init4"]
Expand Down
1 change: 1 addition & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository.workspace = true

[dependencies]
signet-extract.workspace = true
signet-journal.workspace = true
signet-types.workspace = true
signet-zenith.workspace = true

Expand Down
2 changes: 2 additions & 0 deletions crates/evm/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ impl<'a, 'b, C: Extractable> SignetDriver<'a, 'b, C> {
Insp: Inspector<Ctx<State<Db>>>,
{
let ru_height = self.extracts.ru_height;
let host_height = self.extracts.host_block.number();
let (sealed_block, receipts) = self.finish();
BlockResult {
host_height,
sealed_block,
execution_outcome: ExecutionOutcome::new(trevm.finish(), vec![receipts], ru_height),
}
Expand Down
50 changes: 35 additions & 15 deletions crates/evm/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
use crate::ExecutionOutcome;
use alloy::{consensus::Header, primitives::B256};
use signet_journal::{HostJournal, JournalMeta};
use signet_types::primitives::{RecoveredBlock, TransactionSigned};
use trevm::journal::{BlockUpdate, BundleStateIndex};
use std::borrow::Cow;
use trevm::journal::BundleStateIndex;

/// Output of a block execution.
///
/// This is a convenience struct that combines the consensus block object with
/// the result of its execution.
#[derive(Debug, Default)]
pub struct BlockResult<T = TransactionSigned, H = Header> {
pub struct BlockResult<T = TransactionSigned> {
/// The host height.
pub host_height: u64,

/// A reth [`RecoveredBlock`], containing the sealed block and a vec of
/// transaction sender.
pub sealed_block: RecoveredBlock<T, H>,
/// transaction senders.
pub sealed_block: RecoveredBlock<T>,

/// The reth [`ExecutionOutcome`] containing the net state changes and
/// receipts.
pub execution_outcome: ExecutionOutcome,
}

impl<T, H> BlockResult<T, H> {
impl<T> BlockResult<T> {
/// Create a new block result.
pub const fn new(
sealed_block: RecoveredBlock<T, H>,
host_height: u64,
sealed_block: RecoveredBlock<T>,
execution_outcome: ExecutionOutcome,
) -> Self {
Self { sealed_block, execution_outcome }
Self { host_height, sealed_block, execution_outcome }
}

/// Get the rollup block header.
pub const fn header(&self) -> &Header {
self.sealed_block.block.header.header()
}

/// Get the sealed block.
pub const fn sealed_block(&self) -> &RecoveredBlock<T, H> {
pub const fn sealed_block(&self) -> &RecoveredBlock<T> {
&self.sealed_block
}

Expand All @@ -36,12 +48,20 @@ impl<T, H> BlockResult<T, H> {
&self.execution_outcome
}

/// Make a journal of the block result. This indexes the bundle state.
pub fn make_journal(&self, host_block: u64, prev_journal_hash: B256) -> BlockUpdate<'_> {
BlockUpdate::new(
host_block,
prev_journal_hash,
BundleStateIndex::from(self.execution_outcome.bundle()),
)
/// Calculate the [`BundleStateIndex`], making a sorted index of the
/// contents of [`BundleState`] in the [`ExecutionOutcome`].
///
/// [`BundleState`]: trevm::revm::database::BundleState
pub fn index_bundle_state(&self) -> BundleStateIndex<'_> {
BundleStateIndex::from(self.execution_outcome.bundle())
}

const fn journal_meta(&self, prev_journal_hash: B256) -> JournalMeta<'_> {
JournalMeta::new(self.host_height, prev_journal_hash, Cow::Borrowed(self.header()))
}

/// Create a [`HostJournal`] by indexing the bundle state and block header.
pub fn make_host_journal(&self, prev_journal_hash: B256) -> HostJournal<'_> {
HostJournal::new(self.journal_meta(prev_journal_hash), self.index_bundle_state())
}
}
14 changes: 7 additions & 7 deletions crates/journal/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use trevm::journal::{BundleStateIndex, JournalDecode, JournalDecodeError, Journa
#[derive(Debug, Clone)]
pub struct HostJournal<'a> {
/// The metadata
meta: JournalMeta,
meta: JournalMeta<'a>,

/// The changes.
journal: BundleStateIndex<'a>,
Expand All @@ -33,17 +33,17 @@ impl Eq for HostJournal<'_> {}

impl<'a> HostJournal<'a> {
/// Create a new journal.
pub const fn new(meta: JournalMeta, journal: BundleStateIndex<'a>) -> Self {
pub const fn new(meta: JournalMeta<'a>, journal: BundleStateIndex<'a>) -> Self {
Self { meta, journal, serialized: OnceLock::new(), hash: OnceLock::new() }
}

/// Deconstruct the `HostJournal` into its parts.
pub fn into_parts(self) -> (JournalMeta, BundleStateIndex<'a>) {
pub fn into_parts(self) -> (JournalMeta<'a>, BundleStateIndex<'a>) {
(self.meta, self.journal)
}

/// Get the journal meta.
pub const fn meta(&self) -> &JournalMeta {
pub const fn meta(&self) -> &JournalMeta<'a> {
&self.meta
}

Expand All @@ -63,12 +63,12 @@ impl<'a> HostJournal<'a> {
}

/// Get the rollup block header.
pub const fn header(&self) -> &Header {
pub fn header(&self) -> &Header {
self.meta.header()
}

/// Get the rollup height.
pub const fn rollup_height(&self) -> u64 {
pub fn rollup_height(&self) -> u64 {
self.meta.rollup_height()
}

Expand Down Expand Up @@ -166,7 +166,7 @@ pub(crate) mod test {
#[test]
fn roundtrip() {
let original = HostJournal::new(
JournalMeta::new(u64::MAX, B256::repeat_byte(0xff), Header::default()),
JournalMeta::new(u64::MAX, B256::repeat_byte(0xff), Cow::Owned(Header::default())),
make_state_diff(),
);

Expand Down
24 changes: 13 additions & 11 deletions crates/journal/src/meta.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
use std::borrow::Cow;

use alloy::{consensus::Header, primitives::B256};
use trevm::journal::{JournalDecode, JournalDecodeError, JournalEncode};

/// Metadata for a block journal. This includes the block header, the host
/// height, and the hash of the previous journal.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct JournalMeta {
pub struct JournalMeta<'a> {
/// The host height.
host_height: u64,

/// The hash of the previous journal.
prev_journal_hash: B256,

/// The rollup block header.
header: Header,
header: Cow<'a, Header>,
}

impl JournalMeta {
impl<'a> JournalMeta<'a> {
/// Create a new `JournalMeta`.
pub const fn new(host_height: u64, prev_journal_hash: B256, header: Header) -> Self {
pub const fn new(host_height: u64, prev_journal_hash: B256, header: Cow<'a, Header>) -> Self {
Self { host_height, prev_journal_hash, header }
}

/// Deconstruct the `JournalMeta` into its parts.
pub fn into_parts(self) -> (u64, B256, Header) {
(self.host_height, self.prev_journal_hash, self.header)
(self.host_height, self.prev_journal_hash, self.header.into_owned())
}

/// Get the host height.
Expand All @@ -37,17 +39,17 @@ impl JournalMeta {
}

/// Get the rollup block header.
pub const fn header(&self) -> &Header {
&self.header
pub fn header(&self) -> &Header {
self.header.as_ref()
}

/// Get the rollup height.
pub const fn rollup_height(&self) -> u64 {
pub fn rollup_height(&self) -> u64 {
self.header.number
}
}

impl JournalEncode for JournalMeta {
impl JournalEncode for JournalMeta<'_> {
fn serialized_size(&self) -> usize {
8 + 32 + self.header.serialized_size()
}
Expand All @@ -59,7 +61,7 @@ impl JournalEncode for JournalMeta {
}
}

impl JournalDecode for JournalMeta {
impl JournalDecode for JournalMeta<'static> {
fn decode(buf: &mut &[u8]) -> Result<Self, JournalDecodeError> {
let host_height = JournalDecode::decode(buf)?;
let prev_journal_hash = JournalDecode::decode(buf)?;
Expand All @@ -78,7 +80,7 @@ mod test {
let original = JournalMeta {
host_height: 13871,
prev_journal_hash: B256::repeat_byte(0x7),
header: Header::default(),
header: Cow::Owned(Header::default()),
};

let buf = original.encoded();
Expand Down
14 changes: 11 additions & 3 deletions crates/journal/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,15 @@ mod test {
use super::*;
use crate::{HostJournal, JournalMeta};
use alloy::{consensus::Header, primitives::Bytes};
use std::borrow::Cow;
use trevm::{journal::BundleStateIndex, revm::state::Bytecode};

fn journal_at_heights(host: u64, rollup: u64, prev_hash: B256) -> Journal<'static> {
let meta =
JournalMeta::new(host, prev_hash, Header { number: rollup, ..Default::default() });
let meta = JournalMeta::new(
host,
prev_hash,
Cow::Owned(Header { number: rollup, ..Default::default() }),
);
let host = HostJournal::new(meta, Default::default());

Journal::V1(host)
Expand Down Expand Up @@ -389,7 +393,11 @@ mod test {
std::borrow::Cow::Owned(Bytecode::new_legacy(Bytes::from_static(&[0, 1, 2, 3]))),
);
let j1_alt = Journal::V1(HostJournal::new(
JournalMeta::new(101, j0.journal_hash(), Header { number: 1, ..Default::default() }),
JournalMeta::new(
101,
j0.journal_hash(),
Cow::Owned(Header { number: 1, ..Default::default() }),
),
j1_alt_state,
));

Expand Down
7 changes: 4 additions & 3 deletions crates/journal/src/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> Journal<'a> {
}

/// Get the rollup block header.
pub const fn header(&self) -> &Header {
pub fn header(&self) -> &Header {
match self {
Journal::V1(journal) => journal.header(),
}
Expand All @@ -48,7 +48,7 @@ impl<'a> Journal<'a> {
}

/// Get the rollup height.
pub const fn rollup_height(&self) -> u64 {
pub fn rollup_height(&self) -> u64 {
match self {
Journal::V1(journal) => journal.rollup_height(),
}
Expand Down Expand Up @@ -91,11 +91,12 @@ impl JournalDecode for Journal<'static> {
mod test {
use super::*;
use crate::{host::test::make_state_diff, JournalMeta};
use std::borrow::Cow;

#[test]
fn roundtrip() {
let journal = Journal::V1(HostJournal::new(
JournalMeta::new(42, B256::repeat_byte(0x17), Header::default()),
JournalMeta::new(42, B256::repeat_byte(0x17), Cow::Owned(Header::default())),
make_state_diff(),
));
let mut buf = Vec::new();
Expand Down