Skip to content

Commit 053625f

Browse files
committed
Avoid unnecessary slashing protection when publishing blocks (#3188)
## Issue Addressed #3141 ## Proposed Changes Changes the algorithm for proposing blocks from ``` For each BN (first success): - Produce a block - Sign the block and store its root in the slashing protection DB - Publish the block ``` to ``` For each BN (first success): - Produce a block Sign the block and store its root in the slashing protection DB For each BN (first success): - Publish the block ``` Separating the producing from the publishing makes sure that we only add a signed block once to the slashing DB.
1 parent 0428018 commit 053625f

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

validator_client/src/block_service.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
328328
let self_ref = &self;
329329
let proposer_index = self.validator_store.validator_index(&validator_pubkey);
330330
let validator_pubkey_ref = &validator_pubkey;
331-
let signed_block = self
331+
// Request block from first responsive beacon node.
332+
let block = self
332333
.beacon_nodes
333334
.first_success(RequireSynced::No, |beacon_node| async move {
334335
let get_timer = metrics::start_timer_vec(
@@ -378,14 +379,19 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
378379
));
379380
}
380381

381-
let signed_block = self_ref
382-
.validator_store
383-
.sign_block::<Payload>(*validator_pubkey_ref, block, current_slot)
384-
.await
385-
.map_err(|e| {
386-
BlockError::Recoverable(format!("Unable to sign block: {:?}", e))
387-
})?;
382+
Ok::<_, BlockError>(block)
383+
})
384+
.await?;
385+
386+
let signed_block = self_ref
387+
.validator_store
388+
.sign_block::<Payload>(*validator_pubkey_ref, block, current_slot)
389+
.await
390+
.map_err(|e| BlockError::Recoverable(format!("Unable to sign block: {:?}", e)))?;
388391

392+
// Publish block with first available beacon node.
393+
self.beacon_nodes
394+
.first_success(RequireSynced::No, |beacon_node| async {
389395
let _post_timer = metrics::start_timer_vec(
390396
&metrics::BLOCK_SERVICE_TIMES,
391397
&[metrics::BEACON_BLOCK_HTTP_POST],
@@ -412,19 +418,17 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
412418
})?,
413419
}
414420

415-
Ok::<_, BlockError>(signed_block)
421+
info!(
422+
log,
423+
"Successfully published block";
424+
"deposits" => signed_block.message().body().deposits().len(),
425+
"attestations" => signed_block.message().body().attestations().len(),
426+
"graffiti" => ?graffiti.map(|g| g.as_utf8_lossy()),
427+
"slot" => signed_block.slot().as_u64(),
428+
);
429+
Ok::<_, BlockError>(())
416430
})
417431
.await?;
418-
419-
info!(
420-
log,
421-
"Successfully published block";
422-
"deposits" => signed_block.message().body().deposits().len(),
423-
"attestations" => signed_block.message().body().attestations().len(),
424-
"graffiti" => ?graffiti.map(|g| g.as_utf8_lossy()),
425-
"slot" => signed_block.slot().as_u64(),
426-
);
427-
428432
Ok(())
429433
}
430434
}

0 commit comments

Comments
 (0)