@@ -35,9 +35,10 @@ use crate::light_client::{get_light_client_bootstrap, get_light_client_updates};
35
35
use crate :: produce_block:: { produce_blinded_block_v2, produce_block_v2, produce_block_v3} ;
36
36
use crate :: version:: fork_versioned_response;
37
37
use beacon_chain:: {
38
- attestation_verification:: VerifiedAttestation , observed_operations:: ObservationOutcome ,
39
- validator_monitor:: timestamp_now, AttestationError as AttnError , BeaconChain , BeaconChainError ,
40
- BeaconChainTypes , WhenSlotSkipped ,
38
+ attestation_verification:: VerifiedAttestation , blob_verification:: verify_kzg_for_blob_list,
39
+ observed_operations:: ObservationOutcome , validator_monitor:: timestamp_now,
40
+ AttestationError as AttnError , BeaconChain , BeaconChainError , BeaconChainTypes ,
41
+ WhenSlotSkipped ,
41
42
} ;
42
43
use beacon_processor:: { work_reprocessing_queue:: ReprocessQueueMessage , BeaconProcessorSend } ;
43
44
pub use block_id:: BlockId ;
@@ -62,7 +63,7 @@ pub use publish_blocks::{
62
63
use serde:: { Deserialize , Serialize } ;
63
64
use slog:: { crit, debug, error, info, warn, Logger } ;
64
65
use slot_clock:: SlotClock ;
65
- use ssz:: Encode ;
66
+ use ssz:: { Decode , Encode } ;
66
67
pub use state_id:: StateId ;
67
68
use std:: future:: Future ;
68
69
use std:: net:: { IpAddr , Ipv4Addr , SocketAddr } ;
@@ -82,9 +83,9 @@ use tokio_stream::{
82
83
} ;
83
84
use types:: {
84
85
fork_versioned_response:: EmptyMetadata , Attestation , AttestationData , AttestationShufflingId ,
85
- AttesterSlashing , BeaconStateError , CommitteeCache , ConfigAndPreset , Epoch , EthSpec , ForkName ,
86
- ForkVersionedResponse , Hash256 , ProposerPreparationData , ProposerSlashing , RelativeEpoch ,
87
- SignedAggregateAndProof , SignedBlindedBeaconBlock , SignedBlsToExecutionChange ,
86
+ AttesterSlashing , BeaconStateError , BlobSidecarList , CommitteeCache , ConfigAndPreset , Epoch ,
87
+ EthSpec , ForkName , ForkVersionedResponse , Hash256 , ProposerPreparationData , ProposerSlashing ,
88
+ RelativeEpoch , SignedAggregateAndProof , SignedBlindedBeaconBlock , SignedBlsToExecutionChange ,
88
89
SignedContributionAndProof , SignedValidatorRegistrationData , SignedVoluntaryExit , Slot ,
89
90
SyncCommitteeMessage , SyncContributionData ,
90
91
} ;
@@ -4399,13 +4400,68 @@ pub fn serve<T: BeaconChainTypes>(
4399
4400
let post_lighthouse_database_import_blobs = database_path
4400
4401
. and ( warp:: path ( "import_blobs" ) )
4401
4402
. and ( warp:: path:: end ( ) )
4403
+ . and ( warp:: query :: < api_types:: ImportBlobsQuery > ( ) )
4402
4404
. and ( warp_utils:: json:: json ( ) )
4403
4405
. and ( task_spawner_filter. clone ( ) )
4404
4406
. and ( chain_filter. clone ( ) )
4405
4407
. then (
4406
- |blobs, task_spawner : TaskSpawner < T :: EthSpec > , chain : Arc < BeaconChain < T > > | {
4408
+ |query : api_types:: ImportBlobsQuery ,
4409
+ blob_lists : Vec < BlobSidecarList < T :: EthSpec > > ,
4410
+ task_spawner : TaskSpawner < T :: EthSpec > ,
4411
+ chain : Arc < BeaconChain < T > > | {
4407
4412
task_spawner. blocking_json_task ( Priority :: P1 , move || {
4408
- match chain. store . import_historical_blobs ( blobs) {
4413
+ if query. verify {
4414
+ for blob_list in & blob_lists {
4415
+ match verify_kzg_for_blob_list ( blob_list. iter ( ) , & chain. kzg ) {
4416
+ Ok ( ( ) ) => ( ) ,
4417
+ Err ( e) => {
4418
+ return Err ( warp_utils:: reject:: custom_server_error ( format ! (
4419
+ "{e:?}"
4420
+ ) ) )
4421
+ }
4422
+ }
4423
+ }
4424
+ }
4425
+
4426
+ match chain. store . import_blobs_batch ( blob_lists) {
4427
+ Ok ( ( ) ) => Ok ( ( ) ) ,
4428
+ Err ( e) => Err ( warp_utils:: reject:: custom_server_error ( format ! ( "{e:?}" ) ) ) ,
4429
+ }
4430
+ } )
4431
+ } ,
4432
+ ) ;
4433
+
4434
+ // POST lighthouse/database/import_blobs_ssz
4435
+ let post_lighthouse_database_import_blobs_ssz = database_path
4436
+ . and ( warp:: path ( "import_blobs_ssz" ) )
4437
+ . and ( warp:: path:: end ( ) )
4438
+ . and ( warp:: query :: < api_types:: ImportBlobsQuery > ( ) )
4439
+ . and ( warp:: body:: bytes ( ) )
4440
+ . and ( task_spawner_filter. clone ( ) )
4441
+ . and ( chain_filter. clone ( ) )
4442
+ . then (
4443
+ |query : api_types:: ImportBlobsQuery ,
4444
+ body : Bytes ,
4445
+ task_spawner : TaskSpawner < T :: EthSpec > ,
4446
+ chain : Arc < BeaconChain < T > > | {
4447
+ task_spawner. blocking_json_task ( Priority :: P1 , move || {
4448
+ let blob_lists = Vec :: < BlobSidecarList < T :: EthSpec > > :: from_ssz_bytes ( & body)
4449
+ . map_err ( |e| warp_utils:: reject:: custom_server_error ( format ! ( "{e:?}" ) ) ) ?;
4450
+
4451
+ if query. verify {
4452
+ for blob_list in & blob_lists {
4453
+ match verify_kzg_for_blob_list ( blob_list. iter ( ) , & chain. kzg ) {
4454
+ Ok ( ( ) ) => ( ) ,
4455
+ Err ( e) => {
4456
+ return Err ( warp_utils:: reject:: custom_server_error ( format ! (
4457
+ "{e:?}"
4458
+ ) ) )
4459
+ }
4460
+ }
4461
+ }
4462
+ }
4463
+
4464
+ match chain. store . import_blobs_batch ( blob_lists) {
4409
4465
Ok ( ( ) ) => Ok ( ( ) ) ,
4410
4466
Err ( e) => Err ( warp_utils:: reject:: custom_server_error ( format ! ( "{e:?}" ) ) ) ,
4411
4467
}
@@ -4771,6 +4827,7 @@ pub fn serve<T: BeaconChainTypes>(
4771
4827
. uor ( post_lighthouse_liveness)
4772
4828
. uor ( post_lighthouse_database_reconstruct)
4773
4829
. uor ( post_lighthouse_database_import_blobs)
4830
+ . uor ( post_lighthouse_database_import_blobs_ssz)
4774
4831
. uor ( post_lighthouse_block_rewards)
4775
4832
. uor ( post_lighthouse_ui_validator_metrics)
4776
4833
. uor ( post_lighthouse_ui_validator_info)
0 commit comments