From 053625f113b69de425ce2ceaab807de2af5163f0 Mon Sep 17 00:00:00 2001 From: tim gretler Date: Wed, 18 May 2022 06:50:51 +0000 Subject: [PATCH] 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. --- validator_client/src/block_service.rs | 42 +++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/validator_client/src/block_service.rs b/validator_client/src/block_service.rs index 32e63b0705..2ba81eac7a 100644 --- a/validator_client/src/block_service.rs +++ b/validator_client/src/block_service.rs @@ -328,7 +328,8 @@ impl BlockService { let self_ref = &self; let proposer_index = self.validator_store.validator_index(&validator_pubkey); let validator_pubkey_ref = &validator_pubkey; - let signed_block = self + // Request block from first responsive beacon node. + let block = self .beacon_nodes .first_success(RequireSynced::No, |beacon_node| async move { let get_timer = metrics::start_timer_vec( @@ -378,14 +379,19 @@ impl BlockService { )); } - let signed_block = self_ref - .validator_store - .sign_block::(*validator_pubkey_ref, block, current_slot) - .await - .map_err(|e| { - BlockError::Recoverable(format!("Unable to sign block: {:?}", e)) - })?; + Ok::<_, BlockError>(block) + }) + .await?; + let signed_block = self_ref + .validator_store + .sign_block::(*validator_pubkey_ref, block, current_slot) + .await + .map_err(|e| BlockError::Recoverable(format!("Unable to sign block: {:?}", e)))?; + + // Publish block with first available beacon node. + self.beacon_nodes + .first_success(RequireSynced::No, |beacon_node| async { let _post_timer = metrics::start_timer_vec( &metrics::BLOCK_SERVICE_TIMES, &[metrics::BEACON_BLOCK_HTTP_POST], @@ -412,19 +418,17 @@ impl BlockService { })?, } - Ok::<_, BlockError>(signed_block) + info!( + log, + "Successfully published block"; + "deposits" => signed_block.message().body().deposits().len(), + "attestations" => signed_block.message().body().attestations().len(), + "graffiti" => ?graffiti.map(|g| g.as_utf8_lossy()), + "slot" => signed_block.slot().as_u64(), + ); + Ok::<_, BlockError>(()) }) .await?; - - info!( - log, - "Successfully published block"; - "deposits" => signed_block.message().body().deposits().len(), - "attestations" => signed_block.message().body().attestations().len(), - "graffiti" => ?graffiti.map(|g| g.as_utf8_lossy()), - "slot" => signed_block.slot().as_u64(), - ); - Ok(()) } }