Skip to content

Commit

Permalink
rename ELHttpClient -> EngineRpc
Browse files Browse the repository at this point in the history
  • Loading branch information
sapinb committed Jul 27, 2024
1 parent 1f15139 commit d710f43
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
28 changes: 14 additions & 14 deletions crates/evmexec/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use alpen_vertex_state::id::L2BlockId;

use crate::block::EVML2Block;
use crate::el_payload::ElPayload;
use crate::http_client::ELHttpClient;
use crate::http_client::EngineRpc;

fn address_from_slice(slice: &[u8]) -> Option<Address> {
let slice: Option<[u8; 20]> = slice.try_into().ok();
Expand All @@ -31,32 +31,32 @@ fn address_from_slice(slice: &[u8]) -> Option<Address> {
/// (head, safe, finalized)
pub type FCS = (L2BlockId, Option<L2BlockId>, Option<L2BlockId>);

pub struct RpcExecEngineCtl<T: ELHttpClient, D: L2DataProvider> {
pub struct RpcExecEngineCtl<T: EngineRpc, P: L2DataProvider> {
client: T,
fork_choice_state: Mutex<ForkchoiceState>,
tokio_handle: Handle,
database: Arc<D>,
l2_provider: Arc<P>,
}

impl<T: ELHttpClient, D: L2DataProvider> RpcExecEngineCtl<T, D> {
impl<T: EngineRpc, P: L2DataProvider> RpcExecEngineCtl<T, P> {
pub fn new(
client: T,
fork_choice_state: ForkchoiceState,
handle: Handle,
database: Arc<D>,
l2_provider: Arc<P>,
) -> Self {
Self {
client,
fork_choice_state: Mutex::new(fork_choice_state),
tokio_handle: handle,
database,
l2_provider,
}
}
}

impl<T: ELHttpClient, D: L2DataProvider> RpcExecEngineCtl<T, D> {
impl<T: EngineRpc, P: L2DataProvider> RpcExecEngineCtl<T, P> {
fn get_l2block(&self, l2_block_id: &L2BlockId) -> anyhow::Result<L2BlockBundle> {
self.database
self.l2_provider
.get_block_data(*l2_block_id)?
.ok_or(anyhow::anyhow!("missing L2Block"))
}
Expand Down Expand Up @@ -274,7 +274,7 @@ impl<T: ELHttpClient, D: L2DataProvider> RpcExecEngineCtl<T, D> {
}
}

impl<T: ELHttpClient, D: L2DataProvider> ExecEngineCtl for RpcExecEngineCtl<T, D> {
impl<T: EngineRpc, P: L2DataProvider> ExecEngineCtl for RpcExecEngineCtl<T, P> {
fn submit_payload(&self, payload: ExecPayloadData) -> EngineResult<BlockStatus> {
self.tokio_handle.block_on(self.submit_new_payload(payload))
}
Expand Down Expand Up @@ -361,7 +361,7 @@ mod tests {
use alpen_vertex_evmctl::messages::PayloadEnv;
use alpen_vertex_primitives::buf::Buf32;

use crate::http_client::MockELHttpClient;
use crate::http_client::MockEngineRpc;

use super::*;

Expand Down Expand Up @@ -392,7 +392,7 @@ mod tests {

#[tokio::test]
async fn test_update_block_state() {
let mut mock_client = MockELHttpClient::new();
let mut mock_client = MockEngineRpc::new();

let fcs_partial = ForkchoiceStatePartial {
head_block_hash: Some(B256::random()),
Expand Down Expand Up @@ -424,7 +424,7 @@ mod tests {

#[tokio::test]
async fn test_build_block_from_mempool() {
let mut mock_client = MockELHttpClient::new();
let mut mock_client = MockEngineRpc::new();
let fcs = ForkchoiceState::default();

mock_client
Expand Down Expand Up @@ -466,7 +466,7 @@ mod tests {

#[tokio::test]
async fn test_get_payload_status() {
let mut mock_client = MockELHttpClient::new();
let mut mock_client = MockEngineRpc::new();
let fcs = ForkchoiceState::default();

mock_client.expect_get_payload_v2().returning(move |_| {
Expand All @@ -490,7 +490,7 @@ mod tests {

#[tokio::test]
async fn test_submit_new_payload() {
let mut mock_client = MockELHttpClient::new();
let mut mock_client = MockEngineRpc::new();
let fcs = ForkchoiceState::default();

let el_payload = ElPayload {
Expand Down
10 changes: 5 additions & 5 deletions crates/evmexec/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type RpcResult<T> = Result<T, jsonrpsee::core::ClientError>;

#[allow(async_fn_in_trait)]
#[cfg_attr(test, automock)]
pub trait ELHttpClient {
pub trait EngineRpc {
async fn fork_choice_updated_v2(
&self,
fork_choice_state: ForkchoiceState,
Expand All @@ -50,13 +50,13 @@ pub trait ELHttpClient {
}

#[derive(Debug, Clone)]
pub struct ELHttpClientImpl {
pub struct EngineRpcClient {
client: Arc<HttpClient<AuthClientService<HttpBackend>>>,
}

impl ELHttpClientImpl {
impl EngineRpcClient {
pub fn from_url_secret(http_url: &str, secret: JwtSecret) -> Self {
ELHttpClientImpl {
EngineRpcClient {
client: Arc::new(http_client(http_url, secret)),
}
}
Expand All @@ -66,7 +66,7 @@ impl ELHttpClientImpl {
}
}

impl ELHttpClient for ELHttpClientImpl {
impl EngineRpc for EngineRpcClient {
async fn fork_choice_updated_v2(
&self,
fork_choice_state: ForkchoiceState,
Expand Down
2 changes: 1 addition & 1 deletion crates/evmexec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub mod engine;
pub mod preloaded_storage;

pub use fcs::fork_choice_state_initial;
pub use http_client::ELHttpClientImpl as ELHttpClient;
pub use http_client::EngineRpcClient;
4 changes: 2 additions & 2 deletions sequencer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use alpen_vertex_consensus_logic::duty_executor::{self, IdentityData, IdentityKe
use alpen_vertex_consensus_logic::sync_manager;
use alpen_vertex_consensus_logic::sync_manager::SyncManager;
use alpen_vertex_db::traits::Database;
use alpen_vertex_evmexec::{fork_choice_state_initial, ELHttpClient};
use alpen_vertex_evmexec::{fork_choice_state_initial, EngineRpcClient};
use alpen_vertex_primitives::buf::Buf32;
use alpen_vertex_primitives::{block_credential, params::*};
use alpen_vertex_rpc_api::AlpenApiServer;
Expand Down Expand Up @@ -163,7 +163,7 @@ fn main_inner(args: Args) -> anyhow::Result<()> {

// Init engine controller.
let reth_jwtsecret = load_jwtsecret(&config.exec.reth.secret)?;
let client = ELHttpClient::from_url_secret(&config.exec.reth.rpc_url, reth_jwtsecret);
let client = EngineRpcClient::from_url_secret(&config.exec.reth.rpc_url, reth_jwtsecret);

let initial_fcs = fork_choice_state_initial(database.clone(), params.rollup())?;
let eng_ctl = alpen_vertex_evmexec::engine::RpcExecEngineCtl::new(
Expand Down

0 comments on commit d710f43

Please sign in to comment.