|
| 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 {} |
0 commit comments