From 7482d2b24ace1e7b61038dd9a21f710379973408 Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Wed, 8 Nov 2023 12:45:42 -0800 Subject: [PATCH] Add cached VM program check --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- rust/Cargo.toml | 2 +- rust/src/program/execute.rs | 13 +++++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b19bb3bf..bf69c418 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,7 +39,7 @@ dependencies = [ [[package]] name = "aleo" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aleo-rust", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 13f2c8e4..a9ed3e49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleo" -version = "0.6.1" +version = "0.6.2" authors = [ "The Aleo Team " ] description = "Aleo" homepage = "https://aleo.org" @@ -21,7 +21,7 @@ edition = "2021" members = [ "rust", "rust/develop"] [workspace.dependencies.aleo-rust] -version = "0.6.1" +version = "0.6.2" path = "rust" default-features = false diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 6e8a3792..98c22e59 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleo-rust" -version = "0.6.1" +version = "0.6.2" authors = [ "The Aleo Team " ] description = "Rust SDK for managing Aleo programs and communicating with the Aleo network" homepage = "https://aleo.org" diff --git a/rust/src/program/execute.rs b/rust/src/program/execute.rs index 2f613508..3b95752e 100644 --- a/rust/src/program/execute.rs +++ b/rust/src/program/execute.rs @@ -173,6 +173,19 @@ impl ProgramManager { // Initialize the VM if let Some(vm) = vm { + let credits_id = ProgramID::::from_str("credits.aleo")?; + api_client.get_program_imports_from_source(program)?.iter().try_for_each(|(_, import)| { + if import.id() != &credits_id && !vm.process().read().contains_program(import.id()) { + vm.process().write().add_program(import)? + } + Ok::<_, Error>(()) + })?; + + // If the initialization is for an execution, add the program. Otherwise, don't add it as + // it will be added during the deployment process + if !vm.process().read().contains_program(program.id()) { + vm.process().write().add_program(program)?; + } vm.execute(private_key, (program_id, function_name), inputs, fee_record, priority_fee, Some(query), rng) } else { let vm = Self::initialize_vm(api_client, program, true)?;