Skip to content

Commit

Permalink
[fix] Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Jul 27, 2022
1 parent 56a2750 commit 7bbad59
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 97 deletions.
19 changes: 7 additions & 12 deletions aptos-move/aptos-vm/src/adapter_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use anyhow::Result;
use aptos_state_view::StateView;
use aptos_types::{
transaction::{
SignatureCheckedTransaction, SignedTransaction, TransactionOutputWithDeltas,
VMValidatorResult,
SignatureCheckedTransaction, SignedTransaction, TransactionOutputExt, VMValidatorResult,
},
vm_status::{StatusCode, VMStatus},
};
Expand Down Expand Up @@ -67,7 +66,7 @@ pub trait VMAdapter {
txn: &PreprocessedTransaction,
data_cache: &S,
log_context: &AdapterLogSchema,
) -> Result<(VMStatus, TransactionOutputWithDeltas, Option<String>), VMStatus>;
) -> Result<(VMStatus, TransactionOutputExt, Option<String>), VMStatus>;
}

/// Validate a signed transaction by performing the following:
Expand Down Expand Up @@ -202,17 +201,15 @@ pub(crate) fn execute_block_impl<A: VMAdapter, S: StateView>(
debug!(log_context, "Retry after reconfiguration");
continue;
};
let (vm_status, output_with_deltas, sender) = adapter.execute_single_transaction(
let (vm_status, output, sender) = adapter.execute_single_transaction(
&txn,
&data_cache.as_move_resolver(),
&log_context,
)?;
// TODO: here we extract deltas so that we can use them later
let output = output_with_deltas.into();
// TODO: apply deltas.
let (_, output) = output.into();
if !output.status().is_discarded() {
data_cache.push_write_set(output.write_set());
// TODO: also apply deltas.
// data_cache.try_apply_deltas(deltas); (consumes deltas, error on overflow)
} else {
match sender {
Some(s) => trace!(
Expand Down Expand Up @@ -280,11 +277,9 @@ pub(crate) fn preprocess_transaction<A: VMAdapter>(txn: Transaction) -> Preproce
}
}

pub(crate) fn discard_error_vm_status_with_deltas(
err: VMStatus,
) -> (VMStatus, TransactionOutputWithDeltas) {
pub(crate) fn discard_error_vm_status_ext(err: VMStatus) -> (VMStatus, TransactionOutputExt) {
let (vm_status, empty_output) = discard_error_vm_status(err);
(vm_status, TransactionOutputWithDeltas::from(empty_output))
(vm_status, TransactionOutputExt::from(empty_output))
}

pub(crate) fn discard_error_vm_status(err: VMStatus) -> (VMStatus, TransactionOutput) {
Expand Down
80 changes: 37 additions & 43 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use crate::move_vm_ext::{NativeCodeContext, PublishRequest};
use crate::{
adapter_common,
adapter_common::{
discard_error_output, discard_error_vm_status, discard_error_vm_status_with_deltas,
discard_error_output, discard_error_vm_status, discard_error_vm_status_ext,
validate_signature_checked_transaction, validate_signed_transaction,
PreprocessedTransaction, VMAdapter,
},
aptos_vm_impl::{
charge_global_write_gas_usage, get_transaction_output, get_transaction_output_with_deltas,
charge_global_write_gas_usage, get_transaction_output, get_transaction_output_ext,
AptosVMImpl, AptosVMInternals,
},
counters::*,
Expand All @@ -34,7 +34,7 @@ use aptos_types::{
on_chain_config::{new_epoch_event_key, VMConfig, VMPublishingOption, Version},
transaction::{
ChangeSet, ExecutionStatus, ModuleBundle, SignatureCheckedTransaction, SignedTransaction,
Transaction, TransactionOutput, TransactionOutputWithDeltas, TransactionPayload,
Transaction, TransactionOutput, TransactionOutputExt, TransactionPayload,
TransactionStatus, VMValidatorResult, WriteSetPayload,
},
vm_status::{StatusCode, VMStatus},
Expand Down Expand Up @@ -156,7 +156,7 @@ impl AptosVM {
txn_data: &TransactionMetadata,
storage: &S,
log_context: &AdapterLogSchema,
) -> TransactionOutputWithDeltas {
) -> TransactionOutputExt {
self.failed_transaction_cleanup_and_keep_vm_status(
error_code,
gas_status,
Expand All @@ -174,7 +174,7 @@ impl AptosVM {
txn_data: &TransactionMetadata,
storage: &S,
log_context: &AdapterLogSchema,
) -> (VMStatus, TransactionOutputWithDeltas) {
) -> (VMStatus, TransactionOutputExt) {
gas_status.set_metering(false);
let mut session = self.0.new_session(storage, SessionId::txn_meta(txn_data));
match TransactionStatus::from(error_code.clone()) {
Expand All @@ -189,21 +189,21 @@ impl AptosVM {
self.0
.run_failure_epilogue(&mut session, gas_status, txn_data, log_context)
{
return discard_error_vm_status_with_deltas(e);
return discard_error_vm_status_ext(e);
}
let txn_output = get_transaction_output_with_deltas(
let txn_output = get_transaction_output_ext(
&mut (),
session,
gas_status.remaining_gas(),
txn_data,
status,
)
.unwrap_or_else(|e| discard_error_vm_status_with_deltas(e).1);
.unwrap_or_else(|e| discard_error_vm_status_ext(e).1);
(error_code, txn_output)
}
TransactionStatus::Discard(status) => (
VMStatus::Error(status),
TransactionOutputWithDeltas::from(discard_error_output(status)),
TransactionOutputExt::from(discard_error_output(status)),
),
TransactionStatus::Retry => unreachable!(),
}
Expand All @@ -215,14 +215,14 @@ impl AptosVM {
gas_status: &mut GasStatus,
txn_data: &TransactionMetadata,
log_context: &AdapterLogSchema,
) -> Result<(VMStatus, TransactionOutputWithDeltas), VMStatus> {
) -> Result<(VMStatus, TransactionOutputExt), VMStatus> {
gas_status.set_metering(false);
self.0
.run_success_epilogue(&mut session, gas_status, txn_data, log_context)?;

Ok((
VMStatus::Executed,
get_transaction_output_with_deltas(
get_transaction_output_ext(
&mut (),
session,
gas_status.remaining_gas(),
Expand All @@ -232,14 +232,14 @@ impl AptosVM {
))
}

fn execute_script_or_script_function_with_deltas<S: MoveResolverExt>(
fn execute_script_or_script_function_ext<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
gas_status: &mut GasStatus,
txn_data: &TransactionMetadata,
payload: &TransactionPayload,
log_context: &AdapterLogSchema,
) -> Result<(VMStatus, TransactionOutputWithDeltas), VMStatus> {
) -> Result<(VMStatus, TransactionOutputExt), VMStatus> {
fail_point!("move_adapter::execute_script_or_script_function", |_| {
Err(VMStatus::Error(
StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR,
Expand Down Expand Up @@ -311,20 +311,20 @@ impl AptosVM {

fn execute_script_or_script_function<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
session: SessionExt<S>,
gas_status: &mut GasStatus,
txn_data: &TransactionMetadata,
payload: &TransactionPayload,
log_context: &AdapterLogSchema,
) -> Result<(VMStatus, TransactionOutput), VMStatus> {
self.execute_script_or_script_function_with_deltas(
self.execute_script_or_script_function_ext(
session,
gas_status,
txn_data,
payload,
log_context,
)
.map(|(vm_status, output)| (vm_status, output.into()))
.map(|(vm_status, output)| (vm_status, output.into_transaction_output()))
}

fn verify_module_bundle<S: MoveResolverExt>(
Expand Down Expand Up @@ -409,14 +409,14 @@ impl AptosVM {
/// Execute a module bundle load request.
/// TODO: this is going to be deprecated and removed in favor of code publishing via
/// NativeCodeContext
fn execute_modules_with_deltas<S: MoveResolverExt>(
fn execute_modules_ext<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
gas_status: &mut GasStatus,
txn_data: &TransactionMetadata,
modules: &ModuleBundle,
log_context: &AdapterLogSchema,
) -> Result<(VMStatus, TransactionOutputWithDeltas), VMStatus> {
) -> Result<(VMStatus, TransactionOutputExt), VMStatus> {
fail_point!("move_adapter::execute_module", |_| {
Err(VMStatus::Error(
StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR,
Expand Down Expand Up @@ -454,14 +454,14 @@ impl AptosVM {

fn execute_modules<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
session: SessionExt<S>,
gas_status: &mut GasStatus,
txn_data: &TransactionMetadata,
modules: &ModuleBundle,
log_context: &AdapterLogSchema,
) -> Result<(VMStatus, TransactionOutput), VMStatus> {
self.execute_modules_with_deltas(session, gas_status, txn_data, modules, log_context)
.map(|(vm_status, output)| (vm_status, output.into()))
self.execute_modules_ext(session, gas_status, txn_data, modules, log_context)
.map(|(vm_status, output)| (vm_status, output.into_transaction_output()))
}

/// Resolve a pending code publish request registered via the NativeCodeContext.
Expand Down Expand Up @@ -528,12 +528,12 @@ impl AptosVM {
storage: &S,
txn: &SignatureCheckedTransaction,
log_context: &AdapterLogSchema,
) -> (VMStatus, TransactionOutputWithDeltas) {
) -> (VMStatus, TransactionOutputExt) {
macro_rules! unwrap_or_discard {
($res: expr) => {
match $res {
Ok(s) => s,
Err(e) => return discard_error_vm_status_with_deltas(e),
Err(e) => return discard_error_vm_status_ext(e),
}
};
}
Expand All @@ -547,7 +547,7 @@ impl AptosVM {
false,
log_context,
) {
return discard_error_vm_status_with_deltas(err);
return discard_error_vm_status_ext(err);
};

let gas_schedule = unwrap_or_discard!(self.0.get_gas_schedule(log_context));
Expand All @@ -557,24 +557,18 @@ impl AptosVM {
let result = match txn.payload() {
payload @ TransactionPayload::Script(_)
| payload @ TransactionPayload::ScriptFunction(_) => self
.execute_script_or_script_function_with_deltas(
.execute_script_or_script_function_ext(
session,
&mut gas_status,
&txn_data,
payload,
log_context,
),
TransactionPayload::ModuleBundle(m) => self.execute_modules_with_deltas(
session,
&mut gas_status,
&txn_data,
m,
log_context,
),
TransactionPayload::ModuleBundle(m) => {
self.execute_modules_ext(session, &mut gas_status, &txn_data, m, log_context)
}
TransactionPayload::WriteSet(_) => {
return discard_error_vm_status_with_deltas(VMStatus::Error(
StatusCode::UNREACHABLE,
));
return discard_error_vm_status_ext(VMStatus::Error(StatusCode::UNREACHABLE));
}
};

Expand All @@ -589,7 +583,7 @@ impl AptosVM {
Err(err) => {
let txn_status = TransactionStatus::from(err.clone());
if txn_status.is_discarded() {
discard_error_vm_status_with_deltas(err)
discard_error_vm_status_ext(err)
} else {
self.failed_transaction_cleanup_and_keep_vm_status(
err,
Expand Down Expand Up @@ -1087,14 +1081,14 @@ impl VMAdapter for AptosVM {
txn: &PreprocessedTransaction,
data_cache: &S,
log_context: &AdapterLogSchema,
) -> Result<(VMStatus, TransactionOutputWithDeltas, Option<String>), VMStatus> {
) -> Result<(VMStatus, TransactionOutputExt, Option<String>), VMStatus> {
Ok(match txn {
PreprocessedTransaction::BlockMetadata(block_metadata) => {
let (vm_status, output) =
self.process_block_prologue(data_cache, block_metadata.clone(), log_context)?;
(
vm_status,
TransactionOutputWithDeltas::from(output),
TransactionOutputExt::from(output),
Some("block_prologue".to_string()),
)
}
Expand All @@ -1106,7 +1100,7 @@ impl VMAdapter for AptosVM {
)?;
(
vm_status,
TransactionOutputWithDeltas::from(output),
TransactionOutputExt::from(output),
Some("waypoint_write_set".to_string()),
)
}
Expand All @@ -1132,14 +1126,14 @@ impl VMAdapter for AptosVM {
self.process_writeset_transaction(data_cache, txn, log_context)?;
(
vm_status,
TransactionOutputWithDeltas::from(output),
TransactionOutputExt::from(output),
Some("write_set".to_string()),
)
}
PreprocessedTransaction::InvalidSignature => {
let (vm_status, output) =
discard_error_vm_status(VMStatus::Error(StatusCode::INVALID_SIGNATURE));
(vm_status, TransactionOutputWithDeltas::from(output), None)
(vm_status, TransactionOutputExt::from(output), None)
}
PreprocessedTransaction::StateCheckpoint => {
let output = TransactionOutput::new(
Expand All @@ -1150,7 +1144,7 @@ impl VMAdapter for AptosVM {
);
(
VMStatus::Executed,
TransactionOutputWithDeltas::from(output),
TransactionOutputExt::from(output),
Some("state_checkpoint".into()),
)
}
Expand Down Expand Up @@ -1248,7 +1242,7 @@ impl AptosSimulationVM {
storage,
log_context,
);
(vm_status, empty_output.into())
(vm_status, empty_output.into_transaction_output())
}
}
}
Expand Down
23 changes: 7 additions & 16 deletions aptos-move/aptos-vm/src/aptos_vm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use aptos_types::{
on_chain_config::{
ConfigStorage, OnChainConfig, VMConfig, VMPublishingOption, Version, APTOS_VERSION_3,
},
transaction::{
ExecutionStatus, TransactionOutput, TransactionOutputWithDeltas, TransactionStatus,
},
transaction::{ExecutionStatus, TransactionOutput, TransactionOutputExt, TransactionStatus},
vm_status::{StatusCode, VMStatus},
};
use fail::fail_point;
Expand Down Expand Up @@ -565,30 +563,23 @@ pub(crate) fn charge_global_write_gas_usage<R: MoveResolverExt>(
.map_err(|p_err| p_err.finish(Location::Undefined).into_vm_status())
}

pub(crate) fn get_transaction_output_with_deltas<A: AccessPathCache, S: MoveResolverExt>(
pub(crate) fn get_transaction_output_ext<A: AccessPathCache, S: MoveResolverExt>(
ap_cache: &mut A,
session: SessionExt<S>,
gas_left: GasUnits<GasCarrier>,
txn_data: &TransactionMetadata,
status: ExecutionStatus,
) -> Result<TransactionOutputWithDeltas, VMStatus> {
) -> Result<TransactionOutputExt, VMStatus> {
let gas_used: u64 = txn_data.max_gas_amount().sub(gas_left).get();

let session_out = session.finish().map_err(|e| e.into_vm_status())?;

// TODO: this will also extract deltas, which can be preocessed separately.
//
// let (deltas, change_set) = ...
//
let change_set = session_out
.into_change_set_with_deltas(ap_cache)?
.into_inner();
let (delta_set, change_set) = session_out.into_change_set_ext(ap_cache)?.into_inner();
let (write_set, events) = change_set.into_inner();

let txn_output =
TransactionOutput::new(write_set, events, gas_used, TransactionStatus::Keep(status));

Ok(TransactionOutputWithDeltas::new(txn_output))
Ok(TransactionOutputExt::new(delta_set, txn_output))
}

pub(crate) fn get_transaction_output<A: AccessPathCache, S: MoveResolverExt>(
Expand All @@ -598,8 +589,8 @@ pub(crate) fn get_transaction_output<A: AccessPathCache, S: MoveResolverExt>(
txn_data: &TransactionMetadata,
status: ExecutionStatus,
) -> Result<TransactionOutput, VMStatus> {
get_transaction_output_with_deltas(ap_cache, session, gas_left, txn_data, status)
.map(TransactionOutputWithDeltas::into)
get_transaction_output_ext(ap_cache, session, gas_left, txn_data, status)
.map(TransactionOutputExt::into_transaction_output)
}

#[test]
Expand Down
Loading

0 comments on commit 7bbad59

Please sign in to comment.