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:
@@ -60,12 +60,14 @@ impl<T: EthSpec> Block<T> {
|
||||
block_number: block.block_number,
|
||||
parent_hash: block.parent_hash,
|
||||
total_difficulty: block.total_difficulty,
|
||||
timestamp: block.timestamp,
|
||||
},
|
||||
Block::PoS(payload) => ExecutionBlock {
|
||||
block_hash: payload.block_hash,
|
||||
block_number: payload.block_number,
|
||||
parent_hash: payload.parent_hash,
|
||||
total_difficulty,
|
||||
timestamp: payload.timestamp,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -100,6 +102,7 @@ pub struct PoWBlock {
|
||||
pub block_hash: ExecutionBlockHash,
|
||||
pub parent_hash: ExecutionBlockHash,
|
||||
pub total_difficulty: Uint256,
|
||||
pub timestamp: u64,
|
||||
}
|
||||
|
||||
pub struct ExecutionBlockGenerator<T: EthSpec> {
|
||||
@@ -266,6 +269,26 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn modify_last_block(&mut self, block_modifier: impl FnOnce(&mut Block<T>)) {
|
||||
if let Some((last_block_hash, block_number)) =
|
||||
self.block_hashes.keys().max().and_then(|block_number| {
|
||||
self.block_hashes
|
||||
.get(block_number)
|
||||
.map(|block| (block, *block_number))
|
||||
})
|
||||
{
|
||||
let mut block = self.blocks.remove(last_block_hash).unwrap();
|
||||
block_modifier(&mut block);
|
||||
// Update the block hash after modifying the block
|
||||
match &mut block {
|
||||
Block::PoW(b) => b.block_hash = ExecutionBlockHash::from_root(b.tree_hash_root()),
|
||||
Block::PoS(b) => b.block_hash = ExecutionBlockHash::from_root(b.tree_hash_root()),
|
||||
}
|
||||
self.block_hashes.insert(block_number, block.block_hash());
|
||||
self.blocks.insert(block.block_hash(), block);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_payload(&mut self, id: &PayloadId) -> Option<ExecutionPayload<T>> {
|
||||
self.payload_ids.get(id).cloned()
|
||||
}
|
||||
@@ -423,6 +446,7 @@ pub fn generate_pow_block(
|
||||
block_hash: ExecutionBlockHash::zero(),
|
||||
parent_hash,
|
||||
total_difficulty,
|
||||
timestamp: block_number,
|
||||
};
|
||||
|
||||
block.block_hash = ExecutionBlockHash::from_root(block.tree_hash_root());
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::engine_api::{
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use environment::null_logger;
|
||||
use execution_block_generator::{Block, PoWBlock};
|
||||
use execution_block_generator::PoWBlock;
|
||||
use handle_rpc::handle_rpc;
|
||||
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -21,7 +21,7 @@ use tokio::{runtime, sync::oneshot};
|
||||
use types::{EthSpec, ExecutionBlockHash, Uint256};
|
||||
use warp::{http::StatusCode, Filter, Rejection};
|
||||
|
||||
pub use execution_block_generator::{generate_pow_block, ExecutionBlockGenerator};
|
||||
pub use execution_block_generator::{generate_pow_block, Block, ExecutionBlockGenerator};
|
||||
pub use mock_execution_layer::MockExecutionLayer;
|
||||
|
||||
pub const DEFAULT_TERMINAL_DIFFICULTY: u64 = 6400;
|
||||
@@ -334,6 +334,7 @@ impl<T: EthSpec> MockServer<T> {
|
||||
block_hash,
|
||||
parent_hash,
|
||||
total_difficulty,
|
||||
timestamp: block_number,
|
||||
});
|
||||
|
||||
self.ctx
|
||||
|
||||
Reference in New Issue
Block a user