@@ -320,18 +320,6 @@ impl DatabaseWriteOperations for Database {
320320 )
321321 }
322322
323- async fn insert_block (
324- & self ,
325- block_info : BlockInfo ,
326- batch_info : BatchInfo ,
327- ) -> Result < ( ) , DatabaseError > {
328- metered ! (
329- DatabaseOperation :: InsertBlock ,
330- self ,
331- tx_mut( move |tx| async move { tx. insert_block( block_info, batch_info) . await } )
332- )
333- }
334-
335323 async fn insert_genesis_block ( & self , genesis_hash : B256 ) -> Result < ( ) , DatabaseError > {
336324 metered ! (
337325 DatabaseOperation :: InsertGenesisBlock ,
@@ -354,16 +342,16 @@ impl DatabaseWriteOperations for Database {
354342 )
355343 }
356344
357- async fn update_l1_messages_with_l2_block (
345+ async fn update_l1_messages_with_l2_blocks (
358346 & self ,
359- block_info : L2BlockInfoWithL1Messages ,
347+ blocks : Vec < L2BlockInfoWithL1Messages > ,
360348 ) -> Result < ( ) , DatabaseError > {
361349 metered ! (
362350 DatabaseOperation :: UpdateL1MessagesWithL2Block ,
363351 self ,
364352 tx_mut( move |tx| {
365- let block_info = block_info . clone( ) ;
366- async move { tx. update_l1_messages_with_l2_block ( block_info ) . await }
353+ let blocks = blocks . clone( ) ;
354+ async move { tx. update_l1_messages_with_l2_blocks ( blocks ) . await }
367355 } )
368356 )
369357 }
@@ -854,12 +842,14 @@ mod test {
854842 let batch_info: BatchInfo = data. clone ( ) . into ( ) ;
855843 db. insert_batch ( data) . await . unwrap ( ) ;
856844
845+ let mut blocks = Vec :: new ( ) ;
857846 for _ in 0 ..10 {
858847 let block_info =
859848 BlockInfo { number : block_number, hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
860- db. insert_block ( block_info, batch_info) . await . unwrap ( ) ;
861849 block_number += 1 ;
850+ blocks. push ( block_info) ;
862851 }
852+ db. insert_blocks ( blocks, batch_info) . await . unwrap ( ) ;
863853
864854 // Fetch the highest block for the batch hash and verify number.
865855 let highest_block_info =
@@ -893,12 +883,14 @@ mod test {
893883 db. insert_batch ( first_batch) . await . unwrap ( ) ;
894884 db. insert_batch ( second_batch) . await . unwrap ( ) ;
895885
886+ let mut blocks = Vec :: new ( ) ;
896887 for _ in 0 ..10 {
897888 let block_info =
898889 BlockInfo { number : block_number, hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
899- db. insert_block ( block_info, first_batch_info) . await . unwrap ( ) ;
900890 block_number += 1 ;
891+ blocks. push ( block_info) ;
901892 }
893+ db. insert_blocks ( blocks, first_batch_info) . await . unwrap ( ) ;
902894
903895 // Fetch the highest block for the batch hash and verify number.
904896 let highest_block_info =
@@ -1136,10 +1128,9 @@ mod test {
11361128 let mut block_infos = Vec :: new ( ) ;
11371129 for i in 200 ..205 {
11381130 let block_info = BlockInfo { number : i, hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
1139- let l2_block = block_info;
11401131 block_infos. push ( block_info) ;
1141- db. insert_block ( l2_block, batch_info) . await . unwrap ( ) ;
11421132 }
1133+ db. insert_blocks ( block_infos. clone ( ) , batch_info) . await . unwrap ( ) ;
11431134
11441135 // Test getting existing blocks
11451136 for expected_block in block_infos {
@@ -1177,9 +1168,7 @@ mod test {
11771168 let safe_block_1 = BlockInfo { number : 200 , hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
11781169 let safe_block_2 = BlockInfo { number : 201 , hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
11791170
1180- db. insert_block ( safe_block_1, batch_info) . await . unwrap ( ) ;
1181-
1182- db. insert_block ( safe_block_2, batch_info) . await . unwrap ( ) ;
1171+ db. insert_blocks ( vec ! [ safe_block_1, safe_block_2] , batch_info) . await . unwrap ( ) ;
11831172
11841173 // Should return the highest safe block (block 201)
11851174 let latest_safe = db. get_latest_safe_l2_info ( ) . await . unwrap ( ) ;
@@ -1198,11 +1187,12 @@ mod test {
11981187
11991188 // Insert multiple L2 blocks with batch info
12001189 let batch_info = BatchInfo { index : 0 , hash : B256 :: default ( ) } ;
1190+ let mut blocks = Vec :: new ( ) ;
12011191 for i in 400 ..410 {
12021192 let block_info = BlockInfo { number : i, hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
1203-
1204- db. insert_block ( block_info, batch_info) . await . unwrap ( ) ;
1193+ blocks. push ( block_info) ;
12051194 }
1195+ db. insert_blocks ( blocks, batch_info) . await . unwrap ( ) ;
12061196
12071197 // Delete blocks with number > 405
12081198 let deleted_count = db. delete_l2_blocks_gt_block_number ( 405 ) . await . unwrap ( ) ;
@@ -1245,10 +1235,9 @@ mod test {
12451235 for i in 100 ..110 {
12461236 let batch_data = db. get_batch_by_index ( i) . await . unwrap ( ) . unwrap ( ) ;
12471237 let batch_info: BatchInfo = batch_data. into ( ) ;
1248-
12491238 let block_info = BlockInfo { number : 500 + i, hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
12501239
1251- db. insert_block ( block_info, batch_info) . await . unwrap ( ) ;
1240+ db. insert_blocks ( vec ! [ block_info] , batch_info) . await . unwrap ( ) ;
12521241 }
12531242
12541243 // Delete L2 blocks with batch index > 105
@@ -1304,8 +1293,8 @@ mod test {
13041293 L2BlockInfoWithL1Messages { block_info, l1_messages : l1_message_hashes. clone ( ) } ;
13051294
13061295 // Insert block
1307- db. insert_block ( l2_block. block_info , batch_info) . await . unwrap ( ) ;
1308- db. update_l1_messages_with_l2_block ( l2_block) . await . unwrap ( ) ;
1296+ db. insert_blocks ( vec ! [ l2_block. block_info] , batch_info) . await . unwrap ( ) ;
1297+ db. update_l1_messages_with_l2_blocks ( vec ! [ l2_block] ) . await . unwrap ( ) ;
13091298
13101299 // Verify block was inserted
13111300 let retrieved_block = db. get_l2_block_info_by_number ( 500 ) . await . unwrap ( ) ;
@@ -1340,7 +1329,7 @@ mod test {
13401329
13411330 // Insert initial block
13421331 let block_info = BlockInfo { number : 600 , hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
1343- db. insert_block ( block_info, batch_info_1) . await . unwrap ( ) ;
1332+ db. insert_blocks ( vec ! [ block_info] , batch_info_1) . await . unwrap ( ) ;
13441333
13451334 // Verify initial insertion
13461335 let retrieved_block = db. get_l2_block_info_by_number ( 600 ) . await . unwrap ( ) ;
@@ -1359,7 +1348,7 @@ mod test {
13591348 assert_eq ! ( initial_batch_info, batch_info_1) ;
13601349
13611350 // Update the same block with different batch info (upsert)
1362- db. insert_block ( block_info, batch_info_2) . await . unwrap ( ) ;
1351+ db. insert_blocks ( vec ! [ block_info] , batch_info_2) . await . unwrap ( ) ;
13631352
13641353 // Verify the block still exists and was updated
13651354 let retrieved_block = db. get_l2_block_info_by_number ( 600 ) . await . unwrap ( ) . unwrap ( ) ;
@@ -1393,23 +1382,22 @@ mod test {
13931382 let block_1 = BlockInfo { number : 1 , hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
13941383 let block_2 = BlockInfo { number : 2 , hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
13951384 db. insert_batch ( batch_data_1. clone ( ) ) . await . unwrap ( ) ;
1396- db. insert_block ( block_1, batch_data_1. clone ( ) . into ( ) ) . await . unwrap ( ) ;
1397- db. insert_block ( block_2, batch_data_1. clone ( ) . into ( ) ) . await . unwrap ( ) ;
1385+ db. insert_blocks ( vec ! [ block_1, block_2] , batch_data_1. clone ( ) . into ( ) ) . await . unwrap ( ) ;
13981386
13991387 // Insert batch 2 and associate it with one block in the database
14001388 let batch_data_2 =
14011389 BatchCommitData { index : 2 , block_number : 20 , ..Arbitrary :: arbitrary ( & mut u) . unwrap ( ) } ;
14021390 let block_3 = BlockInfo { number : 3 , hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
14031391 db. insert_batch ( batch_data_2. clone ( ) ) . await . unwrap ( ) ;
1404- db. insert_block ( block_3, batch_data_2. clone ( ) . into ( ) ) . await . unwrap ( ) ;
1392+ db. insert_blocks ( vec ! [ block_3] , batch_data_2. clone ( ) . into ( ) ) . await . unwrap ( ) ;
14051393
14061394 // Insert batch 3 produced at the same block number as batch 2 and associate it with one
14071395 // block
14081396 let batch_data_3 =
14091397 BatchCommitData { index : 3 , block_number : 20 , ..Arbitrary :: arbitrary ( & mut u) . unwrap ( ) } ;
14101398 let block_4 = BlockInfo { number : 4 , hash : B256 :: arbitrary ( & mut u) . unwrap ( ) } ;
14111399 db. insert_batch ( batch_data_3. clone ( ) ) . await . unwrap ( ) ;
1412- db. insert_block ( block_4, batch_data_3. clone ( ) . into ( ) ) . await . unwrap ( ) ;
1400+ db. insert_blocks ( vec ! [ block_4] , batch_data_3. clone ( ) . into ( ) ) . await . unwrap ( ) ;
14131401
14141402 db. set_finalized_l1_block_number ( 21 ) . await . unwrap ( ) ;
14151403
0 commit comments