Skip to content
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.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ serde = { version = "1.0.226", default-features = false }
serde_derive = { version = "1.0.226", default-features = false } # must match the serde version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde_json = { version = "1.0.135", default-features = false }
serde_with = { version = "3.14.0", default-features = false }
strum = { version = "0.26", default-features = false, features = ["derive"] }
solana-account = { version = "3.0.0", default-features = false }
solana-account-decoder = { version = "3.0.0", default-features = false }
solana-account-decoder-client-types = { version = "3.0.0", default-features = false }
Expand Down
43 changes: 42 additions & 1 deletion crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use surfpool_mcp::McpOptions;
use surfpool_types::{
BlockProductionMode, CHANGE_TO_DEFAULT_STUDIO_PORT_ONCE_SUPERVISOR_MERGED,
DEFAULT_NETWORK_HOST, DEFAULT_RPC_PORT, DEFAULT_SLOT_TIME_MS, DEFAULT_WS_PORT, RpcConfig,
SimnetConfig, SimnetEvent, StudioConfig, SubgraphConfig, SurfpoolConfig,
SimnetConfig, SimnetEvent, StudioConfig, SubgraphConfig, SurfpoolConfig, SvmFeature,
SvmFeatureConfig,
};
use txtx_cloud::LoginCommand;
use txtx_core::manifest::WorkspaceManifest;
Expand Down Expand Up @@ -227,6 +228,24 @@ pub struct StartSimnet {
/// Path to the Test.toml test suite files to load (eg. surfpool start --anchor-test-config-path ./path/to/Test.toml)
#[arg(long = "anchor-test-config-path")]
pub anchor_test_config_paths: Vec<String>,
/// Enable specific SVM features. Can be specified multiple times. (eg. surfpool start --feature enable-loader-v4 --feature enable-sbpf-v2-deployment-and-execution)
#[arg(long = "feature", short = 'f', value_parser = parse_svm_feature)]
pub features: Vec<SvmFeature>,
/// Disable specific SVM features. Can be specified multiple times. (eg. surfpool start --disable-feature disable-fees-sysvar)
#[arg(long = "disable-feature", value_parser = parse_svm_feature)]
pub disable_features: Vec<SvmFeature>,
/// Enable all SVM features (override mainnet defaults which are used by default)
#[clap(long = "features-all", action=ArgAction::SetTrue, default_value = "false")]
pub all_features: bool,
}

fn parse_svm_feature(s: &str) -> Result<SvmFeature, String> {
SvmFeature::from_str(s).map_err(|_| {
format!(
"Unknown SVM feature: '{}'. Use --help to see available features.",
s
)
})
}

#[derive(clap::ValueEnum, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -319,6 +338,27 @@ impl StartSimnet {
}
}

pub fn feature_config(&self) -> SvmFeatureConfig {
// Use mainnet defaults by default, --all-features enables everything
let mut config = if self.all_features {
SvmFeatureConfig::default()
} else {
SvmFeatureConfig::default_mainnet_features()
};

// Apply explicit enables (these override defaults)
for feature in &self.features {
config = config.enable(*feature);
}

// Apply explicit disables (these override defaults)
for feature in &self.disable_features {
config = config.disable(*feature);
}

config
}

pub fn simnet_config(&self, airdrop_addresses: Vec<Pubkey>) -> SimnetConfig {
let remote_rpc_url = if !self.offline {
Some(self.datasource_rpc_url())
Expand All @@ -341,6 +381,7 @@ impl StartSimnet {
} else {
Some(self.log_bytes_limit)
},
feature_config: self.feature_config(),
}
}

Expand Down
7 changes: 6 additions & 1 deletion crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ pub async fn handle_start_local_surfnet_command(
}

// We start the simnet as soon as possible, as it needs to be ready for deployments
let (surfnet_svm, simnet_events_rx, geyser_events_rx) = SurfnetSvm::new();
let (mut surfnet_svm, simnet_events_rx, geyser_events_rx) = SurfnetSvm::new();

// Apply feature configuration from CLI flags
let feature_config = cmd.feature_config();
surfnet_svm.apply_feature_config(&feature_config);

let (simnet_commands_tx, simnet_commands_rx) = crossbeam::channel::unbounded();
let (subgraph_commands_tx, subgraph_commands_rx) = crossbeam::channel::unbounded();
let (subgraph_events_tx, subgraph_events_rx) = crossbeam::channel::unbounded();
Expand Down
31 changes: 29 additions & 2 deletions crates/core/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{future::Future, sync::Arc};
use blake3::Hash;
use crossbeam_channel::Sender;
use jsonrpc_core::{
BoxFuture, Error, FutureResponse, Metadata, Middleware, Request, Response,
BoxFuture, Error, ErrorCode, FutureResponse, Metadata, Middleware, Request, Response,
futures::{FutureExt, future::Either},
middleware,
};
Expand Down Expand Up @@ -146,14 +146,41 @@ impl Middleware<Option<RunloopContext>> for SurfpoolMiddleware {
F: FnOnce(Request, Option<RunloopContext>) -> X + Send,
X: Future<Output = Option<Response>> + Send + 'static,
{
let Request::Single(jsonrpc_core::Call::MethodCall(ref method_call)) = request else {
let error = Response::from(
Error {
code: ErrorCode::InvalidRequest,
message: "Only method calls are supported".into(),
data: None,
},
None,
);
warn!("Request rejected due to not being a single method call");

return Either::Left(Box::pin(async move { Some(error) }));
};

let method_name = method_call.method.clone();
debug!("Processing request '{}'", method_name);

let meta = Some(RunloopContext {
id: None,
svm_locker: self.surfnet_svm.clone(),
simnet_commands_tx: self.simnet_commands_tx.clone(),
plugin_manager_commands_tx: self.plugin_manager_commands_tx.clone(),
remote_rpc_client: self.remote_rpc_client.clone(),
});
Either::Left(Box::pin(next(request, meta).map(move |res| res)))
Either::Left(Box::pin(next(request, meta).map(move |res| {
if let Some(Response::Single(output)) = &res {
if let jsonrpc_core::Output::Failure(failure) = output {
debug!(
"RPC error for method '{}': code={:?}, message={}",
method_name, failure.error.code, failure.error.message
);
}
}
res
})))
}
}

Expand Down
Loading