Skip to content

Commit e66b077

Browse files
committed
Better handling of some errors
1 parent 32b3beb commit e66b077

File tree

6 files changed

+110
-38
lines changed

6 files changed

+110
-38
lines changed

block_producer/src/block_producer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<P: Preset, W: Wait> BlockProducer<P, W> {
288288
&self,
289289
finalized_deposit_index: DepositIndex,
290290
deposit_requests_start_index: Option<DepositIndex>,
291-
) -> Result<()> {
291+
) {
292292
self.producer_context
293293
.eth1_chain
294294
.finalize_deposits(finalized_deposit_index, deposit_requests_start_index)

block_producer/src/eth1_storage.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub trait Eth1Storage {
300300
&self,
301301
finalized_deposit_index: DepositIndex,
302302
deposit_requests_start_index: Option<DepositIndex>,
303-
) -> Result<()> {
303+
) {
304304
features::log!(
305305
DebugEth1,
306306
"Finalizing deposits: {finalized_deposit_index}, \
@@ -326,7 +326,7 @@ pub trait Eth1Storage {
326326
};
327327

328328
let Some(block_position) = position else {
329-
return Ok(());
329+
return;
330330
};
331331

332332
features::log!(
@@ -361,11 +361,8 @@ pub trait Eth1Storage {
361361
if let Err(error) = self.add_deposits(deposit_events, last_block.number) {
362362
warn!("{error:?}");
363363
new_finalized_blocks.append(&mut unfinalized_blocks);
364-
return Ok(());
365364
}
366365
}
367-
368-
Ok(())
369366
}
370367
}
371368

liveness_tracker/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ impl<P: Preset, W: Wait> LivenessTracker<P, W> {
9797
}
9898
}
9999
ValidatorToLiveness::ValidAttestation(attestation) => {
100-
let state = self.controller.preprocessed_state_at_current_slot()?;
100+
let result = self
101+
.controller
102+
.preprocessed_state_at_current_slot()
103+
.map(|state| self.process_attestation(&attestation, &state));
101104

102-
if let Err(error) = self.process_attestation(&attestation, &state) {
105+
if let Err(error) = result {
103106
warn!("Error while tracking liveness from attestation: {error:?}");
104107
}
105108
}

metrics/src/service.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,15 @@ impl<P: Preset> MetricsService<P> {
183183
// Take state at last slot in epoch
184184
let slot = misc::compute_start_slot_at_epoch::<P>(epoch).saturating_sub(1);
185185

186-
if let Some(state) = self.controller.state_at_slot(slot)? {
186+
let state_opt = match self.controller.state_at_slot(slot) {
187+
Ok(state_opt) => state_opt,
188+
Err(error) => {
189+
warn!("unable to update epoch metrics: {error:?}");
190+
continue;
191+
}
192+
};
193+
194+
if let Some(state) = state_opt {
187195
match self.update_epoch_metrics(&state.value) {
188196
Ok(()) => epoch_with_metrics = Some(epoch),
189197
Err(error) => warn!("unable to update epoch metrics: {error:?}"),

operation_pools/src/attestation_agg_pool/tasks.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use eth1_api::ApiController;
1111
use features::Feature::DebugAttestationPacker;
1212
use fork_choice_control::Wait;
1313
use helper_functions::accessors;
14+
use log::warn;
1415
use prometheus_metrics::Metrics;
1516
use ssz::ContiguousList;
1617
use std_ext::ArcExt as _;
@@ -283,7 +284,15 @@ impl<P: Preset, W: Wait> PoolTask for SetRegisteredValidatorsTask<P, W> {
283284
prepared_proposer_indices,
284285
} = self;
285286

286-
let beacon_state = controller.preprocessed_state_at_current_slot()?;
287+
let beacon_state = match controller.preprocessed_state_at_current_slot() {
288+
Ok(state) => state,
289+
Err(error) => {
290+
warn!(
291+
"failed get preprocessed state at current slot needed for validating registered validator pubkeys: {error}",
292+
);
293+
return Ok(());
294+
}
295+
};
287296

288297
let validator_indices = pubkeys
289298
.into_iter()

validator/src/validator.rs

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,14 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
232232
}
233233
}
234234

235+
pub async fn run(self) -> Result<()> {
236+
self.run_internal().await;
237+
238+
Ok(())
239+
}
240+
235241
#[expect(clippy::too_many_lines)]
236-
pub async fn run(mut self) -> Result<()> {
242+
async fn run_internal(mut self) {
237243
loop {
238244
let mut slasher_to_validator_rx = self
239245
.slasher_to_validator_rx
@@ -244,24 +250,28 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
244250
select! {
245251
message = self.internal_rx.select_next_some() => match message {
246252
InternalMessage::DoppelgangerProtectionResult(result) => {
247-
result?;
253+
if let Err(error) = result {
254+
panic!("Doppelganger protection error: {error}");
255+
}
248256
}
249257
},
250258

251259
message = self.fork_choice_rx.select_next_some() => match message {
252260
ValidatorMessage::Tick(wait_group, tick) => {
253-
self.handle_tick(wait_group, tick).await?;
261+
if let Err(error) = self.handle_tick(wait_group, tick).await {
262+
panic!("error while handling tick: {error:?}");
263+
}
254264
}
255265
ValidatorMessage::FinalizedEth1Data(finalized_eth1_data, deposit_requests_start_index) => {
256-
self.block_producer.finalize_deposits(finalized_eth1_data, deposit_requests_start_index)?;
266+
self.block_producer.finalize_deposits(finalized_eth1_data, deposit_requests_start_index);
257267
},
258268
ValidatorMessage::Head(wait_group, head) => {
259269
if let Some(validator_to_liveness_tx) = &self.validator_to_liveness_tx {
260270
let state = self.controller.state_by_chain_link(&head);
261271
ValidatorToLiveness::Head(head.block.clone_arc(), state).send(validator_to_liveness_tx);
262272
}
263273

264-
self.attest_gossip_block(&wait_group, head).await?;
274+
self.attest_gossip_block(&wait_group, head).await;
265275
}
266276
ValidatorMessage::ValidAttestation(wait_group, attestation) => {
267277
self.attestation_agg_pool
@@ -283,7 +293,13 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
283293
let slot_head = self.safe_slot_head(slot).await;
284294

285295
if let Some(slot_head) = slot_head {
286-
let proposer_index = slot_head.proposer_index()?;
296+
let proposer_index = match slot_head.proposer_index() {
297+
Ok(proposer_index) => proposer_index,
298+
Err(error) => {
299+
error!("failed to compute proposer index while preparing execution payload: {error:?}");
300+
continue;
301+
}
302+
};
287303

288304
let block_build_context = self.block_producer.new_build_context(
289305
slot_head.beacon_state.clone_arc(),
@@ -339,10 +355,16 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
339355

340356
gossip_message = self.p2p_to_validator_rx.select_next_some() => match gossip_message {
341357
P2pToValidator::AttesterSlashing(slashing, gossip_id) => {
342-
let outcome = self
358+
let outcome = match self
343359
.block_producer
344360
.handle_external_attester_slashing(*slashing.clone())
345-
.await?;
361+
.await {
362+
Ok(outcome) => outcome,
363+
Err(error) => {
364+
warn!("failed to handle attester slashing: {error}");
365+
continue;
366+
}
367+
};
346368

347369
if matches!(outcome, PoolAdditionOutcome::Accept) {
348370
self.event_channels.send_attester_slashing_event(&slashing);
@@ -351,10 +373,16 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
351373
self.handle_pool_addition_outcome_for_p2p(outcome, gossip_id);
352374
}
353375
P2pToValidator::ProposerSlashing(slashing, gossip_id) => {
354-
let outcome = self
376+
let outcome = match self
355377
.block_producer
356378
.handle_external_proposer_slashing(*slashing)
357-
.await?;
379+
.await {
380+
Ok(outcome) => outcome,
381+
Err(error) => {
382+
warn!("failed to handle proposer slashing: {error}");
383+
continue;
384+
}
385+
};
358386

359387
if matches!(outcome, PoolAdditionOutcome::Accept) {
360388
self.event_channels.send_proposer_slashing_event(&slashing);
@@ -363,10 +391,16 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
363391
self.handle_pool_addition_outcome_for_p2p(outcome, gossip_id);
364392
}
365393
P2pToValidator::VoluntaryExit(voluntary_exit, gossip_id) => {
366-
let outcome = self
394+
let outcome = match self
367395
.block_producer
368396
.handle_external_voluntary_exit(*voluntary_exit)
369-
.await?;
397+
.await {
398+
Ok(outcome) => outcome,
399+
Err(error) => {
400+
warn!("failed to handle voluntary exit: {error}");
401+
continue;
402+
}
403+
};
370404

371405
if matches!(outcome, PoolAdditionOutcome::Accept) {
372406
self.event_channels.send_voluntary_exit_event(&voluntary_exit);
@@ -447,7 +481,7 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
447481
}
448482
}
449483

450-
complete => break Ok(()),
484+
complete => break,
451485
}
452486
}
453487
}
@@ -585,11 +619,19 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
585619
.as_ref()
586620
.map(|metrics| metrics.validator_attest_tick_times.start_timer());
587621

588-
self.attest_and_start_aggregating(&wait_group, &slot_head)
589-
.await?;
622+
if let Err(error) = self
623+
.attest_and_start_aggregating(&wait_group, &slot_head)
624+
.await
625+
{
626+
error!("failed to produce and publish own attestations: {error:?}");
627+
}
590628

591-
self.publish_sync_committee_messages(&wait_group, &slot_head)
592-
.await?;
629+
if let Err(error) = self
630+
.publish_sync_committee_messages(&wait_group, &slot_head)
631+
.await
632+
{
633+
error!("failed to produce and publish own sync_committee messages: {error:?}");
634+
}
593635
}
594636
TickKind::Aggregate => {
595637
let _timer = self
@@ -757,13 +799,20 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
757799
}
758800
};
759801

760-
let beacon_block_option = block_build_context
802+
let beacon_block_option = match block_build_context
761803
.build_blinded_beacon_block(
762804
randao_reveal,
763805
execution_payload_header_handle,
764806
local_execution_payload_handle,
765807
)
766-
.await?;
808+
.await
809+
{
810+
Ok(block_opt) => block_opt,
811+
Err(error) => {
812+
warn!("failed to produce beacon block: {error}");
813+
return Ok(());
814+
}
815+
};
767816

768817
let Some((
769818
WithBlobsAndMev {
@@ -1261,13 +1310,13 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
12611310
}
12621311
}
12631312

1264-
async fn attest_gossip_block(&mut self, wait_group: &W, head: ChainLink<P>) -> Result<()> {
1313+
async fn attest_gossip_block(&mut self, wait_group: &W, head: ChainLink<P>) {
12651314
let Some(last_tick) = self.last_tick else {
1266-
return Ok(());
1315+
return;
12671316
};
12681317

12691318
if !(last_tick.slot == head.slot() && last_tick.is_before_attesting_interval()) {
1270-
return Ok(());
1319+
return;
12711320
}
12721321

12731322
let slot_head = SlotHead {
@@ -1283,19 +1332,25 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
12831332
// This noticeably improves rewards in Goerli.
12841333
// This is a deviation from the Honest Validator specification.
12851334
if Feature::PublishAttestationsEarly.is_enabled() {
1286-
self.attest_and_start_aggregating(wait_group, &slot_head)
1287-
.await?;
1335+
if let Err(error) = self
1336+
.attest_and_start_aggregating(wait_group, &slot_head)
1337+
.await
1338+
{
1339+
error!("failed to produce and publish own attestations: {error:?}");
1340+
}
12881341
}
12891342

12901343
// Publish sync committee messages late by default.
12911344
// This noticeably improves rewards in Goerli.
12921345
// This is a deviation from the Honest Validator specification.
12931346
if Feature::PublishSyncCommitteeMessagesEarly.is_enabled() {
1294-
self.publish_sync_committee_messages(wait_group, &slot_head)
1295-
.await?;
1347+
if let Err(error) = self
1348+
.publish_sync_committee_messages(wait_group, &slot_head)
1349+
.await
1350+
{
1351+
error!("failed to produce and publish own sync_committee messages: {error:?}");
1352+
}
12961353
}
1297-
1298-
Ok(())
12991354
}
13001355

13011356
fn next_graffiti(&mut self) -> H256 {

0 commit comments

Comments
 (0)