Skip to content

Commit

Permalink
adding another executor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Oct 29, 2024
1 parent 489ceea commit b45470b
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 71 deletions.
34 changes: 18 additions & 16 deletions aptos-move/framework/aptos-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -3468,23 +3468,25 @@ Decrease the supply of a fungible asset by burning.
};
<b>let</b> metadata_address = <a href="object.md#0x1_object_object_address">object::object_address</a>(metadata);

<b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address)) {
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address);
<b>if</b> (amount == 0) {
<b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address)) {
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address);

<b>assert</b>!(
<a href="aggregator_v2.md#0x1_aggregator_v2_try_sub">aggregator_v2::try_sub</a>(&<b>mut</b> supply.current, (amount <b>as</b> u128)),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
} <b>else</b> <b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address)) {
<b>assert</b>!(<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address);
<b>assert</b>!(
supply.current &gt;= (amount <b>as</b> u128),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_state">error::invalid_state</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
supply.current = supply.current - (amount <b>as</b> u128);
} <b>else</b> {
<b>assert</b>!(<b>false</b>, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
<b>assert</b>!(
<a href="aggregator_v2.md#0x1_aggregator_v2_try_sub">aggregator_v2::try_sub</a>(&<b>mut</b> supply.current, (amount <b>as</b> u128)),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
} <b>else</b> <b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address)) {
<b>assert</b>!(<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address);
<b>assert</b>!(
supply.current &gt;= (amount <b>as</b> u128),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_state">error::invalid_state</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
supply.current = supply.current - (amount <b>as</b> u128);
} <b>else</b> {
<b>assert</b>!(<b>false</b>, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
}
}
}
</code></pre>
Expand Down
34 changes: 18 additions & 16 deletions aptos-move/framework/aptos-framework/sources/fungible_asset.move
Original file line number Diff line number Diff line change
Expand Up @@ -1098,23 +1098,25 @@ module aptos_framework::fungible_asset {
};
let metadata_address = object::object_address(metadata);

if (exists<ConcurrentSupply>(metadata_address)) {
let supply = borrow_global_mut<ConcurrentSupply>(metadata_address);
if (amount == 0) {
if (exists<ConcurrentSupply>(metadata_address)) {
let supply = borrow_global_mut<ConcurrentSupply>(metadata_address);

assert!(
aggregator_v2::try_sub(&mut supply.current, (amount as u128)),
error::out_of_range(ESUPPLY_UNDERFLOW)
);
} else if (exists<Supply>(metadata_address)) {
assert!(exists<Supply>(metadata_address), error::not_found(ESUPPLY_NOT_FOUND));
let supply = borrow_global_mut<Supply>(metadata_address);
assert!(
supply.current >= (amount as u128),
error::invalid_state(ESUPPLY_UNDERFLOW)
);
supply.current = supply.current - (amount as u128);
} else {
assert!(false, error::not_found(ESUPPLY_NOT_FOUND));
assert!(
aggregator_v2::try_sub(&mut supply.current, (amount as u128)),
error::out_of_range(ESUPPLY_UNDERFLOW)
);
} else if (exists<Supply>(metadata_address)) {
assert!(exists<Supply>(metadata_address), error::not_found(ESUPPLY_NOT_FOUND));
let supply = borrow_global_mut<Supply>(metadata_address);
assert!(
supply.current >= (amount as u128),
error::invalid_state(ESUPPLY_UNDERFLOW)
);
supply.current = supply.current - (amount as u128);
} else {
assert!(false, error::not_found(ESUPPLY_NOT_FOUND));
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions execution/executor-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ fn log_total_supply(db_reader: &Arc<dyn DbReader>) {
mod tests {
use std::fs;

use crate::{db_generator::bootstrap_with_genesis, init_db_and_executor, native_executor_task::NativeVMBlockExecutor, native_loose_block_executor::{NativeNoStorageLooseSpeculativeBlockExecutor, NativeLooseSpeculativeBlockExecutor}, native_transaction::NativeConfig, pipeline::PipelineConfig, transaction_executor::BENCHMARKS_BLOCK_EXECUTOR_ONCHAIN_CONFIG, transaction_generator::TransactionGenerator, BenchmarkWorkload};
use crate::{db_generator::bootstrap_with_genesis, init_db_and_executor, native_executor_task::NativeVMBlockExecutor, native_loose_block_executor::{NativeLooseSpeculativeBlockExecutor, NativeNoStorageLooseSpeculativeBlockExecutor, NativeValueCacheLooseSpeculativeBlockExecutor}, native_transaction::NativeConfig, pipeline::PipelineConfig, transaction_executor::BENCHMARKS_BLOCK_EXECUTOR_ONCHAIN_CONFIG, transaction_generator::TransactionGenerator, BenchmarkWorkload};
use aptos_config::config::NO_OP_STORAGE_PRUNER_CONFIG;
use aptos_crypto::HashValue;
use aptos_executor::block_executor::{AptosVMBlockExecutor, TransactionBlockExecutor};
Expand Down Expand Up @@ -866,7 +866,7 @@ mod tests {
features.enable(FeatureFlag::NEW_ACCOUNTS_DEFAULT_TO_FA_APT_STORE);
features.enable(FeatureFlag::OPERATIONS_DEFAULT_TO_FA_APT_STORE);

crate::db_generator::create_db_with_accounts::<E>(
crate::db_generator::create_db_with_accounts::<AptosVMBlockExecutor>(
100, /* num_accounts */
// TODO(Gas): double check if this is correct
100_000_000_000, /* init_account_balance */
Expand Down Expand Up @@ -924,8 +924,8 @@ mod tests {
AptosVM::set_concurrency_level_once(1);
AptosVM::set_processed_transactions_detailed_counters();
NativeConfig::set_concurrency_level_once(1);
test_generic_benchmark::<NativeVMBlockExecutor>(
Some(TransactionTypeArg::NoOp),
test_generic_benchmark::<NativeValueCacheLooseSpeculativeBlockExecutor>(
Some(TransactionTypeArg::AptFaTransfer),
true,
);
}
Expand Down
6 changes: 5 additions & 1 deletion execution/executor-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use aptos_config::config::{
EpochSnapshotPrunerConfig, LedgerPrunerConfig, PrunerConfig, StateMerklePrunerConfig,
};
use aptos_executor::block_executor::{AptosVMBlockExecutor, TransactionBlockExecutor};
use aptos_executor_benchmark::{native_executor_task::NativeVMBlockExecutor, native_loose_block_executor::{NativeNoStorageLooseSpeculativeBlockExecutor, NativeLooseSpeculativeBlockExecutor}, native_transaction::NativeConfig, pipeline::PipelineConfig, BenchmarkWorkload};
use aptos_executor_benchmark::{native_executor_task::NativeVMBlockExecutor, native_loose_block_executor::{NativeLooseSpeculativeBlockExecutor, NativeNoStorageLooseSpeculativeBlockExecutor, NativeValueCacheLooseSpeculativeBlockExecutor}, native_transaction::NativeConfig, pipeline::PipelineConfig, BenchmarkWorkload};
use aptos_executor_service::remote_executor_client;
use aptos_experimental_ptx_executor::PtxBlockExecutor;
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -213,6 +213,7 @@ enum BlockExecutorTypeOpt {
NativeVMWithBlockSTM,
NativeLooseSpeculative,
NativeNoStorageLooseSpeculative,
NativeValueCacheLooseSpeculative,
PtxExecutor,
}

Expand Down Expand Up @@ -594,6 +595,9 @@ fn main() {
BlockExecutorTypeOpt::NativeLooseSpeculative => {
run::<NativeLooseSpeculativeBlockExecutor>(opt);
},
BlockExecutorTypeOpt::NativeValueCacheLooseSpeculative => {
run::<NativeValueCacheLooseSpeculativeBlockExecutor>(opt);
}
BlockExecutorTypeOpt::NativeNoStorageLooseSpeculative => {
run::<NativeNoStorageLooseSpeculativeBlockExecutor>(opt);
},
Expand Down
11 changes: 6 additions & 5 deletions execution/executor-benchmark/src/native_executor_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ impl NativeExecutorTask {
Self::check_and_set_sequence_number(sender, sequence_number, view, &mut resource_write_set)?;
Self::withdraw_fa_apt_from_signer(sender, amount, view, gas, &mut resource_write_set, &mut events)?;

Self::check_or_create_account(recipient, fail_on_account_existing, fail_on_account_missing, view, &mut resource_write_set)?;
Self::deposit_fa_apt(recipient, amount, view, gas, &mut resource_write_set, &mut events)?;
if !Self::deposit_fa_apt(recipient, amount, view, gas, &mut resource_write_set, &mut events)? {
Self::check_or_create_account(recipient, fail_on_account_existing, fail_on_account_missing, view, &mut resource_write_set)?;
}
},
NativeTransaction::BatchTransfer { .. } => {
todo!("to implement");
Expand Down Expand Up @@ -341,7 +342,7 @@ impl NativeExecutorTask {
gas: u64,
resource_write_set: &mut BTreeMap<StateKey, AbstractResourceWriteOp>,
events: &mut Vec<(ContractEvent, Option<MoveTypeLayout>)>,
) -> Result<(), ()> {
) -> Result<bool, ()> {
let recipient_store_address = primary_apt_store(recipient_address);
let recipient_fa_store_object_key = DbAccessUtil::new_state_key_object_resource_group(&recipient_store_address);
let fungible_store_rg_tag = FungibleStoreResource::struct_tag();
Expand All @@ -356,7 +357,7 @@ impl NativeExecutorTask {
store: recipient_store_address,
amount: transfer_amount,
}.create_event_v2(), None));
Ok(())
Ok(true)
},
None => {
let receipeint_fa_store = FungibleStoreResource::new(AccountAddress::TEN, transfer_amount, false);
Expand All @@ -367,7 +368,7 @@ impl NativeExecutorTask {
store: recipient_store_address,
amount: transfer_amount,
}.create_event_v2(), None));
Ok(())
Ok(false)
},
}
}
Expand Down
Loading

0 comments on commit b45470b

Please sign in to comment.