mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-30 19:23:50 +00:00
Indicate that invalid blocks are optimistic (#3383)
## Issue Addressed NA ## Proposed Changes This PR will make Lighthouse return blocks with invalid payloads via the API with `execution_optimistic = true`. This seems a bit awkward, however I think it's better than returning a 404 or some other error. Let's consider the case where the only possible head is invalid (#3370 deals with this). In such a scenario all of the duties endpoints will start failing because the head is invalid. I think it would be better if the duties endpoints continue to work, because it's likely that even though the head is invalid the duties are still based upon valid blocks and we want the VC to have them cached. There's no risk to the VC here because we won't actually produce an attestation pointing to an invalid head. Ultimately, I don't think it's particularly important for us to distinguish between optimistic and invalid blocks on the API. Neither should be trusted and the only *real* reason that we track this is so we can try and fork around the invalid blocks. ## Additional Info - ~~Blocked on #3370~~
This commit is contained in:
@@ -68,7 +68,7 @@ fn cached_attestation_duties<T: BeaconChainTypes>(
|
||||
duties,
|
||||
request_indices,
|
||||
dependent_root,
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
chain,
|
||||
)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
|
||||
head.beacon_state_root(),
|
||||
head.beacon_state
|
||||
.clone_with(CloneConfig::committee_caches_only()),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -33,7 +33,7 @@ impl BlockId {
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
Ok((
|
||||
cached_head.head_block_root(),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
))
|
||||
}
|
||||
CoreBlockId::Genesis => Ok((chain.genesis_block_root, false)),
|
||||
@@ -53,7 +53,7 @@ impl BlockId {
|
||||
}
|
||||
CoreBlockId::Slot(slot) => {
|
||||
let execution_optimistic = chain
|
||||
.is_optimistic_head()
|
||||
.is_optimistic_or_invalid_head()
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
let root = chain
|
||||
.block_root_at_slot(*slot, WhenSlotSkipped::None)
|
||||
@@ -85,7 +85,7 @@ impl BlockId {
|
||||
let execution_optimistic = chain
|
||||
.canonical_head
|
||||
.fork_choice_read_lock()
|
||||
.is_optimistic_block(root)
|
||||
.is_optimistic_or_invalid_block(root)
|
||||
.map_err(BeaconChainError::ForkChoiceError)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
Ok((*root, execution_optimistic))
|
||||
@@ -112,7 +112,7 @@ impl BlockId {
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
Ok((
|
||||
cached_head.snapshot.beacon_block.clone_as_blinded(),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
))
|
||||
}
|
||||
CoreBlockId::Slot(slot) => {
|
||||
@@ -167,7 +167,7 @@ impl BlockId {
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
Ok((
|
||||
cached_head.snapshot.beacon_block.clone(),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
))
|
||||
}
|
||||
CoreBlockId::Slot(slot) => {
|
||||
|
||||
@@ -894,7 +894,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
(
|
||||
cached_head.head_block_root(),
|
||||
cached_head.snapshot.beacon_block.clone_as_blinded(),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
)
|
||||
}
|
||||
// Only the parent root parameter, do a forwards-iterator lookup.
|
||||
@@ -1608,7 +1608,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
chain
|
||||
.canonical_head
|
||||
.fork_choice_read_lock()
|
||||
.is_optimistic_block(&root)
|
||||
.is_optimistic_or_invalid_block(&root)
|
||||
.ok()
|
||||
} else {
|
||||
return Err(unsupported_version_rejection(endpoint_version));
|
||||
@@ -1699,7 +1699,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
let sync_distance = current_slot - head_slot;
|
||||
|
||||
let is_optimistic = chain
|
||||
.is_optimistic_head()
|
||||
.is_optimistic_or_invalid_head()
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
|
||||
let syncing_data = api_types::SyncingData {
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn proposer_duties<T: BeaconChainTypes>(
|
||||
chain,
|
||||
request_epoch,
|
||||
dependent_root,
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
proposers,
|
||||
)
|
||||
} else if request_epoch
|
||||
@@ -104,7 +104,7 @@ fn try_proposer_duties_from_cache<T: BeaconChainTypes>(
|
||||
.map_err(warp_utils::reject::beacon_state_error)?;
|
||||
let head_epoch = head_block.slot().epoch(T::EthSpec::slots_per_epoch());
|
||||
let execution_optimistic = chain
|
||||
.is_optimistic_head_block(head_block)
|
||||
.is_optimistic_or_invalid_head_block(head_block)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
|
||||
let dependent_root = match head_epoch.cmp(&request_epoch) {
|
||||
@@ -168,7 +168,7 @@ fn compute_and_cache_proposer_duties<T: BeaconChainTypes>(
|
||||
chain,
|
||||
current_epoch,
|
||||
dependent_root,
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
indices,
|
||||
)
|
||||
}
|
||||
@@ -194,7 +194,7 @@ fn compute_historic_proposer_duties<T: BeaconChainTypes>(
|
||||
head.beacon_state_root(),
|
||||
head.beacon_state
|
||||
.clone_with(CloneConfig::committee_caches_only()),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -28,7 +28,7 @@ impl StateId {
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
return Ok((
|
||||
cached_head.head_state_root(),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
));
|
||||
}
|
||||
CoreStateId::Genesis => return Ok((chain.genesis_state_root, false)),
|
||||
@@ -45,7 +45,7 @@ impl StateId {
|
||||
CoreStateId::Slot(slot) => (
|
||||
*slot,
|
||||
chain
|
||||
.is_optimistic_head()
|
||||
.is_optimistic_or_invalid_head()
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?,
|
||||
),
|
||||
CoreStateId::Root(root) => {
|
||||
@@ -58,7 +58,7 @@ impl StateId {
|
||||
let execution_optimistic = chain
|
||||
.canonical_head
|
||||
.fork_choice_read_lock()
|
||||
.is_optimistic_block_no_fallback(&hot_summary.latest_block_root)
|
||||
.is_optimistic_or_invalid_block_no_fallback(&hot_summary.latest_block_root)
|
||||
.map_err(BeaconChainError::ForkChoiceError)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
return Ok((*root, execution_optimistic));
|
||||
@@ -74,7 +74,7 @@ impl StateId {
|
||||
.finalized_checkpoint
|
||||
.root;
|
||||
let execution_optimistic = fork_choice
|
||||
.is_optimistic_block_no_fallback(&finalized_root)
|
||||
.is_optimistic_or_invalid_block_no_fallback(&finalized_root)
|
||||
.map_err(BeaconChainError::ForkChoiceError)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
return Ok((*root, execution_optimistic));
|
||||
@@ -133,7 +133,7 @@ impl StateId {
|
||||
.snapshot
|
||||
.beacon_state
|
||||
.clone_with_only_committee_caches(),
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
));
|
||||
}
|
||||
CoreStateId::Slot(slot) => (self.root(chain)?, Some(*slot)),
|
||||
@@ -198,7 +198,7 @@ impl StateId {
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
return func(
|
||||
&head.snapshot.beacon_state,
|
||||
execution_status.is_optimistic(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
);
|
||||
}
|
||||
_ => self.state(chain)?,
|
||||
@@ -241,7 +241,7 @@ pub fn checkpoint_slot_and_execution_optimistic<T: BeaconChainTypes>(
|
||||
};
|
||||
|
||||
let execution_optimistic = fork_choice
|
||||
.is_optimistic_block_no_fallback(root)
|
||||
.is_optimistic_or_invalid_block_no_fallback(root)
|
||||
.map_err(BeaconChainError::ForkChoiceError)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn sync_committee_duties<T: BeaconChainTypes>(
|
||||
// Even when computing duties from state, any block roots pulled using the request epoch are
|
||||
// still dependent on the head. So using `is_optimistic_head` is fine for both cases.
|
||||
let execution_optimistic = chain
|
||||
.is_optimistic_head()
|
||||
.is_optimistic_or_invalid_head()
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
|
||||
// Try using the head's sync committees to satisfy the request. This should be sufficient for
|
||||
|
||||
Reference in New Issue
Block a user