Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ impl SurfpoolError {
error.data = Some(json!("Failed to access internal Surfnet context"));
Self(error)
}

pub fn get_balance() -> Self {
let mut error = Error::internal_error();
error.data = Some(json!("Context slot too old"));
Self(error)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this error that is no longer being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

pub fn set_account<T>(pubkey: Pubkey, e: T) -> Self
where
T: ToString,
Expand Down
23 changes: 21 additions & 2 deletions crates/core/src/rpc/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use solana_rpc_client_api::response::Response as RpcResponse;
use super::{RunloopContext, SurfnetRpcContext};
use crate::{
SURFPOOL_IDENTITY_PUBKEY,
error::SurfpoolError,
rpc::{State, utils::verify_pubkey},
surfnet::{FINALIZATION_SLOT_THRESHOLD, GetAccountResult, locker::SvmAccessContext},
};
Expand Down Expand Up @@ -586,17 +587,29 @@ impl Minimal for SurfpoolMinimalRpc {
&self,
meta: Self::Metadata,
pubkey_str: String,
_config: Option<RpcContextConfig>, // TODO: use config
config: Option<RpcContextConfig>,
) -> BoxFuture<Result<RpcResponse<u64>>> {
let pubkey = match verify_pubkey(&pubkey_str) {
Ok(res) => res,
Err(e) => return e.into(),
};

let (commitment_config, min_ctx_slot): (CommitmentConfig, Option<u64>) = match config {
Some(RpcContextConfig {
commitment: Some(commitment),
min_context_slot,
}) => (commitment, min_context_slot),
Some(RpcContextConfig {
commitment: None,
min_context_slot,
}) => (CommitmentConfig::confirmed(), min_context_slot),
None => (CommitmentConfig::confirmed(), None),
};

let SurfnetRpcContext {
svm_locker,
remote_ctx,
} = match meta.get_rpc_context(CommitmentConfig::confirmed()) {
} = match meta.get_rpc_context(commitment_config) {
Ok(res) => res,
Err(e) => return e.into(),
};
Expand All @@ -608,6 +621,12 @@ impl Minimal for SurfpoolMinimalRpc {
..
} = svm_locker.get_account(&remote_ctx, &pubkey, None).await?;

if let Some(min_slot) = min_ctx_slot
&& slot < min_slot
{
return Err(SurfpoolError::get_balance().into());
}

let balance = match &account_update {
GetAccountResult::FoundAccount(_, account, _)
| GetAccountResult::FoundProgramAccount((_, account), _)
Expand Down