Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rpc): Migrate alloy-rs/op-alloy-rpc-jsonrpsee->op-rs/maili-rpc-jsonrpsee #24

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ ethereum_ssz = "0.8.2"
miniz_oxide = "0.8.2"
alloc-no-stdlib = "2.0.4"
brotli = { version = "7.0.0", default-features = false }
getrandom = { version = "0.2.15", features = ["js"] } # required for brotli to wasm32-unkown-unkown

# rpc
jsonrpsee = { version = "0.24.7", features = [
Expand Down
45 changes: 45 additions & 0 deletions crates/rpc-jsonrpsee/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "maili-rpc-jsonrpsee"
description = "Optimism RPC Client"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
authors.workspace = true
repository.workspace = true
exclude.workspace = true

[lints]
workspace = true

[dependencies]
# Workspace
maili-protocol = { workspace = true, default-features = false, features = ["serde"] }
maili-rpc-types-engine = { workspace = true, default-features = false, features = ["serde"] }

# OP-Alloy
op-alloy-rpc-types.workspace = true

# Alloy
alloy-eips.workspace = true
alloy-primitives.workspace = true

# rpc
jsonrpsee.workspace = true
getrandom.workspace = true

[features]
default = ["std"]
std = [
"maili-protocol/std",
"maili-rpc-types-engine/std",
"op-alloy-rpc-types/std",
"alloy-eips/std",
"alloy-primitives/std",
]
client = [
"jsonrpsee/client",
"jsonrpsee/async-client",
]
10 changes: 10 additions & 0 deletions crates/rpc-jsonrpsee/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## `maili-rpc-jsonrpsee`

<a href="https://github.com/op-rs/maili/actions/workflows/ci.yml"><img src="https://github.com/op-rs/maili/actions/workflows/ci.yml/badge.svg?label=ci" alt="CI"></a>
<a href="https://crates.io/crates/maili-rpc-jsonrpsee"><img src="https://img.shields.io/crates/v/maili-rpc-jsonrpsee.svg" alt="maili-rpc-jsonrpsee crate"></a>
<a href="https://github.com/op-rs/maili/blob/main/LICENSE-MIT"><img src="https://img.shields.io/badge/License-MIT-d1d1f6.svg?label=license&labelColor=2a2f35" alt="MIT License"></a>
<a href="https://github.com/op-rs/maili/blob/main/LICENSE-APACHE"><img src="https://img.shields.io/badge/License-APACHE-d1d1f6.svg?label=license&labelColor=2a2f35" alt="Apache License"></a>
<a href="https://op-rs.github.io/maili"><img src="https://img.shields.io/badge/Book-854a15?logo=mdBook&labelColor=2a2f35" alt="Book"></a>


Low-level Optimism JSON-RPC server and client implementations.
15 changes: 15 additions & 0 deletions crates/rpc-jsonrpsee/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/op-rs/maili/main/assets/square.png",
html_favicon_url = "https://raw.githubusercontent.com/op-rs/maili/main/assets/favicon.ico"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

pub mod traits;

#[allow(unused_imports)]
use getrandom as _; // required for compiling wasm32-unknown-unknown
162 changes: 162 additions & 0 deletions crates/rpc-jsonrpsee/src/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#![allow(missing_docs)]

//! Rollup Node

use alloc::{boxed::Box, string::String, vec::Vec};
use core::net::IpAddr;

use alloy_eips::BlockNumberOrTag;
use alloy_primitives::{B256, U64};
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use maili_protocol::{ExecutingMessage, SafetyLevel};
use maili_rpc_types_engine::{ProtocolVersion, SuperchainSignal};
use op_alloy_rpc_types::{
OutputResponse, PeerDump, PeerInfo, PeerStats, RollupConfig, SafeHeadResponse, SyncStatus,
};

/// Optimism specified rpc interface.
///
/// https://docs.optimism.io/builders/node-operators/json-rpc
/// https://github.com/ethereum-optimism/optimism/blob/8dd17a7b114a7c25505cd2e15ce4e3d0f7e3f7c1/op-node/node/api.go#L114
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "optimism"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "optimism"))]
pub trait RollupNode {
/// Get the output root at a specific block.
#[method(name = "outputAtBlock")]
async fn op_output_at_block(&self, block_number: BlockNumberOrTag)
-> RpcResult<OutputResponse>;

/// Gets the safe head at an L1 block height.
#[method(name = "safeHeadAtL1Block")]
async fn op_safe_head_at_l1_block(
&self,
block_number: BlockNumberOrTag,
) -> RpcResult<SafeHeadResponse>;

/// Get the synchronization status.
#[method(name = "syncStatus")]
async fn op_sync_status(&self) -> RpcResult<SyncStatus>;

/// Get the rollup configuration parameters.
#[method(name = "rollupConfig")]
async fn op_rollup_config(&self) -> RpcResult<RollupConfig>;

/// Get the software version.
#[method(name = "version")]
async fn op_version(&self) -> RpcResult<String>;
}

/// The opp2p namespace handles peer interactions.
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "opp2p"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "opp2p"))]
pub trait OpP2PApi {
/// Returns information of node
#[method(name = "self")]
async fn opp2p_self(&self) -> RpcResult<PeerInfo>;

#[method(name = "peers")]
async fn opp2p_peers(&self) -> RpcResult<PeerDump>;

#[method(name = "peerStats")]
async fn opp2p_peer_stats(&self) -> RpcResult<PeerStats>;

#[method(name = "discoveryTable")]
async fn opp2p_discovery_table(&self) -> RpcResult<Vec<String>>;

#[method(name = "blockPeer")]
async fn opp2p_block_peer(&self, peer: String) -> RpcResult<()>;

#[method(name = "listBlockedPeers")]
async fn opp2p_list_blocked_peers(&self) -> RpcResult<Vec<String>>;

#[method(name = "blocAddr")]
async fn opp2p_block_addr(&self, ip: IpAddr) -> RpcResult<()>;

#[method(name = "unblockAddr")]
async fn opp2p_unblock_addr(&self, ip: IpAddr) -> RpcResult<()>;

#[method(name = "listBlockedAddrs")]
async fn opp2p_list_blocked_addrs(&self) -> RpcResult<Vec<IpAddr>>;

/// todo: should be IPNet?
#[method(name = "blockSubnet")]
async fn opp2p_block_subnet(&self, subnet: String) -> RpcResult<()>;

/// todo: should be IPNet?
#[method(name = "unblockSubnet")]
async fn opp2p_unblock_subnet(&self, subnet: String) -> RpcResult<()>;

/// todo: should be IPNet?
#[method(name = "listBlockedSubnets")]
async fn opp2p_list_blocked_subnets(&self) -> RpcResult<Vec<String>>;

#[method(name = "protectPeer")]
async fn opp2p_protect_peer(&self, peer: String) -> RpcResult<()>;

#[method(name = "unprotectPeer")]
async fn opp2p_unprotect_peer(&self, peer: String) -> RpcResult<()>;

#[method(name = "connectPeer")]
async fn opp2p_connect_peer(&self, peer: String) -> RpcResult<()>;

#[method(name = "disconnectPeer")]
async fn opp2p_disconnect_peer(&self, peer: String) -> RpcResult<()>;
}

/// The admin namespace endpoints
/// https://github.com/ethereum-optimism/optimism/blob/c7ad0ebae5dca3bf8aa6f219367a95c15a15ae41/op-node/node/api.go#L28-L36
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "admin"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "admin"))]
pub trait OpAdminApi {
#[method(name = "resetDerivationPipeline")]
async fn admin_reset_derivation_pipeline(&self) -> RpcResult<()>;

#[method(name = "startSequencer")]
async fn admin_start_sequencer(&self, block_hash: B256) -> RpcResult<()>;

#[method(name = "stopSequencer")]
async fn admin_stop_sequencer(&self) -> RpcResult<B256>;

#[method(name = "sequencerActive")]
async fn admin_sequencer_active(&self) -> RpcResult<bool>;
}

/// Engine API extension for Optimism superchain signaling
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "engine"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "engine"))]
pub trait EngineApiExt {
/// Signal superchain v1 message
///
/// The execution engine SHOULD warn when the recommended version is newer than the current
/// version. The execution engine SHOULD take safety precautions if it does not meet
/// the required version.
///
/// # Returns
/// The latest supported OP-Stack protocol version of the execution engine.
///
/// See: <https://specs.optimism.io/protocol/exec-engine.html#engine_signalsuperchainv1>
#[method(name = "signalSuperchainV1")]
async fn signal_superchain_v1(&self, signal: SuperchainSignal) -> RpcResult<ProtocolVersion>;
}

/// Op API extension for controlling the miner.
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "miner"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "miner"))]
pub trait MinerApiExt {
/// Sets the maximum data availability size of any tx allowed in a block, and the total max l1
/// data size of the block. 0 means no maximum.
#[method(name = "setMaxDASize")]
async fn set_max_da_size(&self, max_tx_size: U64, max_block_size: U64) -> RpcResult<bool>;
}

/// Supervisor API for interop.
#[rpc(client, namespace = "supervisor")]
pub trait SupervisorApi {
/// Checks if the given messages meet the given minimum safety level.
#[method(name = "checkMessages")]
async fn check_messages(
&self,
messages: Vec<ExecutingMessage>,
min_safety: SafetyLevel,
) -> RpcResult<()>;
}
Loading