1
1
use alloy_consensus:: { ReceiptEnvelope , TxReceipt } ;
2
2
use alloy_eips:: eip6110:: DepositRequest ;
3
- use alloy_primitives:: { Address , Log } ;
3
+ use alloy_primitives:: { Address , Bloom , Log } ;
4
+ use std:: sync:: OnceLock ;
4
5
5
6
/// Information externalized during block execution.
6
7
///
@@ -13,6 +14,9 @@ pub struct BlockOutput<T: TxReceipt = ReceiptEnvelope> {
13
14
14
15
/// The senders of the transactions in the block, in order.
15
16
senders : Vec < Address > ,
17
+
18
+ /// The logs bloom of the block.
19
+ bloom : OnceLock < Bloom > ,
16
20
}
17
21
18
22
impl Default for BlockOutput {
@@ -25,7 +29,25 @@ impl<T: TxReceipt> BlockOutput<T> {
25
29
/// Create a new block output with memory allocated to hold `capacity`
26
30
/// transaction outcomes.
27
31
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 ( ) ;
29
51
}
30
52
31
53
/// Reserve memory for `capacity` transaction outcomes.
@@ -44,6 +66,12 @@ impl<T: TxReceipt> BlockOutput<T> {
44
66
self . receipts . iter ( ) . flat_map ( |r| r. logs ( ) )
45
67
}
46
68
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
+
47
75
/// Get a reference the senders of the transactions in the block.
48
76
pub fn senders ( & self ) -> & [ Address ] {
49
77
& self . senders
@@ -60,6 +88,7 @@ impl<T: TxReceipt> BlockOutput<T> {
60
88
///
61
89
/// [EIP-6110]: https://eips.ethereum.org/EIPS/eip-6110
62
90
pub fn push_result ( & mut self , receipt : T , sender : Address ) {
91
+ self . unseal ( ) ;
63
92
self . push_receipt ( receipt) ;
64
93
self . push_sender ( sender) ;
65
94
}
0 commit comments