Skip to content

Commit 4521c6e

Browse files
feat: add surfnet_offlineAccount RPC method (#566)
Co-authored-by: Micaiah Reid <micaiahreid@gmail.com>
1 parent 4d3168f commit 4521c6e

File tree

6 files changed

+658
-65
lines changed

6 files changed

+658
-65
lines changed

crates/core/src/rpc/surfnet_cheatcodes.rs

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use solana_transaction::versioned::VersionedTransaction;
1818
use spl_associated_token_account_interface::address::get_associated_token_address_with_program_id;
1919
use surfpool_types::{
2020
AccountSnapshot, CheatcodeControlConfig, CheatcodeFilter, ClockCommand, ExportSnapshotConfig,
21-
GetStreamedAccountsResponse, GetSurfnetInfoResponse, Idl, ResetAccountConfig,
22-
RpcProfileResultConfig, Scenario, SimnetCommand, SimnetEvent, StreamAccountConfig,
23-
UiKeyedProfileResult,
21+
GetStreamedAccountsResponse, GetSurfnetInfoResponse, Idl, OfflineAccountConfig,
22+
ResetAccountConfig, RpcProfileResultConfig, Scenario, SimnetCommand, SimnetEvent,
23+
StreamAccountConfig, UiKeyedProfileResult,
2424
types::{AccountUpdate, SetSomeAccount, SupplyUpdate, TokenAccountUpdate, UuidOrSignature},
2525
};
2626

@@ -870,6 +870,48 @@ pub trait SurfnetCheatcodes {
870870
#[rpc(meta, name = "surfnet_resetNetwork")]
871871
fn reset_network(&self, meta: Self::Metadata) -> BoxFuture<Result<RpcResponse<()>>>;
872872

873+
/// A cheat code to prevent an account from being downloaded from the remote RPC.
874+
///
875+
/// ## Parameters
876+
/// - `pubkey_str`: The base-58 encoded public key of the account/program to block.
877+
/// - `config`: A `OfflineAccountConfig` specifying whether to also mark accounts offline
878+
/// owned by this pubkey. If omitted, only the account itself is marked offline.
879+
///
880+
/// ## Returns
881+
/// An `RpcResponse<()>` indicating whether the download block registration was successful.
882+
///
883+
/// ## Example Request
884+
/// ```json
885+
/// {
886+
/// "jsonrpc": "2.0",
887+
/// "id": 1,
888+
/// "method": "surfnet_offlineAccount",
889+
/// "params": [ "4EXSeLGxVBpAZwq7vm6evLdewpcvE2H56fpqL2pPiLFa", { "includeOwnedAccounts": true } ]
890+
/// }
891+
/// ```
892+
///
893+
/// ## Example Response
894+
/// ```json
895+
/// {
896+
/// "jsonrpc": "2.0",
897+
/// "result": {
898+
/// "context": {
899+
/// "slot": 123456789,
900+
/// "apiVersion": "2.3.8"
901+
/// },
902+
/// "value": null
903+
/// },
904+
/// "id": 1
905+
/// }
906+
/// ```
907+
#[rpc(meta, name = "surfnet_offlineAccount")]
908+
fn offline_account(
909+
&self,
910+
meta: Self::Metadata,
911+
pubkey_str: String,
912+
config: Option<OfflineAccountConfig>,
913+
) -> BoxFuture<Result<RpcResponse<()>>>;
914+
873915
/// A cheat code to export a snapshot of all accounts in the Surfnet SVM.
874916
///
875917
/// This method retrieves the current state of all accounts stored in the Surfnet Virtual Machine (SVM)
@@ -1935,6 +1977,35 @@ impl SurfnetCheatcodes for SurfnetCheatcodesRpc {
19351977
})
19361978
}
19371979

1980+
fn offline_account(
1981+
&self,
1982+
meta: Self::Metadata,
1983+
pubkey_str: String,
1984+
config: Option<OfflineAccountConfig>,
1985+
) -> BoxFuture<Result<RpcResponse<()>>> {
1986+
let SurfnetRpcContext { svm_locker, .. } =
1987+
match meta.get_rpc_context(CommitmentConfig::confirmed()) {
1988+
Ok(res) => res,
1989+
Err(e) => return e.into(),
1990+
};
1991+
let pubkey = match verify_pubkey(&pubkey_str) {
1992+
Ok(res) => res,
1993+
Err(e) => return e.into(),
1994+
};
1995+
let config = config.unwrap_or_default();
1996+
let include_owned_accounts = config.include_owned_accounts.unwrap_or_default();
1997+
1998+
Box::pin(async move {
1999+
svm_locker
2000+
.insert_offline_account(pubkey, include_owned_accounts)
2001+
.await?;
2002+
Ok(RpcResponse {
2003+
context: RpcResponseContext::new(svm_locker.get_latest_absolute_slot()),
2004+
value: (),
2005+
})
2006+
})
2007+
}
2008+
19382009
fn stream_account(
19392010
&self,
19402011
meta: Self::Metadata,

0 commit comments

Comments
 (0)