mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Don't create a execution payload with same timestamp as terminal block (#3331)
## Issue Addressed Resolves #3316 ## Proposed Changes This PR fixes an issue where lighthouse created a transition block with `block.execution_payload().timestamp == terminal_block.timestamp` if the terminal block was created at the slot boundary.
This commit is contained in:
@@ -3908,14 +3908,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
ForkName::Base | ForkName::Altair => return Ok(()),
|
||||
_ => {
|
||||
// We are post-bellatrix
|
||||
if execution_layer
|
||||
if let Some(payload_attributes) = execution_layer
|
||||
.payload_attributes(next_slot, params.head_root)
|
||||
.await
|
||||
.is_some()
|
||||
{
|
||||
// We are a proposer, check for terminal_pow_block_hash
|
||||
if let Some(terminal_pow_block_hash) = execution_layer
|
||||
.get_terminal_pow_block_hash(&self.spec)
|
||||
.get_terminal_pow_block_hash(&self.spec, payload_attributes.timestamp)
|
||||
.await
|
||||
.map_err(Error::ForkchoiceUpdate)?
|
||||
{
|
||||
|
||||
@@ -393,7 +393,7 @@ where
|
||||
}
|
||||
|
||||
let terminal_pow_block_hash = execution_layer
|
||||
.get_terminal_pow_block_hash(spec)
|
||||
.get_terminal_pow_block_hash(spec, timestamp)
|
||||
.await
|
||||
.map_err(BlockProductionError::TerminalPoWBlockLookupFailed)?;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ use rayon::prelude::*;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slog::Logger;
|
||||
use slot_clock::TestingSlotClock;
|
||||
use state_processing::per_block_processing::compute_timestamp_at_slot;
|
||||
use state_processing::{
|
||||
state_advance::{complete_state_advance, partial_state_advance},
|
||||
StateRootStrategy,
|
||||
@@ -521,6 +522,11 @@ where
|
||||
self.chain.head_beacon_state_cloned()
|
||||
}
|
||||
|
||||
pub fn get_timestamp_at_slot(&self) -> u64 {
|
||||
let state = self.get_current_state();
|
||||
compute_timestamp_at_slot(&state, &self.spec).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_current_state_and_root(&self) -> (BeaconState<E>, Hash256) {
|
||||
let head = self.chain.head_snapshot();
|
||||
let state_root = head.beacon_state_root();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![cfg(not(debug_assertions))] // Tests run too slow in debug.
|
||||
|
||||
use beacon_chain::test_utils::BeaconChainHarness;
|
||||
use execution_layer::test_utils::{generate_pow_block, DEFAULT_TERMINAL_BLOCK};
|
||||
use execution_layer::test_utils::{generate_pow_block, Block, DEFAULT_TERMINAL_BLOCK};
|
||||
use types::*;
|
||||
|
||||
const VALIDATOR_COUNT: usize = 32;
|
||||
@@ -22,6 +22,7 @@ fn verify_execution_payload_chain<T: EthSpec>(chain: &[FullPayload<T>]) {
|
||||
prev_ep.execution_payload.block_number + 1,
|
||||
ep.execution_payload.block_number
|
||||
);
|
||||
assert!(ep.execution_payload.timestamp > prev_ep.execution_payload.timestamp);
|
||||
}
|
||||
prev_ep = Some(ep.clone());
|
||||
}
|
||||
@@ -169,6 +170,30 @@ async fn base_altair_merge_with_terminal_block_after_fork() {
|
||||
.move_to_terminal_block()
|
||||
.unwrap();
|
||||
|
||||
// Add a slot duration to get to the next slot
|
||||
let timestamp = harness.get_timestamp_at_slot() + harness.spec.seconds_per_slot;
|
||||
|
||||
harness
|
||||
.execution_block_generator()
|
||||
.modify_last_block(|block| {
|
||||
if let Block::PoW(terminal_block) = block {
|
||||
terminal_block.timestamp = timestamp;
|
||||
}
|
||||
});
|
||||
|
||||
harness.extend_slots(1).await;
|
||||
|
||||
let one_after_merge_head = &harness.chain.head_snapshot().beacon_block;
|
||||
assert_eq!(
|
||||
*one_after_merge_head
|
||||
.message()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap(),
|
||||
FullPayload::default()
|
||||
);
|
||||
assert_eq!(one_after_merge_head.slot(), merge_fork_slot + 2);
|
||||
|
||||
/*
|
||||
* Next merge block should include an exec payload.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user