mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-03 12:54:27 +00:00
Add execute_payload to block_gen
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2084,6 +2084,7 @@ dependencies = [
|
|||||||
"slog",
|
"slog",
|
||||||
"task_executor",
|
"task_executor",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tree_hash",
|
||||||
"types",
|
"types",
|
||||||
"warp",
|
"warp",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -25,3 +25,4 @@ hex = "0.4.2"
|
|||||||
eth2_ssz_types = { path = "../../consensus/ssz_types"}
|
eth2_ssz_types = { path = "../../consensus/ssz_types"}
|
||||||
lru = "0.6.0"
|
lru = "0.6.0"
|
||||||
exit-future = "0.2.0"
|
exit-future = "0.2.0"
|
||||||
|
tree_hash = { path = "../../consensus/tree_hash"}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use crate::engine_api::http::JsonPreparePayloadRequest;
|
use crate::engine_api::{http::JsonPreparePayloadRequest, ExecutePayloadResponse};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use tree_hash::TreeHash;
|
||||||
use types::{EthSpec, ExecutionPayload, Hash256, Uint256};
|
use types::{EthSpec, ExecutionPayload, Hash256, Uint256};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
@@ -24,6 +25,7 @@ pub struct ExecutionBlockGenerator<T: EthSpec> {
|
|||||||
/*
|
/*
|
||||||
* PoS block parameters
|
* PoS block parameters
|
||||||
*/
|
*/
|
||||||
|
pub pending_payloads: HashMap<Hash256, ExecutionPayload<T>>,
|
||||||
pub merge_blocks: HashMap<Hash256, ExecutionPayload<T>>,
|
pub merge_blocks: HashMap<Hash256, ExecutionPayload<T>>,
|
||||||
pub merge_block_numbers: HashMap<u64, Hash256>,
|
pub merge_block_numbers: HashMap<u64, Hash256>,
|
||||||
pub latest_merge_block: Option<u64>,
|
pub latest_merge_block: Option<u64>,
|
||||||
@@ -40,6 +42,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
|
|||||||
terminal_total_difficulty,
|
terminal_total_difficulty,
|
||||||
terminal_block_number,
|
terminal_block_number,
|
||||||
// PoS params
|
// PoS params
|
||||||
|
pending_payloads: <_>::default(),
|
||||||
merge_blocks: <_>::default(),
|
merge_blocks: <_>::default(),
|
||||||
merge_block_numbers: <_>::default(),
|
merge_block_numbers: <_>::default(),
|
||||||
latest_merge_block: None,
|
latest_merge_block: None,
|
||||||
@@ -124,7 +127,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
|
|||||||
let id = self.next_payload_id;
|
let id = self.next_payload_id;
|
||||||
self.next_payload_id += 1;
|
self.next_payload_id += 1;
|
||||||
|
|
||||||
let execution_payload = ExecutionPayload {
|
let mut execution_payload = ExecutionPayload {
|
||||||
parent_hash: payload.parent_hash,
|
parent_hash: payload.parent_hash,
|
||||||
coinbase: payload.fee_recipient,
|
coinbase: payload.fee_recipient,
|
||||||
receipt_root: Hash256::repeat_byte(42),
|
receipt_root: Hash256::repeat_byte(42),
|
||||||
@@ -141,15 +144,33 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
|
|||||||
transactions: vec![].into(),
|
transactions: vec![].into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
execution_payload.block_hash = execution_payload.tree_hash_root();
|
||||||
|
|
||||||
self.payload_ids.insert(id, execution_payload);
|
self.payload_ids.insert(id, execution_payload);
|
||||||
|
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_payload_id(&mut self, id: u64) -> Option<ExecutionPayload<T>> {
|
pub fn get_payload(&mut self, id: u64) -> Option<ExecutionPayload<T>> {
|
||||||
self.payload_ids.remove(&id)
|
self.payload_ids.remove(&id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn execute_payload(&mut self, payload: ExecutionPayload<T>) -> ExecutePayloadResponse {
|
||||||
|
let parent = if let Some(parent) = self.block_by_hash(payload.parent_hash) {
|
||||||
|
parent
|
||||||
|
} else {
|
||||||
|
return ExecutePayloadResponse::Invalid;
|
||||||
|
};
|
||||||
|
|
||||||
|
if payload.block_number != parent.block_number + 1 {
|
||||||
|
return ExecutePayloadResponse::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.pending_payloads.insert(payload.block_hash, payload);
|
||||||
|
|
||||||
|
ExecutePayloadResponse::Valid
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert_pos_block(&mut self, number: u64) -> Result<(), String> {
|
pub fn insert_pos_block(&mut self, number: u64) -> Result<(), String> {
|
||||||
self.sanitize_pos_block_number(number)?;
|
self.sanitize_pos_block_number(number)?;
|
||||||
self.latest_merge_block = Some(number);
|
self.latest_merge_block = Some(number);
|
||||||
|
|||||||
Reference in New Issue
Block a user