11use alloy_consensus:: { ReceiptEnvelope , TxReceipt } ;
22use alloy_eips:: eip6110:: DepositRequest ;
3- use alloy_primitives:: { Address , Log } ;
3+ use alloy_primitives:: { Address , Bloom , Log } ;
4+ use std:: sync:: OnceLock ;
45
56/// Information externalized during block execution.
67///
@@ -13,6 +14,9 @@ pub struct BlockOutput<T: TxReceipt = ReceiptEnvelope> {
1314
1415 /// The senders of the transactions in the block, in order.
1516 senders : Vec < Address > ,
17+
18+ /// The logs bloom of the block.
19+ bloom : OnceLock < Bloom > ,
1620}
1721
1822impl Default for BlockOutput {
@@ -25,7 +29,25 @@ impl<T: TxReceipt> BlockOutput<T> {
2529 /// Create a new block output with memory allocated to hold `capacity`
2630 /// transaction outcomes.
2731 pub fn with_capacity ( capacity : usize ) -> Self {
28- Self { receipts : Vec :: with_capacity ( capacity) , senders : Vec :: with_capacity ( capacity) }
32+ Self {
33+ receipts : Vec :: with_capacity ( capacity) ,
34+ senders : Vec :: with_capacity ( capacity) ,
35+ bloom : Default :: default ( ) ,
36+ }
37+ }
38+
39+ fn seal ( & self ) {
40+ self . bloom . get_or_init ( || {
41+ let mut bloom = Bloom :: default ( ) ;
42+ for log in self . logs ( ) {
43+ bloom. accrue_log ( log) ;
44+ }
45+ bloom
46+ } ) ;
47+ }
48+
49+ fn unseal ( & mut self ) {
50+ self . bloom . take ( ) ;
2951 }
3052
3153 /// Reserve memory for `capacity` transaction outcomes.
@@ -44,6 +66,12 @@ impl<T: TxReceipt> BlockOutput<T> {
4466 self . receipts . iter ( ) . flat_map ( |r| r. logs ( ) )
4567 }
4668
69+ /// Get the logs bloom of the block.
70+ pub fn logs_bloom ( & self ) -> Bloom {
71+ self . seal ( ) ;
72+ self . bloom . get ( ) . cloned ( ) . unwrap ( )
73+ }
74+
4775 /// Get a reference the senders of the transactions in the block.
4876 pub fn senders ( & self ) -> & [ Address ] {
4977 & self . senders
@@ -60,6 +88,7 @@ impl<T: TxReceipt> BlockOutput<T> {
6088 ///
6189 /// [EIP-6110]: https://eips.ethereum.org/EIPS/eip-6110
6290 pub fn push_result ( & mut self , receipt : T , sender : Address ) {
91+ self . unseal ( ) ;
6392 self . push_receipt ( receipt) ;
6493 self . push_sender ( sender) ;
6594 }
0 commit comments