|
| 1 | +use alloy_primitives::{Address, Bytes, B256, U256}; |
| 2 | +use alloy_rpc_types::{ |
| 3 | + engine::{ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus}, |
| 4 | + Block, BlockId, BlockNumberOrTag, TransactionReceipt, |
| 5 | +}; |
| 6 | +use jsonrpsee::proc_macros::rpc; |
| 7 | +use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpPayloadAttributes}; |
| 8 | + |
| 9 | +use super::rpc::RpcResult; |
| 10 | + |
| 11 | +pub const CAPABILITIES: &[&str] = &["engine_forkchoiceUpdatedV3", "engine_getPayloadV3", "engine_newPayloadV3"]; |
| 12 | + |
| 13 | +/// The Engine API is used by the consensus layer to interact with the execution layer. Here we |
| 14 | +/// implement a minimal subset of the API for the gateway to return blocks to the op-node |
| 15 | +/// |
| 16 | +/// ref: https://github.com/ethereum/execution-apis/tree/main/src/engine |
| 17 | +/// ref: https://specs.optimism.io/protocol/exec-engine.html#engine-api |
| 18 | +/// |
| 19 | +/// NOTE: currently only v3 endpoints are supported |
| 20 | +#[rpc(client, server, namespace = "engine")] |
| 21 | +pub trait EngineApi { |
| 22 | + /// Used by the op-node to set which blocks are considered canonical. |
| 23 | + /// |
| 24 | + /// If payload attributes is set then block production for next block should start and a |
| 25 | + /// `PayloadId` is returned to be called in `get_payload` |
| 26 | + #[method(name = "forkchoiceUpdatedV3")] |
| 27 | + async fn fork_choice_updated_v3( |
| 28 | + &self, |
| 29 | + fork_choice_state: ForkchoiceState, |
| 30 | + payload_attributes: Option<OpPayloadAttributes>, |
| 31 | + ) -> RpcResult<ForkchoiceUpdated>; |
| 32 | + |
| 33 | + /// Used to validate an execution payload |
| 34 | + #[method(name = "newPayloadV3")] |
| 35 | + async fn new_payload_v3( |
| 36 | + &self, |
| 37 | + payload: ExecutionPayloadV3, |
| 38 | + versioned_hashes: Vec<B256>, |
| 39 | + parent_beacon_block_root: B256, |
| 40 | + ) -> RpcResult<PayloadStatus>; |
| 41 | + |
| 42 | + /// Used to fetch an execution payload from a previous `payload_id` set in `forkchoiceUpdatedV3` |
| 43 | + #[method(name = "getPayloadV3")] |
| 44 | + async fn get_payload_v3(&self, payload_id: PayloadId) -> RpcResult<OpExecutionPayloadEnvelopeV3>; |
| 45 | +} |
| 46 | + |
| 47 | +/// The Eth API is used to interact with the EL directly. |
| 48 | +/// |
| 49 | +/// This is a temporary API that the gateway implements to serve the latest preconf state, before a |
| 50 | +/// gossip protocol is implemented in op-node. Historical state will not be served from this API |
| 51 | +#[rpc(client, server, namespace = "eth")] |
| 52 | +pub trait EthApi { |
| 53 | + /// Sends signed transaction, returning its hash |
| 54 | + #[method(name = "sendRawTransaction")] |
| 55 | + async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<B256>; |
| 56 | + |
| 57 | + /// Returns the receipt of a transaction by transaction hash |
| 58 | + #[method(name = "getTransactionReceipt")] |
| 59 | + async fn transaction_receipt(&self, hash: B256) -> RpcResult<Option<TransactionReceipt>>; |
| 60 | + |
| 61 | + /// Returns the number of most recent block |
| 62 | + #[method(name = "blockNumber")] |
| 63 | + async fn block_number(&self) -> RpcResult<U256>; |
| 64 | + |
| 65 | + /// Returns a block with a given identifier |
| 66 | + #[method(name = "getBlockByNumber")] |
| 67 | + async fn block_by_number(&self, number: BlockNumberOrTag, full: bool) -> RpcResult<Option<Block>>; |
| 68 | + |
| 69 | + /// Returns information about a block by hash. |
| 70 | + #[method(name = "getBlockByHash")] |
| 71 | + async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<Block>>; |
| 72 | + |
| 73 | + /// Returns the nonce of a given address at a given block number. |
| 74 | + #[method(name = "getTransactionCount")] |
| 75 | + async fn transaction_count(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256>; |
| 76 | + |
| 77 | + /// Returns the balance of the account of given address. |
| 78 | + #[method(name = "getBalance")] |
| 79 | + async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256>; |
| 80 | +} |
0 commit comments