Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[not for review] test concurrent opt-in #13195

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions aptos-move/framework/aptos-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -1813,11 +1813,14 @@ Check whether the balance of a given store is >= <code>amount</code>.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_is_address_balance_at_least">is_address_balance_at_least</a>(store_addr: <b>address</b>, amount: u64): bool <b>acquires</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>, <a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a> {
<b>if</b> (<a href="fungible_asset.md#0x1_fungible_asset_concurrent_fungible_balance_exists_inline">concurrent_fungible_balance_exists_inline</a>(store_addr)) {
<b>let</b> balance_resource = <b>borrow_global</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a>&gt;(store_addr);
<a href="aggregator_v2.md#0x1_aggregator_v2_is_at_least">aggregator_v2::is_at_least</a>(&balance_resource.balance, amount)
} <b>else</b> <b>if</b> (<a href="fungible_asset.md#0x1_fungible_asset_store_exists_inline">store_exists_inline</a>(store_addr)) {
<b>borrow_global</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr).balance &gt;= amount
<b>if</b> (<a href="fungible_asset.md#0x1_fungible_asset_store_exists_inline">store_exists_inline</a>(store_addr)) {
<b>let</b> store = <b>borrow_global</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr);
<b>if</b> (store.balance == 0 && <a href="fungible_asset.md#0x1_fungible_asset_concurrent_fungible_balance_exists_inline">concurrent_fungible_balance_exists_inline</a>(store_addr)) {
<b>let</b> balance_resource = <b>borrow_global</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a>&gt;(store_addr);
<a href="aggregator_v2.md#0x1_aggregator_v2_is_at_least">aggregator_v2::is_at_least</a>(&balance_resource.balance, amount)
} <b>else</b> {
store.balance &gt;= amount
}
} <b>else</b> {
amount == 0
}
Expand Down Expand Up @@ -2885,7 +2888,7 @@ Destroy an empty fungible asset.

<b>assert</b>!(metadata == store_metadata, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="fungible_asset.md#0x1_fungible_asset_EFUNGIBLE_ASSET_AND_STORE_MISMATCH">EFUNGIBLE_ASSET_AND_STORE_MISMATCH</a>));

<b>if</b> (<a href="fungible_asset.md#0x1_fungible_asset_concurrent_fungible_balance_exists_inline">concurrent_fungible_balance_exists_inline</a>(store_addr)) {
<b>if</b> (store.balance == 0 && <a href="fungible_asset.md#0x1_fungible_asset_concurrent_fungible_balance_exists_inline">concurrent_fungible_balance_exists_inline</a>(store_addr)) {
<b>let</b> balance_resource = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a>&gt;(store_addr);
<a href="aggregator_v2.md#0x1_aggregator_v2_add">aggregator_v2::add</a>(&<b>mut</b> balance_resource.balance, amount);
} <b>else</b> {
Expand Down Expand Up @@ -2921,14 +2924,14 @@ Extract <code>amount</code> of the fungible asset from <code>store</code>.
amount: u64,
): <a href="fungible_asset.md#0x1_fungible_asset_FungibleAsset">FungibleAsset</a> <b>acquires</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>, <a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a> {
<b>assert</b>!(<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr), <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_EFUNGIBLE_STORE_EXISTENCE">EFUNGIBLE_STORE_EXISTENCE</a>));
<b>if</b> (<a href="fungible_asset.md#0x1_fungible_asset_auto_upgrade_to_concurrent_fungible_balance">auto_upgrade_to_concurrent_fungible_balance</a>()) {
<a href="fungible_asset.md#0x1_fungible_asset_ensure_store_upgraded_to_concurrent_internal">ensure_store_upgraded_to_concurrent_internal</a>(store_addr);
};
// <b>if</b> (<a href="fungible_asset.md#0x1_fungible_asset_auto_upgrade_to_concurrent_fungible_balance">auto_upgrade_to_concurrent_fungible_balance</a>()) {
// <a href="fungible_asset.md#0x1_fungible_asset_ensure_store_upgraded_to_concurrent_internal">ensure_store_upgraded_to_concurrent_internal</a>(store_addr);
// };

<b>let</b> store = <b>borrow_global</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr);
<b>let</b> metadata = store.metadata;
<b>if</b> (amount != 0) {
<b>if</b> (<a href="fungible_asset.md#0x1_fungible_asset_concurrent_fungible_balance_exists_inline">concurrent_fungible_balance_exists_inline</a>(store_addr)) {
<b>if</b> (store.balance == 0 && <a href="fungible_asset.md#0x1_fungible_asset_concurrent_fungible_balance_exists_inline">concurrent_fungible_balance_exists_inline</a>(store_addr)) {
<b>let</b> balance_resource = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a>&gt;(store_addr);
<b>assert</b>!(
<a href="aggregator_v2.md#0x1_aggregator_v2_try_sub">aggregator_v2::try_sub</a>(&<b>mut</b> balance_resource.balance, amount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,14 @@ module aptos_framework::fungible_asset {

/// Check whether the balance of a given store is >= `amount`.
public(friend) fun is_address_balance_at_least(store_addr: address, amount: u64): bool acquires FungibleStore, ConcurrentFungibleBalance {
if (concurrent_fungible_balance_exists_inline(store_addr)) {
let balance_resource = borrow_global<ConcurrentFungibleBalance>(store_addr);
aggregator_v2::is_at_least(&balance_resource.balance, amount)
} else if (store_exists_inline(store_addr)) {
borrow_global<FungibleStore>(store_addr).balance >= amount
if (store_exists_inline(store_addr)) {
let store = borrow_global<FungibleStore>(store_addr);
if (store.balance == 0 && concurrent_fungible_balance_exists_inline(store_addr)) {
let balance_resource = borrow_global<ConcurrentFungibleBalance>(store_addr);
aggregator_v2::is_at_least(&balance_resource.balance, amount)
} else {
store.balance >= amount
}
} else {
amount == 0
}
Expand Down Expand Up @@ -861,7 +864,7 @@ module aptos_framework::fungible_asset {

assert!(metadata == store_metadata, error::invalid_argument(EFUNGIBLE_ASSET_AND_STORE_MISMATCH));

if (concurrent_fungible_balance_exists_inline(store_addr)) {
if (store.balance == 0 && concurrent_fungible_balance_exists_inline(store_addr)) {
let balance_resource = borrow_global_mut<ConcurrentFungibleBalance>(store_addr);
aggregator_v2::add(&mut balance_resource.balance, amount);
} else {
Expand All @@ -884,7 +887,7 @@ module aptos_framework::fungible_asset {
let store = borrow_global<FungibleStore>(store_addr);
let metadata = store.metadata;
if (amount != 0) {
if (concurrent_fungible_balance_exists_inline(store_addr)) {
if (store.balance == 0 && concurrent_fungible_balance_exists_inline(store_addr)) {
let balance_resource = borrow_global_mut<ConcurrentFungibleBalance>(store_addr);
assert!(
aggregator_v2::try_sub(&mut balance_resource.balance, amount),
Expand Down
2 changes: 1 addition & 1 deletion types/src/on_chain_config/aptos_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl FeatureFlag {
FeatureFlag::OBJECT_NATIVE_DERIVED_ADDRESS,
FeatureFlag::DISPATCHABLE_FUNGIBLE_ASSET,
FeatureFlag::CONCURRENT_FUNGIBLE_ASSETS,
FeatureFlag::MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE,
// FeatureFlag::MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE,
]
}
}
Expand Down