Skip to content

Commit

Permalink
aavoide deserializing modules & perf check
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Mar 7, 2024
1 parent 006246e commit f0f08d6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
9 changes: 8 additions & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ impl AptosVM {

fn validate_and_execute_entry_function(
&self,
resolver: &impl AptosMoveResolver,
session: &mut SessionExt,
gas_meter: &mut impl AptosGasMeter,
traversal_context: &mut TraversalContext,
Expand All @@ -745,7 +746,8 @@ impl AptosVM {
entry_fn.ty_args(),
)?;

if is_friend_or_private && is_entry_function_unbiasable(session, entry_fn)? {
// TODO(George): change the order once performance is confirmed.
if is_entry_function_unbiasable(resolver, session, entry_fn)? && is_friend_or_private {
let txn_context = session
.get_native_extensions()
.get_mut::<RandomnessContext>();
Expand Down Expand Up @@ -804,6 +806,7 @@ impl AptosVM {
},
TransactionPayload::EntryFunction(entry_fn) => {
self.validate_and_execute_entry_function(
resolver,
&mut session,
gas_meter,
traversal_context,
Expand Down Expand Up @@ -901,6 +904,7 @@ impl AptosVM {
MultisigTransactionPayload::EntryFunction(entry_function) => {
aptos_try!({
return_on_failure!(self.execute_multisig_entry_function(
resolver,
&mut session,
gas_meter,
traversal_context,
Expand Down Expand Up @@ -1018,6 +1022,7 @@ impl AptosVM {
let execution_result = match payload {
MultisigTransactionPayload::EntryFunction(entry_function) => self
.execute_multisig_entry_function(
resolver,
&mut session,
gas_meter,
traversal_context,
Expand Down Expand Up @@ -1113,6 +1118,7 @@ impl AptosVM {

fn execute_multisig_entry_function(
&self,
resolver: &impl AptosMoveResolver,
session: &mut SessionExt,
gas_meter: &mut impl AptosGasMeter,
traversal_context: &mut TraversalContext,
Expand All @@ -1123,6 +1129,7 @@ impl AptosVM {
// If txn args are not valid, we'd still consider the transaction as executed but
// failed. This is primarily because it's unrecoverable at this point.
self.validate_and_execute_entry_function(
resolver,
session,
gas_meter,
traversal_context,
Expand Down
18 changes: 6 additions & 12 deletions aptos-move/aptos-vm/src/verifier/randomness.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::move_vm_ext::SessionExt;
use crate::move_vm_ext::{AptosMoveResolver, SessionExt};
use aptos_types::transaction::EntryFunction;
use move_binary_format::{
errors::{Location, VMResult},
CompiledModule,
};
use move_binary_format::errors::VMResult;

/// Returns true if function has an annotation that it is unbiasable.
pub(crate) fn is_entry_function_unbiasable(
resolver: &impl AptosMoveResolver,
session: &mut SessionExt,
entry_fn: &EntryFunction,
) -> VMResult<bool> {
let module_bytes = session.load_module(entry_fn.module())?;
let module = CompiledModule::deserialize_with_config(
&module_bytes,
&session.get_vm_config().deserializer_config,
)
.map_err(|e| e.finish(Location::Undefined))?;

let module = session
.get_move_vm()
.load_module(entry_fn.module(), resolver)?;
let metadata = aptos_framework::get_metadata_from_compiled_module(&module);
if let Some(metadata) = metadata {
Ok(metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ fn test_only_private_entry_function_can_be_annotated() {
"randomness.data/invalid_pack_non_entry",
&mut h
)
.is_err());
.is_err());
assert!(deploy_code(
AccountAddress::ONE,
"randomness.data/invalid_pack_public_entry",
&mut h
)
.is_err());
.is_err());
}

#[test]
Expand Down

0 comments on commit f0f08d6

Please sign in to comment.