Skip to content

Commit df71842

Browse files
committed
feat: JournalDb trait
1 parent 1514ad2 commit df71842

File tree

7 files changed

+57
-5
lines changed

7 files changed

+57
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ signet-zenith = "0.9.0"
5353
ajj = { version = "0.3.4" }
5454

5555
# trevm
56-
trevm = { version = "0.27.0", features = ["full_env_cfg"] }
56+
trevm = { version = "0.27.1", features = ["full_env_cfg"] }
5757

5858
# Alloy periphery crates
5959
alloy = { version = "1.0.19", features = [

crates/db/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ repository.workspace = true
1111
[dependencies]
1212
signet-node-types.workspace = true
1313

14-
1514
signet-evm.workspace = true
1615
signet-types.workspace = true
1716
signet-zenith.workspace = true
1817

18+
trevm.workspace = true
19+
1920
alloy.workspace = true
2021

2122
reth.workspace = true

crates/db/src/journal/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Utilities for working with Signet journals in a reth database.
2+
3+
mod r#trait;
4+
pub use r#trait::JournalDb;

crates/db/src/journal/trait.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use crate::RuWriter;
2+
use alloy::consensus::{BlockHeader, Header};
3+
use reth::{providers::ProviderResult, revm::db::BundleState};
4+
use signet_evm::{BlockResult, ExecutionOutcome};
5+
use signet_types::primitives::{RecoveredBlock, SealedBlock, SealedHeader, TransactionSigned};
6+
use trevm::journal::BlockUpdate;
7+
8+
/// A database that can be updated with journals.
9+
pub trait JournalDb: RuWriter {
10+
/// Ingest a journal into the database.
11+
///
12+
/// This will create a [`BlockResult`] from the provided header and update,
13+
/// and append it to the database using [`RuWriter::append_host_block`].
14+
///
15+
/// This DOES NOT update tables containing historical transactions,
16+
/// receipts, events, etc. It only updates tables related to headers,
17+
/// and state.
18+
///
19+
/// This is intended to be used for tx simulation, and other purposes that
20+
/// need fast state access WITHTOUT needing to retrieve historical data.
21+
fn ingest(&self, header: &Header, update: BlockUpdate<'_>) -> ProviderResult<()> {
22+
let journal_hash = update.journal_hash();
23+
24+
// TODO: remove the clone in future versions. This can be achieved by
25+
// _NOT_ making a `BlockResult` and instead manually updating relevan
26+
// tables. However, this means diverging more fro the underlying reth
27+
// logic that we are currently re-using.
28+
let bundle_state: BundleState = update.journal().clone().into();
29+
let execution_outcome = ExecutionOutcome::new(bundle_state, vec![], header.number());
30+
31+
let block: SealedBlock<TransactionSigned, Header> =
32+
SealedBlock { header: SealedHeader::new(header.to_owned()), body: Default::default() };
33+
let block_result =
34+
BlockResult { sealed_block: RecoveredBlock::new(block, vec![]), execution_outcome };
35+
36+
self.append_host_block(
37+
None,
38+
std::iter::empty(),
39+
std::iter::empty(),
40+
std::iter::empty(),
41+
&block_result,
42+
journal_hash,
43+
)
44+
}
45+
}
46+
47+
impl<T> JournalDb for T where T: RuWriter {}

crates/db/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub use chain::{DbExtractionResults, RuChain};
1717
mod convert;
1818
pub use convert::DataCompat;
1919

20+
pub mod journal;
21+
2022
mod provider;
2123

2224
mod tables;

crates/db/src/provider.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ where
430430
/// see the documentation for each function.
431431
fn append_host_block(
432432
&self,
433-
host_height: u64,
434433
header: Option<Zenith::BlockHeader>,
435434
transacts: impl IntoIterator<Item = Transact>,
436435
enters: impl IntoIterator<Item = Passage::Enter>,
@@ -480,7 +479,7 @@ where
480479

481480
self.update_pipeline_stages(ru_height, false)?;
482481

483-
debug!(target: "signet_db_lifecycle", host_height, ru_height, "Appended blocks");
482+
debug!(target: "signet_db_lifecycle", ru_height, "Appended blocks");
484483

485484
Ok(())
486485
}

crates/db/src/traits.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ pub trait RuWriter {
254254
#[allow(clippy::too_many_arguments)]
255255
fn append_host_block(
256256
&self,
257-
host_height: u64,
258257
header: Option<Zenith::BlockHeader>,
259258
transacts: impl IntoIterator<Item = Transactor::Transact>,
260259
enters: impl IntoIterator<Item = Passage::Enter>,

0 commit comments

Comments
 (0)