Add AIR script to the AquaVM's anomaly data (#280)

Save AIR script to AnomlalyData struct.

Increments versions of `avm-data-store` to 0.3.0 and `avm-server` to 0.22.0.
This commit is contained in:
Ivan Boldyrev 2022-06-30 12:26:37 +03:00 committed by GitHub
parent cc4fba4455
commit 4acfb19e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 7 deletions

4
Cargo.lock generated
View File

@ -233,14 +233,14 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "avm-data-store" name = "avm-data-store"
version = "0.2.0" version = "0.3.0"
dependencies = [ dependencies = [
"serde", "serde",
] ]
[[package]] [[package]]
name = "avm-server" name = "avm-server"
version = "0.21.0" version = "0.22.0"
dependencies = [ dependencies = [
"air-interpreter-interface", "air-interpreter-interface",
"avm-data-store", "avm-data-store",

View File

@ -1,7 +1,7 @@
[package] [package]
name = "avm-server" name = "avm-server"
description = "Fluence AIR VM" description = "Fluence AIR VM"
version = "0.21.0" version = "0.22.0"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
edition = "2018" edition = "2018"
license = "Apache-2.0" license = "Apache-2.0"
@ -17,7 +17,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
air-interpreter-interface = { version = "0.10.0", path = "../../crates/air-lib/interpreter-interface" } air-interpreter-interface = { version = "0.10.0", path = "../../crates/air-lib/interpreter-interface" }
avm-data-store = { version = "0.2.0", path = "../../crates/data-store" } avm-data-store = { version = "0.3.0", path = "../../crates/data-store" }
fluence-faas = "0.16.2" fluence-faas = "0.16.2"
polyplets = { version = "0.2.0", path = "../../crates/air-lib/polyplets" } polyplets = { version = "0.2.0", path = "../../crates/air-lib/polyplets" }

View File

@ -83,6 +83,7 @@ impl<E> AVM<E> {
particle_parameters: ParticleParameters<'_, '_>, particle_parameters: ParticleParameters<'_, '_>,
call_results: CallResults, call_results: CallResults,
) -> AVMResult<AVMOutcome, E> { ) -> AVMResult<AVMOutcome, E> {
let air = air.into();
let particle_id = particle_parameters.particle_id.as_str(); let particle_id = particle_parameters.particle_id.as_str();
let prev_data = self.data_store.read_data(particle_id)?; let prev_data = self.data_store.read_data(particle_id)?;
let current_data = data.into(); let current_data = data.into();
@ -92,7 +93,7 @@ impl<E> AVM<E> {
let outcome = self let outcome = self
.runner .runner
.call( .call(
air, air.clone(),
prev_data, prev_data,
current_data.clone(), current_data.clone(),
particle_parameters.init_peer_id.clone().into_owned(), particle_parameters.init_peer_id.clone().into_owned(),
@ -106,6 +107,7 @@ impl<E> AVM<E> {
let memory_delta = self.memory_stats().memory_size - memory_size_before; let memory_delta = self.memory_stats().memory_size - memory_size_before;
if self.data_store.detect_anomaly(execution_time, memory_delta) { if self.data_store.detect_anomaly(execution_time, memory_delta) {
self.save_anomaly_data( self.save_anomaly_data(
&air,
&current_data, &current_data,
&particle_parameters, &particle_parameters,
&outcome, &outcome,
@ -134,6 +136,7 @@ impl<E> AVM<E> {
fn save_anomaly_data( fn save_anomaly_data(
&mut self, &mut self,
air_script: &str,
current_data: &[u8], current_data: &[u8],
particle_parameters: &ParticleParameters<'_, '_>, particle_parameters: &ParticleParameters<'_, '_>,
avm_outcome: &RawAVMOutcome, avm_outcome: &RawAVMOutcome,
@ -149,9 +152,10 @@ impl<E> AVM<E> {
serde_json::to_vec(avm_outcome).map_err(AVMError::AnomalyDataSeError)?; serde_json::to_vec(avm_outcome).map_err(AVMError::AnomalyDataSeError)?;
let anomaly_data = AnomalyData::new( let anomaly_data = AnomalyData::new(
air_script,
&ser_particle, &ser_particle,
&prev_data, &prev_data,
&current_data, current_data,
&ser_avm_outcome, &ser_avm_outcome,
execution_time, execution_time,
memory_delta, memory_delta,

View File

@ -1,6 +1,6 @@
[package] [package]
name = "avm-data-store" name = "avm-data-store"
version = "0.2.0" version = "0.3.0"
description = "Definition of the AVM DataStore trait" description = "Definition of the AVM DataStore trait"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
edition = "2018" edition = "2018"

View File

@ -49,6 +49,7 @@ pub trait DataStore {
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct AnomalyData<'data> { pub struct AnomalyData<'data> {
pub air_script: &'data str,
pub particle: &'data [u8], // it's byte because of the restriction on trait objects methods pub particle: &'data [u8], // it's byte because of the restriction on trait objects methods
pub prev_data: &'data [u8], pub prev_data: &'data [u8],
pub current_data: &'data [u8], pub current_data: &'data [u8],
@ -59,6 +60,7 @@ pub struct AnomalyData<'data> {
impl<'data> AnomalyData<'data> { impl<'data> AnomalyData<'data> {
pub fn new( pub fn new(
air_script: &'data str,
particle: &'data [u8], particle: &'data [u8],
prev_data: &'data [u8], prev_data: &'data [u8],
current_data: &'data [u8], current_data: &'data [u8],
@ -67,6 +69,7 @@ impl<'data> AnomalyData<'data> {
memory_delta: usize, memory_delta: usize,
) -> Self { ) -> Self {
Self { Self {
air_script,
particle, particle,
prev_data, prev_data,
current_data, current_data,