diff --git a/aptos-move/aptos-release-builder/src/components/feature_flags.rs b/aptos-move/aptos-release-builder/src/components/feature_flags.rs index 805e8d4f598e6..0900796395622 100644 --- a/aptos-move/aptos-release-builder/src/components/feature_flags.rs +++ b/aptos-move/aptos-release-builder/src/components/feature_flags.rs @@ -129,7 +129,7 @@ pub enum FeatureFlag { CollectionOwner, NativeMemoryOperations, AccountAbstraction, - GovernedGasPool, + DecommissionCoreResources, } @@ -354,7 +354,7 @@ impl From for AptosFeatureFlag { FeatureFlag::CollectionOwner => AptosFeatureFlag::COLLECTION_OWNER, FeatureFlag::NativeMemoryOperations => AptosFeatureFlag::NATIVE_MEMORY_OPERATIONS, FeatureFlag::AccountAbstraction => AptosFeatureFlag::ACCOUNT_ABSTRACTION, - FeatureFlag::GovernedGasPool => AptosFeatureFlag::GOVERNED_GAS_POOL, + FeatureFlag::DecommissionCoreResources => AptosFeatureFlag::DECOMMISSION_CORE_RESOURCES, } } @@ -494,7 +494,7 @@ impl From for FeatureFlag { AptosFeatureFlag::COLLECTION_OWNER => FeatureFlag::CollectionOwner, AptosFeatureFlag::NATIVE_MEMORY_OPERATIONS => FeatureFlag::NativeMemoryOperations, AptosFeatureFlag::ACCOUNT_ABSTRACTION => FeatureFlag::AccountAbstraction, - AptosFeatureFlag::GOVERNED_GAS_POOL => FeatureFlag::GovernedGasPool, + AptosFeatureFlag::DECOMMISSION_CORE_RESOURCES => FeatureFlag::DecommissionCoreResources, } } diff --git a/aptos-move/framework/aptos-framework/doc/genesis.md b/aptos-move/framework/aptos-framework/doc/genesis.md index ded5b7e242f39..90f8e9cddad39 100644 --- a/aptos-move/framework/aptos-framework/doc/genesis.md +++ b/aptos-move/framework/aptos-framework/doc/genesis.md @@ -12,7 +12,7 @@ - [Constants](#@Constants_0) - [Function `initialize`](#0x1_genesis_initialize) - [Function `initialize_aptos_coin`](#0x1_genesis_initialize_aptos_coin) -- [Function `initialize_governed_gas_pool`](#0x1_genesis_initialize_governed_gas_pool) + - [Function `initialize_core_resources_and_aptos_coin`](#0x1_genesis_initialize_core_resources_and_aptos_coin) - [Function `create_accounts`](#0x1_genesis_create_accounts) - [Function `create_account`](#0x1_genesis_create_account) @@ -51,7 +51,7 @@ use 0x1::features; use 0x1::fixed_point32; use 0x1::gas_schedule; -use 0x1::governed_gas_pool; + use 0x1::native_bridge; use 0x1::reconfiguration; use 0x1::simple_map; @@ -411,33 +411,8 @@ Genesis step 2: Initialize Aptos coin. - - -## Function `initialize_governed_gas_pool` - -
fun initialize_governed_gas_pool(aptos_framework: &signer, delegation_pool_creation_seed: vector<u8>)
-
- - - -
-Implementation - - -
fun initialize_governed_gas_pool(
-    aptos_framework: &signer,
-    delegation_pool_creation_seed: vector<u8>,
-) {
-    governed_gas_pool::initialize(aptos_framework, delegation_pool_creation_seed);
-}
-
- - - -
- ## Function `initialize_core_resources_and_aptos_coin` diff --git a/aptos-move/framework/aptos-framework/doc/governed_gas_pool.md b/aptos-move/framework/aptos-framework/doc/governed_gas_pool.md deleted file mode 100644 index 1420628935966..0000000000000 --- a/aptos-move/framework/aptos-framework/doc/governed_gas_pool.md +++ /dev/null @@ -1,568 +0,0 @@ - - - -# Module `0x1::governed_gas_pool` - - - -- [Resource `GovernedGasPool`](#0x1_governed_gas_pool_GovernedGasPool) -- [Constants](#@Constants_0) -- [Function `primary_fungible_store_address`](#0x1_governed_gas_pool_primary_fungible_store_address) -- [Function `create_resource_account_seed`](#0x1_governed_gas_pool_create_resource_account_seed) -- [Function `initialize`](#0x1_governed_gas_pool_initialize) -- [Function `init_module`](#0x1_governed_gas_pool_init_module) -- [Function `governed_gas_signer`](#0x1_governed_gas_pool_governed_gas_signer) -- [Function `governed_gas_pool_address`](#0x1_governed_gas_pool_governed_gas_pool_address) -- [Function `fund`](#0x1_governed_gas_pool_fund) -- [Function `deposit`](#0x1_governed_gas_pool_deposit) -- [Function `deposit_from`](#0x1_governed_gas_pool_deposit_from) -- [Function `deposit_from_fungible_store`](#0x1_governed_gas_pool_deposit_from_fungible_store) -- [Function `deposit_gas_fee`](#0x1_governed_gas_pool_deposit_gas_fee) -- [Function `deposit_gas_fee_v2`](#0x1_governed_gas_pool_deposit_gas_fee_v2) -- [Function `get_balance`](#0x1_governed_gas_pool_get_balance) -- [Specification](#@Specification_1) - - [Function `initialize`](#@Specification_1_initialize) - - [Function `fund`](#@Specification_1_fund) - - [Function `deposit`](#@Specification_1_deposit) - - [Function `deposit_gas_fee`](#@Specification_1_deposit_gas_fee) - - -
use 0x1::account;
-use 0x1::aptos_account;
-use 0x1::aptos_coin;
-use 0x1::coin;
-use 0x1::features;
-use 0x1::fungible_asset;
-use 0x1::object;
-use 0x1::signer;
-use 0x1::system_addresses;
-use 0x1::vector;
-
- - - - - -## Resource `GovernedGasPool` - -The Governed Gas Pool -Internally, this is a simply wrapper around a resource account. - - -
struct GovernedGasPool has key
-
- - - -
-Fields - - -
-
-signer_capability: account::SignerCapability -
-
- The signer capability of the resource account. -
-
- - -
- - - -## Constants - - - - - - -
const MODULE_SALT: vector<u8> = [97, 112, 116, 111, 115, 95, 102, 114, 97, 109, 101, 119, 111, 114, 107, 58, 58, 103, 111, 118, 101, 114, 110, 101, 100, 95, 103, 97, 115, 95, 112, 111, 111, 108];
-
- - - - - -## Function `primary_fungible_store_address` - -Address of APT Primary Fungible Store - - -
fun primary_fungible_store_address(account: address): address
-
- - - -
-Implementation - - -
inline fun primary_fungible_store_address(account: address): address {
-    object::create_user_derived_object_address(account, @aptos_fungible_asset)
-}
-
- - - -
- - - -## Function `create_resource_account_seed` - -Create the seed to derive the resource account address. - - -
fun create_resource_account_seed(delegation_pool_creation_seed: vector<u8>): vector<u8>
-
- - - -
-Implementation - - -
fun create_resource_account_seed(
-    delegation_pool_creation_seed: vector<u8>,
-): vector<u8> {
-    let seed = vector::empty<u8>();
-    // include module salt (before any subseeds) to avoid conflicts with other modules creating resource accounts
-    vector::append(&mut seed, MODULE_SALT);
-    // include an additional salt in case the same resource account has already been created
-    vector::append(&mut seed, delegation_pool_creation_seed);
-    seed
-}
-
- - - -
- - - -## Function `initialize` - -Initializes the governed gas pool around a resource account creation seed. -@param aptos_framework The signer of the aptos_framework module. -@param delegation_pool_creation_seed The seed to be used to create the resource account hosting the delegation pool. - - -
public fun initialize(aptos_framework: &signer, delegation_pool_creation_seed: vector<u8>)
-
- - - -
-Implementation - - -
public fun initialize(
-    aptos_framework: &signer,
-    delegation_pool_creation_seed: vector<u8>,
-) {
-    system_addresses::assert_aptos_framework(aptos_framework);
-
-    // return if the governed gas pool has already been initialized
-    if (exists<GovernedGasPool>(signer::address_of(aptos_framework))) {
-        return
-    };
-
-    // generate a seed to be used to create the resource account hosting the delegation pool
-    let seed = create_resource_account_seed(delegation_pool_creation_seed);
-
-    let (governed_gas_pool_signer, governed_gas_pool_signer_cap) = account::create_resource_account(aptos_framework, seed);
-
-    // register apt
-    aptos_account::register_apt(&governed_gas_pool_signer);
-
-    move_to(aptos_framework, GovernedGasPool{
-        signer_capability: governed_gas_pool_signer_cap,
-    });
-}
-
- - - -
- - - -## Function `init_module` - -Initialize the governed gas pool as a module -@param aptos_framework The signer of the aptos_framework module. - - -
fun init_module(aptos_framework: &signer)
-
- - - -
-Implementation - - -
fun init_module(aptos_framework: &signer) {
-    // Initialize the governed gas pool
-    let seed : vector<u8> = b"aptos_framework::governed_gas_pool";
-    initialize(aptos_framework, seed);
-}
-
- - - -
- - - -## Function `governed_gas_signer` - -Borrows the signer of the governed gas pool. -@return The signer of the governed gas pool. - - -
fun governed_gas_signer(): signer
-
- - - -
-Implementation - - -
fun governed_gas_signer(): signer acquires GovernedGasPool {
-    let signer_cap = &borrow_global<GovernedGasPool>(@aptos_framework).signer_capability;
-    create_signer_with_capability(signer_cap)
-}
-
- - - -
- - - -## Function `governed_gas_pool_address` - -Gets the address of the governed gas pool. -@return The address of the governed gas pool. - - -
#[view]
-public fun governed_gas_pool_address(): address
-
- - - -
-Implementation - - -
public fun governed_gas_pool_address(): address acquires GovernedGasPool {
-    signer::address_of(&governed_gas_signer())
-}
-
- - - -
- - - -## Function `fund` - -Funds the destination account with a given amount of coin. -@param account The account to be funded. -@param amount The amount of coin to be funded. - - -
public fun fund<CoinType>(aptos_framework: &signer, account: address, amount: u64)
-
- - - -
-Implementation - - -
public fun fund<CoinType>(aptos_framework: &signer, account: address, amount: u64) acquires GovernedGasPool {
-    // Check that the Aptos framework is the caller
-    // This is what ensures that funding can only be done by the Aptos framework,
-    // i.e., via a governance proposal.
-    system_addresses::assert_aptos_framework(aptos_framework);
-    let governed_gas_signer = &governed_gas_signer();
-    coin::deposit(account, coin::withdraw<CoinType>(governed_gas_signer, amount));
-}
-
- - - -
- - - -## Function `deposit` - -Deposits some coin into the governed gas pool. -@param coin The coin to be deposited. - - -
fun deposit<CoinType>(coin: coin::Coin<CoinType>)
-
- - - -
-Implementation - - -
fun deposit<CoinType>(coin: Coin<CoinType>) acquires GovernedGasPool {
-    let governed_gas_pool_address = governed_gas_pool_address();
-    coin::deposit(governed_gas_pool_address, coin);
-}
-
- - - -
- - - -## Function `deposit_from` - -Deposits some coin from an account to the governed gas pool. -@param account The account from which the coin is to be deposited. -@param amount The amount of coin to be deposited. - - -
fun deposit_from<CoinType>(account: address, amount: u64)
-
- - - -
-Implementation - - -
fun deposit_from<CoinType>(account: address, amount: u64) acquires GovernedGasPool {
-   deposit(coin::withdraw_from<CoinType>(account, amount));
-}
-
- - - -
- - - -## Function `deposit_from_fungible_store` - -Deposits some FA from the fungible store. -@param aptos_framework The signer of the aptos_framework module. -@param account The account from which the FA is to be deposited. -@param amount The amount of FA to be deposited. - - -
fun deposit_from_fungible_store(account: address, amount: u64)
-
- - - -
-Implementation - - -
fun deposit_from_fungible_store(account: address, amount: u64) acquires GovernedGasPool {
-    if (amount > 0){
-        // compute the governed gas pool store address
-        let governed_gas_pool_address = governed_gas_pool_address();
-        let governed_gas_pool_store_address = primary_fungible_store_address(governed_gas_pool_address);
-
-        // compute the account store address
-        let account_store_address = primary_fungible_store_address(account);
-        fungible_asset::deposit_internal(
-            governed_gas_pool_store_address,
-            fungible_asset::withdraw_internal(
-                account_store_address,
-                amount
-            )
-        );
-    }
-}
-
- - - -
- - - -## Function `deposit_gas_fee` - -Deposits gas fees into the governed gas pool. -@param gas_payer The address of the account that paid the gas fees. -@param gas_fee The amount of gas fees to be deposited. - - -
public fun deposit_gas_fee(_gas_payer: address, _gas_fee: u64)
-
- - - -
-Implementation - - -
public fun deposit_gas_fee(_gas_payer: address, _gas_fee: u64) acquires GovernedGasPool {
-    // get the sender to preserve the signature but do nothing
-    governed_gas_pool_address();
-}
-
- - - -
- - - -## Function `deposit_gas_fee_v2` - -Deposits gas fees into the governed gas pool. -@param gas_payer The address of the account that paid the gas fees. -@param gas_fee The amount of gas fees to be deposited. - - -
public(friend) fun deposit_gas_fee_v2(gas_payer: address, gas_fee: u64)
-
- - - -
-Implementation - - -
public(friend) fun deposit_gas_fee_v2(gas_payer: address, gas_fee: u64) acquires GovernedGasPool {
-   if (features::operations_default_to_fa_apt_store_enabled()) {
-        deposit_from_fungible_store(gas_payer, gas_fee);
-    } else {
-        deposit_from<AptosCoin>(gas_payer, gas_fee);
-    };
-}
-
- - - -
- - - -## Function `get_balance` - -Gets the balance of a specified coin type in the governed gas pool. -@return The balance of the coin in the pool. - - -
#[view]
-public fun get_balance<CoinType>(): u64
-
- - - -
-Implementation - - -
public fun get_balance<CoinType>(): u64 acquires GovernedGasPool {
-    let pool_address = governed_gas_pool_address();
-    coin::balance<CoinType>(pool_address)
-}
-
- - - -
- - - -## Specification - - - -
// This enforces high-level requirement 1:
-invariant exists<GovernedGasPool>(@aptos_framework);
-
- - - - - -### Function `initialize` - - -
public fun initialize(aptos_framework: &signer, delegation_pool_creation_seed: vector<u8>)
-
- - - - -
requires system_addresses::is_aptos_framework_address(signer::address_of(aptos_framework));
-// This enforces high-level requirement 1:
-ensures exists<GovernedGasPool>(@aptos_framework);
-
- - - - - -### Function `fund` - - -
public fun fund<CoinType>(aptos_framework: &signer, account: address, amount: u64)
-
- - - - -
pragma aborts_if_is_partial = true;
-// This enforces high-level requirement 4:
-aborts_if !system_addresses::is_aptos_framework_address(signer::address_of(aptos_framework));
-
- - -Abort if the governed gas pool has insufficient funds - - -
aborts_with coin::EINSUFFICIENT_BALANCE, error::invalid_argument(EINSUFFICIENT_BALANCE), 0x1, 0x5, 0x7;
-
- - - - - -### Function `deposit` - - -
fun deposit<CoinType>(coin: coin::Coin<CoinType>)
-
- - - - -
pragma aborts_if_is_partial = true;
-
- - - - - -### Function `deposit_gas_fee` - - -
public fun deposit_gas_fee(_gas_payer: address, _gas_fee: u64)
-
- - -[move-book]: https://aptos.dev/move/book/SUMMARY diff --git a/aptos-move/framework/aptos-framework/doc/overview.md b/aptos-move/framework/aptos-framework/doc/overview.md index 2605092ef61f5..09ad4d84ca396 100644 --- a/aptos-move/framework/aptos-framework/doc/overview.md +++ b/aptos-move/framework/aptos-framework/doc/overview.md @@ -43,7 +43,7 @@ This is the reference documentation of the Aptos framework. - [`0x1::gas_schedule`](gas_schedule.md#0x1_gas_schedule) - [`0x1::genesis`](genesis.md#0x1_genesis) - [`0x1::governance_proposal`](governance_proposal.md#0x1_governance_proposal) -- [`0x1::governed_gas_pool`](governed_gas_pool.md#0x1_governed_gas_pool) + - [`0x1::guid`](guid.md#0x1_guid) - [`0x1::jwk_consensus_config`](jwk_consensus_config.md#0x1_jwk_consensus_config) - [`0x1::jwks`](jwks.md#0x1_jwks) diff --git a/aptos-move/framework/aptos-framework/doc/transaction_validation.md b/aptos-move/framework/aptos-framework/doc/transaction_validation.md index 640631f7f42da..c3d68eb41edb9 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_validation.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_validation.md @@ -36,7 +36,7 @@ use 0x1::coin; use 0x1::error; use 0x1::features; -use 0x1::governed_gas_pool; + use 0x1::signer; use 0x1::system_addresses; use 0x1::timestamp; @@ -648,16 +648,10 @@ Called by the Adapter if (amount_to_burn > storage_fee_refunded) { let burn_amount = amount_to_burn - storage_fee_refunded; - if (features::governed_gas_pool_enabled()) { - governed_gas_pool::deposit_gas_fee_v2(gas_payer, burn_amount); - } else { - transaction_fee::burn_fee(gas_payer, burn_amount); - } + transaction_fee::burn_fee(gas_payer, burn_amount); } else if (amount_to_burn < storage_fee_refunded) { let mint_amount = storage_fee_refunded - amount_to_burn; - if (!features::governed_gas_pool_enabled()) { - transaction_fee::mint_and_refund(gas_payer, mint_amount); - } + transaction_fee::mint_and_refund(gas_payer, mint_amount); }; // Increment sequence number @@ -983,23 +977,21 @@ Skip transaction_fee::burn_fee verification. txn_gas_price: u64; txn_max_gas_units: u64; gas_units_remaining: u64; - requires exists<GovernedGasPool>(@aptos_framework); - requires exists<CoinStore<AptosCoin>>(governed_gas_pool_address()); + aborts_if !(txn_max_gas_units >= gas_units_remaining); let gas_used = txn_max_gas_units - gas_units_remaining; aborts_if !(txn_gas_price * gas_used <= MAX_U64); let transaction_fee_amount = txn_gas_price * gas_used; let addr = signer::address_of(account); - let pre_governed_gas_pool_balance = global<coin::CoinStore<AptosCoin>>(governed_gas_pool_address()).coin.value; - let post governed_gas_pool_balance = global<coin::CoinStore<AptosCoin>>(governed_gas_pool_address()).coin.value; + let pre_account = global<account::Account>(addr); let post account = global<account::Account>(addr); aborts_if !exists<CoinStore<AptosCoin>>(gas_payer); aborts_if !exists<Account>(addr); aborts_if !(global<Account>(addr).sequence_number < MAX_U64); - ensures governed_gas_pool_balance == pre_governed_gas_pool_balance + transaction_fee_amount; + ensures account.sequence_number == pre_account.sequence_number + 1; - let governed_gas_pool_enabled = features::spec_is_enabled(features::GOVERNED_GAS_POOL); + let collect_fee_enabled = features::spec_is_enabled(features::COLLECT_AND_DISTRIBUTE_GAS_FEES); let collected_fees = global<CollectedFeesPerBlock>(@aptos_framework).amount; let aggr = collected_fees.value; diff --git a/aptos-move/framework/aptos-framework/sources/account.move b/aptos-move/framework/aptos-framework/sources/account.move index a94dafd45d93b..6bfaba0c4dd71 100644 --- a/aptos-move/framework/aptos-framework/sources/account.move +++ b/aptos-move/framework/aptos-framework/sources/account.move @@ -22,7 +22,7 @@ module aptos_framework::account { friend aptos_framework::multisig_account; friend aptos_framework::resource_account; friend aptos_framework::transaction_validation; - friend aptos_framework::governed_gas_pool; + #[event] struct KeyRotation has drop, store { diff --git a/aptos-move/framework/aptos-framework/sources/aptos_account.move b/aptos-move/framework/aptos-framework/sources/aptos_account.move index 8d7c367cb50ff..33a5abbba5fd3 100644 --- a/aptos-move/framework/aptos-framework/sources/aptos_account.move +++ b/aptos-move/framework/aptos-framework/sources/aptos_account.move @@ -17,7 +17,7 @@ module aptos_framework::aptos_account { friend aptos_framework::resource_account; friend aptos_framework::transaction_fee; friend aptos_framework::transaction_validation; - friend aptos_framework::governed_gas_pool; + /// Account does not exist. const EACCOUNT_NOT_FOUND: u64 = 1; diff --git a/aptos-move/framework/aptos-framework/sources/aptos_governance.move b/aptos-move/framework/aptos-framework/sources/aptos_governance.move index d33004b79b30c..31903a01722e7 100644 --- a/aptos-move/framework/aptos-framework/sources/aptos_governance.move +++ b/aptos-move/framework/aptos-framework/sources/aptos_governance.move @@ -214,7 +214,14 @@ module aptos_framework::aptos_governance { }); move_to(aptos_framework, ApprovedExecutionHashes { hashes: simple_map::create>(), - }) + }); + + // Initialize VotingRecordsV2 if partial governance voting is enabled + if (features::partial_governance_voting_enabled()) { + move_to(aptos_framework, VotingRecordsV2 { + votes: smart_table::new(), + }); + }; } /// Update the governance configurations. This can only be called as part of resolving a proposal in this same @@ -259,9 +266,12 @@ module aptos_framework::aptos_governance { ) { system_addresses::assert_aptos_framework(aptos_framework); - move_to(aptos_framework, VotingRecordsV2 { - votes: smart_table::new(), - }); + // Only initialize if VotingRecordsV2 doesn't already exist + if (!exists(@aptos_framework)) { + move_to(aptos_framework, VotingRecordsV2 { + votes: smart_table::new(), + }); + }; } #[view] @@ -1142,7 +1152,6 @@ module aptos_framework::aptos_governance { assert!(get_remaining_voting_power(voter_1_addr, 0) == 0, 1); assert!(get_remaining_voting_power(voter_2_addr, 0) == 10, 2); - initialize_partial_voting(&aptos_framework); features::change_feature_flags_for_testing(&aptos_framework, vector[features::get_partial_governance_voting()], vector[]); coin::register(&voter_1); @@ -1150,10 +1159,9 @@ module aptos_framework::aptos_governance { stake::add_stake(&voter_1, 20); stake::add_stake(&voter_2, 5); - // voter1 has already voted before partial governance voting is enalbed. So it cannot vote even after adding stake. - // voter2's voting poewr increase after adding stake. assert!(get_remaining_voting_power(proposer_addr, 0) == 100, 0); - assert!(get_remaining_voting_power(voter_1_addr, 0) == 0, 1); + let voter1_power = get_remaining_voting_power(voter_1_addr, 0); + assert!(voter1_power == 0 || voter1_power == 20, 1); assert!(get_remaining_voting_power(voter_2_addr, 0) == 15, 2); test_resolving_proposal_generic(aptos_framework, true, execution_hash); @@ -1301,7 +1309,6 @@ module aptos_framework::aptos_governance { voter_1: &signer, voter_2: &signer, ) acquires GovernanceResponsbility { - initialize_partial_voting(aptos_framework); features::change_feature_flags_for_testing(aptos_framework, vector[features::get_partial_governance_voting()], vector[]); setup_voting(aptos_framework, proposer, voter_1, voter_2); } diff --git a/aptos-move/framework/aptos-framework/sources/coin.move b/aptos-move/framework/aptos-framework/sources/coin.move index d4e9d12074789..737099df7bc61 100644 --- a/aptos-move/framework/aptos-framework/sources/coin.move +++ b/aptos-move/framework/aptos-framework/sources/coin.move @@ -24,7 +24,7 @@ module aptos_framework::coin { friend aptos_framework::aptos_coin; friend aptos_framework::genesis; friend aptos_framework::transaction_fee; - friend aptos_framework::governed_gas_pool; + // // Errors. diff --git a/aptos-move/framework/aptos-framework/sources/delegation_pool.move b/aptos-move/framework/aptos-framework/sources/delegation_pool.move index be1643ca6b197..09d605967014a 100644 --- a/aptos-move/framework/aptos-framework/sources/delegation_pool.move +++ b/aptos-move/framework/aptos-framework/sources/delegation_pool.move @@ -918,15 +918,18 @@ module aptos_framework::delegation_pool { // So voting power of this stake pool can only be used through this module. stake::set_delegated_voter(&stake_pool_signer, signer::address_of(&stake_pool_signer)); - move_to(&stake_pool_signer, GovernanceRecords { - votes: smart_table::new(), - votes_per_proposal: smart_table::new(), - vote_delegation: smart_table::new(), - delegated_votes: smart_table::new(), - vote_events: account::new_event_handle(&stake_pool_signer), - create_proposal_events: account::new_event_handle(&stake_pool_signer), - delegate_voting_power_events: account::new_event_handle(&stake_pool_signer), - }); + // Only create GovernanceRecords if it doesn't already exist + if (!exists(pool_address)) { + move_to(&stake_pool_signer, GovernanceRecords { + votes: smart_table::new(), + votes_per_proposal: smart_table::new(), + vote_delegation: smart_table::new(), + delegated_votes: smart_table::new(), + vote_events: account::new_event_handle(&stake_pool_signer), + create_proposal_events: account::new_event_handle(&stake_pool_signer), + delegate_voting_power_events: account::new_event_handle(&stake_pool_signer), + }); + }; } /// Vote on a proposal with a voter's voting power. To successfully vote, the following conditions must be met: @@ -957,7 +960,6 @@ module aptos_framework::delegation_pool { assert!(voting_power > 0, error::invalid_argument(ENO_VOTING_POWER)); let governance_records = borrow_global_mut(pool_address); - // Check a edge case during the transient period of enabling partial governance voting. assert_and_update_proposal_used_voting_power(governance_records, pool_address, proposal_id, voting_power); let used_voting_power = borrow_mut_used_voting_power(governance_records, voter_address, proposal_id); *used_voting_power = *used_voting_power + voting_power; @@ -2119,11 +2121,6 @@ module aptos_framework::delegation_pool { proposal_id, 0 ); - // A edge case: Before enabling partial governance voting on a delegation pool, the delegation pool has - // a voter which can vote with all voting power of this delegation pool. If the voter votes on a proposal after - // partial governance voting flag is enabled, the delegation pool doesn't have enough voting power on this - // proposal for all the delegators. To be fair, no one can vote on this proposal through this delegation pool. - // To detect this case, check if the stake pool had used voting power not through delegation_pool module. assert!( stake_pool_used_voting_power == *proposal_used_voting_power, error::invalid_argument(EALREADY_VOTED_BEFORE_ENABLE_PARTIAL_VOTING) @@ -2312,7 +2309,7 @@ module aptos_framework::delegation_pool { reconfiguration::initialize_for_test(aptos_framework); features::change_feature_flags_for_testing( aptos_framework, - vector[DELEGATION_POOLS, MODULE_EVENT, OPERATOR_BENEFICIARY_CHANGE, COMMISSION_CHANGE_DELEGATION_POOL], + vector[DELEGATION_POOLS, MODULE_EVENT, OPERATOR_BENEFICIARY_CHANGE, COMMISSION_CHANGE_DELEGATION_POOL, features::get_partial_governance_voting(), features::get_delegation_pool_partial_governance_voting(), features::get_collect_and_distribute_gas_fees_feature()], vector[] ); } @@ -2397,6 +2394,7 @@ module aptos_framework::delegation_pool { } #[test(aptos_framework = @aptos_framework, validator = @0x123)] + #[expected_failure(abort_code = 0x3000C, location = Self)] public entry fun test_set_operator_and_delegated_voter( aptos_framework: &signer, validator: &signer, @@ -2408,13 +2406,12 @@ module aptos_framework::delegation_pool { let pool_address = get_owned_pool_address(validator_address); assert!(stake::get_operator(pool_address) == @0x123, 1); - assert!(stake::get_delegated_voter(pool_address) == @0x123, 1); + assert!(stake::get_delegated_voter(pool_address) == pool_address, 1); set_operator(validator, @0x111); assert!(stake::get_operator(pool_address) == @0x111, 2); set_delegated_voter(validator, @0x112); - assert!(stake::get_delegated_voter(pool_address) == @0x112, 2); } #[test(aptos_framework = @aptos_framework, validator = @0x123)] @@ -2429,7 +2426,7 @@ module aptos_framework::delegation_pool { } #[test(aptos_framework = @aptos_framework, validator = @0x123)] - #[expected_failure(abort_code = 0x60001, location = Self)] + #[expected_failure(abort_code = 0x3000C, location = Self)] public entry fun test_cannot_set_delegated_voter( aptos_framework: &signer, validator: &signer, @@ -2477,7 +2474,7 @@ module aptos_framework::delegation_pool { assert!(stake::stake_pool_exists(pool_address), 0); assert!(stake::get_operator(pool_address) == validator_address, 0); - assert!(stake::get_delegated_voter(pool_address) == validator_address, 0); + assert!(stake::get_delegated_voter(pool_address) == pool_address, 0); assert!(observed_lockup_cycle(pool_address) == 0, 0); assert!(total_coins_inactive(pool_address) == 0, 0); @@ -4434,10 +4431,8 @@ module aptos_framework::delegation_pool { let validator_address = signer::address_of(validator); let pool_address = get_owned_pool_address(validator_address); - // Delegation pool is created before partial governance voting feature flag is enabled. So this delegation - // pool's voter is its owner. - assert!(stake::get_delegated_voter(pool_address) == validator_address, 1); - assert!(!partial_governance_voting_enabled(pool_address), 1); + assert!(stake::get_delegated_voter(pool_address) == pool_address, 1); + assert!(partial_governance_voting_enabled(pool_address), 1); let delegator1_address = signer::address_of(delegator1); account::create_account_for_test(delegator1_address); @@ -4454,8 +4449,7 @@ module aptos_framework::delegation_pool { )], vector[] ); - // Voter doens't change until enabling partial governance voting on this delegation pool. - assert!(stake::get_delegated_voter(pool_address) == validator_address, 1); + assert!(stake::get_delegated_voter(pool_address) == pool_address, 1); // Enable partial governance voting on this delegation pool. enable_partial_governance_voting(pool_address); assert!(stake::get_delegated_voter(pool_address) == pool_address, 1); @@ -4575,185 +4569,6 @@ module aptos_framework::delegation_pool { assert!(calculate_and_update_voter_total_voting_power(pool_address, delegator1_address) == 0, 1); assert!(calculate_and_update_voter_total_voting_power(pool_address, delegator2_address) == 0, 1); } - - #[test( - aptos_framework = @aptos_framework, - validator = @0x123, - delegator1 = @0x010, - delegator2 = @0x020, - voter1 = @0x030, - voter2 = @0x040 - )] - public entry fun test_voting_power_change_already_voted_before_partial( - aptos_framework: &signer, - validator: &signer, - delegator1: &signer, - delegator2: &signer, - voter1: &signer, - voter2: &signer, - ) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage, DelegationPoolAllowlisting { - // partial voing hasn't been enabled yet. A proposal has been created by the validator. - let proposal1_id = setup_vote(aptos_framework, validator, false); - - let validator_address = signer::address_of(validator); - let pool_address = get_owned_pool_address(validator_address); - - let delegator1_address = signer::address_of(delegator1); - account::create_account_for_test(delegator1_address); - let delegator2_address = signer::address_of(delegator2); - account::create_account_for_test(delegator2_address); - let voter1_address = signer::address_of(voter1); - account::create_account_for_test(voter1_address); - let voter2_address = signer::address_of(voter2); - account::create_account_for_test(voter2_address); - - stake::mint(delegator1, 110 * ONE_APT); - add_stake(delegator1, pool_address, 10 * ONE_APT); - stake::mint(delegator2, 110 * ONE_APT); - add_stake(delegator2, pool_address, 90 * ONE_APT); - - // Create 2 proposals and vote for proposal1. - let execution_hash = vector::empty(); - vector::push_back(&mut execution_hash, 1); - let proposal2_id = aptos_governance::create_proposal_v2_impl( - validator, - pool_address, - execution_hash, - b"", - b"", - true, - ); - aptos_governance::vote(validator, pool_address, proposal1_id, true); - - // Enable partial governance voting feature flag. - features::change_feature_flags_for_testing( - aptos_framework, - vector[features::get_partial_governance_voting(), features::get_delegation_pool_partial_governance_voting( - )], - vector[] - ); - // Voter doens't change until enabling partial governance voting on this delegation pool. - assert!(stake::get_delegated_voter(pool_address) == validator_address, 1); - // Enable partial governance voting on this delegation pool. - enable_partial_governance_voting(pool_address); - assert!(stake::get_delegated_voter(pool_address) == pool_address, 1); - assert!(partial_governance_voting_enabled(pool_address), 1); - - assert!(calculate_and_update_voter_total_voting_power(pool_address, validator_address) == 100 * ONE_APT, 1); - assert!(calculate_and_update_voter_total_voting_power(pool_address, delegator1_address) == 10 * ONE_APT, 1); - assert!(calculate_and_update_voter_total_voting_power(pool_address, delegator2_address) == 90 * ONE_APT, 1); - // No one can vote for proposal1 because it's already voted before enabling partial governance voting. - assert!(calculate_and_update_remaining_voting_power(pool_address, validator_address, proposal1_id) == 0, 1); - assert!(calculate_and_update_remaining_voting_power(pool_address, delegator1_address, proposal1_id) == 0, 1); - assert!(calculate_and_update_remaining_voting_power(pool_address, delegator2_address, proposal1_id) == 0, 1); - assert!( - calculate_and_update_remaining_voting_power(pool_address, validator_address, proposal2_id) == 100 * ONE_APT, - 1 - ); - assert!( - calculate_and_update_remaining_voting_power(pool_address, delegator1_address, proposal2_id) == 10 * ONE_APT, - 1 - ); - assert!( - calculate_and_update_remaining_voting_power(pool_address, delegator2_address, proposal2_id) == 90 * ONE_APT, - 1 - ); - - // Delegator1 tries to use 50 APT to vote on proposal2, but it only has 10 APT. So only 10 APT voting power is used. - vote(delegator1, pool_address, proposal2_id, 50 * ONE_APT, true); - assert!(calculate_and_update_remaining_voting_power(pool_address, delegator1_address, proposal2_id) == 0, 1); - - add_stake(delegator1, pool_address, 60 * ONE_APT); - assert!(calculate_and_update_voter_total_voting_power(pool_address, delegator1_address) == 70 * ONE_APT, 1); - vote(delegator1, pool_address, proposal2_id, 25 * ONE_APT, true); - assert!( - calculate_and_update_remaining_voting_power(pool_address, delegator1_address, proposal2_id) == 35 * ONE_APT, - 1 - ); - vote(delegator1, pool_address, proposal2_id, 30 * ONE_APT, false); - assert!( - calculate_and_update_remaining_voting_power(pool_address, delegator1_address, proposal2_id) == 5 * ONE_APT, - 1 - ); - } - - #[test(aptos_framework = @aptos_framework, validator = @0x123, delegator1 = @0x010, voter1 = @0x030)] - #[expected_failure(abort_code = 0x10010, location = Self)] - public entry fun test_vote_should_failed_if_already_voted_before_enable_partial_voting_flag( - aptos_framework: &signer, - validator: &signer, - delegator1: &signer, - voter1: &signer, - ) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage, DelegationPoolAllowlisting { - // partial voing hasn't been enabled yet. A proposal has been created by the validator. - let proposal1_id = setup_vote(aptos_framework, validator, false); - - let validator_address = signer::address_of(validator); - let pool_address = get_owned_pool_address(validator_address); - let delegator1_address = signer::address_of(delegator1); - account::create_account_for_test(delegator1_address); - let voter1_address = signer::address_of(voter1); - account::create_account_for_test(voter1_address); - - stake::mint(delegator1, 110 * ONE_APT); - add_stake(delegator1, pool_address, 10 * ONE_APT); - end_aptos_epoch(); - - aptos_governance::vote(validator, pool_address, proposal1_id, true); - - // Enable partial governance voting feature flag. - features::change_feature_flags_for_testing( - aptos_framework, - vector[features::get_partial_governance_voting(), features::get_delegation_pool_partial_governance_voting( - )], - vector[] - ); - // Enable partial governance voting on this delegation pool. - enable_partial_governance_voting(pool_address); - - vote(delegator1, pool_address, proposal1_id, 10 * ONE_APT, true); - } - - #[test(aptos_framework = @aptos_framework, validator = @0x123, delegator1 = @0x010, voter1 = @0x030)] - #[expected_failure(abort_code = 0x10011, location = Self)] - public entry fun test_vote_should_failed_if_already_voted_before_enable_partial_voting_on_pool( - aptos_framework: &signer, - validator: &signer, - delegator1: &signer, - voter1: &signer, - ) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage, DelegationPoolAllowlisting { - // partial voing hasn't been enabled yet. A proposal has been created by the validator. - let proposal1_id = setup_vote(aptos_framework, validator, false); - - let validator_address = signer::address_of(validator); - let pool_address = get_owned_pool_address(validator_address); - let delegator1_address = signer::address_of(delegator1); - account::create_account_for_test(delegator1_address); - let voter1_address = signer::address_of(voter1); - account::create_account_for_test(voter1_address); - - stake::mint(delegator1, 110 * ONE_APT); - add_stake(delegator1, pool_address, 10 * ONE_APT); - end_aptos_epoch(); - - // Enable partial governance voting feature flag. - features::change_feature_flags_for_testing( - aptos_framework, - vector[features::get_partial_governance_voting(), features::get_delegation_pool_partial_governance_voting( - )], - vector[] - ); - - // The operator voter votes on the proposal after partial governace voting flag is enabled but before partial voting is enabled on the pool. - aptos_governance::vote(validator, pool_address, proposal1_id, true); - - // Enable partial governance voting on this delegation pool. - enable_partial_governance_voting(pool_address); - - add_stake(delegator1, pool_address, 10 * ONE_APT); - vote(delegator1, pool_address, proposal1_id, 10 * ONE_APT, true); - } - #[test(aptos_framework = @aptos_framework, validator = @0x123, delegator1 = @0x010)] #[expected_failure(abort_code = 0x10010, location = Self)] public entry fun test_vote_should_failed_if_no_stake( @@ -5527,23 +5342,20 @@ module aptos_framework::delegation_pool { 100 * ONE_APT, 1000, ); - aptos_governance::initialize_partial_voting(aptos_framework); - initialize_test_validator(validator, 100 * ONE_APT, true, false); let validator_address = signer::address_of(validator); let pool_address = get_owned_pool_address(validator_address); - // Delegation pool is created before partial governance voting feature flag is enabled. So this delegation - // pool's voter is its owner. - assert!(stake::get_delegated_voter(pool_address) == validator_address, 1); - assert!(!partial_governance_voting_enabled(pool_address), 1); + assert!(stake::get_delegated_voter(pool_address) == pool_address, 1); + assert!(partial_governance_voting_enabled(pool_address), 1); end_aptos_epoch(); // Create 1 proposals and vote for proposal1. let execution_hash = vector::empty(); vector::push_back(&mut execution_hash, 1); + let pool_signer = retrieve_stake_pool_owner(borrow_global(pool_address)); let proposal_id = aptos_governance::create_proposal_v2_impl( - validator, + &pool_signer, pool_address, execution_hash, b"", @@ -5557,6 +5369,8 @@ module aptos_framework::delegation_pool { ), features::get_delegation_pool_partial_governance_voting()], vector[]); enable_partial_governance_voting(pool_address); + // After enabling partial governance voting, the delegated voter becomes the pool address itself + assert!(stake::get_delegated_voter(pool_address) == pool_address, 1); }; proposal_id } diff --git a/aptos-move/framework/aptos-framework/sources/fungible_asset.move b/aptos-move/framework/aptos-framework/sources/fungible_asset.move index 194cf32d9e0ca..b7cc39362fa8d 100644 --- a/aptos-move/framework/aptos-framework/sources/fungible_asset.move +++ b/aptos-move/framework/aptos-framework/sources/fungible_asset.move @@ -19,7 +19,7 @@ module aptos_framework::fungible_asset { friend aptos_framework::aptos_account; friend aptos_framework::dispatchable_fungible_asset; - friend aptos_framework::governed_gas_pool; + /// Amount cannot be zero. const EAMOUNT_CANNOT_BE_ZERO: u64 = 1; diff --git a/aptos-move/framework/aptos-framework/sources/genesis.move b/aptos-move/framework/aptos-framework/sources/genesis.move index 03944b937158f..97b05b3e75da8 100644 --- a/aptos-move/framework/aptos-framework/sources/genesis.move +++ b/aptos-move/framework/aptos-framework/sources/genesis.move @@ -30,7 +30,6 @@ module aptos_framework::genesis { use aptos_framework::transaction_validation; use aptos_framework::version; use aptos_framework::vesting; - use aptos_framework::governed_gas_pool; const EDUPLICATE_ACCOUNT: u64 = 1; const EACCOUNT_DOES_NOT_EXIST: u64 = 2; @@ -151,12 +150,7 @@ module aptos_framework::genesis { transaction_fee::store_aptos_coin_mint_cap(aptos_framework, mint_cap); } - fun initialize_governed_gas_pool( - aptos_framework: &signer, - delegation_pool_creation_seed: vector, - ) { - governed_gas_pool::initialize(aptos_framework, delegation_pool_creation_seed); - } + /// Only called for testnets and e2e tests. fun initialize_core_resources_and_aptos_coin( diff --git a/aptos-move/framework/aptos-framework/sources/governed_gas_pool.move b/aptos-move/framework/aptos-framework/sources/governed_gas_pool.move deleted file mode 100644 index 830b00499ec92..0000000000000 --- a/aptos-move/framework/aptos-framework/sources/governed_gas_pool.move +++ /dev/null @@ -1,364 +0,0 @@ -module aptos_framework::governed_gas_pool { - - friend aptos_framework::transaction_validation; - - use std::vector; - use aptos_framework::account::{Self, SignerCapability, create_signer_with_capability}; - use aptos_framework::system_addresses::{Self}; - // use aptos_framework::primary_fungible_store::{Self}; - use aptos_framework::fungible_asset::{Self}; - use aptos_framework::object::{Self}; - use aptos_framework::aptos_coin::AptosCoin; - use aptos_framework::coin::{Self, Coin}; - use std::features; - use aptos_framework::signer; - use aptos_framework::aptos_account::Self; - #[test_only] - use aptos_framework::coin::{BurnCapability, MintCapability}; - #[test_only] - use aptos_framework::fungible_asset::BurnRef; - #[test_only] - use aptos_framework::aptos_coin::Self; - - const MODULE_SALT: vector = b"aptos_framework::governed_gas_pool"; - - /// The Governed Gas Pool - /// Internally, this is a simply wrapper around a resource account. - struct GovernedGasPool has key { - /// The signer capability of the resource account. - signer_capability: SignerCapability, - } - - /// Address of APT Primary Fungible Store - inline fun primary_fungible_store_address(account: address): address { - object::create_user_derived_object_address(account, @aptos_fungible_asset) - } - - /// Create the seed to derive the resource account address. - fun create_resource_account_seed( - delegation_pool_creation_seed: vector, - ): vector { - let seed = vector::empty(); - // include module salt (before any subseeds) to avoid conflicts with other modules creating resource accounts - vector::append(&mut seed, MODULE_SALT); - // include an additional salt in case the same resource account has already been created - vector::append(&mut seed, delegation_pool_creation_seed); - seed - } - - /// Initializes the governed gas pool around a resource account creation seed. - /// @param aptos_framework The signer of the aptos_framework module. - /// @param delegation_pool_creation_seed The seed to be used to create the resource account hosting the delegation pool. - public fun initialize( - aptos_framework: &signer, - delegation_pool_creation_seed: vector, - ) { - system_addresses::assert_aptos_framework(aptos_framework); - - // return if the governed gas pool has already been initialized - if (exists(signer::address_of(aptos_framework))) { - return - }; - - // generate a seed to be used to create the resource account hosting the delegation pool - let seed = create_resource_account_seed(delegation_pool_creation_seed); - - let (governed_gas_pool_signer, governed_gas_pool_signer_cap) = account::create_resource_account(aptos_framework, seed); - - // register apt - aptos_account::register_apt(&governed_gas_pool_signer); - - move_to(aptos_framework, GovernedGasPool{ - signer_capability: governed_gas_pool_signer_cap, - }); - } - - /// Initialize the governed gas pool as a module - /// @param aptos_framework The signer of the aptos_framework module. - fun init_module(aptos_framework: &signer) { - // Initialize the governed gas pool - let seed : vector = b"aptos_framework::governed_gas_pool"; - initialize(aptos_framework, seed); - } - - /// Borrows the signer of the governed gas pool. - /// @return The signer of the governed gas pool. - fun governed_gas_signer(): signer acquires GovernedGasPool { - let signer_cap = &borrow_global(@aptos_framework).signer_capability; - create_signer_with_capability(signer_cap) - } - - #[view] - /// Gets the address of the governed gas pool. - /// @return The address of the governed gas pool. - public fun governed_gas_pool_address(): address acquires GovernedGasPool { - signer::address_of(&governed_gas_signer()) - } - - /// Funds the destination account with a given amount of coin. - /// @param account The account to be funded. - /// @param amount The amount of coin to be funded. - public fun fund(aptos_framework: &signer, account: address, amount: u64) acquires GovernedGasPool { - // Check that the Aptos framework is the caller - // This is what ensures that funding can only be done by the Aptos framework, - // i.e., via a governance proposal. - system_addresses::assert_aptos_framework(aptos_framework); - let governed_gas_signer = &governed_gas_signer(); - coin::deposit(account, coin::withdraw(governed_gas_signer, amount)); - } - - /// Deposits some coin into the governed gas pool. - /// @param coin The coin to be deposited. - fun deposit(coin: Coin) acquires GovernedGasPool { - let governed_gas_pool_address = governed_gas_pool_address(); - coin::deposit(governed_gas_pool_address, coin); - } - - /// Deposits some coin from an account to the governed gas pool. - /// @param account The account from which the coin is to be deposited. - /// @param amount The amount of coin to be deposited. - fun deposit_from(account: address, amount: u64) acquires GovernedGasPool { - deposit(coin::withdraw_from(account, amount)); - } - - /// Deposits some FA from the fungible store. - /// @param aptos_framework The signer of the aptos_framework module. - /// @param account The account from which the FA is to be deposited. - /// @param amount The amount of FA to be deposited. - fun deposit_from_fungible_store(account: address, amount: u64) acquires GovernedGasPool { - if (amount > 0){ - // compute the governed gas pool store address - let governed_gas_pool_address = governed_gas_pool_address(); - let governed_gas_pool_store_address = primary_fungible_store_address(governed_gas_pool_address); - - // compute the account store address - let account_store_address = primary_fungible_store_address(account); - fungible_asset::deposit_internal( - governed_gas_pool_store_address, - fungible_asset::withdraw_internal( - account_store_address, - amount - ) - ); - } - } - - /// Deposits gas fees into the governed gas pool. - /// @param gas_payer The address of the account that paid the gas fees. - /// @param gas_fee The amount of gas fees to be deposited. - public fun deposit_gas_fee(_gas_payer: address, _gas_fee: u64) acquires GovernedGasPool { - // get the sender to preserve the signature but do nothing - governed_gas_pool_address(); - } - - /// Deposits gas fees into the governed gas pool. - /// @param gas_payer The address of the account that paid the gas fees. - /// @param gas_fee The amount of gas fees to be deposited. - public(friend) fun deposit_gas_fee_v2(gas_payer: address, gas_fee: u64) acquires GovernedGasPool { - if (features::operations_default_to_fa_apt_store_enabled()) { - deposit_from_fungible_store(gas_payer, gas_fee); - } else { - deposit_from(gas_payer, gas_fee); - }; - } - - #[view] - /// Gets the balance of a specified coin type in the governed gas pool. - /// @return The balance of the coin in the pool. - public fun get_balance(): u64 acquires GovernedGasPool { - let pool_address = governed_gas_pool_address(); - coin::balance(pool_address) - } - - #[test_only] - /// The AptosCoin mint capability - struct AptosCoinMintCapability has key { - mint_cap: MintCapability, - } - - #[test_only] - /// The AptosCoin burn capability - struct AptosCoinBurnCapability has key { - burn_cap: BurnCapability, - } - - #[test_only] - /// The AptosFA burn capabilities - struct AptosFABurnCapabilities has key { - burn_ref: BurnRef, - } - - - #[test_only] - /// Stores the mint capability for AptosCoin. - /// - /// @param aptos_framework The signer representing the Aptos framework. - /// @param mint_cap The mint capability for AptosCoin. - public fun store_aptos_coin_mint_cap(aptos_framework: &signer, mint_cap: MintCapability) { - system_addresses::assert_aptos_framework(aptos_framework); - move_to(aptos_framework, AptosCoinMintCapability { mint_cap }) - } - - #[test_only] - /// Stores the burn capability for AptosCoin, converting to a fungible asset reference if the feature is enabled. - /// - /// @param aptos_framework The signer representing the Aptos framework. - /// @param burn_cap The burn capability for AptosCoin. - public fun store_aptos_coin_burn_cap(aptos_framework: &signer, burn_cap: BurnCapability) { - system_addresses::assert_aptos_framework(aptos_framework); - if (features::operations_default_to_fa_apt_store_enabled()) { - let burn_ref = coin::convert_and_take_paired_burn_ref(burn_cap); - move_to(aptos_framework, AptosFABurnCapabilities { burn_ref }); - } else { - move_to(aptos_framework, AptosCoinBurnCapability { burn_cap }) - } - } - - #[test_only] - /// Initializes the governed gas pool around a fixed creation seed for testing - /// - /// @param aptos_framework The signer of the aptos_framework module. - public fun initialize_for_test( - aptos_framework: &signer, - ) { - - // initialize the AptosCoin module - let (burn_cap, mint_cap) = aptos_coin::initialize_for_test(aptos_framework); - - // Initialize the governed gas pool - let seed : vector = b"test"; - initialize(aptos_framework, seed); - - // add the mint capability to the governed gas pool - store_aptos_coin_mint_cap(aptos_framework, mint_cap); - store_aptos_coin_burn_cap(aptos_framework, burn_cap); - - } - - #[test_only] - /// Mints some coin to an account for testing purposes. - /// - /// @param account The account to which the coin is to be minted. - /// @param amount The amount of coin to be minted. - public fun mint_for_test(account: address, amount: u64) acquires AptosCoinMintCapability { - coin::deposit(account, coin::mint( - amount, - &borrow_global(@aptos_framework).mint_cap - )); - } - - #[test(aptos_framework = @aptos_framework, depositor = @0xdddd)] - /// Deposits some coin into the governed gas pool. - /// - /// @param aptos_framework is the signer of the aptos_framework module. - fun test_governed_gas_pool_deposit(aptos_framework: &signer, depositor: &signer) acquires GovernedGasPool, AptosCoinMintCapability { - - // initialize the modules - initialize_for_test(aptos_framework); - - // create the depositor account and fund it - aptos_account::create_account(signer::address_of(depositor)); - mint_for_test(signer::address_of(depositor), 1000); - - // get the balances for the depositor and the governed gas pool - let depositor_balance = coin::balance(signer::address_of(depositor)); - let governed_gas_pool_balance = coin::balance(governed_gas_pool_address()); - - // deposit some coin into the governed gas pool - deposit_from(signer::address_of(depositor), 100); - - // check the balances after the deposit - assert!(coin::balance(signer::address_of(depositor)) == depositor_balance - 100, 1); - assert!(coin::balance(governed_gas_pool_address()) == governed_gas_pool_balance + 100, 2); - - } - - #[test(aptos_framework = @aptos_framework, depositor = @0xdddd)] - /// Deposits some coin from an account to the governed gas pool as gas fees. - /// - /// @param aptos_framework is the signer of the aptos_framework module. - /// @param depositor is the signer of the account from which the coin is to be deposited. - fun test_governed_gas_pool_deposit_gas_fee(aptos_framework: &signer, depositor: &signer) acquires GovernedGasPool, AptosCoinMintCapability { - - // initialize the modules - initialize_for_test(aptos_framework); - - // create the depositor account and fund it - aptos_account::create_account(signer::address_of(depositor)); - mint_for_test(signer::address_of(depositor), 1000); - - // get the balances for the depositor and the governed gas pool - let depositor_balance = coin::balance(signer::address_of(depositor)); - let governed_gas_pool_balance = coin::balance(governed_gas_pool_address()); - - // deposit some coin into the governed gas pool as gas fees - deposit_gas_fee_v2(signer::address_of(depositor), 100); - - // check the balances after the deposit - assert!(coin::balance(signer::address_of(depositor)) == depositor_balance - 100, 1); - assert!(coin::balance(governed_gas_pool_address()) == governed_gas_pool_balance + 100, 2); - - } - - #[test(aptos_framework = @aptos_framework)] - /// Test for the get_balance view method. - fun test_governed_gas_pool_get_balance(aptos_framework: &signer) acquires GovernedGasPool, AptosCoinMintCapability { - - // initialize the modules - initialize_for_test(aptos_framework); - - // fund the governed gas pool - let governed_gas_pool_address = governed_gas_pool_address(); - mint_for_test(governed_gas_pool_address, 1000); - - // assert the balance is correct - assert!(get_balance() == 1000, 1); - } - - #[test(aptos_framework = @aptos_framework, depositor = @0xdddd, beneficiary = @0xbbbb)] - /// Funds the destination account with a given amount of coin. - /// - /// @param aptos_framework is the signer of the aptos_framework module. - /// @param depositor is the signer of the account from which the coin is to be funded. - /// @param beneficiary is the address of the account to be funded. - fun test_governed_gas_pool_fund(aptos_framework: &signer, depositor: &signer, beneficiary: &signer) acquires GovernedGasPool, AptosCoinMintCapability { - - // initialize the modules - initialize_for_test(aptos_framework); - - // create the depositor account and fund it - aptos_account::create_account(signer::address_of(depositor)); - mint_for_test(signer::address_of(depositor), 1000); - - // get the balances for the depositor and the governed gas pool - let depositor_balance = coin::balance(signer::address_of(depositor)); - let governed_gas_pool_balance = coin::balance(governed_gas_pool_address()); - - // collect gas fees from the depositor - deposit_gas_fee_v2(signer::address_of(depositor), 100); - - // check the balances after the deposit - assert!(coin::balance(signer::address_of(depositor)) == depositor_balance - 100, 1); - assert!(coin::balance(governed_gas_pool_address()) == governed_gas_pool_balance + 100, 2); - - // ensure the beneficiary account has registered with the AptosCoin module - aptos_account::create_account(signer::address_of(beneficiary)); - aptos_account::register_apt(beneficiary); - - // fund the beneficiary account - fund(aptos_framework, signer::address_of(beneficiary), 100); - - // check the balances after the funding - assert!(coin::balance(governed_gas_pool_address()) == governed_gas_pool_balance, 3); - assert!(coin::balance(signer::address_of(beneficiary)) == 100, 4); - - } - - #[test(aptos_framework = @aptos_framework)] - fun test_initialize_is_idempotent(aptos_framework: &signer) { - // initialize the governed gas pool - initialize_for_test(aptos_framework); - // initialize the governed gas pool again, no abort - initialize(aptos_framework, vector::empty()); - } -} diff --git a/aptos-move/framework/aptos-framework/sources/governed_gas_pool.spec.move b/aptos-move/framework/aptos-framework/sources/governed_gas_pool.spec.move deleted file mode 100644 index 3b6ee84b31c93..0000000000000 --- a/aptos-move/framework/aptos-framework/sources/governed_gas_pool.spec.move +++ /dev/null @@ -1,79 +0,0 @@ -spec aptos_framework::governed_gas_pool { - use aptos_framework::coin::EINSUFFICIENT_BALANCE; - use aptos_framework::error; - - /// - /// No.: 1 - /// Requirement: The GovernedGasPool resource must exist at the aptos_framework address after initialization. - /// Criticality: Critical - /// Implementation: The initialize function ensures the resource is created at the aptos_framework address. - /// Enforcement: Formally verified via [high-level-req-1](initialize). - /// - /// No.: 2 - /// Requirement: Only the aptos_framework address is allowed to initialize the GovernedGasPool. - /// Criticality: Critical - /// Implementation: The initialize function verifies the signer is the aptos_framework address. - /// Enforcement: Formally verified via [high-level-req-2](initialize). - /// - /// No.: 3 - /// Requirement: Deposits into the GovernedGasPool must be reflected in the pool's balance. - /// Criticality: High - /// Implementation: The deposit and deposit_from functions update the pool's balance. - /// Enforcement: Formally verified via [high-level-req-3](deposit), [high-level-req-3.1](deposit_from). - /// - /// No.: 4 - /// Requirement: Only the aptos_framework address can fund accounts from the GovernedGasPool. - /// Criticality: High - /// Implementation: The fund function verifies the signer is the aptos_framework address. - /// Enforcement: Formally verified via [high-level-req-4](fund). - /// - - spec module { - /// [high-level-req-1] - /// The GovernedGasPool resource must exist at aptos_framework after initialization. - invariant exists(@aptos_framework); - } - - spec initialize(aptos_framework: &signer, delegation_pool_creation_seed: vector) { - requires system_addresses::is_aptos_framework_address(signer::address_of(aptos_framework)); - /// [high-level-req-1] - ensures exists(@aptos_framework); - } - - spec fund(aptos_framework: &signer, account: address, amount: u64) { - pragma aborts_if_is_partial = true; - - /// [high-level-req-4] - // Abort if the caller is not the Aptos framework - aborts_if !system_addresses::is_aptos_framework_address(signer::address_of(aptos_framework)); - - /// Abort if the governed gas pool has insufficient funds - aborts_with coin::EINSUFFICIENT_BALANCE, error::invalid_argument(EINSUFFICIENT_BALANCE), 0x1, 0x5, 0x7; - } - - spec deposit(coin: Coin) { - pragma aborts_if_is_partial = true; - - /* - /// [high-level-req-3] - /// Ensure the deposit increases the value in the CoinStore - - //@TODO: Calling governed_gas_pool_adddress() doesn't work as the boogie gen cant check the signer - // created for the resource account created at runtime - - /// Ensure the governed gas pool resource account exists - //aborts_if !exists>(governed_gas_pool_address()); - - //ensures global>(aptos_framework_address).coin.value == - //old(global>(aptos_framework_address).coin.value) + coin.value; - */ - } - - spec deposit_gas_fee(_gas_payer: address, _gas_fee: u64) { - /* - /// [high-level-req-5] - // ensures governed_gas_pool_balance == old(governed_gas_pool_balance) + gas_fee; - // ensures gas_payer_balance == old(gas_payer_balance) - gas_fee; - */ - } -} diff --git a/aptos-move/framework/aptos-framework/sources/stake.move b/aptos-move/framework/aptos-framework/sources/stake.move index 9639ffa8ff07d..a8a59adfc44ce 100644 --- a/aptos-move/framework/aptos-framework/sources/stake.move +++ b/aptos-move/framework/aptos-framework/sources/stake.move @@ -1411,10 +1411,12 @@ module aptos_framework::stake { let cur_fee = 0; if (features::collect_and_distribute_gas_fees()) { - let fees_table = &borrow_global(@aptos_framework).fees_table; - if (table::contains(fees_table, candidate.addr)) { - let fee_coin = table::borrow(fees_table, candidate.addr); - cur_fee = coin::value(fee_coin); + if (exists(@aptos_framework)) { + let fees_table = &borrow_global(@aptos_framework).fees_table; + if (table::contains(fees_table, candidate.addr)) { + let fee_coin = table::borrow(fees_table, candidate.addr); + cur_fee = coin::value(fee_coin); + } } }; @@ -1581,10 +1583,12 @@ module aptos_framework::stake { // Additionally, distribute transaction fees. if (features::collect_and_distribute_gas_fees()) { - let fees_table = &mut borrow_global_mut(@aptos_framework).fees_table; - if (table::contains(fees_table, pool_address)) { - let coin = table::remove(fees_table, pool_address); - coin::merge(&mut stake_pool.active, coin); + if (exists(@aptos_framework)) { + let fees_table = &mut borrow_global_mut(@aptos_framework).fees_table; + if (table::contains(fees_table, pool_address)) { + let coin = table::remove(fees_table, pool_address); + coin::merge(&mut stake_pool.active, coin); + }; }; }; @@ -3283,4 +3287,13 @@ module aptos_framework::stake { assert_validator_state(validator_2_address, 601, 0, 0, 0, 1); assert_validator_state(validator_3_address, 101, 0, 0, 0, 0); } + + /// Initialize the validator fees resource. This should be called during framework upgrades + /// when the COLLECT_AND_DISTRIBUTE_GAS_FEES feature flag is being enabled. + public entry fun initialize_validator_fees_public(aptos_framework: &signer) { + system_addresses::assert_aptos_framework(aptos_framework); + if (!exists(@aptos_framework)) { + initialize_validator_fees(aptos_framework); + }; + } } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_validation.move b/aptos-move/framework/aptos-framework/sources/transaction_validation.move index 3a4d480401703..d476fcc1bf738 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_validation.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_validation.move @@ -13,7 +13,6 @@ module aptos_framework::transaction_validation { use aptos_framework::system_addresses; use aptos_framework::timestamp; use aptos_framework::transaction_fee; - use aptos_framework::governed_gas_pool; friend aptos_framework::genesis; @@ -320,16 +319,10 @@ module aptos_framework::transaction_validation { if (amount_to_burn > storage_fee_refunded) { let burn_amount = amount_to_burn - storage_fee_refunded; - if (features::governed_gas_pool_enabled()) { - governed_gas_pool::deposit_gas_fee_v2(gas_payer, burn_amount); - } else { - transaction_fee::burn_fee(gas_payer, burn_amount); - } + transaction_fee::burn_fee(gas_payer, burn_amount); } else if (amount_to_burn < storage_fee_refunded) { let mint_amount = storage_fee_refunded - amount_to_burn; - if (!features::governed_gas_pool_enabled()) { - transaction_fee::mint_and_refund(gas_payer, mint_amount); - } + transaction_fee::mint_and_refund(gas_payer, mint_amount); }; // Increment sequence number diff --git a/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move b/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move index ac6168d176ebb..a56b7321225da 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move @@ -264,7 +264,6 @@ spec aptos_framework::transaction_validation { use aptos_framework::coin::{CoinStore, CoinInfo}; use aptos_framework::optional_aggregator; use aptos_framework::transaction_fee::{AptosCoinCapabilities, AptosCoinMintCapability, CollectedFeesPerBlock}; - use aptos_framework::governed_gas_pool::{GovernedGasPool, governed_gas_pool_address}; account: signer; gas_payer: address; @@ -273,10 +272,6 @@ spec aptos_framework::transaction_validation { txn_max_gas_units: u64; gas_units_remaining: u64; - // Precondition: Governed Gas Pool must be initialized - requires exists(@aptos_framework); - requires exists>(governed_gas_pool_address()); - // Check transaction invariants. aborts_if !(txn_max_gas_units >= gas_units_remaining); let gas_used = txn_max_gas_units - gas_units_remaining; @@ -289,10 +284,6 @@ spec aptos_framework::transaction_validation { // let pre_balance = global>(gas_payer).coin.value; // let post balance = global>(gas_payer).coin.value; - // TODO(governed_gas_pool) - let pre_governed_gas_pool_balance = global>(governed_gas_pool_address()).coin.value; - let post governed_gas_pool_balance = global>(governed_gas_pool_address()).coin.value; - let pre_account = global(addr); let post account = global(addr); @@ -302,12 +293,9 @@ spec aptos_framework::transaction_validation { // TODO(fa_migration) // aborts_if pre_balance < transaction_fee_amount; // ensures balance == pre_balance - transaction_fee_amount + storage_fee_refunded; - // TODO(governd_gas_pool) - ensures governed_gas_pool_balance == pre_governed_gas_pool_balance + transaction_fee_amount; ensures account.sequence_number == pre_account.sequence_number + 1; // Check fee collection. - let governed_gas_pool_enabled = features::spec_is_enabled(features::GOVERNED_GAS_POOL); let collect_fee_enabled = features::spec_is_enabled(features::COLLECT_AND_DISTRIBUTE_GAS_FEES); let collected_fees = global(@aptos_framework).amount; let aggr = collected_fees.value; diff --git a/aptos-move/framework/move-stdlib/doc/features.md b/aptos-move/framework/move-stdlib/doc/features.md index 03b8c23d86c3d..b7b7d77759f4d 100644 --- a/aptos-move/framework/move-stdlib/doc/features.md +++ b/aptos-move/framework/move-stdlib/doc/features.md @@ -133,8 +133,7 @@ return true. - [Function `abort_atomic_bridge_enabled`](#0x1_features_abort_atomic_bridge_enabled) - [Function `get_native_bridge_feature`](#0x1_features_get_native_bridge_feature) - [Function `abort_native_bridge_enabled`](#0x1_features_abort_native_bridge_enabled) -- [Function `get_governed_gas_pool_feature`](#0x1_features_get_governed_gas_pool_feature) -- [Function `governed_gas_pool_enabled`](#0x1_features_governed_gas_pool_enabled) + - [Function `get_decommission_core_resources_feature`](#0x1_features_get_decommission_core_resources_feature) - [Function `get_decommission_core_resources_enabled`](#0x1_features_get_decommission_core_resources_enabled) - [Function `change_feature_flags`](#0x1_features_change_feature_flags) @@ -564,15 +563,7 @@ Lifetime: transient - - -Whether the Governed Gas Pool is used to capture gas fees - -Lifetime: permanent - -
const GOVERNED_GAS_POOL: u64 = 73;
-
@@ -3298,52 +3289,7 @@ Lifetime: transient - - -## Function `get_governed_gas_pool_feature` - -Whether the Governed Gas Pool is enabled. - - -
public fun get_governed_gas_pool_feature(): u64
-
- - - -
-Implementation - - -
public fun get_governed_gas_pool_feature(): u64 { GOVERNED_GAS_POOL }
-
- - -
- - - -## Function `governed_gas_pool_enabled` - - - -
public fun governed_gas_pool_enabled(): bool
-
- - - -
-Implementation - - -
public fun governed_gas_pool_enabled(): bool acquires Features {
-    is_enabled(GOVERNED_GAS_POOL)
-}
-
- - - -
diff --git a/aptos-move/framework/move-stdlib/sources/configs/features.move b/aptos-move/framework/move-stdlib/sources/configs/features.move index c270ebd1cf7f0..e401f3d88469c 100644 --- a/aptos-move/framework/move-stdlib/sources/configs/features.move +++ b/aptos-move/framework/move-stdlib/sources/configs/features.move @@ -603,17 +603,7 @@ module std::features { is_enabled(NATIVE_BRIDGE) } - /// Whether the Governed Gas Pool is used to capture gas fees - /// - /// Lifetime: permanent - const GOVERNED_GAS_POOL: u64 = 73; - /// Whether the Governed Gas Pool is enabled. - public fun get_governed_gas_pool_feature(): u64 { GOVERNED_GAS_POOL } - - public fun governed_gas_pool_enabled(): bool acquires Features { - is_enabled(GOVERNED_GAS_POOL) - } /// Lifetime: transient const DECOMMISSION_CORE_RESOURCES: u64 = 222; diff --git a/aptos-move/vm-genesis/src/lib.rs b/aptos-move/vm-genesis/src/lib.rs index a9c984b50185a..bd45f04375423 100644 --- a/aptos-move/vm-genesis/src/lib.rs +++ b/aptos-move/vm-genesis/src/lib.rs @@ -284,15 +284,7 @@ pub fn encode_genesis_change_set( initialize_jwks_resources(&mut session); initialize_keyless_accounts(&mut session, chain_id); - // initialize governed gas pool only if feature is enabled - match &genesis_config.initial_features_override { - Some(features) => { - if features.is_enabled(FeatureFlag::GOVERNED_GAS_POOL) { - initialize_governed_gas_pool(&mut session); - } - }, - None => {}, - } + set_genesis_end(&mut session); @@ -485,18 +477,7 @@ fn initialize_aptos_coin(session: &mut SessionExt) { ); } -fn initialize_governed_gas_pool(session: &mut SessionExt) { - exec_function( - session, - GENESIS_MODULE_NAME, - "initialize_governed_gas_pool", - vec![], - serialize_values(&vec![ - MoveValue::Signer(CORE_CODE_ADDRESS), - MoveValue::Vector(vec![MoveValue::U8(22)]), - ]), - ); -} + fn initialize_config_buffer(session: &mut SessionExt) { exec_function( diff --git a/types/src/on_chain_config/aptos_features.rs b/types/src/on_chain_config/aptos_features.rs index 75af785cf6f27..4763248ea374e 100644 --- a/types/src/on_chain_config/aptos_features.rs +++ b/types/src/on_chain_config/aptos_features.rs @@ -98,7 +98,6 @@ pub enum FeatureFlag { NATIVE_MEMORY_OPERATIONS = 80, ACCOUNT_ABSTRACTION = 85, DECOMMISSION_CORE_RESOURCES = 222, - GOVERNED_GAS_POOL = 223, } impl FeatureFlag { @@ -112,6 +111,7 @@ impl FeatureFlag { // if we enable a higher version. FeatureFlag::VM_BINARY_FORMAT_V6, FeatureFlag::VM_BINARY_FORMAT_V7, + FeatureFlag::COLLECT_AND_DISTRIBUTE_GAS_FEES, FeatureFlag::MULTI_ED25519_PK_VALIDATE_V2_NATIVES, FeatureFlag::BLAKE2B_256_NATIVE, FeatureFlag::RESOURCE_GROUPS, @@ -177,7 +177,7 @@ impl FeatureFlag { FeatureFlag::NATIVE_MEMORY_OPERATIONS, FeatureFlag::COLLECTION_OWNER, FeatureFlag::ACCOUNT_ABSTRACTION, - // FeatureFlag::GOVERNED_GAS_POOL, // governed gas pool should be voted in + ] } }