mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
Implement engine API v1.0.0-alpha.4 (#2810)
* Added ForkchoiceUpdatedV1 & GetPayloadV1 * Added ExecutePayloadV1 * Added new geth test vectors * Separated Json Object/Serialization Code into file * Deleted code/tests for Requests Removed from spec * Finally fixed serialization of null '0x' * Made Naming of JSON Structs Consistent * Fix clippy lints * Remove u64 payload id * Remove unused serde impls * Swap to [u8; 8] for payload id * Tidy * Adjust some block gen return vals * Tidy * Add fallback when payload id is unknown * Remove comment Co-authored-by: Mark Mackey <mark@sigmaprime.io>
This commit is contained in:
@@ -4,11 +4,13 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const LATEST_TAG: &str = "latest";
|
||||
|
||||
use crate::engines::ForkChoiceState;
|
||||
pub use types::{Address, EthSpec, ExecutionPayload, Hash256, Uint256};
|
||||
|
||||
pub mod http;
|
||||
pub mod json_structures;
|
||||
|
||||
pub type PayloadId = u64;
|
||||
pub type PayloadId = [u8; 8];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
@@ -23,6 +25,7 @@ pub enum Error {
|
||||
ExecutionBlockNotFound(Hash256),
|
||||
ExecutionHeadBlockNotFound,
|
||||
ParentHashEqualsBlockHash(Hash256),
|
||||
PayloadIdUnavailable,
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for Error {
|
||||
@@ -52,50 +55,35 @@ pub trait EngineApi {
|
||||
block_hash: Hash256,
|
||||
) -> Result<Option<ExecutionBlock>, Error>;
|
||||
|
||||
async fn prepare_payload(
|
||||
&self,
|
||||
parent_hash: Hash256,
|
||||
timestamp: u64,
|
||||
random: Hash256,
|
||||
fee_recipient: Address,
|
||||
) -> Result<PayloadId, Error>;
|
||||
|
||||
async fn execute_payload<T: EthSpec>(
|
||||
async fn execute_payload_v1<T: EthSpec>(
|
||||
&self,
|
||||
execution_payload: ExecutionPayload<T>,
|
||||
) -> Result<ExecutePayloadResponse, Error>;
|
||||
|
||||
async fn get_payload<T: EthSpec>(
|
||||
async fn get_payload_v1<T: EthSpec>(
|
||||
&self,
|
||||
payload_id: PayloadId,
|
||||
) -> Result<ExecutionPayload<T>, Error>;
|
||||
|
||||
async fn consensus_validated(
|
||||
async fn forkchoice_updated_v1(
|
||||
&self,
|
||||
block_hash: Hash256,
|
||||
status: ConsensusStatus,
|
||||
) -> Result<(), Error>;
|
||||
|
||||
async fn forkchoice_updated(
|
||||
&self,
|
||||
head_block_hash: Hash256,
|
||||
finalized_block_hash: Hash256,
|
||||
) -> Result<(), Error>;
|
||||
forkchoice_state: ForkChoiceState,
|
||||
payload_attributes: Option<PayloadAttributes>,
|
||||
) -> Result<ForkchoiceUpdatedResponse, Error>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum ExecutePayloadResponse {
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum ExecutePayloadResponseStatus {
|
||||
Valid,
|
||||
Invalid,
|
||||
Syncing,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum ConsensusStatus {
|
||||
Valid,
|
||||
Invalid,
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExecutePayloadResponse {
|
||||
pub status: ExecutePayloadResponseStatus,
|
||||
pub latest_valid_hash: Option<Hash256>,
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
|
||||
@@ -114,3 +102,21 @@ pub struct ExecutionBlock {
|
||||
pub parent_hash: Hash256,
|
||||
pub total_difficulty: Uint256,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct PayloadAttributes {
|
||||
pub timestamp: u64,
|
||||
pub random: Hash256,
|
||||
pub fee_recipient: Address,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum ForkchoiceUpdatedResponseStatus {
|
||||
Success,
|
||||
Syncing,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ForkchoiceUpdatedResponse {
|
||||
pub status: ForkchoiceUpdatedResponseStatus,
|
||||
pub payload_id: Option<PayloadId>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user