-
Notifications
You must be signed in to change notification settings - Fork 3
feat(admin rpc): add command to enable/disable automatic sequencing #289
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a8288d7
add command to enable/disable automatic sequencing in rollup node man…
jonastheis 47bb6ad
Merge remote-tracking branch 'origin/main' into feat/automatic-sequen…
jonastheis 5fbbc77
add rpc extension
jonastheis 4d46249
implement async trait that actually enables/disables sequencer
jonastheis d607942
Merge remote-tracking branch 'origin/main' into feat/automatic-sequen…
jonastheis 1c21edb
address review comments
jonastheis 22efb2c
add e2e test
jonastheis 14d0c37
fix issues with test and finish implementing e2e test
jonastheis e96870d
add wait_for to test
jonastheis 8a90935
do not gate client for tests
jonastheis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
use async_trait::async_trait; | ||
use jsonrpsee::{ | ||
core::RpcResult, | ||
proc_macros::rpc, | ||
types::{error, ErrorObjectOwned}, | ||
}; | ||
use reth_network_api::FullNetwork; | ||
use reth_scroll_node::ScrollNetworkPrimitives; | ||
use rollup_node_manager::RollupManagerHandle; | ||
use tokio::sync::{oneshot, Mutex, OnceCell}; | ||
|
||
/// RPC extension for rollup node management operations. | ||
/// | ||
/// This struct provides a custom JSON-RPC namespace (`rollupNode`) that exposes | ||
/// rollup management functionality to RPC clients. It manages a connection to the | ||
/// rollup manager through a handle that is initialized lazily via a oneshot channel. | ||
#[derive(Debug)] | ||
pub struct RollupNodeRpcExt<N> | ||
where | ||
N: FullNetwork<Primitives = ScrollNetworkPrimitives>, | ||
{ | ||
/// Cached rollup manager handle, initialized lazily via `OnceCell` | ||
handle: tokio::sync::OnceCell<RollupManagerHandle<N>>, | ||
/// Oneshot channel receiver for obtaining the rollup manager handle during initialization | ||
rx: Mutex<Option<oneshot::Receiver<RollupManagerHandle<N>>>>, | ||
} | ||
|
||
impl<N> RollupNodeRpcExt<N> | ||
where | ||
N: FullNetwork<Primitives = ScrollNetworkPrimitives>, | ||
{ | ||
/// Creates a new RPC extension with a receiver for the rollup manager handle. | ||
pub fn new(rx: oneshot::Receiver<RollupManagerHandle<N>>) -> Self { | ||
Self { rx: Mutex::new(Some(rx)), handle: OnceCell::new() } | ||
} | ||
|
||
/// Gets or initializes the rollup manager handle. | ||
/// | ||
/// This method lazily initializes the rollup manager handle by consuming the oneshot | ||
/// receiver. Subsequent calls will return the cached handle. | ||
async fn rollup_manager_handle(&self) -> eyre::Result<&RollupManagerHandle<N>> { | ||
self.handle | ||
.get_or_try_init(|| async { | ||
let rx = { | ||
let mut g = self.rx.lock().await; | ||
g.take().ok_or_else(|| eyre::eyre!("receiver already consumed"))? | ||
}; | ||
rx.await.map_err(|e| eyre::eyre!("failed to receive handle: {e}")) | ||
}) | ||
.await | ||
} | ||
} | ||
|
||
/// Defines the `rollupNode` JSON-RPC namespace for rollup management operations. | ||
/// | ||
/// This trait provides a custom RPC namespace that exposes rollup node management | ||
/// functionality to external clients. The namespace is exposed as `rollupNode` and | ||
/// provides methods for controlling automatic sequencing behavior. | ||
/// | ||
/// # Usage | ||
/// These methods can be called via JSON-RPC using the `rollupNode` namespace: | ||
/// ```json | ||
/// {"jsonrpc": "2.0", "method": "rollupNode_enableAutomaticSequencing", "params": [], "id": 1} | ||
/// ``` | ||
/// or using cast: | ||
/// ```bash | ||
/// cast rpc rollupNode_enableAutomaticSequencing | ||
/// ``` | ||
#[rpc(server, client, namespace = "rollupNode")] | ||
pub trait RollupNodeExtApi { | ||
/// Enables automatic sequencing in the rollup node. | ||
#[method(name = "enableAutomaticSequencing")] | ||
async fn enable_automatic_sequencing(&self) -> RpcResult<bool>; | ||
|
||
/// Disables automatic sequencing in the rollup node. | ||
#[method(name = "disableAutomaticSequencing")] | ||
async fn disable_automatic_sequencing(&self) -> RpcResult<bool>; | ||
} | ||
|
||
#[async_trait] | ||
impl<N> RollupNodeExtApiServer for RollupNodeRpcExt<N> | ||
where | ||
N: FullNetwork<Primitives = ScrollNetworkPrimitives>, | ||
{ | ||
async fn enable_automatic_sequencing(&self) -> RpcResult<bool> { | ||
let handle = self.rollup_manager_handle().await.map_err(|e| { | ||
ErrorObjectOwned::owned( | ||
error::INTERNAL_ERROR_CODE, | ||
format!("Failed to get rollup manager handle: {}", e), | ||
None::<()>, | ||
) | ||
})?; | ||
|
||
handle.enable_automatic_sequencing().await.map_err(|e| { | ||
ErrorObjectOwned::owned( | ||
error::INTERNAL_ERROR_CODE, | ||
format!("Failed to enable automatic sequencing: {}", e), | ||
None::<()>, | ||
) | ||
}) | ||
} | ||
|
||
async fn disable_automatic_sequencing(&self) -> RpcResult<bool> { | ||
let handle = self.rollup_manager_handle().await.map_err(|e| { | ||
ErrorObjectOwned::owned( | ||
error::INTERNAL_ERROR_CODE, | ||
format!("Failed to get rollup manager handle: {}", e), | ||
None::<()>, | ||
) | ||
})?; | ||
|
||
handle.disable_automatic_sequencing().await.map_err(|e| { | ||
ErrorObjectOwned::owned( | ||
error::INTERNAL_ERROR_CODE, | ||
format!("Failed to disable automatic sequencing: {}", e), | ||
None::<()>, | ||
) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.