11use crate :: ExecutionOutcome ;
22use alloy:: { consensus:: Header , primitives:: B256 } ;
3+ use signet_journal:: { HostJournal , JournalMeta } ;
34use signet_types:: primitives:: { RecoveredBlock , TransactionSigned } ;
4- use trevm:: journal:: { BlockUpdate , BundleStateIndex } ;
5+ use std:: borrow:: Cow ;
6+ use trevm:: journal:: BundleStateIndex ;
57
68/// Output of a block execution.
79///
810/// This is a convenience struct that combines the consensus block object with
911/// the result of its execution.
1012#[ derive( Debug , Default ) ]
11- pub struct BlockResult < T = TransactionSigned , H = Header > {
13+ pub struct BlockResult < T = TransactionSigned > {
14+ /// The host height.
15+ pub host_height : u64 ,
16+
1217 /// A reth [`RecoveredBlock`], containing the sealed block and a vec of
13- /// transaction sender.
14- pub sealed_block : RecoveredBlock < T , H > ,
18+ /// transaction senders.
19+ pub sealed_block : RecoveredBlock < T > ,
20+
1521 /// The reth [`ExecutionOutcome`] containing the net state changes and
1622 /// receipts.
1723 pub execution_outcome : ExecutionOutcome ,
1824}
1925
20- impl < T , H > BlockResult < T , H > {
26+ impl < T > BlockResult < T > {
2127 /// Create a new block result.
2228 pub const fn new (
23- sealed_block : RecoveredBlock < T , H > ,
29+ host_height : u64 ,
30+ sealed_block : RecoveredBlock < T > ,
2431 execution_outcome : ExecutionOutcome ,
2532 ) -> Self {
26- Self { sealed_block, execution_outcome }
33+ Self { host_height, sealed_block, execution_outcome }
34+ }
35+
36+ /// Get the rollup block header.
37+ pub const fn header ( & self ) -> & Header {
38+ self . sealed_block . block . header . header ( )
2739 }
2840
2941 /// Get the sealed block.
30- pub const fn sealed_block ( & self ) -> & RecoveredBlock < T , H > {
42+ pub const fn sealed_block ( & self ) -> & RecoveredBlock < T > {
3143 & self . sealed_block
3244 }
3345
@@ -36,12 +48,20 @@ impl<T, H> BlockResult<T, H> {
3648 & self . execution_outcome
3749 }
3850
39- /// Make a journal of the block result. This indexes the bundle state.
40- pub fn make_journal ( & self , host_block : u64 , prev_journal_hash : B256 ) -> BlockUpdate < ' _ > {
41- BlockUpdate :: new (
42- host_block,
43- prev_journal_hash,
44- BundleStateIndex :: from ( self . execution_outcome . bundle ( ) ) ,
45- )
51+ /// Calculate the [`BundleStateIndex`], making a sorted index of the
52+ /// contents of [`BundleState`] in the [`ExecutionOutcome`].
53+ ///
54+ /// [`BundleState`]: trevm::revm::database::BundleState
55+ pub fn index_bundle_state ( & self ) -> BundleStateIndex < ' _ > {
56+ BundleStateIndex :: from ( self . execution_outcome . bundle ( ) )
57+ }
58+
59+ const fn journal_meta ( & self , prev_journal_hash : B256 ) -> JournalMeta < ' _ > {
60+ JournalMeta :: new ( self . host_height , prev_journal_hash, Cow :: Borrowed ( self . header ( ) ) )
61+ }
62+
63+ /// Create a [`HostJournal`] by indexing the bundle state and block header.
64+ pub fn make_host_journal ( & self , prev_journal_hash : B256 ) -> HostJournal < ' _ > {
65+ HostJournal :: new ( self . journal_meta ( prev_journal_hash) , self . index_bundle_state ( ) )
4666 }
4767}
0 commit comments