@@ -12,26 +12,22 @@ mod error;
1212extern crate alloc as std;
1313
1414use crate :: { data_source:: CodecDataSource , error:: DerivationPipelineError } ;
15- use std:: { sync :: Arc , vec:: Vec } ;
15+ use std:: vec:: Vec ;
1616
1717use alloy_primitives:: B256 ;
1818use alloy_rpc_types_engine:: PayloadAttributes ;
19- use futures:: { stream, Stream , StreamExt } ;
2019use reth_scroll_chainspec:: SCROLL_FEE_VAULT_ADDRESS ;
2120use rollup_node_primitives:: BatchCommitData ;
2221use rollup_node_providers:: L1Provider ;
2322use scroll_alloy_rpc_types_engine:: ScrollPayloadAttributes ;
2423use scroll_codec:: Codec ;
2524
26- /// Returns an iterator over [`ScrollPayloadAttributes`] from the [`BatchCommitData`] and a
25+ /// Returns a vector of [`ScrollPayloadAttributes`] from the [`BatchCommitData`] and a
2726/// [`L1Provider`].
2827pub async fn derive < P : L1Provider > (
2928 batch : BatchCommitData ,
3029 l1_provider : & mut P ,
31- ) -> Result <
32- impl Stream < Item = Result < ScrollPayloadAttributes , DerivationPipelineError > > + use < ' _ , P > ,
33- DerivationPipelineError ,
34- > {
30+ ) -> Result < Vec < ScrollPayloadAttributes > , DerivationPipelineError > {
3531 // fetch the blob then decode the input batch.
3632 let blob = if let Some ( hash) = batch. blob_versioned_hash {
3733 l1_provider. blob ( batch. block_timestamp , hash) . await ?
@@ -54,42 +50,42 @@ pub async fn derive<P: L1Provider>(
5450 return Err ( DerivationPipelineError :: MissingL1MessageQueueCursor )
5551 }
5652
57- let provider = Arc :: new ( & * l1_provider ) ;
58- let iter = stream :: iter ( decoded . data . into_l2_blocks ( ) )
59- . map ( move |data| ( data , provider . clone ( ) ) )
60- . then ( | ( mut block , provider ) | async move {
61- // query the appropriate amount of l1 messages.
62- let mut txs = Vec :: with_capacity ( block. context . num_l1_messages as usize ) ;
63- for _ in 0 ..block . context . num_l1_messages {
64- let l1_message = provider
65- . next_l1_message ( )
66- . await
67- . map_err ( Into :: into ) ?
68- . ok_or ( DerivationPipelineError :: MissingL1Message ) ? ;
69- let mut bytes = Vec :: new ( ) ;
70- l1_message . eip2718_encode ( & mut bytes) ;
71- txs . push ( bytes . into ( ) ) ;
72- }
73-
74- // add the block transactions.
75- txs . append ( & mut block . transactions ) ;
76-
77- // construct the payload attributes.
78- Ok ( ScrollPayloadAttributes {
79- payload_attributes : PayloadAttributes {
80- timestamp : block . context . timestamp ,
81- prev_randao : B256 :: ZERO ,
82- // TODO: this should be based off the current configuration value.
83- suggested_fee_recipient : SCROLL_FEE_VAULT_ADDRESS ,
84- withdrawals : None ,
85- parent_beacon_block_root : None ,
86- } ,
87- transactions : Some ( txs ) ,
88- no_tx_pool : true ,
89- } )
90- } ) ;
91-
92- Ok ( iter )
53+ let blocks = decoded . data . into_l2_blocks ( ) ;
54+ let mut attributes = Vec :: with_capacity ( blocks . len ( ) ) ;
55+ for mut block in blocks {
56+ // query the appropriate amount of l1 messages.
57+ let mut txs = Vec :: with_capacity ( block . context . num_l1_messages as usize ) ;
58+ for _ in 0 .. block. context . num_l1_messages {
59+ let l1_message = l1_provider
60+ . next_l1_message ( )
61+ . await
62+ . map_err ( Into :: into ) ?
63+ . ok_or ( DerivationPipelineError :: MissingL1Message ) ? ;
64+ let mut bytes = Vec :: new ( ) ;
65+ l1_message . eip2718_encode ( & mut bytes) ;
66+ txs . push ( bytes. into ( ) ) ;
67+ }
68+
69+ // add the block transactions.
70+ txs . append ( & mut block. transactions ) ;
71+
72+ // construct the payload attributes.
73+ let attribute = ScrollPayloadAttributes {
74+ payload_attributes : PayloadAttributes {
75+ timestamp : block . context . timestamp ,
76+ // TODO: this should be based off the current configuration value.
77+ suggested_fee_recipient : SCROLL_FEE_VAULT_ADDRESS ,
78+ prev_randao : B256 :: ZERO ,
79+ withdrawals : None ,
80+ parent_beacon_block_root : None ,
81+ } ,
82+ transactions : Some ( txs ) ,
83+ no_tx_pool : true ,
84+ } ;
85+ attributes . push ( attribute ) ;
86+ }
87+
88+ Ok ( attributes )
9389}
9490
9591#[ cfg( test) ]
@@ -169,18 +165,15 @@ mod tests {
169165 } ] ;
170166 let mut provider = TestL1MessageProvider { messages : Arc :: new ( Mutex :: new ( l1_messages) ) } ;
171167
172- let attributes: Vec < _ > = derive ( batch_data, & mut provider) . await ?. collect ( ) . await ;
173- let attributes = attributes. into_iter ( ) . collect :: < Result < Vec < _ > , _ > > ( ) ?;
168+ let attributes = derive ( batch_data, & mut provider) . await ?;
174169 let attribute =
175170 attributes. iter ( ) . find ( |a| a. payload_attributes . timestamp == 1696935384 ) . unwrap ( ) ;
176171
177172 let expected = ScrollPayloadAttributes {
178173 payload_attributes : PayloadAttributes {
179174 timestamp : 1696935384 ,
180- prev_randao : B256 :: ZERO ,
181175 suggested_fee_recipient : SCROLL_FEE_VAULT_ADDRESS ,
182- withdrawals : None ,
183- parent_beacon_block_root : None ,
176+ ..Default :: default ( )
184177 } ,
185178 transactions : Some ( vec ! [ bytes!( "7ef901b7218302904094781e90f1c8fc4611c9b7497c3b47f99ef6969cbc80b901848ef1332e0000000000000000000000007f2b8c31f88b6006c382775eea88297ec1e3e9050000000000000000000000006ea73e05adc79974b931123675ea8f78ffdacdf0000000000000000000000000000000000000000000000000006a94d74f430000000000000000000000000000000000000000000000000000000000000000002100000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a4232e8748000000000000000000000000ca266224613396a0e8d4c2497dbc4f33dd6cdeff000000000000000000000000ca266224613396a0e8d4c2497dbc4f33dd6cdeff000000000000000000000000000000000000000000000000006a94d74f4300000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000947885bcbd5cecef1336b5300fb5186a12ddd8c478" ) , bytes!( "7ef901b7228302904094781e90f1c8fc4611c9b7497c3b47f99ef6969cbc80b901848ef1332e0000000000000000000000007f2b8c31f88b6006c382775eea88297ec1e3e9050000000000000000000000006ea73e05adc79974b931123675ea8f78ffdacdf000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a4232e8748000000000000000000000000982fe4a7cbd74bb3422ebe46333c3e8046c12c7f000000000000000000000000982fe4a7cbd74bb3422ebe46333c3e8046c12c7f00000000000000000000000000000000000000000000000000470de4df8200000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000947885bcbd5cecef1336b5300fb5186a12ddd8c478" ) ] ) ,
186179 no_tx_pool : true ,
@@ -191,10 +184,8 @@ mod tests {
191184 let expected = ScrollPayloadAttributes {
192185 payload_attributes : PayloadAttributes {
193186 timestamp : 1696935657 ,
194- prev_randao : B256 :: ZERO ,
195187 suggested_fee_recipient : SCROLL_FEE_VAULT_ADDRESS ,
196- withdrawals : None ,
197- parent_beacon_block_root : None ,
188+ ..Default :: default ( )
198189 } ,
199190 transactions : Some ( vec ! [ bytes!( "f88c8202658417d7840082a4f294530000000000000000000000000000000000000280a4bede39b500000000000000000000000000000000000000000000000000000001669aa2f583104ec4a07461e6555f927393ebdf5f183738450c3842bc3b86a1db7549d9bee21fadd0b1a06d7ba96897bd9fb8e838a327d3ca34be66da11955f10d1fb2264949071e9e8cd" ) ] ) ,
200191 no_tx_pool : true ,
0 commit comments