Skip to content

Commit

Permalink
remove aptos-move/e2e-tests-replay
Browse files Browse the repository at this point in the history
Removing this per offline discussion.
Consolidate change set conversion logic into SessionOut.

Closes: aptos-labs#846
  • Loading branch information
msmouse authored and aptos-bot committed May 8, 2022
1 parent 2acc8f4 commit 416bc14
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1,348 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ members = [
"aptos-move/aptos-validator-interface",
"aptos-move/aptos-vm",
"aptos-move/e2e-tests",
"aptos-move/e2e-tests-replay",
"aptos-move/e2e-testsuite",
"aptos-move/framework",
"aptos-move/framework/cached-packages",
Expand Down
87 changes: 1 addition & 86 deletions aptos-move/aptos-vm/src/aptos_vm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ use aptos_state_view::StateView;
use aptos_types::{
account_config,
account_config::ChainSpecificAccountInfo,
contract_event::ContractEvent,
event::EventKey,
on_chain_config::{
ConfigStorage, OnChainConfig, VMConfig, VMPublishingOption, Version, APTOS_VERSION_3,
},
state_store::state_key::StateKey,
transaction::{ExecutionStatus, TransactionOutput, TransactionStatus},
vm_status::{StatusCode, VMStatus},
write_set::{WriteOp, WriteSet, WriteSetMut},
};
use fail::fail_point;
use move_deps::{
Expand All @@ -34,18 +30,16 @@ use move_deps::{
},
move_core_types::{
account_address::AccountAddress,
effects::{ChangeSet as MoveChangeSet, Event as MoveEvent},
gas_schedule::{CostTable, GasAlgebra, GasCarrier, GasUnits, InternalGasUnits},
language_storage::ModuleId,
move_resource::MoveStructType,
resolver::ResourceResolver,
value::{serialize_values, MoveValue},
},
move_table_extension::TableChangeSet,
move_vm_runtime::{logging::expect_no_verification_errors, session::Session},
move_vm_types::gas_schedule::{calculate_intrinsic_gas, GasStatus},
};
use std::{convert::TryFrom, sync::Arc};
use std::sync::Arc;

#[derive(Clone)]
/// A wrapper to make VMRuntime standalone and thread safe.
Expand Down Expand Up @@ -548,85 +542,6 @@ impl<'a> AptosVMInternals<'a> {
}
}

pub fn convert_changeset_and_events(
changeset: MoveChangeSet,
events: Vec<MoveEvent>,
) -> Result<(WriteSet, Vec<ContractEvent>), VMStatus> {
let mut out_write_set = WriteSetMut::new(vec![]);
let mut out_events = Vec::new();
convert_changeset_and_events_cached(
&mut (),
changeset,
events,
&mut out_write_set,
&mut out_events,
)?;
let ws = out_write_set
.freeze()
.map_err(|_| VMStatus::Error(StatusCode::DATA_FORMAT_ERROR))?;
Ok((ws, out_events))
}

pub fn convert_changeset_and_events_cached<C: AccessPathCache>(
ap_cache: &mut C,
changeset: MoveChangeSet,
events: Vec<MoveEvent>,
out_write_set: &mut WriteSetMut,
out_events: &mut Vec<ContractEvent>,
) -> Result<(), VMStatus> {
for (addr, account_changeset) in changeset.into_inner() {
let (modules, resources) = account_changeset.into_inner();
for (struct_tag, blob_opt) in resources {
let ap = ap_cache.get_resource_path(addr, struct_tag);
let op = match blob_opt {
None => WriteOp::Deletion,
Some(blob) => WriteOp::Value(blob),
};
out_write_set.push((StateKey::AccessPath(ap), op))
}

for (name, blob_opt) in modules {
let ap = ap_cache.get_module_path(ModuleId::new(addr, name));
let op = match blob_opt {
None => WriteOp::Deletion,
Some(blob) => WriteOp::Value(blob),
};

out_write_set.push((StateKey::AccessPath(ap), op))
}
}

let events = events
.into_iter()
.map(|(guid, seq_num, ty_tag, blob)| {
let key = EventKey::try_from(guid.as_slice())
.map_err(|_| VMStatus::Error(StatusCode::EVENT_KEY_MISMATCH))?;
Ok(ContractEvent::new(key, seq_num, ty_tag, blob))
})
.collect::<Result<Vec<_>, VMStatus>>()?;

out_events.extend(events.into_iter());
Ok(())
}

pub fn convert_table_changeset(
table_changeset: TableChangeSet,
out_write_set: &mut WriteSetMut,
) -> Result<(), VMStatus> {
for (handle, change) in table_changeset.changes {
for (key, value_opt) in change.entries {
let state_key = StateKey::table_item(handle.0, key);
if let Some(bytes) = value_opt {
out_write_set.push((state_key, WriteOp::Value(bytes)))
} else {
out_write_set.push((state_key, WriteOp::Deletion))
}
}
}

Ok(())
}

pub(crate) fn charge_global_write_gas_usage<R: MoveResolverExt>(
gas_status: &mut GasStatus,
session: &Session<R>,
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub mod script_to_script_function;
pub mod system_module_names;
pub mod transaction_metadata;

pub use crate::{aptos_vm::AptosVM, aptos_vm_impl::convert_changeset_and_events};
pub use crate::aptos_vm::AptosVM;

use aptos_state_view::StateView;
use aptos_types::{
Expand Down
80 changes: 58 additions & 22 deletions aptos-move/aptos-vm/src/move_vm_ext/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
access_path_cache::AccessPathCache,
aptos_vm_impl::{convert_changeset_and_events_cached, convert_table_changeset},
move_vm_ext::MoveResolverExt,
access_path_cache::AccessPathCache, move_vm_ext::MoveResolverExt,
transaction_metadata::TransactionMetadata,
};
use aptos_crypto::{hash::CryptoHash, HashValue};
use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher};
use aptos_types::{
block_metadata::BlockMetadata,
contract_event::ContractEvent,
event::EventKey,
state_store::state_key::StateKey,
transaction::{ChangeSet, SignatureCheckedTransaction},
write_set::WriteSetMut,
write_set::{WriteOp, WriteSetMut},
};
use move_deps::{
move_binary_format::errors::{Location, VMResult},
move_core_types::{
account_address::AccountAddress,
effects::{ChangeSet as MoveChangeSet, Event as MoveEvent},
language_storage::ModuleId,
vm_status::{StatusCode, VMStatus},
},
move_table_extension::{NativeTableContext, TableChange, TableChangeSet},
move_vm_runtime::session::Session,
};
use serde::{Deserialize, Serialize};
use std::{
convert::TryInto,
convert::{TryFrom, TryInto},
ops::{Deref, DerefMut},
};

Expand Down Expand Up @@ -138,26 +140,60 @@ impl SessionOutput {
self,
ap_cache: &mut C,
) -> Result<ChangeSet, VMStatus> {
let mut out_write_set = WriteSetMut::new(Vec::new());
let mut out_events = Vec::new();
convert_changeset_and_events_cached(
ap_cache,
self.change_set,
self.events,
&mut out_write_set,
&mut out_events,
)?;

convert_table_changeset(self.table_change_set, &mut out_write_set)?;

let ws = out_write_set
let Self {
change_set,
events,
table_change_set,
} = self;

let mut write_set_mut = WriteSetMut::new(Vec::new());
for (addr, account_changeset) in change_set.into_inner() {
let (modules, resources) = account_changeset.into_inner();
for (struct_tag, blob_opt) in resources {
let ap = ap_cache.get_resource_path(addr, struct_tag);
let op = match blob_opt {
None => WriteOp::Deletion,
Some(blob) => WriteOp::Value(blob),
};
write_set_mut.push((StateKey::AccessPath(ap), op))
}

for (name, blob_opt) in modules {
let ap = ap_cache.get_module_path(ModuleId::new(addr, name));
let op = match blob_opt {
None => WriteOp::Deletion,
Some(blob) => WriteOp::Value(blob),
};

write_set_mut.push((StateKey::AccessPath(ap), op))
}
}

for (handle, change) in table_change_set.changes {
for (key, value_opt) in change.entries {
let state_key = StateKey::table_item(handle.0, key);
if let Some(bytes) = value_opt {
write_set_mut.push((state_key, WriteOp::Value(bytes)))
} else {
write_set_mut.push((state_key, WriteOp::Deletion))
}
}
}

let write_set = write_set_mut
.freeze()
.map_err(|_| VMStatus::Error(StatusCode::DATA_FORMAT_ERROR))?;
Ok(ChangeSet::new(ws, out_events))
}

pub fn unpack(self) -> (MoveChangeSet, Vec<MoveEvent>, TableChangeSet) {
(self.change_set, self.events, self.table_change_set)
let events = events
.into_iter()
.map(|(guid, seq_num, ty_tag, blob)| {
let key = EventKey::try_from(guid.as_slice())
.map_err(|_| VMStatus::Error(StatusCode::EVENT_KEY_MISMATCH))?;
Ok(ContractEvent::new(key, seq_num, ty_tag, blob))
})
.collect::<Result<Vec<_>, VMStatus>>()?;

Ok(ChangeSet::new(write_set, events))
}

pub fn squash(&mut self, other: Self) -> Result<(), VMStatus> {
Expand Down
21 changes: 0 additions & 21 deletions aptos-move/e2e-tests-replay/Cargo.toml

This file was deleted.

Loading

0 comments on commit 416bc14

Please sign in to comment.