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

fix: unnecessary vault creation [fixes NET-440] #1566

Merged
merged 12 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
10 changes: 3 additions & 7 deletions aquamarine/src/particle_data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ impl ParticleDataStore {
.iter()
.collect()
}

pub fn create_particle_vault(&self, key: &str) -> Result<()> {
self.vault.create(key)?;

Ok(())
}
}

const EXECUTION_TIME_THRESHOLD: Duration = Duration::from_millis(500);
Expand All @@ -83,12 +77,13 @@ impl DataStore for ParticleDataStore {
fn initialize(&mut self) -> Result<()> {
create_dir(&self.particle_data_store).map_err(CreateDataStore)?;

// self.vault.initialize()?;
self.vault.initialize()?;

Ok(())
}

fn store_data(&mut self, data: &[u8], particle_id: &str, current_peer_id: &str) -> Result<()> {
log::debug!(target: "particle_reap", "Storing data for particle {}", particle_id);
let data_path = self.data_file(particle_id, current_peer_id);
std::fs::write(&data_path, data).map_err(|err| StoreData(err, data_path))?;

Expand All @@ -102,6 +97,7 @@ impl DataStore for ParticleDataStore {
}

fn cleanup_data(&mut self, particle_id: &str, current_peer_id: &str) -> Result<()> {
log::debug!(target: "particle_reap", "Cleaning up particle data for particle {}", particle_id);
remove_file(&self.data_file(particle_id, current_peer_id)).map_err(CleanupData)?;
self.vault.cleanup(particle_id)?;

Expand Down
3 changes: 2 additions & 1 deletion aquamarine/src/plumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,16 @@ impl<RT: AquaRuntime, F: ParticleFunctionStatic> Plumber<RT, F> {
// Remove expired actors
if let Some((vm_id, mut vm)) = self.vm_pool.get_vm() {
let now = now_ms();

self.actors.retain(|(particle_id, peer_id), actor| {
// if actor hasn't yet expired or is still executing, keep it
// TODO: if actor is expired, cancel execution and return VM back to pool
// https://github.com/fluencelabs/fluence/issues/1212
if !actor.is_expired(now) || actor.is_executing() {
return true; // keep actor
}

log::debug!(
target: "particle_reap",
"Reaping particle's actor particle_id={particle_id}, peer_id={peer_id})"
);
// cleanup files and dirs after particle processing (vault & prev_data)
Expand Down
12 changes: 6 additions & 6 deletions crates/server-config/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ pub struct RootKeyPairArgs {
)]
path: Option<PathBuf>,
#[arg(
short('f'),
long,
value_parser(["ed25519", "secp256k1", "rsa"]),
id = "ROOT_KEY_FORMAT",
help_heading = "Node keypair",
display_order = 12,
short('f'),
long,
value_parser(["ed25519", "secp256k1", "rsa"]),
id = "ROOT_KEY_FORMAT",
help_heading = "Node keypair",
display_order = 12,
)]
format: Option<String>,

Expand Down
2 changes: 1 addition & 1 deletion particle-builtins/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ where
}

fn call_service(&self, function_args: Args, particle: ParticleParams) -> FunctionOutcome {
self.services.call_service(function_args, particle)
self.services.call_service(function_args, particle, true)
}

fn get_interface(&self, args: Args, params: ParticleParams) -> Result<JValue, JError> {
Expand Down
14 changes: 11 additions & 3 deletions particle-services/src/app_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,12 @@ impl ParticleAppServices {
Ok(())
}

pub fn call_service(&self, function_args: Args, particle: ParticleParams) -> FunctionOutcome {
pub fn call_service(
&self,
function_args: Args,
particle: ParticleParams,
create_vault: bool,
) -> FunctionOutcome {
let call_time_start = Instant::now();
let services = self.services.read();
let aliases = self.aliases.read();
Expand Down Expand Up @@ -447,7 +452,9 @@ impl ParticleAppServices {
let service_type = self.get_service_type(service, &worker_id);

// TODO: move particle vault creation to aquamarine::particle_functions
self.create_vault(&particle.id)?;
if create_vault {
self.create_vault(&particle.id)?;
}
let params = CallParameters {
host_id: worker_id.to_string(),
particle_id: particle.id,
Expand Down Expand Up @@ -535,6 +542,7 @@ impl ParticleAppServices {
particle_id: Option<String>,
init_peer_id: PeerId,
particle_ttl: Duration,
create_vault: bool,
) -> FunctionOutcome {
let args = Args {
service_id: service_id.to_string(),
Expand All @@ -553,7 +561,7 @@ impl ParticleAppServices {
signature: vec![],
};

self.call_service(args, particle)
justprosh marked this conversation as resolved.
Show resolved Hide resolved
self.call_service(args, particle, create_vault)
}

fn add_alias_inner(
Expand Down
4 changes: 4 additions & 0 deletions sorcerer/src/script_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Sorcerer {
None,
worker_id,
self.spell_script_particle_ttl,
false,
);

let res = process_func_outcome::<U32Value>(func_outcome, &spell_id, "get_u32");
Expand Down Expand Up @@ -65,6 +66,7 @@ impl Sorcerer {
None,
worker_id,
self.spell_script_particle_ttl,
false,
);

process_func_outcome::<UnitValue>(func_outcome, &spell_id, "set_u32").map(drop)
Expand All @@ -79,6 +81,7 @@ impl Sorcerer {
None,
worker_id,
self.spell_script_particle_ttl,
false,
);

Ok(process_func_outcome::<ScriptValue>(
Expand Down Expand Up @@ -138,6 +141,7 @@ impl Sorcerer {
None,
worker_id,
self.spell_script_particle_ttl,
false,
);

process_func_outcome::<UnitValue>(func_outcome, &event.spell_id, "list_push_string")
Expand Down
1 change: 1 addition & 0 deletions sorcerer/src/sorcerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl Sorcerer {
None,
spell_owner,
self.spell_script_particle_ttl,
false,
),
spell_id,
"get_trigger_config",
Expand Down
7 changes: 7 additions & 0 deletions sorcerer/src/spells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub(crate) async fn spell_install(
None,
worker_id,
Duration::from_millis(params.ttl as u64),
false,
),
&spell_id,
"set_script_source_to_file",
Expand All @@ -112,6 +113,7 @@ pub(crate) async fn spell_install(
None,
worker_id,
Duration::from_millis(params.ttl as u64),
false,
),
&spell_id,
"set_json_fields",
Expand All @@ -127,6 +129,7 @@ pub(crate) async fn spell_install(
None,
worker_id,
Duration::from_millis(params.ttl as u64),
false,
),
&spell_id,
"set_trigger_config",
Expand Down Expand Up @@ -249,6 +252,7 @@ pub(crate) async fn spell_update_config(
None,
worker_id,
Duration::from_millis(params.ttl as u64),
false,
),
&spell_id,
"set_trigger_config",
Expand Down Expand Up @@ -298,6 +302,7 @@ pub(crate) fn get_spell_arg(
Some(params.id.clone()),
params.init_peer_id,
Duration::from_millis(params.ttl as u64),
true, //TODO: check it
justprosh marked this conversation as resolved.
Show resolved Hide resolved
),
spell_id,
"get_string",
Expand All @@ -324,6 +329,7 @@ pub(crate) fn store_error(
Some(params.id.clone()),
params.init_peer_id,
Duration::from_millis(params.ttl as u64),
false,
),
spell_id,
"store_error",
Expand Down Expand Up @@ -353,6 +359,7 @@ pub(crate) fn store_response(
Some(params.id.clone()),
params.init_peer_id,
Duration::from_millis(params.ttl as u64),
false,
),
spell_id,
"set_json_fields",
Expand Down