Refuse to sign sync committee messages when head is optimistic (#3191)

## Issue Addressed

Resolves #3151 

## Proposed Changes

When fetching duties for sync committee contributions, check the value of `execution_optimistic` of the head block from the BN and refuse to sign any sync committee messages `if execution_optimistic == true`.

## Additional Info
- Is backwards compatible with older BNs
- Finding a way to add test coverage for this would be prudent. Open to suggestions.
This commit is contained in:
Mac L
2022-07-27 00:51:05 +00:00
parent d316305411
commit 44fae52cd7
4 changed files with 70 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ use environment::RuntimeContext;
use eth2::types::BlockId;
use futures::future::join_all;
use futures::future::FutureExt;
use slog::{crit, debug, error, info, trace};
use slog::{crit, debug, error, info, trace, warn};
use slot_clock::SlotClock;
use std::collections::HashMap;
use std::ops::Deref;
@@ -174,17 +174,39 @@ impl<T: SlotClock + 'static, E: EthSpec> SyncCommitteeService<T, E> {
return Ok(());
}
// Fetch block root for `SyncCommitteeContribution`.
let block_root = self
// Fetch `block_root` and `execution_optimistic` for `SyncCommitteeContribution`.
let response = self
.beacon_nodes
.first_success(RequireSynced::Yes, |beacon_node| async move {
beacon_node.get_beacon_blocks_root(BlockId::Head).await
})
.await
.map_err(|e| e.to_string())?
.ok_or_else(|| format!("No block root found for slot {}", slot))?
.data
.root;
.ok_or_else(|| format!("No block root found for slot {}", slot))?;
let block_root = response.data.root;
if let Some(execution_optimistic) = response.execution_optimistic {
if execution_optimistic {
warn!(
log,
"Refusing to sign sync committee messages for optimistic head block";
"slot" => slot,
);
return Ok(());
}
} else if let Some(bellatrix_fork_epoch) = self.duties_service.spec.bellatrix_fork_epoch {
// If the slot is post Bellatrix, do not sign messages when we cannot verify the
// optimistic status of the head block.
if slot.epoch(E::slots_per_epoch()) > bellatrix_fork_epoch {
warn!(
log,
"Refusing to sign sync committee messages for a head block with an unknown \
optimistic status";
"slot" => slot,
);
return Ok(());
}
}
// Spawn one task to publish all of the sync committee signatures.
let validator_duties = slot_duties.duties;