Skip to content

Commit

Permalink
feat: deployments part ii (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru authored Feb 4, 2025
1 parent 7b07051 commit 09ddb23
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 136 deletions.
34 changes: 29 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.1.2"
version = "0.1.3"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ anyhow = "1.0.95"
url = "2.5.4"
dialoguer = "0.11.0"
mustache = "0.9.0"
crossbeam = "0.8.4"

[features]
default = ["cli"]
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Context {

pub const DEFAULT_SLOT_TIME_MS: &str = "400";
pub const DEFAULT_BINDING_PORT: &str = "8899";
pub const DEFAULT_BINDING_ADDRESS: &str = "localhost";
pub const DEFAULT_BINDING_ADDRESS: &str = "127.0.0.1";
pub const DEFAULT_RPC_URL: &str = "https://api.mainnet-beta.solana.com";

#[allow(dead_code)]
Expand Down
34 changes: 21 additions & 13 deletions crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{scaffold::detect_program_frameworks, tui};
use std::sync::mpsc::{channel, Receiver};
use crate::{runbook::execute_runbook, scaffold::detect_program_frameworks, tui};

use super::{Context, StartSimnet};
use surfpool_core::{
simnet::SimnetEvent,
start_simnet,
types::{RpcConfig, SimnetConfig, SurfpoolConfig},
};
use txtx_core::kit::{channel::Receiver, helpers::fs::FileLocation, types::frontend::BlockEvent};

pub async fn handle_start_simnet_command(cmd: &StartSimnet, ctx: &Context) -> Result<(), String> {
let config = SurfpoolConfig {
Expand All @@ -21,7 +21,7 @@ pub async fn handle_start_simnet_command(cmd: &StartSimnet, ctx: &Context) -> Re
},
};

let (simnet_events_tx, simnet_events_rx) = channel();
let (simnet_events_tx, simnet_events_rx) = crossbeam::channel::unbounded();
let ctx_cloned = ctx.clone();
// Start backend - background task
let _handle = hiro_system_kit::thread_named("simnet")
Expand Down Expand Up @@ -49,29 +49,37 @@ pub async fn handle_start_simnet_command(cmd: &StartSimnet, ctx: &Context) -> Re

// Propose deployments (use --no-deploy)

match detect_program_frameworks(&cmd.manifest_path).await {
Err(e) => error!(ctx.expect_logger(), "{}", e),
Ok(Some(framework)) => {
info!(
ctx.expect_logger(),
"Loading contracts from {:?}", framework
)
let deployment = match detect_program_frameworks(&cmd.manifest_path).await {
Err(e) => {
error!(ctx.expect_logger(), "{}", e);
None
}
_ => {}
Ok(deployment) => deployment,
};

let deploy_progress_rx = if let Some((framework, programs)) = deployment {
let (progress_tx, progress_rx) = crossbeam::channel::unbounded();
let manifest_location = FileLocation::from_path_string(&cmd.manifest_path)?;
execute_runbook("v1", progress_tx, &manifest_location).await?;
Some(progress_rx)
} else {
None
};

// Start frontend - kept on main thread
if cmd.no_tui {
log_events(simnet_events_rx, cmd.debug, ctx)?;
log_events(simnet_events_rx, cmd.debug, deploy_progress_rx, ctx)?;
} else {
tui::simnet::start_app(simnet_events_rx, cmd.debug).map_err(|e| format!("{}", e))?;
tui::simnet::start_app(simnet_events_rx, cmd.debug, deploy_progress_rx)
.map_err(|e| format!("{}", e))?;
}
Ok(())
}

fn log_events(
simnet_events_rx: Receiver<SimnetEvent>,
include_debug_logs: bool,
deploy_progress_rx: Option<Receiver<BlockEvent>>,
ctx: &Context,
) -> Result<(), String> {
info!(
Expand Down
51 changes: 3 additions & 48 deletions crates/cli/src/runbook/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use ratatui::widgets::Block;
use std::io::Write;
use txtx_addon_network_svm::SvmNetworkAddon;
use txtx_core::{
kit::{
channel::unbounded,
channel::{unbounded, Sender},
helpers::fs::FileLocation,
types::{
frontend::{BlockEvent, ProgressBarStatusColor},
Expand All @@ -28,6 +29,7 @@ pub fn get_addon_by_namespace(namespace: &str) -> Option<Box<dyn Addon>> {

pub async fn execute_runbook(
runbook_id: &str,
progress_tx: Sender<BlockEvent>,
manifest_location: &FileLocation,
) -> Result<(), String> {
let base_dir_location = manifest_location.get_parent_location()?;
Expand Down Expand Up @@ -59,53 +61,6 @@ pub async fn execute_runbook(

runbook.enable_full_execution_mode();

let (progress_tx, progress_rx) = unbounded();
// should not be generating actions
let _ = hiro_system_kit::thread_named("Display background tasks logs").spawn(move || {
while let Ok(msg) = progress_rx.recv() {
match msg {
BlockEvent::UpdateProgressBarStatus(update) => {
match update.new_status.status_color {
ProgressBarStatusColor::Yellow => {
print!(
"\r{} {} {:<150}",
yellow!("→"),
yellow!(format!("{}", update.new_status.status)),
update.new_status.message,
);
}
ProgressBarStatusColor::Green => {
print!(
"\r{} {} {:<150}\n",
green!("✓"),
green!(format!("{}", update.new_status.status)),
update.new_status.message,
);
}
ProgressBarStatusColor::Red => {
print!(
"\r{} {} {:<150}\n",
red!("x"),
red!(format!("{}", update.new_status.status)),
update.new_status.message,
);
}
ProgressBarStatusColor::Purple => {
print!(
"\r{} {} {:<150}\n",
purple!("→"),
purple!(format!("{}", update.new_status.status)),
update.new_status.message,
);
}
};
std::io::stdout().flush().unwrap();
}
_ => {}
}
}
});

let res = start_unsupervised_runbook_runloop(&mut runbook, &progress_tx).await;
if let Err(diags) = res {
println!("{} Execution aborted", red!("x"));
Expand Down
1 change: 0 additions & 1 deletion crates/cli/src/scaffold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub async fn detect_program_frameworks(
anchor::try_get_programs_from_project(base_dir.clone())?
{
scaffold_runbooks_layout(runbook, base_dir)?;
execute_runbook("v1", &manifest_location).await?;
return Ok(Some((framework, programs)));
}

Expand Down
Loading

0 comments on commit 09ddb23

Please sign in to comment.