Skip to content

Commit

Permalink
use MoveResolverExt everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse authored and aptos-bot committed Apr 27, 2022
1 parent 141bfcb commit 6b032c1
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 67 deletions.
10 changes: 7 additions & 3 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions api/src/tests/converter_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

use crate::{current_function_name, tests::new_test_context};
use aptos_api_types::{new_vm_ascii_string, AsConverter, MoveConverter, MoveType};
use aptos_vm::data_cache::AsMoveResolver;
use aptos_vm::{data_cache::AsMoveResolver, move_vm_ext::MoveResolverExt};
use move_core_types::{
account_address::AccountAddress,
resolver::MoveResolver,
value::{MoveStruct, MoveValue as VmMoveValue},
};
use serde::Serialize;
Expand Down Expand Up @@ -56,7 +55,7 @@ async fn test_value_conversion() {
);
}

fn assert_value_conversion<'r, R: MoveResolver, V: Serialize>(
fn assert_value_conversion<'r, R: MoveResolverExt, V: Serialize>(
converter: &MoveConverter<'r, R>,
json_move_type: &str,
json_value: V,
Expand Down
6 changes: 3 additions & 3 deletions api/types/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use aptos_types::{
vm_status::{AbortLocation, KeptVMStatus},
write_set::WriteOp,
};
use aptos_vm::move_vm_ext::MoveResolverExt;
use move_binary_format::file_format::FunctionHandleIndex;
use move_core_types::{
identifier::Identifier,
language_storage::{ModuleId, StructTag, TypeTag},
resolver::MoveResolver,
value::{MoveStructLayout, MoveTypeLayout},
};
use move_resource_viewer::MoveValueAnnotator;
Expand All @@ -39,7 +39,7 @@ pub struct MoveConverter<'a, R: ?Sized> {
inner: MoveValueAnnotator<'a, R>,
}

impl<'a, R: MoveResolver + ?Sized> MoveConverter<'a, R> {
impl<'a, R: MoveResolverExt + ?Sized> MoveConverter<'a, R> {
pub fn new(inner: &'a R) -> Self {
Self {
inner: MoveValueAnnotator::new(inner),
Expand Down Expand Up @@ -598,7 +598,7 @@ pub trait AsConverter<R> {
fn as_converter(&self) -> MoveConverter<R>;
}

impl<R: MoveResolver> AsConverter<R> for R {
impl<R: MoveResolverExt> AsConverter<R> for R {
fn as_converter(&self) -> MoveConverter<R> {
MoveConverter::new(self)
}
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-resource-viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ publish = false
edition = "2018"

[dependencies]
aptos-vm = { path = "../../aptos-move/aptos-vm" }
aptos-workspace-hack = { path = "../../crates/aptos-workspace-hack" }
move-resource-viewer = { git = "https://github.com/move-language/move", rev = "1b6b7513dcc1a5c866f178ca5c1e74beb2ce181e" }
aptos-types = { path = "../../types" }
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/aptos-resource-viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use aptos_types::{
access_path::AccessPath, account_address::AccountAddress, account_state::AccountState,
contract_event::ContractEvent,
};
use aptos_vm::move_vm_ext::MoveResolverExt;
use move_core_types::language_storage::StructTag;
use move_resource_viewer::MoveValueAnnotator;
use std::{
collections::BTreeMap,
fmt::{Display, Formatter},
};

use move_core_types::resolver::MoveResolver;
pub use move_resource_viewer::{AnnotatedMoveStruct, AnnotatedMoveValue};

pub struct AptosValueAnnotator<'a, T>(MoveValueAnnotator<'a, T>);
Expand All @@ -22,7 +22,7 @@ pub struct AptosValueAnnotator<'a, T>(MoveValueAnnotator<'a, T>);
#[derive(Debug)]
pub struct AnnotatedAccountStateBlob(BTreeMap<StructTag, AnnotatedMoveStruct>);

impl<'a, T: MoveResolver> AptosValueAnnotator<'a, T> {
impl<'a, T: MoveResolverExt> AptosValueAnnotator<'a, T> {
pub fn new(storage: &'a T) -> Self {
Self(MoveValueAnnotator::new(storage))
}
Expand Down
11 changes: 5 additions & 6 deletions aptos-move/aptos-vm/src/adapter_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use aptos_types::{
transaction::{SignatureCheckedTransaction, SignedTransaction, VMValidatorResult},
vm_status::{StatusCode, VMStatus},
};
use move_core_types::resolver::MoveResolver;

use crate::{
data_cache::AsMoveResolver,
logging::AdapterLogSchema,
move_vm_ext::{SessionExt, SessionId},
move_vm_ext::{MoveResolverExt, SessionExt, SessionId},
};
use aptos_logger::prelude::*;
use aptos_types::{
Expand All @@ -35,7 +34,7 @@ pub trait VMAdapter {
/// Creates a new Session backed by the given storage.
/// TODO: this doesn't belong in this trait. We should be able to remove
/// this after redesigning cache ownership model.
fn new_session<'r, R: MoveResolver>(
fn new_session<'r, R: MoveResolverExt>(
&self,
remote: &'r R,
session_id: SessionId,
Expand All @@ -49,7 +48,7 @@ pub trait VMAdapter {
fn check_transaction_format(&self, txn: &SignedTransaction) -> Result<(), VMStatus>;

/// Runs the prologue for the given transaction.
fn run_prologue<S: MoveResolver>(
fn run_prologue<S: MoveResolverExt>(
&self,
session: &mut SessionExt<S>,
transaction: &SignatureCheckedTransaction,
Expand All @@ -60,7 +59,7 @@ pub trait VMAdapter {
fn should_restart_execution(output: &TransactionOutput) -> bool;

/// Execute a single transaction.
fn execute_single_transaction<S: MoveResolver + StateView>(
fn execute_single_transaction<S: MoveResolverExt + StateView>(
&self,
txn: &PreprocessedTransaction,
data_cache: &S,
Expand Down Expand Up @@ -113,7 +112,7 @@ pub fn validate_signed_transaction<A: VMAdapter>(
result
}

pub(crate) fn validate_signature_checked_transaction<S: MoveResolver, A: VMAdapter>(
pub(crate) fn validate_signature_checked_transaction<S: MoveResolverExt, A: VMAdapter>(
adapter: &A,
session: &mut SessionExt<S>,
transaction: &SignatureCheckedTransaction,
Expand Down
33 changes: 16 additions & 17 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
data_cache::StateViewCache,
errors::expect_only_successful_execution,
logging::AdapterLogSchema,
move_vm_ext::{SessionExt, SessionId},
move_vm_ext::{MoveResolverExt, SessionExt, SessionId},
script_to_script_function,
system_module_names::*,
transaction_metadata::TransactionMetadata,
Expand Down Expand Up @@ -42,7 +42,6 @@ use move_core_types::{
account_address::AccountAddress,
gas_schedule::{GasAlgebra, GasUnits},
language_storage::ModuleId,
resolver::MoveResolver,
transaction_argument::convert_txn_args,
value::{serialize_values, MoveValue},
};
Expand Down Expand Up @@ -183,7 +182,7 @@ impl AptosVM {
}

/// Load a module into its internal MoveVM's code cache.
pub fn load_module<S: MoveResolver>(
pub fn load_module<S: MoveResolverExt>(
&self,
module_id: &ModuleId,
state: &S,
Expand All @@ -193,7 +192,7 @@ impl AptosVM {

/// Generates a transaction output for a transaction that encountered errors during the
/// execution process. This is public for now only for tests.
pub fn failed_transaction_cleanup<S: MoveResolver>(
pub fn failed_transaction_cleanup<S: MoveResolverExt>(
&self,
error_code: VMStatus,
gas_status: &mut GasStatus,
Expand All @@ -211,7 +210,7 @@ impl AptosVM {
.1
}

fn failed_transaction_cleanup_and_keep_vm_status<S: MoveResolver>(
fn failed_transaction_cleanup_and_keep_vm_status<S: MoveResolverExt>(
&self,
error_code: VMStatus,
gas_status: &mut GasStatus,
Expand Down Expand Up @@ -252,7 +251,7 @@ impl AptosVM {
}
}

fn success_transaction_cleanup<S: MoveResolver>(
fn success_transaction_cleanup<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
gas_status: &mut GasStatus,
Expand All @@ -275,7 +274,7 @@ impl AptosVM {
))
}

fn execute_script_or_script_function<S: MoveResolver>(
fn execute_script_or_script_function<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
gas_status: &mut GasStatus,
Expand Down Expand Up @@ -360,7 +359,7 @@ impl AptosVM {
}
}

fn execute_modules<S: MoveResolver>(
fn execute_modules<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
gas_status: &mut GasStatus,
Expand Down Expand Up @@ -394,7 +393,7 @@ impl AptosVM {
self.success_transaction_cleanup(session, gas_status, txn_data, log_context)
}

pub(crate) fn execute_user_transaction<S: MoveResolver>(
pub(crate) fn execute_user_transaction<S: MoveResolverExt>(
&self,
storage: &S,
txn: &SignatureCheckedTransaction,
Expand Down Expand Up @@ -468,7 +467,7 @@ impl AptosVM {
}
}

fn execute_writeset<S: MoveResolver>(
fn execute_writeset<S: MoveResolverExt>(
&self,
storage: &S,
writeset_payload: &WriteSetPayload,
Expand Down Expand Up @@ -539,7 +538,7 @@ impl AptosVM {
Ok(())
}

pub(crate) fn process_waypoint_change_set<S: MoveResolver + StateView>(
pub(crate) fn process_waypoint_change_set<S: MoveResolverExt + StateView>(
&self,
storage: &S,
writeset_payload: WriteSetPayload,
Expand All @@ -564,7 +563,7 @@ impl AptosVM {
))
}

pub(crate) fn process_block_prologue<S: MoveResolver>(
pub(crate) fn process_block_prologue<S: MoveResolverExt>(
&self,
storage: &S,
block_metadata: BlockMetadata,
Expand Down Expand Up @@ -618,7 +617,7 @@ impl AptosVM {
Ok((VMStatus::Executed, output))
}

pub(crate) fn process_writeset_transaction<S: MoveResolver + StateView>(
pub(crate) fn process_writeset_transaction<S: MoveResolverExt + StateView>(
&self,
storage: &S,
txn: &SignatureCheckedTransaction,
Expand Down Expand Up @@ -660,7 +659,7 @@ impl AptosVM {
)
}

pub fn execute_writeset_transaction<S: MoveResolver + StateView>(
pub fn execute_writeset_transaction<S: MoveResolverExt + StateView>(
&self,
storage: &S,
writeset_payload: &WriteSetPayload,
Expand Down Expand Up @@ -829,7 +828,7 @@ impl VMValidator for AptosVM {
}

impl VMAdapter for AptosVM {
fn new_session<'r, R: MoveResolver>(
fn new_session<'r, R: MoveResolverExt>(
&self,
remote: &'r R,
session_id: SessionId,
Expand All @@ -849,7 +848,7 @@ impl VMAdapter for AptosVM {
Ok(())
}

fn run_prologue<S: MoveResolver>(
fn run_prologue<S: MoveResolverExt>(
&self,
session: &mut SessionExt<S>,
transaction: &SignatureCheckedTransaction,
Expand Down Expand Up @@ -886,7 +885,7 @@ impl VMAdapter for AptosVM {
.any(|event| *event.key() == new_epoch_event_key)
}

fn execute_single_transaction<S: MoveResolver + StateView>(
fn execute_single_transaction<S: MoveResolverExt + StateView>(
&self,
txn: &PreprocessedTransaction,
data_cache: &S,
Expand Down
Loading

0 comments on commit 6b032c1

Please sign in to comment.