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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ test-ledger
.surfpool

# local
runbooks
txtx.yml
11 changes: 7 additions & 4 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ surfpool-studio-ui = { path = "crates/studio", default-features = false }
surfpool-subgraph = { path = "crates/subgraph", default-features = false }
surfpool-types = { path = "crates/types", default-features = false }

txtx-addon-kit = "0.4.11"
txtx-addon-network-svm = { version = "0.3.15" }
txtx-addon-network-svm-types = { version = "0.3.14" }
txtx-addon-kit = "0.4.10"
txtx-addon-network-svm = { version = "0.3.16" }
txtx-addon-network-svm-types = { version = "0.3.15" }
txtx-cloud = { version = "0.1.13", features = [
"clap",
"toml",
Expand All @@ -170,7 +170,7 @@ txtx-core = { version = "0.4.13" }
txtx-gql = { version = "0.3.7" }
txtx-supervisor-ui = { version = "0.2.9", default-features = false }

[patch.crates-io]
# [patch.crates-io]
## Local
# txtx-addon-kit = { path = "../txtx/crates/txtx-addon-kit" }
# txtx-core = { path = "../txtx/crates/txtx-core" }
Expand Down
3 changes: 0 additions & 3 deletions crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ pub struct StartSimnet {
/// Display streams of logs instead of terminal UI dashboard(eg. surfpool start --no-tui)
#[clap(long = "no-tui", default_value = "false")]
pub no_tui: bool,
/// Include debug logs (eg. surfpool start --debug)
#[clap(long = "debug", action=ArgAction::SetTrue, default_value = "false")]
pub debug: bool,
/// Disable auto deployments (eg. surfpool start --no-deploy)
#[clap(long = "no-deploy", default_value = "false")]
pub no_deploy: bool,
Expand Down
24 changes: 10 additions & 14 deletions crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ pub async fn handle_start_local_surfnet_command(
// Non blocking check for new versions
#[cfg(feature = "version_check")]
{
let local_version = env!("CARGO_PKG_VERSION");
let mut local_version = env!("CARGO_PKG_VERSION");
if cmd.ci {
local_version = format!("{}-ci", local_version);
}
let response = txtx_gql::kit::reqwest::get(format!(
"{}/api/versions?v=/{}",
super::DEFAULT_CLOUD_URL,
Expand Down Expand Up @@ -237,13 +240,14 @@ async fn start_service(
} else {
DisplayedUrl::Studio(sanitized_config)
};
let include_debug_logs = cmd.log_level.to_lowercase().eq("debug");

// Start frontend - kept on main thread
if cmd.daemon || cmd.no_tui {
log_events(
simnet_events_rx,
subgraph_events_rx,
cmd.debug,
include_debug_logs,
deploy_progress_rx,
simnet_commands_tx,
runloop_terminator.unwrap(),
Expand All @@ -252,7 +256,7 @@ async fn start_service(
tui::simnet::start_app(
simnet_events_rx,
simnet_commands_tx,
cmd.debug,
include_debug_logs,
deploy_progress_rx,
displayed_url,
breaker,
Expand Down Expand Up @@ -317,11 +321,7 @@ fn log_events(
SimnetEvent::EpochInfoUpdate(_) => {
info!("{}", event.epoch_info_update_msg());
}
SimnetEvent::SystemClockUpdated(_) => {
if include_debug_logs {
info!("{}", event.clock_update_msg());
}
}
SimnetEvent::SystemClockUpdated(_) => {}
SimnetEvent::ClockUpdate(_) => {}
SimnetEvent::ErrorLog(_dt, log) => {
error!("{}", log);
Expand All @@ -330,9 +330,7 @@ fn log_events(
info!("{}", log);
}
SimnetEvent::DebugLog(_dt, log) => {
if include_debug_logs {
debug!("{}", log);
}
debug!("{}", log);
}
SimnetEvent::WarnLog(_dt, log) => {
warn!("{}", log);
Expand Down Expand Up @@ -396,9 +394,7 @@ fn log_events(
info!("{}", log);
}
SubgraphEvent::DebugLog(_dt, log) => {
if include_debug_logs {
info!("{}", log);
}
debug!("{}", log);
}
SubgraphEvent::WarnLog(_dt, log) => {
warn!("{}", log);
Expand Down
63 changes: 57 additions & 6 deletions crates/cli/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use juniper_graphql_ws::ConnectionConfig;
use log::{debug, error, info, trace, warn};
#[cfg(feature = "explorer")]
use rust_embed::RustEmbed;
use surfpool_core::scenarios::TemplateRegistry;
use surfpool_gql::{
DynamicSchema,
db::schema::collections,
Expand All @@ -28,7 +29,8 @@ use surfpool_gql::{
};
use surfpool_studio_ui::serve_studio_static_files;
use surfpool_types::{
DataIndexingCommand, SanitizedConfig, SubgraphCommand, SubgraphEvent, SurfpoolConfig,
DataIndexingCommand, OverrideTemplate, SanitizedConfig, SubgraphCommand, SubgraphEvent,
SurfpoolConfig,
};
use txtx_core::kit::types::types::Value;
use txtx_gql::kit::uuid::Uuid;
Expand Down Expand Up @@ -62,13 +64,17 @@ pub async fn start_subgraph_and_explorer_server(
let schema_wrapped = Data::new(schema);
let context_wrapped = Data::new(RwLock::new(context));
let config_wrapped = Data::new(RwLock::new(config.clone()));
let collections_metadata_lookup_wrapped = Data::new(RwLock::new(collections_metadata_lookup));

// Initialize template registry and load templates
let template_registry_wrapped = Data::new(RwLock::new(TemplateRegistry::new()));

let subgraph_handle = start_subgraph_runloop(
subgraph_events_tx,
subgraph_commands_rx,
context_wrapped.clone(),
schema_wrapped.clone(),
collections_metadata_lookup,
collections_metadata_lookup_wrapped.clone(),
config,
ctx,
)?;
Expand All @@ -78,6 +84,8 @@ pub async fn start_subgraph_and_explorer_server(
.app_data(schema_wrapped.clone())
.app_data(context_wrapped.clone())
.app_data(config_wrapped.clone())
.app_data(collections_metadata_lookup_wrapped.clone())
.app_data(template_registry_wrapped.clone())
.wrap(
Cors::default()
.allow_any_origin()
Expand All @@ -90,8 +98,11 @@ pub async fn start_subgraph_and_explorer_server(
.wrap(middleware::Compress::default())
.wrap(middleware::Logger::default())
.service(get_config)
.service(get_indexers)
.service(get_scenario_templates)
.service(
web::scope("/workspace")
.route("/v1/indexers", web::post().to(post_graphql))
.route("/v1/graphql?<request..>", web::get().to(get_graphql))
.route("/v1/graphql", web::post().to(post_graphql))
.route("/v1/subscriptions", web::get().to(subscriptions)),
Expand Down Expand Up @@ -145,6 +156,42 @@ async fn get_config(
.body(api_config.to_string()))
}

#[actix_web::get("/workspace/v1/indexers")]
async fn get_indexers(
collections_metadata_lookup: Data<RwLock<CollectionsMetadataLookup>>,
) -> Result<HttpResponse, Error> {
let lookup = collections_metadata_lookup.read().map_err(|_| {
actix_web::error::ErrorInternalServerError("Failed to read collections metadata")
})?;

let collections: Vec<&CollectionMetadata> = lookup.entries.values().collect();
let response = serde_json::to_string(&collections).map_err(|_| {
actix_web::error::ErrorInternalServerError("Failed to serialize collections")
})?;

Ok(HttpResponse::Ok()
.content_type("application/json")
.body(response))
}

#[actix_web::get("/v1/scenarios/templates")]
async fn get_scenario_templates(
template_registry: Data<RwLock<TemplateRegistry>>,
) -> Result<HttpResponse, Error> {
let registry = template_registry.read().map_err(|_| {
actix_web::error::ErrorInternalServerError("Failed to read template registry")
})?;

let templates: Vec<&OverrideTemplate> = registry.all();
let response = serde_json::to_string(&templates)
.map_err(|_| actix_web::error::ErrorInternalServerError("Failed to serialize templates"))?;

Ok(HttpResponse::Ok()
.content_type("application/json")
.body(response))
}

#[allow(dead_code)]
#[cfg(not(feature = "explorer"))]
fn handle_embedded_file(_path: &str) -> HttpResponse {
HttpResponse::NotFound().body("404 Not Found")
Expand Down Expand Up @@ -221,7 +268,7 @@ fn start_subgraph_runloop(
subgraph_commands_rx: Receiver<SubgraphCommand>,
gql_context: Data<RwLock<DataloaderContext>>,
gql_schema: Data<RwLock<Option<DynamicSchema>>>,
mut collections_metadata_lookup: CollectionsMetadataLookup,
collections_metadata_lookup: Data<RwLock<CollectionsMetadataLookup>>,
config: SanitizedConfig,
ctx: &Context,
) -> Result<JoinHandle<Result<(), String>>, String> {
Expand Down Expand Up @@ -263,10 +310,14 @@ fn start_subgraph_runloop(
if let Err(e) = gql_context.pool.register_collection(&metadata, &request, &worker_id) {
error!("{}", e);
}
collections_metadata_lookup.add_collection(metadata);
gql_schema.replace(new_dynamic_schema(collections_metadata_lookup.clone()));

let console_url = format!("{}/subgraphs", config.studio_url.clone());
let mut lookup = collections_metadata_lookup.write().map_err(|_| {
format!("{err_ctx}: Failed to acquire write lock on collections metadata lookup")
})?;
lookup.add_collection(metadata);
gql_schema.replace(new_dynamic_schema(lookup.clone()));

let console_url = format!("{}/accounts", config.studio_url.clone());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, don't know if I love /accounts, cause we could still be indexing events

let _ = sender.send(console_url);
}
SubgraphCommand::ObserveCollection(subgraph_observer_rx) => {
Expand Down
Loading