Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: state poc #37

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 19 additions & 10 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ path = "src/main.rs"
[dependencies]
surfpool-core = { workspace = true }
# surfpool-core = { version = "0.1" }
# txtx-core = { path = "../../../txtx/crates/txtx-core" }
# txtx-addon-network-svm = { package = "txtx-addon-network-svm", path = "../../../txtx/addons/svm" }
txtx-core = { version = "0.2.2" }
txtx-addon-network-svm = { version = "0.1.3" }
txtx-core = { path = "../../../txtx/crates/txtx-core" }
txtx-addon-network-svm = { package = "txtx-addon-network-svm", path = "../../../txtx/addons/svm" }
# txtx-core = { version = "0.2.2" }
# txtx-addon-network-svm = { version = "0.1.3" }
Comment on lines +19 to +22
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify external dependencies.

The dependencies are using paths outside the repository (../../../txtx/), which could cause issues with reproducible builds. Consider:

  1. Moving these dependencies into the repository, or
  2. Publishing them to crates.io and using version specifications.

🏁 Script executed:

#!/bin/bash
# Description: Check if the external dependencies exist and are accessible.

# Test: Check if the txtx-core path exists
if [ -d "../../../txtx/crates/txtx-core" ]; then
    echo "txtx-core path exists"
else
    echo "txtx-core path does not exist"
fi

# Test: Check if the txtx-addon-network-svm path exists
if [ -d "../../../txtx/addons/svm" ]; then
    echo "txtx-addon-network-svm path exists"
else
    echo "txtx-addon-network-svm path does not exist"
fi

Length of output: 245


External Dependencies Missing – Action Required

The verification confirms that both dependency paths (../../../txtx/crates/txtx-core and ../../../txtx/addons/svm) do not exist. This outcome directly supports the concern that these external path dependencies could lead to reproducibility issues. It is advisable to either incorporate these dependencies into the repository or publish them to crates.io and use version specifications to avoid future build complications.

  • Location: crates/cli/Cargo.toml (lines 19-22)

hiro-system-kit = "0.3.1"
atty = "0.2.13"
ansi_term = "0.12.1"
Expand Down Expand Up @@ -48,4 +48,4 @@ mime_guess = "2.0.4"
[features]
default = ["cli"]
cli = ["clap", "toml", "ctrlc", "hiro-system-kit/log"]
explorer = []
explorer = []
48 changes: 37 additions & 11 deletions crates/cli/src/runbook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use txtx_core::{
manifest::{file::read_runbooks_from_manifest, WorkspaceManifest},
start_unsupervised_runbook_runloop,
std::StdAddon,
types::RunbookSnapshotContext,
};

pub fn get_addon_by_namespace(namespace: &str) -> Option<Box<dyn Addon>> {
Expand All @@ -21,20 +22,24 @@ pub fn get_addon_by_namespace(namespace: &str) -> Option<Box<dyn Addon>> {
}
None
}

pub const DEFAULT_ENVIRONMENT: &str = "localnet";
pub async fn execute_runbook(
runbook_id: String,
progress_tx: Sender<BlockEvent>,
txtx_manifest_location: FileLocation,
) -> Result<(), String> {
let manifest = WorkspaceManifest::from_location(&txtx_manifest_location)?;
let runbook_selector = vec![runbook_id.to_string()];
let mut runbooks =
read_runbooks_from_manifest(&manifest, &Some("localnet".into()), Some(&runbook_selector))?;
let mut runbooks = read_runbooks_from_manifest(
&manifest,
&Some(DEFAULT_ENVIRONMENT.into()),
Some(&runbook_selector),
)?;
let top_level_inputs_map =
manifest.get_runbook_inputs(&Some("localnet".into()), &vec![], None)?;
manifest.get_runbook_inputs(&Some(DEFAULT_ENVIRONMENT.into()), &vec![], None)?;

let Some((mut runbook, runbook_sources, _state, _smt)) = runbooks.swap_remove(&runbook_id)
let Some((mut runbook, runbook_sources, _state, runbook_state_location)) =
runbooks.swap_remove(&runbook_id)
else {
return Err(format!("Deployment {} not found", runbook_id));
};
Expand All @@ -54,6 +59,32 @@ pub async fn execute_runbook(

runbook.enable_full_execution_mode();

if let Some(state_file_location) = runbook_state_location.clone() {
match state_file_location.load_execution_snapshot(
true,
&runbook.runbook_id.name,
&runbook.top_level_inputs_map.current_top_level_input_name(),
) {
Ok(old_snapshot) => {
let ctx = RunbookSnapshotContext::new();
let execution_context_backups = runbook.backup_execution_contexts();
let new = runbook.simulate_and_snapshot_flows(&old_snapshot).await?;
let consolidated_changes = ctx.diff(old_snapshot, new);

runbook.prepare_flows_for_new_plans(
&consolidated_changes.new_plans_to_add,
execution_context_backups,
);

let _ =
runbook.prepared_flows_for_updated_plans(&consolidated_changes.plans_to_update);
}
Err(e) => {
println!("{} {}", red!("x"), e);
}
}
}

let res = start_unsupervised_runbook_runloop(&mut runbook, &progress_tx).await;
if let Err(diags) = res {
println!("{} Execution aborted", red!("x"));
Expand All @@ -64,12 +95,7 @@ pub async fn execute_runbook(
return Ok(());
}

if let Err(diags) = res {
for diag in diags.iter() {
println!("{} {}", red!("x"), diag);
}
std::process::exit(1);
}
let _ = runbook.write_runbook_state(runbook_state_location)?;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle the state writing result.

The result of writing the runbook state is ignored with let _. Consider handling potential errors.

-    let _ = runbook.write_runbook_state(runbook_state_location)?;
+    runbook.write_runbook_state(runbook_state_location)?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let _ = runbook.write_runbook_state(runbook_state_location)?;
runbook.write_runbook_state(runbook_state_location)?;


Ok(())
}
Loading