kona_node_service/actors/sequencer/
conductor.rs

1use alloy_rpc_client::ReqwestClient;
2use alloy_transport::{RpcError, TransportErrorKind};
3use op_alloy_rpc_types_engine::OpExecutionPayloadEnvelope;
4use url::Url;
5
6/// A client for communicating with the conductor service via RPC
7#[derive(Debug, Clone)]
8pub struct ConductorClient {
9    /// The inner RPC provider
10    rpc: ReqwestClient,
11}
12
13impl ConductorClient {
14    /// Creates a new conductor client using HTTP transport
15    pub fn new_http(url: Url) -> Self {
16        let rpc = ReqwestClient::new_http(url);
17        Self { rpc }
18    }
19
20    /// Check if the node is a leader of the conductor.
21    pub async fn leader(&self) -> Result<bool, ConductorError> {
22        let result: bool = self.rpc.request("conductor_leader", ()).await?;
23        Ok(result)
24    }
25
26    /// Check if the conductor is active.
27    pub async fn conductor_active(&self) -> Result<bool, ConductorError> {
28        let result: bool = self.rpc.request("conductor_active", ()).await?;
29        Ok(result)
30    }
31
32    /// Override the leader of the conductor.
33    pub async fn override_leader(&self) -> Result<(), ConductorError> {
34        let _result: () = self.rpc.request("conductor_overrideLeader", ()).await?;
35        Ok(())
36    }
37
38    /// Commit an unsafe payload to the conductor.
39    pub async fn commit_unsafe_payload(
40        &self,
41        payload: &OpExecutionPayloadEnvelope,
42    ) -> Result<(), ConductorError> {
43        let _result: () = self.rpc.request("conductor_commitUnsafePayload", [payload]).await?;
44        Ok(())
45    }
46}
47
48/// Error type for conductor operations
49#[derive(Debug, thiserror::Error)]
50pub enum ConductorError {
51    /// An error occurred while making an RPC call to the conductor.
52    #[error("RPC error: {0}")]
53    Rpc(#[from] RpcError<TransportErrorKind>),
54}