@@ -86,6 +86,8 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
8686 network_globals : Arc < NetworkGlobals < T :: EthSpec > > ,
8787) -> Result < Response , Rejection > {
8888 let seen_timestamp = timestamp_now ( ) ;
89+ let block_publishing_delay_for_testing = chain. config . block_publishing_delay ;
90+ let data_column_publishing_delay_for_testing = chain. config . data_column_publishing_delay ;
8991
9092 let ( unverified_block, unverified_blobs, is_locally_built_block) = match provenanced_block {
9193 ProvenancedBlock :: Local ( block, blobs, _) => ( block, blobs, true ) ,
@@ -147,6 +149,14 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
147149
148150 let should_publish_block = gossip_verified_block_result. is_ok ( ) ;
149151 if BroadcastValidation :: Gossip == validation_level && should_publish_block {
152+ if let Some ( block_publishing_delay) = block_publishing_delay_for_testing {
153+ debug ! (
154+ log,
155+ "Publishing block with artificial delay" ;
156+ "block_publishing_delay" => ?block_publishing_delay
157+ ) ;
158+ tokio:: time:: sleep ( block_publishing_delay) . await ;
159+ }
150160 publish_block_p2p (
151161 block. clone ( ) ,
152162 sender_clone. clone ( ) ,
@@ -207,6 +217,23 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
207217 }
208218
209219 if gossip_verified_columns. iter ( ) . map ( Option :: is_some) . count ( ) > 0 {
220+ if let Some ( data_column_publishing_delay) = data_column_publishing_delay_for_testing {
221+ // Subtract block publishing delay if it is also used.
222+ // Note: if `data_column_publishing_delay` is less than `block_publishing_delay`, it
223+ // will still be delayed by `block_publishing_delay`. This could be solved with spawning
224+ // async tasks but the limitation is minor and I believe it's probably not worth
225+ // affecting the mainnet code path.
226+ let block_publishing_delay = block_publishing_delay_for_testing. unwrap_or_default ( ) ;
227+ let delay = data_column_publishing_delay. saturating_sub ( block_publishing_delay) ;
228+ if !delay. is_zero ( ) {
229+ debug ! (
230+ log,
231+ "Publishing data columns with artificial delay" ;
232+ "data_column_publishing_delay" => ?data_column_publishing_delay
233+ ) ;
234+ tokio:: time:: sleep ( delay) . await ;
235+ }
236+ }
210237 publish_column_sidecars ( network_tx, & gossip_verified_columns, & chain) . map_err ( |_| {
211238 warp_utils:: reject:: custom_server_error ( "unable to publish data column sidecars" . into ( ) )
212239 } ) ?;
0 commit comments