Skip to content

Commit

Permalink
removing auto-upgrade checks. adding a test
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed May 28, 2024
1 parent 6db6d57 commit 3c7e61a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 86 deletions.
10 changes: 5 additions & 5 deletions aptos-move/aptos-release-builder/src/components/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub enum FeatureFlag {
OperationsDefaultToFaAptStore,
AggregatorV2IsAtLeastApi,
ConcurrentFungibleBalance,
MigrateToConcurrentFungibleBalance,
DefaultToConcurrentFungibleBalance,
}

fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
Expand Down Expand Up @@ -307,8 +307,8 @@ impl From<FeatureFlag> for AptosFeatureFlag {
AptosFeatureFlag::AGGREGATOR_V2_IS_AT_LEAST_API
},
FeatureFlag::ConcurrentFungibleBalance => AptosFeatureFlag::CONCURRENT_FUNGIBLE_BALANCE,
FeatureFlag::MigrateToConcurrentFungibleBalance => {
AptosFeatureFlag::MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE
FeatureFlag::DefaultToConcurrentFungibleBalance => {
AptosFeatureFlag::DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE
},
}
}
Expand Down Expand Up @@ -427,8 +427,8 @@ impl From<AptosFeatureFlag> for FeatureFlag {
FeatureFlag::AggregatorV2IsAtLeastApi
},
AptosFeatureFlag::CONCURRENT_FUNGIBLE_BALANCE => FeatureFlag::ConcurrentFungibleBalance,
AptosFeatureFlag::MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE => {
FeatureFlag::MigrateToConcurrentFungibleBalance
AptosFeatureFlag::DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE => {
FeatureFlag::DefaultToConcurrentFungibleBalance
},
}
}
Expand Down
34 changes: 1 addition & 33 deletions aptos-move/framework/aptos-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ metadata object can be any object that equipped with <code><a href="fungible_ass
- [Function `default_to_concurrent_fungible_supply`](#0x1_fungible_asset_default_to_concurrent_fungible_supply)
- [Function `allow_upgrade_to_concurrent_fungible_balance`](#0x1_fungible_asset_allow_upgrade_to_concurrent_fungible_balance)
- [Function `default_to_concurrent_fungible_balance`](#0x1_fungible_asset_default_to_concurrent_fungible_balance)
- [Function `auto_upgrade_to_concurrent_fungible_balance`](#0x1_fungible_asset_auto_upgrade_to_concurrent_fungible_balance)
- [Function `add_fungibility`](#0x1_fungible_asset_add_fungibility)
- [Function `set_untransferable`](#0x1_fungible_asset_set_untransferable)
- [Function `is_untransferable`](#0x1_fungible_asset_is_untransferable)
Expand Down Expand Up @@ -1159,31 +1158,7 @@ Provided withdraw function type doesn't meet the signature requirement.


<pre><code>inline <b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_default_to_concurrent_fungible_balance">default_to_concurrent_fungible_balance</a>(): bool {
<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_migrate_to_concurrent_fungible_balance_enabled">features::migrate_to_concurrent_fungible_balance_enabled</a>()
}
</code></pre>



</details>

<a id="0x1_fungible_asset_auto_upgrade_to_concurrent_fungible_balance"></a>

## Function `auto_upgrade_to_concurrent_fungible_balance`



<pre><code><b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_auto_upgrade_to_concurrent_fungible_balance">auto_upgrade_to_concurrent_fungible_balance</a>(): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code>inline <b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_auto_upgrade_to_concurrent_fungible_balance">auto_upgrade_to_concurrent_fungible_balance</a>(): bool {
<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_migrate_to_concurrent_fungible_balance_enabled">features::migrate_to_concurrent_fungible_balance_enabled</a>()
<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_default_to_concurrent_fungible_balance_enabled">features::default_to_concurrent_fungible_balance_enabled</a>()
}
</code></pre>

Expand Down Expand Up @@ -2973,10 +2948,6 @@ Destroy an empty fungible asset.
<b>let</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleAsset">FungibleAsset</a> { metadata, amount } = fa;
<b>if</b> (amount == 0) <b>return</b>;

<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>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>let</b> store = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr);
<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>));
Expand Down Expand Up @@ -3017,9 +2988,6 @@ 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>let</b> store = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr);
<b>let</b> metadata = store.metadata;
Expand Down
54 changes: 36 additions & 18 deletions aptos-move/framework/aptos-framework/sources/fungible_asset.move
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,7 @@ module aptos_framework::fungible_asset {
}

inline fun default_to_concurrent_fungible_balance(): bool {
features::migrate_to_concurrent_fungible_balance_enabled()
}

inline fun auto_upgrade_to_concurrent_fungible_balance(): bool {
features::migrate_to_concurrent_fungible_balance_enabled()
features::default_to_concurrent_fungible_balance_enabled()
}

/// Make an existing object fungible by adding the Metadata resource.
Expand Down Expand Up @@ -887,10 +883,6 @@ module aptos_framework::fungible_asset {
let FungibleAsset { metadata, amount } = fa;
if (amount == 0) return;

if (auto_upgrade_to_concurrent_fungible_balance()) {
ensure_store_upgraded_to_concurrent_internal(store_addr);
};

assert!(exists<FungibleStore>(store_addr), error::not_found(EFUNGIBLE_STORE_EXISTENCE));
let store = borrow_global_mut<FungibleStore>(store_addr);
assert!(metadata == store.metadata, error::invalid_argument(EFUNGIBLE_ASSET_AND_STORE_MISMATCH));
Expand All @@ -911,9 +903,6 @@ module aptos_framework::fungible_asset {
amount: u64,
): FungibleAsset acquires FungibleStore, ConcurrentFungibleBalance {
assert!(exists<FungibleStore>(store_addr), error::not_found(EFUNGIBLE_STORE_EXISTENCE));
if (auto_upgrade_to_concurrent_fungible_balance()) {
ensure_store_upgraded_to_concurrent_internal(store_addr);
};

let store = borrow_global_mut<FungibleStore>(store_addr);
let metadata = store.metadata;
Expand Down Expand Up @@ -1284,7 +1273,7 @@ module aptos_framework::fungible_asset {
fun test_fungible_asset_upgrade(fx: &signer, creator: &signer) acquires Supply, ConcurrentSupply, FungibleStore, ConcurrentFungibleBalance {
let supply_feature = features::get_concurrent_fungible_assets_feature();
let balance_feature = features::get_concurrent_fungible_balance_feature();
let default_balance_feature = features::get_migrate_to_concurrent_fungible_balance_feature();
let default_balance_feature = features::get_default_to_concurrent_fungible_balance_feature();

features::change_feature_flags(fx, vector[], vector[supply_feature, balance_feature, default_balance_feature]);

Expand All @@ -1301,6 +1290,9 @@ module aptos_framework::fungible_asset {
assert!(supply(test_token) == option::some(30), 5);

deposit_with_ref(&transfer_ref, creator_store, fa);
assert!(exists<FungibleStore>(object::object_address(&creator_store)), 13);
assert!(borrow_store_resource(&creator_store).balance == 30, 14);
assert!(!exists<ConcurrentFungibleBalance>(object::object_address(&creator_store)), 15);

features::change_feature_flags(fx, vector[supply_feature, balance_feature], vector[default_balance_feature]);

Expand All @@ -1310,18 +1302,44 @@ module aptos_framework::fungible_asset {
assert!(!exists<Supply>(object::object_address(&test_token)), 6);
assert!(exists<ConcurrentSupply>(object::object_address(&test_token)), 7);

let fb = mint(&mint_ref, 20);
assert!(supply(test_token) == option::some(50), 8);

// automatic conversion of balance
deposit_with_ref(&transfer_ref, creator_store, fb);
// assert conversion of balance
upgrade_store_to_concurrent(creator, creator_store);
withdraw_with_ref(&transfer_ref, creator_store, fb);
// both store and new balance need to exist. Old balance should be 0.
assert!(exists<FungibleStore>(object::object_address(&creator_store)), 9);
assert!(borrow_store_resource(&creator_store).balance == 0, 10);
assert!(exists<ConcurrentFungibleBalance>(object::object_address(&creator_store)), 11);
assert!(aggregator_v2::read(&borrow_global<ConcurrentFungibleBalance>(object::object_address(&creator_store)).balance) == 50, 12);
}

#[test(fx = @aptos_framework, creator = @0xcafe)]
fun test_fungible_asset_default_concurrent(fx: &signer, creator: &signer) acquires Supply, ConcurrentSupply, FungibleStore, ConcurrentFungibleBalance {
let supply_feature = features::get_concurrent_fungible_assets_feature();
let balance_feature = features::get_concurrent_fungible_balance_feature();
let default_balance_feature = features::get_default_to_concurrent_fungible_balance_feature();

features::change_feature_flags(fx, vector[supply_feature, balance_feature, default_balance_feature], vector[]);

let (creator_ref, token_object) = create_test_token(creator);
let (mint_ref, transfer_ref, _burn) = init_test_metadata(&creator_ref);
let test_token = object::convert<TestToken, Metadata>(token_object);
assert!(exists<Supply>(object::object_address(&test_token)), 1);
assert!(!exists<ConcurrentSupply>(object::object_address(&test_token)), 2);
let creator_store = create_test_store(creator, test_token);
assert!(!exists<FungibleStore>(object::object_address(&creator_store)), 3);
assert!(exists<ConcurrentFungibleBalance>(object::object_address(&creator_store)), 4);

let fa = mint(&mint_ref, 30);
assert!(supply(test_token) == option::some(30), 5);

deposit_with_ref(&transfer_ref, creator_store, fa);

assert!(exists<FungibleStore>(object::object_address(&creator_store)), 9);
assert!(borrow_store_resource(&creator_store).balance == 0, 10);
assert!(exists<ConcurrentFungibleBalance>(object::object_address(&creator_store)), 11);
assert!(aggregator_v2::read(&borrow_global<ConcurrentFungibleBalance>(object::object_address(&creator_store)).balance) == 50, 12);
}

#[deprecated]
#[resource_group_member(group = aptos_framework::object::ObjectGroup)]
struct FungibleAssetEvents has key {
Expand Down
45 changes: 22 additions & 23 deletions aptos-move/framework/move-stdlib/doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ return true.
- [Function `operations_default_to_fa_apt_store_enabled`](#0x1_features_operations_default_to_fa_apt_store_enabled)
- [Function `get_concurrent_fungible_balance_feature`](#0x1_features_get_concurrent_fungible_balance_feature)
- [Function `concurrent_fungible_balance_enabled`](#0x1_features_concurrent_fungible_balance_enabled)
- [Function `get_migrate_to_concurrent_fungible_balance_feature`](#0x1_features_get_migrate_to_concurrent_fungible_balance_feature)
- [Function `migrate_to_concurrent_fungible_balance_enabled`](#0x1_features_migrate_to_concurrent_fungible_balance_enabled)
- [Function `get_default_to_concurrent_fungible_balance_feature`](#0x1_features_get_default_to_concurrent_fungible_balance_feature)
- [Function `default_to_concurrent_fungible_balance_enabled`](#0x1_features_default_to_concurrent_fungible_balance_enabled)
- [Function `change_feature_flags`](#0x1_features_change_feature_flags)
- [Function `change_feature_flags_internal`](#0x1_features_change_feature_flags_internal)
- [Function `change_feature_flags_for_next_epoch`](#0x1_features_change_feature_flags_for_next_epoch)
Expand Down Expand Up @@ -430,6 +430,17 @@ Lifetime: transient



<a id="0x1_features_DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE"></a>

Whether to default new Fungible Store to the concurrent variant.
Lifetime: transient


<pre><code><b>const</b> <a href="features.md#0x1_features_DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE">DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE</a>: u64 = 68;
</code></pre>



<a id="0x1_features_DELEGATION_POOLS"></a>

Whether delegation pools are enabled.
Expand Down Expand Up @@ -599,18 +610,6 @@ Whether checking the maximum object nesting is enabled.



<a id="0x1_features_MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE"></a>

Whether to default new Fungible Stores and migrate existing ones
to the concurrent variant.
Lifetime: transient


<pre><code><b>const</b> <a href="features.md#0x1_features_MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE">MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE</a>: u64 = 68;
</code></pre>



<a id="0x1_features_MODULE_EVENT"></a>

Whether emit function in <code>event.<b>move</b></code> are enabled for module events.
Expand Down Expand Up @@ -3069,13 +3068,13 @@ Lifetime: transient

</details>

<a id="0x1_features_get_migrate_to_concurrent_fungible_balance_feature"></a>
<a id="0x1_features_get_default_to_concurrent_fungible_balance_feature"></a>

## Function `get_migrate_to_concurrent_fungible_balance_feature`
## Function `get_default_to_concurrent_fungible_balance_feature`



<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_migrate_to_concurrent_fungible_balance_feature">get_migrate_to_concurrent_fungible_balance_feature</a>(): u64
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_default_to_concurrent_fungible_balance_feature">get_default_to_concurrent_fungible_balance_feature</a>(): u64
</code></pre>


Expand All @@ -3084,20 +3083,20 @@ Lifetime: transient
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_migrate_to_concurrent_fungible_balance_feature">get_migrate_to_concurrent_fungible_balance_feature</a>(): u64 { <a href="features.md#0x1_features_MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE">MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE</a> }
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_default_to_concurrent_fungible_balance_feature">get_default_to_concurrent_fungible_balance_feature</a>(): u64 { <a href="features.md#0x1_features_DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE">DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE</a> }
</code></pre>



</details>

<a id="0x1_features_migrate_to_concurrent_fungible_balance_enabled"></a>
<a id="0x1_features_default_to_concurrent_fungible_balance_enabled"></a>

## Function `migrate_to_concurrent_fungible_balance_enabled`
## Function `default_to_concurrent_fungible_balance_enabled`



<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_migrate_to_concurrent_fungible_balance_enabled">migrate_to_concurrent_fungible_balance_enabled</a>(): bool
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_default_to_concurrent_fungible_balance_enabled">default_to_concurrent_fungible_balance_enabled</a>(): bool
</code></pre>


Expand All @@ -3106,8 +3105,8 @@ Lifetime: transient
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_migrate_to_concurrent_fungible_balance_enabled">migrate_to_concurrent_fungible_balance_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE">MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE</a>)
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_default_to_concurrent_fungible_balance_enabled">default_to_concurrent_fungible_balance_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE">DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE</a>)
}
</code></pre>

Expand Down
11 changes: 5 additions & 6 deletions aptos-move/framework/move-stdlib/sources/configs/features.move
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,14 @@ module std::features {
is_enabled(CONCURRENT_FUNGIBLE_BALANCE)
}

/// Whether to default new Fungible Stores and migrate existing ones
/// to the concurrent variant.
/// Whether to default new Fungible Store to the concurrent variant.
/// Lifetime: transient
const MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE: u64 = 68;
const DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE: u64 = 68;

public fun get_migrate_to_concurrent_fungible_balance_feature(): u64 { MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE }
public fun get_default_to_concurrent_fungible_balance_feature(): u64 { DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE }

public fun migrate_to_concurrent_fungible_balance_enabled(): bool acquires Features {
is_enabled(MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE)
public fun default_to_concurrent_fungible_balance_enabled(): bool acquires Features {
is_enabled(DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE)
}

// ============================================================================================
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 @@ -84,7 +84,7 @@ pub enum FeatureFlag {
OPERATIONS_DEFAULT_TO_FA_APT_STORE = 65,
AGGREGATOR_V2_IS_AT_LEAST_API = 66,
CONCURRENT_FUNGIBLE_BALANCE = 67,
MIGRATE_TO_CONCURRENT_FUNGIBLE_BALANCE = 68,
DEFAULT_TO_CONCURRENT_FUNGIBLE_BALANCE = 68,
}

impl FeatureFlag {
Expand Down

0 comments on commit 3c7e61a

Please sign in to comment.