@@ -86,8 +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 = chain. config . block_publishing_delay ;
90- let data_column_publishing_delay = chain. config . data_column_publishing_delay ;
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 ;
9191
9292 let ( unverified_block, unverified_blobs, is_locally_built_block) = match provenanced_block {
9393 ProvenancedBlock :: Local ( block, blobs, _) => ( block, blobs, true ) ,
@@ -105,13 +105,8 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
105105 let publish_block_p2p = move |block : Arc < SignedBeaconBlock < T :: EthSpec > > ,
106106 sender,
107107 log,
108- seen_timestamp,
109- block_publishing_delay|
108+ seen_timestamp|
110109 -> Result < ( ) , BlockError > {
111- // Add delay before publishing the block to the network.
112- if let Some ( block_publishing_delay) = block_publishing_delay {
113- std:: thread:: sleep ( block_publishing_delay) ;
114- }
115110 let publish_timestamp = timestamp_now ( ) ;
116111 let publish_delay = publish_timestamp
117112 . checked_sub ( seen_timestamp)
@@ -154,12 +149,19 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
154149
155150 let should_publish_block = gossip_verified_block_result. is_ok ( ) ;
156151 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+ }
157160 publish_block_p2p (
158161 block. clone ( ) ,
159162 sender_clone. clone ( ) ,
160163 log. clone ( ) ,
161164 seen_timestamp,
162- block_publishing_delay,
163165 )
164166 . map_err ( |_| warp_utils:: reject:: custom_server_error ( "unable to publish" . into ( ) ) ) ?;
165167 }
@@ -175,7 +177,6 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
175177 sender_clone. clone ( ) ,
176178 log. clone ( ) ,
177179 seen_timestamp,
178- block_publishing_delay,
179180 ) ?,
180181 BroadcastValidation :: ConsensusAndEquivocation => {
181182 check_slashable ( & chain, block_root, & block_to_publish, & log) ?;
@@ -184,7 +185,6 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
184185 sender_clone. clone ( ) ,
185186 log. clone ( ) ,
186187 seen_timestamp,
187- block_publishing_delay,
188188 ) ?;
189189 }
190190 } ;
@@ -217,9 +217,22 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
217217 }
218218
219219 if gossip_verified_columns. iter ( ) . map ( Option :: is_some) . count ( ) > 0 {
220- // Add delay before publishing the data columns to the network.
221- if let Some ( data_column_publishing_delay) = data_column_publishing_delay {
222- tokio:: time:: sleep ( data_column_publishing_delay) . await ;
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+ }
223236 }
224237 publish_column_sidecars ( network_tx, & gossip_verified_columns, & chain) . map_err ( |_| {
225238 warp_utils:: reject:: custom_server_error ( "unable to publish data column sidecars" . into ( ) )
0 commit comments