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

feat(air-interpreter)!: rkyv-serialized JValues #814

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
02d5a4d
Initial version of custom JSON value
monoid Jan 26, 2024
ba1686f
Rc-based JSON value
monoid Jan 26, 2024
c74cdd9
Sketch of Rc JSON value
monoid Jan 29, 2024
628d233
Update MacOS M1 benches
monoid Jan 29, 2024
47196b5
Update Linux x64 benchmarks
monoid Jan 29, 2024
b3ccec1
Various refactorings and improvements
monoid Jan 30, 2024
f1cfa9e
Test compilation fixes
monoid Jan 31, 2024
2981168
feat(performance): reduced stack size (#799)
raftedproc Jan 28, 2024
637fbd5
feat(cli): use eyre in air-cli (#808)
monoid Jan 30, 2024
1fc6323
Fix tests
monoid Feb 1, 2024
ad1b074
Update MacOS ARM benchmark
monoid Feb 1, 2024
e069ac9
Update Linux x64 benchmarks
monoid Feb 1, 2024
a7dcd06
Remove `JValuable::into_jvalue`
monoid Feb 1, 2024
6d5b342
Make fmt and clippy happy
monoid Feb 1, 2024
f28fb5b
value serialization/deserialization tests
monoid Feb 4, 2024
85be1e7
Merge branch 'master' into feat/VM-422-rc-based-json-value
monoid Feb 4, 2024
bfe1485
Update MacOS M1 benches
monoid Feb 4, 2024
c6b7a74
Store JsonString in certain AST nodes
monoid Feb 4, 2024
432af74
Add license comments
monoid Feb 5, 2024
cc3018a
Introduce "preserve_order" feature flag
monoid Feb 5, 2024
41e383f
Merge branch 'master' into feat/VM-422-rc-based-json-value
monoid Feb 5, 2024
0a37f7c
Fix tests and clippy
monoid Feb 5, 2024
d1c6dd5
Do not run doctests with sanitizers
monoid Feb 5, 2024
3da2da1
Reconsider docstrings
monoid Feb 5, 2024
9df2b39
Rename some methods
monoid Feb 6, 2024
63c8e33
rkyv JValue
monoid Feb 6, 2024
f7c8bc8
Store RawValue as JValue
monoid Feb 6, 2024
0a51913
Update MacOS M1 benchmarks
monoid Feb 6, 2024
41c1766
Number type
monoid Feb 7, 2024
e0e69f9
Add `air_interpreter_data::Number`
monoid Feb 7, 2024
78c4576
Get rid of RawValue
monoid Feb 7, 2024
57a75bb
`From<JValue> for serde_json::Value`
monoid Feb 8, 2024
a825bc9
Fix tests
monoid Feb 8, 2024
1cf0b70
Add gen-bench-data Cargo.toml
monoid Feb 8, 2024
09de5f8
Serialize JValue objects with AsVec
monoid Feb 8, 2024
839389b
Update MacOS M1 benchmarks
monoid Feb 8, 2024
84c2b91
Improve formatting
monoid Feb 8, 2024
f6478c7
Fix signatures tests
monoid Feb 8, 2024
7b92d0a
More formatting
monoid Feb 8, 2024
343b58f
Merge branch 'master' into feat/VM-454-rkyv-json-value
monoid Feb 13, 2024
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: 6 additions & 4 deletions Cargo.lock

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

14 changes: 6 additions & 8 deletions air/src/execution_step/execution_context/cid_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use air_interpreter_data::CanonCidAggregate;
use air_interpreter_data::CanonResultCidAggregate;
use air_interpreter_data::CidInfo;
use air_interpreter_data::CidTracker;
use air_interpreter_data::RawValue;
use air_interpreter_data::ServiceResultCidAggregate;
use air_interpreter_data::TracePos;
use polyplets::SecurityTetraplet;
Expand All @@ -33,7 +32,7 @@ use std::rc::Rc;

#[derive(Debug, Default, Clone)]
pub struct ExecutionCidState {
pub value_tracker: CidTracker<RawValue>,
pub value_tracker: CidTracker<JValue>,
pub tetraplet_tracker: CidTracker<SecurityTetraplet>,
pub canon_element_tracker: CidTracker<CanonCidAggregate>,
pub canon_result_tracker: CidTracker<CanonResultCidAggregate>,
Expand Down Expand Up @@ -73,8 +72,7 @@ impl ExecutionCidState {
tetraplet: RcSecurityTetraplet,
argument_hash: Rc<str>,
) -> Result<CID<ServiceResultCidAggregate>, UncatchableError> {
let vm_value = RawValue::from_value(value);
let value_cid = self.value_tracker.track_raw_value(vm_value);
let value_cid = self.value_tracker.track_value(value)?;
let tetraplet_cid = self.tetraplet_tracker.track_value(tetraplet)?;
let service_result_agg = ServiceResultCidAggregate::new(value_cid, argument_hash, tetraplet_cid);

Expand All @@ -87,8 +85,8 @@ impl ExecutionCidState {
&mut self,
canon_value: &ValueAggregate,
) -> Result<CID<CanonCidAggregate>, UncatchableError> {
let vm_value = RawValue::from_value(canon_value.get_result().clone());
let value_cid = self.value_tracker.track_raw_value(vm_value);
let value = canon_value.get_result().clone();
let value_cid = self.value_tracker.track_value(value)?;
let tetraplet = self.tetraplet_tracker.track_value(canon_value.get_tetraplet())?;

let canon_value_aggregate = CanonCidAggregate::new(value_cid, tetraplet, canon_value.get_provenance());
Expand All @@ -97,11 +95,11 @@ impl ExecutionCidState {
.map_err(UncatchableError::from)
}

pub(crate) fn get_value_by_cid(&self, cid: &CID<RawValue>) -> Result<JValue, UncatchableError> {
pub(crate) fn get_value_by_cid(&self, cid: &CID<JValue>) -> Result<JValue, UncatchableError> {
self.value_tracker
.get(cid)
.ok_or_else(|| UncatchableError::ValueForCidNotFound("value", cid.get_inner()))
.map(|vm_value| vm_value.get_value())
.map(|rc_value| (*rc_value).clone())
}

pub(crate) fn get_tetraplet_by_cid(
Expand Down
4 changes: 2 additions & 2 deletions air/src/execution_step/lambda_applier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ fn try_jvalue_as_idx(jvalue: &JValue) -> LambdaResult<u32> {
}
}

fn try_number_to_u32(accessor: &serde_json::Number) -> LambdaResult<u32> {
fn try_number_to_u32(accessor: &air_interpreter_value::Number) -> LambdaResult<u32> {
accessor
.as_u64()
.and_then(|v| u32::try_from(v).ok())
.ok_or(LambdaError::IndexAccessNotU32 {
accessor: accessor.clone(),
accessor: accessor.clone().into(),
})
}
7 changes: 1 addition & 6 deletions air/tests/test_module/features/data_merging/data_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,7 @@ fn fold_merge() {
};

let service_result_agg = data.cid_info.service_result_store.get(cid).unwrap();
let value = data
.cid_info
.value_store
.get(&service_result_agg.value_cid)
.unwrap()
.get_value();
let value = &*data.cid_info.value_store.get(&service_result_agg.value_cid).unwrap();

if let JValue::String(ref var_name) = value {
let current_count: usize = calls_count.get(var_name).copied().unwrap_or_default();
Expand Down
4 changes: 2 additions & 2 deletions air/tests/test_module/features/signatures/corruption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_attack_replace_value() {
let mut mallory_cid_info = serde_json::to_value::<CidInfo>(mallory_cid_state.into()).unwrap();
let mut cnt = 0;
for (_cid, val) in mallory_cid_info["value_store"].as_object_mut().unwrap().iter_mut() {
if val.as_str().unwrap() == json!("alice").to_string() {
if val.as_str().unwrap() == json!("alice") {
*val = json!("evil").to_string().into();
cnt += 1;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ fn test_attack_replace_value() {
PreparationError::CidStoreVerificationError(
CidVerificationError::ValueMismatch {
// fragile: it is OK if this exact string changes on compiler upgrade
type_name: "air_interpreter_data::raw_value::RawValue",
type_name: "air_interpreter_value::value::JValue",
cid_repr: "bagaaihrayhxgqijfajraxivb7hxwshhbsdqk4j5zyqypb54zggmn5v7mmwxq".into(),
}
.into()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use air::interpreter_data::ExecutedState;
use air::ExecutionCidState;
use air::UncatchableError::*;
use air_interpreter_data::RawValue;
use air_interpreter_data::ValueRef;
use air_test_framework::AirScriptExecutor;
use air_test_utils::prelude::*;
Expand Down Expand Up @@ -139,10 +138,8 @@ fn malformed_call_service_failed() {
let mut cid_state = ExecutionCidState::new();

// Craft an artificial incorrect error result
let value = json!("error");
let value_cid = cid_state
.value_tracker
.track_raw_value(RawValue::from_value(value.clone()));
let value: JValue = "error".into();
let value_cid = cid_state.value_tracker.track_value(value.clone()).unwrap();
let tetraplet = SecurityTetraplet::literal_tetraplet(peer_id);
let tetraplet_cid = cid_state.tetraplet_tracker.track_value(tetraplet).unwrap();
let service_result_agg = ServiceResultCidAggregate {
Expand All @@ -161,7 +158,7 @@ fn malformed_call_service_failed() {
let mut vm = create_avm(unit_call_service(), peer_id);
let air = format!(r#"(call "{peer_id}" ("" "") [] var)"#);
let result = vm.call(&air, vec![], data, TestRunParameters::default()).unwrap();
let expected_serde_error = serde_json::from_value::<CallServiceFailed>(value).unwrap_err();
let expected_serde_error = serde_json::from_value::<CallServiceFailed>(value.into()).unwrap_err();
let expected_error = MalformedCallServiceFailed(expected_serde_error);
assert_error_eq!(&result, expected_error);
}
Expand Down
Loading
Loading