@@ -34,9 +34,10 @@ use crate::light_client::{get_light_client_bootstrap, get_light_client_updates};
34
34
use crate :: produce_block:: { produce_blinded_block_v2, produce_block_v2, produce_block_v3} ;
35
35
use crate :: version:: fork_versioned_response;
36
36
use beacon_chain:: {
37
- attestation_verification:: VerifiedAttestation , observed_operations:: ObservationOutcome ,
38
- validator_monitor:: timestamp_now, AttestationError as AttnError , BeaconChain , BeaconChainError ,
39
- BeaconChainTypes , WhenSlotSkipped ,
37
+ attestation_verification:: VerifiedAttestation , blob_verification:: verify_kzg_for_blob_list,
38
+ observed_operations:: ObservationOutcome , validator_monitor:: timestamp_now,
39
+ AttestationError as AttnError , BeaconChain , BeaconChainError , BeaconChainTypes ,
40
+ WhenSlotSkipped ,
40
41
} ;
41
42
use beacon_processor:: { work_reprocessing_queue:: ReprocessQueueMessage , BeaconProcessorSend } ;
42
43
pub use block_id:: BlockId ;
@@ -65,7 +66,7 @@ use serde::{Deserialize, Serialize};
65
66
use serde_json:: Value ;
66
67
use slog:: { crit, debug, error, info, warn, Logger } ;
67
68
use slot_clock:: SlotClock ;
68
- use ssz:: Encode ;
69
+ use ssz:: { Decode , Encode } ;
69
70
pub use state_id:: StateId ;
70
71
use std:: future:: Future ;
71
72
use std:: net:: { IpAddr , Ipv4Addr , SocketAddr } ;
@@ -85,11 +86,12 @@ use tokio_stream::{
85
86
} ;
86
87
use types:: {
87
88
fork_versioned_response:: EmptyMetadata , Attestation , AttestationData , AttestationShufflingId ,
88
- AttesterSlashing , BeaconStateError , ChainSpec , CommitteeCache , ConfigAndPreset , Epoch , EthSpec ,
89
- ForkName , ForkVersionedResponse , Hash256 , ProposerPreparationData , ProposerSlashing ,
90
- RelativeEpoch , SignedAggregateAndProof , SignedBlindedBeaconBlock , SignedBlsToExecutionChange ,
91
- SignedContributionAndProof , SignedValidatorRegistrationData , SignedVoluntaryExit , Slot ,
92
- SyncCommitteeMessage , SyncContributionData ,
89
+ AttesterSlashing , BeaconStateError , BlobSidecarList , ChainSpec , CommitteeCache ,
90
+ ConfigAndPreset , Epoch , EthSpec , ForkName , ForkVersionedResponse , Hash256 ,
91
+ ProposerPreparationData , ProposerSlashing , RelativeEpoch , SignedAggregateAndProof ,
92
+ SignedBlindedBeaconBlock , SignedBlsToExecutionChange , SignedContributionAndProof ,
93
+ SignedValidatorRegistrationData , SignedVoluntaryExit , Slot , SyncCommitteeMessage ,
94
+ SyncContributionData ,
93
95
} ;
94
96
use validator:: pubkey_to_validator_index;
95
97
use version:: {
@@ -4450,13 +4452,68 @@ pub fn serve<T: BeaconChainTypes>(
4450
4452
let post_lighthouse_database_import_blobs = database_path
4451
4453
. and ( warp:: path ( "import_blobs" ) )
4452
4454
. and ( warp:: path:: end ( ) )
4455
+ . and ( warp:: query :: < api_types:: ImportBlobsQuery > ( ) )
4453
4456
. and ( warp_utils:: json:: json ( ) )
4454
4457
. and ( task_spawner_filter. clone ( ) )
4455
4458
. and ( chain_filter. clone ( ) )
4456
4459
. then (
4457
- |blobs, task_spawner : TaskSpawner < T :: EthSpec > , chain : Arc < BeaconChain < T > > | {
4460
+ |query : api_types:: ImportBlobsQuery ,
4461
+ blob_lists : Vec < BlobSidecarList < T :: EthSpec > > ,
4462
+ task_spawner : TaskSpawner < T :: EthSpec > ,
4463
+ chain : Arc < BeaconChain < T > > | {
4458
4464
task_spawner. blocking_json_task ( Priority :: P1 , move || {
4459
- match chain. store . import_historical_blobs ( blobs) {
4465
+ if query. verify {
4466
+ for blob_list in & blob_lists {
4467
+ match verify_kzg_for_blob_list ( blob_list. iter ( ) , & chain. kzg ) {
4468
+ Ok ( ( ) ) => ( ) ,
4469
+ Err ( e) => {
4470
+ return Err ( warp_utils:: reject:: custom_server_error ( format ! (
4471
+ "{e:?}"
4472
+ ) ) )
4473
+ }
4474
+ }
4475
+ }
4476
+ }
4477
+
4478
+ match chain. store . import_blobs_batch ( blob_lists) {
4479
+ Ok ( ( ) ) => Ok ( ( ) ) ,
4480
+ Err ( e) => Err ( warp_utils:: reject:: custom_server_error ( format ! ( "{e:?}" ) ) ) ,
4481
+ }
4482
+ } )
4483
+ } ,
4484
+ ) ;
4485
+
4486
+ // POST lighthouse/database/import_blobs_ssz
4487
+ let post_lighthouse_database_import_blobs_ssz = database_path
4488
+ . and ( warp:: path ( "import_blobs_ssz" ) )
4489
+ . and ( warp:: path:: end ( ) )
4490
+ . and ( warp:: query :: < api_types:: ImportBlobsQuery > ( ) )
4491
+ . and ( warp:: body:: bytes ( ) )
4492
+ . and ( task_spawner_filter. clone ( ) )
4493
+ . and ( chain_filter. clone ( ) )
4494
+ . then (
4495
+ |query : api_types:: ImportBlobsQuery ,
4496
+ body : Bytes ,
4497
+ task_spawner : TaskSpawner < T :: EthSpec > ,
4498
+ chain : Arc < BeaconChain < T > > | {
4499
+ task_spawner. blocking_json_task ( Priority :: P1 , move || {
4500
+ let blob_lists = Vec :: < BlobSidecarList < T :: EthSpec > > :: from_ssz_bytes ( & body)
4501
+ . map_err ( |e| warp_utils:: reject:: custom_server_error ( format ! ( "{e:?}" ) ) ) ?;
4502
+
4503
+ if query. verify {
4504
+ for blob_list in & blob_lists {
4505
+ match verify_kzg_for_blob_list ( blob_list. iter ( ) , & chain. kzg ) {
4506
+ Ok ( ( ) ) => ( ) ,
4507
+ Err ( e) => {
4508
+ return Err ( warp_utils:: reject:: custom_server_error ( format ! (
4509
+ "{e:?}"
4510
+ ) ) )
4511
+ }
4512
+ }
4513
+ }
4514
+ }
4515
+
4516
+ match chain. store . import_blobs_batch ( blob_lists) {
4460
4517
Ok ( ( ) ) => Ok ( ( ) ) ,
4461
4518
Err ( e) => Err ( warp_utils:: reject:: custom_server_error ( format ! ( "{e:?}" ) ) ) ,
4462
4519
}
@@ -4826,6 +4883,7 @@ pub fn serve<T: BeaconChainTypes>(
4826
4883
. uor ( post_lighthouse_liveness)
4827
4884
. uor ( post_lighthouse_database_reconstruct)
4828
4885
. uor ( post_lighthouse_database_import_blobs)
4886
+ . uor ( post_lighthouse_database_import_blobs_ssz)
4829
4887
. uor ( post_lighthouse_block_rewards)
4830
4888
. uor ( post_lighthouse_ui_validator_metrics)
4831
4889
. uor ( post_lighthouse_ui_validator_info)
0 commit comments