Skip to content

Commit

Permalink
Remove events from the Move VM (#18235)
Browse files Browse the repository at this point in the history
## Description 

Remove code related to events

## Test plan 

existing tests

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
dariorussi authored Jun 14, 2024
1 parent 55f370f commit 3cd2ea4
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ pub fn publish(
}

if !has_error {
let (changeset, events) = session.finish().0?;
assert!(events.is_empty());
let changeset = session.finish().0?;
if verbose {
explain_publish_changeset(&changeset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn run(
txn_args,
)
} else {
let (_changeset, _events) = session.finish().0?;
let _changeset = session.finish().0?;
Ok(())
}
}
4 changes: 1 addition & 3 deletions external-crates/move/crates/move-core-types/src/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::{
account_address::AccountAddress,
identifier::Identifier,
language_storage::{ModuleId, StructTag, TypeTag},
language_storage::{ModuleId, StructTag},
};
use anyhow::{bail, Result};
use std::collections::btree_map::{self, BTreeMap};
Expand Down Expand Up @@ -300,5 +300,3 @@ impl ChangeSet {
})
}
}

pub type Event = (Vec<u8>, u64, TypeTag, Vec<u8>);
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl SimpleVMTestAdapter {

// save changeset
// TODO support events
let (changeset, _events) = session.finish().0?;
let changeset = session.finish().0?;
self.storage.apply(changeset).unwrap();
Ok(res)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl SharedTestingConfig {
.into(),
);
match session.finish_with_extensions().0 {
Ok((cs, _, extensions)) => (Ok(cs), Ok(extensions), return_result, test_run_info),
Ok((cs, extensions)) => (Ok(cs), Ok(extensions), return_result, test_run_info),
Err(err) => (Err(err.clone()), Err(err), return_result, test_run_info),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::compiler::{as_module, compile_units};
use move_binary_format::errors::VMResult;
use move_core_types::{
account_address::AccountAddress,
effects::{ChangeSet, Event},
effects::ChangeSet,
identifier::Identifier,
language_storage::ModuleId,
runtime_value::{serialize_values, MoveValue},
Expand Down Expand Up @@ -57,7 +57,7 @@ fn fail_arg_deserialize() {
fn mutref_output_success() {
let mod_code = setup_module();
let result = run(&mod_code, USE_MUTREF_LABEL, MoveValue::U64(1));
let (_, _, ret_values) = result.unwrap();
let (_, ret_values) = result.unwrap();
assert_eq!(1, ret_values.mutable_reference_outputs.len());
let parsed = parse_u64_arg(&ret_values.mutable_reference_outputs.first().unwrap().1);
assert_eq!(EXPECT_MUTREF_OUT_VALUE, parsed);
Expand Down Expand Up @@ -86,7 +86,7 @@ fn run(
module: &ModuleCode,
fun_name: &str,
arg_val0: MoveValue,
) -> VMResult<(ChangeSet, Vec<Event>, SerializedReturnValues)> {
) -> VMResult<(ChangeSet, SerializedReturnValues)> {
let module_id = &module.0;
let modules = vec![module.clone()];
let (vm, storage) = setup_vm(&modules);
Expand All @@ -103,8 +103,8 @@ fn run(
&mut UnmeteredGasMeter,
)
.and_then(|ret_values| {
let (change_set, events) = session.finish().0?;
Ok((change_set, events, ret_values))
let change_set = session.finish().0?;
Ok((change_set, ret_values))
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Adapter {
.publish_module(binary, DEFAULT_ACCOUNT, &mut UnmeteredGasMeter)
.unwrap_or_else(|e| panic!("failure publishing module: {e:?}\n{:#?}", module));
}
let (changeset, _) = session.finish().0.expect("failure getting write set");
let changeset = session.finish().0.expect("failure getting write set");
self.store
.apply(changeset)
.expect("failure applying write set");
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Adapter {
.publish_module_bundle(binaries, DEFAULT_ACCOUNT, &mut UnmeteredGasMeter)
.unwrap_or_else(|e| panic!("failure publishing module bundle: {e:?}"));

let (changeset, _) = session.finish().0.expect("failure getting write set");
let changeset = session.finish().0.expect("failure getting write set");
self.store
.apply(changeset)
.expect("failure applying write set");
Expand Down
19 changes: 4 additions & 15 deletions external-crates/move/crates/move-vm-runtime/src/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::loader::Loader;
use move_binary_format::errors::*;
use move_core_types::{
account_address::AccountAddress,
effects::{AccountChangeSet, ChangeSet, Event, Op},
effects::{AccountChangeSet, ChangeSet, Op},
gas_algebra::NumBytes,
identifier::{IdentStr, Identifier},
language_storage::{ModuleId, TypeTag},
Expand Down Expand Up @@ -53,7 +53,6 @@ pub(crate) struct TransactionDataCache<'l, S> {
remote: S,
loader: &'l Loader,
account_map: BTreeMap<AccountAddress, AccountDataCache>,
event_data: Vec<(Vec<u8>, u64, Type, MoveTypeLayout, Value)>,
}

impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
Expand All @@ -64,18 +63,17 @@ impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
remote,
loader,
account_map: BTreeMap::new(),
event_data: vec![],
}
}

/// Make a write set from the updated (dirty, deleted) global resources along with
/// published modules.
///
/// Gives all proper guarantees on lifetime of global data as well.
pub(crate) fn into_effects(mut self) -> (PartialVMResult<(ChangeSet, Vec<Event>)>, S) {
pub(crate) fn into_effects(mut self) -> (PartialVMResult<ChangeSet>, S) {
(self.impl_into_effects(), self.remote)
}
fn impl_into_effects(&mut self) -> PartialVMResult<(ChangeSet, Vec<Event>)> {
fn impl_into_effects(&mut self) -> PartialVMResult<ChangeSet> {
let mut change_set = ChangeSet::new();
for (addr, account_data_cache) in std::mem::take(&mut self.account_map).into_iter() {
let mut modules = BTreeMap::new();
Expand Down Expand Up @@ -123,16 +121,7 @@ impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
}
}

let mut events = vec![];
for (guid, seq_num, ty, ty_layout, val) in std::mem::take(&mut self.event_data) {
let ty_tag = self.loader.type_to_type_tag(&ty)?;
let blob = val
.simple_serialize(&ty_layout)
.ok_or_else(|| PartialVMError::new(StatusCode::INTERNAL_TYPE_ERROR))?;
events.push((guid, seq_num, ty_tag, blob))
}

Ok((change_set, events))
Ok(change_set)
}

pub(crate) fn num_mutated_accounts(&self, sender: &AccountAddress) -> u64 {
Expand Down
8 changes: 4 additions & 4 deletions external-crates/move/crates/move-vm-runtime/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use move_binary_format::{
use move_core_types::{
account_address::AccountAddress,
annotated_value as A,
effects::{ChangeSet, Event},
effects::ChangeSet,
identifier::IdentStr,
language_storage::{ModuleId, TypeTag},
resolver::MoveResolver,
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
/// This function should always succeed with no user errors returned, barring invariant violations.
///
/// This MUST NOT be called if there is a previous invocation that failed with an invariant violation.
pub fn finish(self) -> (VMResult<(ChangeSet, Vec<Event>)>, S) {
pub fn finish(self) -> (VMResult<ChangeSet>, S) {
let (res, remote) = self.data_cache.into_effects();
(res.map_err(|e| e.finish(Location::Undefined)), remote)
}
Expand All @@ -186,7 +186,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
pub fn finish_with_extensions(
self,
) -> (
VMResult<(ChangeSet, Vec<Event>, NativeContextExtensions<'r>)>,
VMResult<(ChangeSet, NativeContextExtensions<'r>)>,
S,
) {
let Session {
Expand All @@ -196,7 +196,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
} = self;
let (res, remote) = data_cache.into_effects();
(
res.map(|(change_set, events)| (change_set, events, native_extensions))
res.map(|change_set| (change_set, native_extensions))
.map_err(|e| e.finish(Location::Undefined)),
remote,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::loader::Loader;
use move_binary_format::errors::*;
use move_core_types::{
account_address::AccountAddress,
effects::{AccountChangeSet, ChangeSet, Event, Op},
effects::{AccountChangeSet, ChangeSet, Op},
gas_algebra::NumBytes,
identifier::{IdentStr, Identifier},
language_storage::{ModuleId, TypeTag},
Expand Down Expand Up @@ -53,7 +53,6 @@ pub(crate) struct TransactionDataCache<'l, S> {
remote: S,
loader: &'l Loader,
account_map: BTreeMap<AccountAddress, AccountDataCache>,
event_data: Vec<(Vec<u8>, u64, Type, MoveTypeLayout, Value)>,
}

impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
Expand All @@ -64,18 +63,17 @@ impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
remote,
loader,
account_map: BTreeMap::new(),
event_data: vec![],
}
}

/// Make a write set from the updated (dirty, deleted) global resources along with
/// published modules.
///
/// Gives all proper guarantees on lifetime of global data as well.
pub(crate) fn into_effects(mut self) -> (PartialVMResult<(ChangeSet, Vec<Event>)>, S) {
pub(crate) fn into_effects(mut self) -> (PartialVMResult<ChangeSet>, S) {
(self.impl_into_effects(), self.remote)
}
fn impl_into_effects(&mut self) -> PartialVMResult<(ChangeSet, Vec<Event>)> {
fn impl_into_effects(&mut self) -> PartialVMResult<ChangeSet> {
let mut change_set = ChangeSet::new();
for (addr, account_data_cache) in std::mem::take(&mut self.account_map).into_iter() {
let mut modules = BTreeMap::new();
Expand Down Expand Up @@ -123,16 +121,7 @@ impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
}
}

let mut events = vec![];
for (guid, seq_num, ty, ty_layout, val) in std::mem::take(&mut self.event_data) {
let ty_tag = self.loader.type_to_type_tag(&ty)?;
let blob = val
.simple_serialize(&ty_layout)
.ok_or_else(|| PartialVMError::new(StatusCode::INTERNAL_TYPE_ERROR))?;
events.push((guid, seq_num, ty_tag, blob))
}

Ok((change_set, events))
Ok(change_set)
}

pub(crate) fn num_mutated_accounts(&self, sender: &AccountAddress) -> u64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use move_binary_format::{
use move_core_types::{
account_address::AccountAddress,
annotated_value as A,
effects::{ChangeSet, Event},
effects::ChangeSet,
identifier::IdentStr,
language_storage::{ModuleId, TypeTag},
resolver::MoveResolver,
Expand Down Expand Up @@ -163,7 +163,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
/// This function should always succeed with no user errors returned, barring invariant violations.
///
/// This MUST NOT be called if there is a previous invocation that failed with an invariant violation.
pub fn finish(self) -> (VMResult<(ChangeSet, Vec<Event>)>, S) {
pub fn finish(self) -> (VMResult<ChangeSet>, S) {
let (res, remote) = self.data_cache.into_effects();
(res.map_err(|e| e.finish(Location::Undefined)), remote)
}
Expand All @@ -172,7 +172,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
pub fn finish_with_extensions(
self,
) -> (
VMResult<(ChangeSet, Vec<Event>, NativeContextExtensions<'r>)>,
VMResult<(ChangeSet, NativeContextExtensions<'r>)>,
S,
) {
let Session {
Expand All @@ -182,7 +182,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
} = self;
let (res, remote) = data_cache.into_effects();
(
res.map(|(change_set, events)| (change_set, events, native_extensions))
res.map(|change_set| (change_set, native_extensions))
.map_err(|e| e.finish(Location::Undefined)),
remote,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::loader::Loader;
use move_binary_format::errors::*;
use move_core_types::{
account_address::AccountAddress,
effects::{AccountChangeSet, ChangeSet, Event, Op},
effects::{AccountChangeSet, ChangeSet, Op},
gas_algebra::NumBytes,
identifier::{IdentStr, Identifier},
language_storage::{ModuleId, TypeTag},
Expand Down Expand Up @@ -53,7 +53,6 @@ pub(crate) struct TransactionDataCache<'l, S> {
remote: S,
loader: &'l Loader,
account_map: BTreeMap<AccountAddress, AccountDataCache>,
event_data: Vec<(Vec<u8>, u64, Type, MoveTypeLayout, Value)>,
}

impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
Expand All @@ -64,18 +63,17 @@ impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
remote,
loader,
account_map: BTreeMap::new(),
event_data: vec![],
}
}

/// Make a write set from the updated (dirty, deleted) global resources along with
/// published modules.
///
/// Gives all proper guarantees on lifetime of global data as well.
pub(crate) fn into_effects(mut self) -> (PartialVMResult<(ChangeSet, Vec<Event>)>, S) {
pub(crate) fn into_effects(mut self) -> (PartialVMResult<ChangeSet>, S) {
(self.impl_into_effects(), self.remote)
}
fn impl_into_effects(&mut self) -> PartialVMResult<(ChangeSet, Vec<Event>)> {
fn impl_into_effects(&mut self) -> PartialVMResult<ChangeSet> {
let mut change_set = ChangeSet::new();
for (addr, account_data_cache) in std::mem::take(&mut self.account_map).into_iter() {
let mut modules = BTreeMap::new();
Expand Down Expand Up @@ -123,16 +121,7 @@ impl<'l, S: MoveResolver> TransactionDataCache<'l, S> {
}
}

let mut events = vec![];
for (guid, seq_num, ty, ty_layout, val) in std::mem::take(&mut self.event_data) {
let ty_tag = self.loader.type_to_type_tag(&ty)?;
let blob = val
.simple_serialize(&ty_layout)
.ok_or_else(|| PartialVMError::new(StatusCode::INTERNAL_TYPE_ERROR))?;
events.push((guid, seq_num, ty_tag, blob))
}

Ok((change_set, events))
Ok(change_set)
}

pub(crate) fn num_mutated_accounts(&self, sender: &AccountAddress) -> u64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use move_binary_format::{
use move_core_types::{
account_address::AccountAddress,
annotated_value as A,
effects::{ChangeSet, Event},
effects::ChangeSet,
identifier::IdentStr,
language_storage::{ModuleId, TypeTag},
resolver::MoveResolver,
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
/// This function should always succeed with no user errors returned, barring invariant violations.
///
/// This MUST NOT be called if there is a previous invocation that failed with an invariant violation.
pub fn finish(self) -> (VMResult<(ChangeSet, Vec<Event>)>, S) {
pub fn finish(self) -> (VMResult<ChangeSet>, S) {
let (res, remote) = self.data_cache.into_effects();
(res.map_err(|e| e.finish(Location::Undefined)), remote)
}
Expand All @@ -186,7 +186,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
pub fn finish_with_extensions(
self,
) -> (
VMResult<(ChangeSet, Vec<Event>, NativeContextExtensions<'r>)>,
VMResult<(ChangeSet, NativeContextExtensions<'r>)>,
S,
) {
let Session {
Expand All @@ -196,7 +196,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
} = self;
let (res, remote) = data_cache.into_effects();
(
res.map(|(change_set, events)| (change_set, events, native_extensions))
res.map(|change_set| (change_set, native_extensions))
.map_err(|e| e.finish(Location::Undefined)),
remote,
)
Expand Down
Loading

0 comments on commit 3cd2ea4

Please sign in to comment.