Skip to content

Commit

Permalink
updates to types
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Nov 6, 2024
1 parent 9a6638d commit 4499818
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 95 deletions.
4 changes: 2 additions & 2 deletions aptos-move/aptos-vm/src/block_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct AptosTransactionOutput {
}

impl AptosTransactionOutput {
pub(crate) fn new(output: VMOutput) -> Self {
pub fn new(output: VMOutput) -> Self {
Self {
vm_output: Mutex::new(Some(output)),
committed_output: OnceCell::new(),
Expand All @@ -138,7 +138,7 @@ impl AptosTransactionOutput {
self.committed_output.get().unwrap()
}

fn take_output(mut self) -> TransactionOutput {
pub fn take_output(mut self) -> TransactionOutput {
match self.committed_output.take() {
Some(output) => output,
// TODO: revisit whether we should always get it via committed, or o.w. create a
Expand Down
34 changes: 16 additions & 18 deletions aptos-move/framework/aptos-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -3468,25 +3468,23 @@ 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> (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>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
27 changes: 26 additions & 1 deletion execution/executor-benchmark/src/db_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use aptos_types::{
account_address::AccountAddress,
account_config::{
AccountResource, CoinInfoResource, CoinStoreResource, ConcurrentSupplyResource,
FungibleStoreResource, ObjectCoreResource, ObjectGroupResource,
FungibleStoreResource, ObjectCoreResource, ObjectGroupResource, TypeInfoResource,
},
event::{EventHandle, EventKey},
state_store::{state_key::StateKey, StateView},
write_set::TOTAL_SUPPLY_STATE_KEY,
AptosCoinType, CoinType,
};
use itertools::Itertools;
use move_core_types::{
identifier::Identifier,
language_storage::{StructTag, TypeTag},
Expand Down Expand Up @@ -168,4 +169,28 @@ impl DbAccessUtil {
pub fn new_object_core(address: AccountAddress, owner: AccountAddress) -> ObjectCoreResource {
ObjectCoreResource::new(owner, false, EventHandle::new(EventKey::new(1, address), 0))
}

pub fn new_type_info_resource<T: MoveStructType>() -> anyhow::Result<TypeInfoResource> {
let struct_tag = T::struct_tag();
Ok(TypeInfoResource {
account_address: struct_tag.address,
module_name: bcs::to_bytes(&struct_tag.module.to_string())?,
struct_name: bcs::to_bytes(
&if struct_tag.type_args.is_empty() {
struct_tag.name.to_string()
} else {
format!(
"{}<{}>",
struct_tag.name,
struct_tag
.type_args
.iter()
.map(|v| v.to_string())
.join(", ")
)
.to_string()
},
)?,
})
}
}
2 changes: 1 addition & 1 deletion execution/executor-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ mod tests {
};

let other_db = init_db(&config);
let other_executor = BlockExecutor::<AptosVMBlockExecutor>::new(other_db.clone());
let other_executor = BlockExecutor::<E>::new(other_db.clone());

let parent_block_id = other_executor.committed_block_id();
let block_id = HashValue::random();
Expand Down
4 changes: 2 additions & 2 deletions execution/executor-benchmark/src/native/native_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use aptos_types::{
account_config::{
primary_apt_store, AccountResource, CoinDeposit, CoinInfoResource, CoinRegister,
CoinStoreResource, CoinWithdraw, ConcurrentSupplyResource, DepositFAEvent,
FungibleStoreResource, TypeInfoResource, WithdrawFAEvent,
FungibleStoreResource, WithdrawFAEvent,
},
block_executor::config::{
BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig,
Expand Down Expand Up @@ -825,7 +825,7 @@ impl NativeVMExecutorTask {
events.push((
CoinRegister {
account: AccountAddress::ONE,
type_info: TypeInfoResource::new::<AptosCoinType>()
type_info: DbAccessUtil::new_type_info_resource::<AptosCoinType>()
.map_err(hide_error)?,
}
.create_event_v2(),
Expand Down
Loading

0 comments on commit 4499818

Please sign in to comment.