mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 20:39:10 +00:00
Don't return errors when fork choice fails (#3370)
## Issue Addressed
NA
## Proposed Changes
There are scenarios where the only viable head will have an invalid execution payload, in this scenario the `get_head` function on `proto_array` will return an error. We must recover from this scenario by importing blocks from the network.
This PR stops `BeaconChain::recompute_head` from returning an error so that we can't accidentally start down-scoring peers or aborting block import just because the current head has an invalid payload.
## Reviewer Notes
The following changes are included:
1. Allow `fork_choice.get_head` to fail gracefully in `BeaconChain::process_block` when trying to update the `early_attester_cache`; simply don't add the block to the cache rather than aborting the entire process.
1. Don't return an error from `BeaconChain::recompute_head_at_current_slot` and `BeaconChain::recompute_head` to defensively prevent calling functions from aborting any process just because the fork choice function failed to run.
- This should have practically no effect, since most callers were still continuing if recomputing the head failed.
- The outlier is that the API will return 200 rather than a 500 when fork choice fails.
1. Add the `ProtoArrayForkChoice::set_all_blocks_to_optimistic` function to recover from the scenario where we've rebooted and the persisted fork choice has an invalid head.
This commit is contained in:
@@ -2128,7 +2128,7 @@ async fn weak_subjectivity_sync() {
|
||||
.process_block(Arc::new(full_block), CountUnrealized::True)
|
||||
.await
|
||||
.unwrap();
|
||||
beacon_chain.recompute_head_at_current_slot().await.unwrap();
|
||||
beacon_chain.recompute_head_at_current_slot().await;
|
||||
|
||||
// Check that the new block's state can be loaded correctly.
|
||||
let state_root = block.state_root();
|
||||
@@ -2460,11 +2460,7 @@ async fn revert_minority_fork_on_resume() {
|
||||
.build();
|
||||
|
||||
// Head should now be just before the fork.
|
||||
resumed_harness
|
||||
.chain
|
||||
.recompute_head_at_current_slot()
|
||||
.await
|
||||
.unwrap();
|
||||
resumed_harness.chain.recompute_head_at_current_slot().await;
|
||||
assert_eq!(resumed_harness.head_slot(), fork_slot - 1);
|
||||
|
||||
// Head track should know the canonical head and the rogue head.
|
||||
@@ -2482,11 +2478,7 @@ async fn revert_minority_fork_on_resume() {
|
||||
.unwrap();
|
||||
|
||||
// The canonical head should be the block from the majority chain.
|
||||
resumed_harness
|
||||
.chain
|
||||
.recompute_head_at_current_slot()
|
||||
.await
|
||||
.unwrap();
|
||||
resumed_harness.chain.recompute_head_at_current_slot().await;
|
||||
assert_eq!(resumed_harness.head_slot(), block.slot());
|
||||
assert_eq!(resumed_harness.head_block_root(), block.canonical_root());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user