-
Notifications
You must be signed in to change notification settings - Fork 126
feature(rpc): Adds rpc methods to enable/disable other cheatcodes #557
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
Open
0xzrf
wants to merge
8
commits into
solana-foundation:main
Choose a base branch
from
0xzrf:cheatcode_enable_disable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
69862a1
feature(rpc): Adds cheatcode rpc methods to enable/disable other chea…
0xzrf 88578c6
added cargo +nightly fmt --all -- --check fix
0xzrf d620266
pr improvement
0xzrf f68e806
Added proper functionality and tests for enable/disable cheatcode
0xzrf d1843a7
fix: automatically generate list of available cheatcodes
MicaiahReid 737f70b
fix: update tests for new enable/disable cheatcodes changes
MicaiahReid 1419d28
added Result handling from Mutex::lock()
0xzrf be1443c
added types
0xzrf 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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,9 +14,10 @@ use solana_system_interface::program as system_program; | |||||
| use solana_transaction::versioned::VersionedTransaction; | ||||||
| use spl_associated_token_account_interface::address::get_associated_token_address_with_program_id; | ||||||
| use surfpool_types::{ | ||||||
| AccountSnapshot, ClockCommand, ExportSnapshotConfig, GetStreamedAccountsResponse, | ||||||
| GetSurfnetInfoResponse, Idl, ResetAccountConfig, RpcProfileResultConfig, Scenario, | ||||||
| SimnetCommand, SimnetEvent, StreamAccountConfig, UiKeyedProfileResult, | ||||||
| AccountSnapshot, CheatcodeControlConfig, CheatcodeFilter, ClockCommand, ExportSnapshotConfig, | ||||||
| GetStreamedAccountsResponse, GetSurfnetInfoResponse, Idl, ResetAccountConfig, RpcCheatcodes, | ||||||
| RpcProfileResultConfig, Scenario, SimnetCommand, SimnetEvent, StreamAccountConfig, | ||||||
| UiKeyedProfileResult, | ||||||
| types::{AccountUpdate, SetSomeAccount, SupplyUpdate, TokenAccountUpdate, UuidOrSignature}, | ||||||
| }; | ||||||
|
|
||||||
|
|
@@ -179,6 +180,92 @@ pub trait SurfnetCheatcodes { | |||||
| update: AccountUpdate, | ||||||
| ) -> BoxFuture<Result<RpcResponse<()>>>; | ||||||
|
|
||||||
| /// Enables one or more Surfpool cheatcode RPC methods for the current session. | ||||||
| /// | ||||||
| /// This method allows developers to re-enable cheatcode methods that were previously disabled. | ||||||
| /// Each cheatcode name must match a valid `surfnet_*` RPC method (e.g. `surfnet_setAccount`, `surfnet_timeTravel`). | ||||||
| /// | ||||||
| /// ## Parameters | ||||||
| /// - `cheatcodes`: A list of cheatcode method names to enable, as strings (e.g. `["surfnet_setAccount", "surfnet_timeTravel"]`). | ||||||
| /// | ||||||
| /// ## Returns | ||||||
| /// A `RpcResponse<()>` indicating whether the enable operation was successful. | ||||||
| /// | ||||||
| /// ## Example Request | ||||||
| /// ```json | ||||||
| /// { | ||||||
| /// "jsonrpc": "2.0", | ||||||
| /// "id": 1, | ||||||
| /// "method": "surfnet_enableCheatcode", | ||||||
| /// "params": [["surfnet_setAccount", "surfnet_timeTravel"]] | ||||||
| /// } | ||||||
| /// ``` | ||||||
| /// | ||||||
| /// ## Example Response | ||||||
| /// ```json | ||||||
| /// { | ||||||
| /// "jsonrpc": "2.0", | ||||||
| /// "result": {}, | ||||||
| /// "id": 1 | ||||||
| /// } | ||||||
| /// ``` | ||||||
| /// | ||||||
| /// # Notes | ||||||
| /// Invalid cheatcode names return an error. Use `surfnet_disableCheatcode` to disable methods and `surfnet_lockout` to allow disabling `surfnet_enableCheatcode` and `surfnet_disableCheatcode` themselves. | ||||||
| /// | ||||||
| /// # See Also | ||||||
| /// - `surfnet_disableCheatcode`, `surfnet_disableAllCheatcodes`, `surfnet_lockout` | ||||||
| #[rpc(meta, name = "surfnet_enableCheatcode")] | ||||||
| fn enable_cheatcode( | ||||||
| &self, | ||||||
| meta: Self::Metadata, | ||||||
| cheatcodes_filter: CheatcodeFilter, | ||||||
| ) -> Result<RpcResponse<()>>; | ||||||
|
|
||||||
| /// Disables one or more Surfpool cheatcode RPC methods for the current session. | ||||||
| /// | ||||||
| /// This method allows developers to turn off specific cheatcode methods so they are no longer callable. | ||||||
| /// Each cheatcode name must match a valid `surfnet_*` RPC method. When lockout is not enabled, | ||||||
| /// `surfnet_enableCheatcode` and `surfnet_disableCheatcode` cannot be disabled. | ||||||
| /// | ||||||
| /// ## Parameters | ||||||
| /// - `cheatcodes`: A list of cheatcode method names to disable, as strings (e.g. `["surfnet_setAccount"]`). | ||||||
| /// | ||||||
| /// ## Returns | ||||||
| /// A `RpcResponse<()>` indicating whether the disable operation was successful. | ||||||
| /// | ||||||
| /// ## Example Request | ||||||
| /// ```json | ||||||
| /// { | ||||||
| /// "jsonrpc": "2.0", | ||||||
| /// "id": 1, | ||||||
| /// "method": "surfnet_disableCheatcode", | ||||||
| /// "params": [["surfnet_setAccount", "surfnet_timeTravel"]] | ||||||
| /// } | ||||||
| /// ``` | ||||||
| /// | ||||||
| /// ## Example Response | ||||||
| /// ```json | ||||||
| /// { | ||||||
| /// "jsonrpc": "2.0", | ||||||
| /// "result": {}, | ||||||
| /// "id": 1 | ||||||
| /// } | ||||||
| /// ``` | ||||||
| /// | ||||||
| /// # Notes | ||||||
| /// Call `surfnet_lockout` first if you need to disable `surfnet_enableCheatcode` or `surfnet_disableCheatcode`. | ||||||
| /// | ||||||
| /// # See Also | ||||||
| /// - `surfnet_enableCheatcode`, `surfnet_disableAllCheatcodes`, `surfnet_lockout` | ||||||
| #[rpc(meta, name = "surfnet_disableCheatcode")] | ||||||
| fn disable_cheatcode( | ||||||
| &self, | ||||||
| meta: Self::Metadata, | ||||||
| cheatcodes_filter: CheatcodeFilter, | ||||||
| lockout: Option<CheatcodeControlConfig>, | ||||||
| ) -> Result<RpcResponse<()>>; | ||||||
|
|
||||||
| /// A "cheat code" method for developers to set or update a token account in Surfpool. | ||||||
| /// | ||||||
| /// This method allows developers to set or update various properties of a token account, | ||||||
|
|
@@ -1201,6 +1288,111 @@ impl SurfnetCheatcodes for SurfnetCheatcodesRpc { | |||||
| }) | ||||||
| } | ||||||
|
|
||||||
| fn disable_cheatcode( | ||||||
| &self, | ||||||
| meta: Self::Metadata, | ||||||
| cheatcodes_filter: CheatcodeFilter, | ||||||
| control_config: Option<CheatcodeControlConfig>, | ||||||
| ) -> Result<RpcResponse<()>> { | ||||||
| let svm_locker = match meta.get_svm_locker() { | ||||||
| Ok(locker) => locker, | ||||||
| Err(e) => return Err(e.into()), | ||||||
| }; | ||||||
|
|
||||||
| let CheatcodeControlConfig { lockout } = control_config.unwrap_or_default(); | ||||||
| let lockout = lockout.unwrap_or_default(); | ||||||
|
|
||||||
| if let Some(runloop_ctx) = meta { | ||||||
| let mut cheatcode_ctx = runloop_ctx.cheatcode_config.lock().unwrap(); | ||||||
|
|
||||||
| match cheatcodes_filter { | ||||||
| CheatcodeFilter::All(all) => { | ||||||
| if all.ne("all") { | ||||||
| return Err(SurfpoolError::disable_cheatcode( | ||||||
| "Invalid optioin provided for disabling all cheatcodes. Try using \"all\"".to_string(), | ||||||
| ) | ||||||
| .into()); | ||||||
| } | ||||||
|
|
||||||
| cheatcode_ctx.disable_all(lockout); | ||||||
| } | ||||||
| CheatcodeFilter::List(cheatdcodes) => { | ||||||
| for cheatcode in cheatdcodes { | ||||||
| if !lockout && cheatcode.eq(&String::from(RpcCheatcodes::EnableCheatcode)) { | ||||||
| return Err(SurfpoolError::disable_cheatcode( | ||||||
| "Cannot disable surfnet_enableCheatcode rpc method when lockout is not enabledd".to_string(), | ||||||
|
||||||
| "Cannot disable surfnet_enableCheatcode rpc method when lockout is not enabledd".to_string(), | |
| "Cannot disable surfnet_enableCheatcode rpc method when lockout is not enabled".to_string(), |
Outdated
Collaborator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| "Invalid optioin provided for enabling all cheatcodes. Try using \"all\"".to_string(), | |
| "Invalid option provided for enabling all cheatcodes. Try using 'all' or providing an array of specific cheatcodes".to_string(), |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.