diff --git a/build/StarcoinFramework/BuildInfo.yaml b/build/StarcoinFramework/BuildInfo.yaml index 51c55bd6..1663543b 100644 --- a/build/StarcoinFramework/BuildInfo.yaml +++ b/build/StarcoinFramework/BuildInfo.yaml @@ -201,9 +201,6 @@ compiled_package_info: ? address: "0x00000000000000000000000000000001" name: PackageTxnManager : StarcoinFramework - ? address: "0x00000000000000000000000000000001" - name: PackageTxnManagerUpgradeScripts - : StarcoinFramework ? address: "0x00000000000000000000000000000001" name: PriceOracle : StarcoinFramework @@ -324,7 +321,7 @@ compiled_package_info: ? address: "0x00000000000000000000000000000001" name: YieldFarmingV2 : StarcoinFramework - source_digest: 1D41BF5CECA715897417BA720EEB91368D3F512C8DDF1CF8A6E97165AD03EF08 + source_digest: 3A318003A4127B552F66FB6577C0D1A8246A05B25E8143962F8EB45E6F091C4F build_flags: dev_mode: false test_mode: false diff --git a/build/StarcoinFramework/bytecode_modules/Account.mv b/build/StarcoinFramework/bytecode_modules/Account.mv index 0cc01c9f..b197aad8 100644 Binary files a/build/StarcoinFramework/bytecode_modules/Account.mv and b/build/StarcoinFramework/bytecode_modules/Account.mv differ diff --git a/build/StarcoinFramework/bytecode_modules/PackageTxnManager.mv b/build/StarcoinFramework/bytecode_modules/PackageTxnManager.mv index 5769480f..ba53e2f0 100644 Binary files a/build/StarcoinFramework/bytecode_modules/PackageTxnManager.mv and b/build/StarcoinFramework/bytecode_modules/PackageTxnManager.mv differ diff --git a/build/StarcoinFramework/docs/Account.md b/build/StarcoinFramework/docs/Account.md index d5d8c8dd..826f5009 100644 --- a/build/StarcoinFramework/docs/Account.md +++ b/build/StarcoinFramework/docs/Account.md @@ -23,7 +23,6 @@ The module for the account resource that governs every account - [Constants](#@Constants_0) - [Function `remove_signer_capability`](#0x1_Account_remove_signer_capability) - [Function `get_genesis_capability`](#0x1_Account_get_genesis_capability) -- [Function `get_capability_for`](#0x1_Account_get_capability_for) - [Function `create_signer_with_cap`](#0x1_Account_create_signer_with_cap) - [Function `destroy_signer_cap`](#0x1_Account_destroy_signer_cap) - [Function `signer_address`](#0x1_Account_signer_address) @@ -858,31 +857,6 @@ This function can only called once by signer. - - - - -## Function `get_capability_for` - - - -
public(friend) fun get_capability_for(addr: address): Account::SignerCapability
-
- - - -
-Implementation - - -
public (friend) fun get_capability_for(addr: address): SignerCapability {
-    let signer_cap = SignerCapability { addr };
-    signer_cap
-}
-
- - -
diff --git a/build/StarcoinFramework/docs/PackageTxnManager.md b/build/StarcoinFramework/docs/PackageTxnManager.md index 94261aee..ba095e45 100644 --- a/build/StarcoinFramework/docs/PackageTxnManager.md +++ b/build/StarcoinFramework/docs/PackageTxnManager.md @@ -462,15 +462,6 @@ module upgrade plan event when submitting a module upgrade plan - - - - -
const ERR_NOT_UPGRADE_YET: u64 = 5;
-
- - - @@ -958,6 +949,12 @@ extract out UpgradePlanCapability from signer. acquires TwoPhaseUpgradeV2,UpgradePlanCapability,ModuleUpgradeStrategy,UpgradePlanEventHolder{ let account_address = Signer::address_of(account); let cap = borrow_global<UpgradePlanCapability>(account_address); + assert!(get_module_upgrade_strategy(cap.account_address) == STRATEGY_TWO_PHASE, Errors::invalid_argument(ESTRATEGY_NOT_TWO_PHASE)); + if (!exists<UpgradePlanEventHolder>(account_address)) { + move_to(account, UpgradePlanEventHolder { + upgrade_plan_event: Event::new_event_handle<UpgradePlanEvent>(account) + }) + }; submit_upgrade_plan_with_cap_v2(cap, package_hash, version, enforced); } @@ -999,7 +996,6 @@ extract out UpgradePlanCapability from signer.
public fun submit_upgrade_plan_with_cap_v2(cap: &UpgradePlanCapability, package_hash: vector<u8>, version: u64, enforced: bool)
 acquires TwoPhaseUpgradeV2, ModuleUpgradeStrategy, UpgradePlanEventHolder{
     let package_address = cap.account_address;
-    assert!(exists<UpgradePlanEventHolder>(package_address), Errors::not_published(ERR_NOT_UPGRADE_YET));
     assert!(get_module_upgrade_strategy(package_address) == STRATEGY_TWO_PHASE, Errors::invalid_argument(ESTRATEGY_NOT_TWO_PHASE));
 
     let tpu = borrow_global_mut<TwoPhaseUpgradeV2>(package_address);
@@ -1007,11 +1003,17 @@ extract out UpgradePlanCapability from signer.
     let plan = UpgradePlanV2 { package_hash, active_after_time, version, enforced };
     tpu.plan = Option::some(copy plan);
 
-    let event_holder = borrow_global_mut<UpgradePlanEventHolder>(package_address);
-    Event::emit_event<UpgradePlanEvent>(&mut event_holder.upgrade_plan_event, UpgradePlanEvent {
-        package_address,
-        plan
-    });
+    // TODO
+    // if UpgradePlanCapability was delegated to DAO or contract,
+    // it's hard to upgrade the address to claim an UpgradePlanEventHolder.
+    // Try to fix this!
+    if (exists<UpgradePlanEventHolder>(package_address)) {
+        let event_holder = borrow_global_mut<UpgradePlanEventHolder>(package_address);
+        Event::emit_event<UpgradePlanEvent>(&mut event_holder.upgrade_plan_event, UpgradePlanEvent {
+            package_address,
+            plan
+        });
+    }
 }
 
diff --git a/build/StarcoinFramework/docs/README.md b/build/StarcoinFramework/docs/README.md index 81b6b6d9..b539990b 100644 --- a/build/StarcoinFramework/docs/README.md +++ b/build/StarcoinFramework/docs/README.md @@ -77,7 +77,6 @@ This is the root document for the Move StarcoinFramework module documentation. T - [`0x1::Option`](Option.md#0x1_Option) - [`0x1::Oracle`](Oracle.md#0x1_Oracle) - [`0x1::PackageTxnManager`](PackageTxnManager.md#0x1_PackageTxnManager) -- [`0x1::PackageTxnManagerUpgradeScripts`](PackageTxnManagerUpgrade.md#0x1_PackageTxnManagerUpgradeScripts) - [`0x1::PriceOracle`](Oracle.md#0x1_PriceOracle) - [`0x1::PriceOracleAggregator`](Oracle.md#0x1_PriceOracleAggregator) - [`0x1::PriceOracleScripts`](Oracle.md#0x1_PriceOracleScripts) diff --git a/build/StarcoinFramework/source_maps/Account.mvsm b/build/StarcoinFramework/source_maps/Account.mvsm index 918a1733..543155e5 100644 Binary files a/build/StarcoinFramework/source_maps/Account.mvsm and b/build/StarcoinFramework/source_maps/Account.mvsm differ diff --git a/build/StarcoinFramework/source_maps/PackageTxnManager.mvsm b/build/StarcoinFramework/source_maps/PackageTxnManager.mvsm index 3beb412d..42c91c07 100644 Binary files a/build/StarcoinFramework/source_maps/PackageTxnManager.mvsm and b/build/StarcoinFramework/source_maps/PackageTxnManager.mvsm differ diff --git a/integration-tests/daospace/dao_account.exp b/integration-tests/daospace/dao_account.exp index c0cb6d52..d5653729 100644 --- a/integration-tests/daospace/dao_account.exp +++ b/integration-tests/daospace/dao_account.exp @@ -8,7 +8,7 @@ task 2 'run'. lines 6-23: task 3 'run'. lines 28-40: { - "gas_used": 114656, + "gas_used": 95609, "status": "Executed" } diff --git a/integration-tests/daospace/dao_grant.exp b/integration-tests/daospace/dao_grant.exp index 9b06c7b3..d724bbc3 100644 --- a/integration-tests/daospace/dao_grant.exp +++ b/integration-tests/daospace/dao_grant.exp @@ -18,7 +18,7 @@ task 5 'run'. lines 13-21: task 8 'run'. lines 123-134: { - "gas_used": 8232282, + "gas_used": 1768185, "status": "Executed" } diff --git a/integration-tests/daospace/dao_proposal.exp b/integration-tests/daospace/dao_proposal.exp index af070c4b..976527c7 100644 --- a/integration-tests/daospace/dao_proposal.exp +++ b/integration-tests/daospace/dao_proposal.exp @@ -2,7 +2,7 @@ processed 42 tasks task 7 'run'. lines 169-180: { - "gas_used": 8229485, + "gas_used": 1765388, "status": "Executed" } diff --git a/integration-tests/daospace/dao_proposal_rejected.exp b/integration-tests/daospace/dao_proposal_rejected.exp index 0978acd8..e108d96e 100644 --- a/integration-tests/daospace/dao_proposal_rejected.exp +++ b/integration-tests/daospace/dao_proposal_rejected.exp @@ -2,7 +2,7 @@ processed 40 tasks task 7 'run'. lines 126-135: { - "gas_used": 996494, + "gas_used": 1168754, "status": { "MoveAbort": { "location": { diff --git a/integration-tests/daospace/dao_upgrade.exp b/integration-tests/daospace/dao_upgrade.exp index 7551ec76..3737f75b 100644 --- a/integration-tests/daospace/dao_upgrade.exp +++ b/integration-tests/daospace/dao_upgrade.exp @@ -29,7 +29,7 @@ Publish failure: Discard { status_code: StrView(2015), status_code_name: "UNEXPE task 13 'run'. lines 160-167: { - "gas_used": 142127, + "gas_used": 123208, "status": "Executed" } diff --git a/integration-tests/daospace/dao_upgrade_incompatible.exp b/integration-tests/daospace/dao_upgrade_incompatible.exp index 7bb762fd..402d27b7 100644 --- a/integration-tests/daospace/dao_upgrade_incompatible.exp +++ b/integration-tests/daospace/dao_upgrade_incompatible.exp @@ -8,7 +8,7 @@ task 4 'run'. lines 97-105: task 8 'run'. lines 121-136: { - "gas_used": 173698, + "gas_used": 200239, "status": "Executed" } @@ -20,7 +20,7 @@ task 9 'run'. lines 138-147: task 11 'run'. lines 151-159: { - "gas_used": 110070, + "gas_used": 123208, "status": "Executed" } @@ -29,7 +29,7 @@ Publish failure: MiscellaneousError task 14 'run'. lines 166-174: { - "gas_used": 110070, + "gas_used": 123208, "status": "Executed" } diff --git a/integration-tests/daospace/stake_to_sbt_plugin.exp b/integration-tests/daospace/stake_to_sbt_plugin.exp index d15c2015..88cac220 100644 --- a/integration-tests/daospace/stake_to_sbt_plugin.exp +++ b/integration-tests/daospace/stake_to_sbt_plugin.exp @@ -2,7 +2,7 @@ processed 17 tasks task 5 'run'. lines 71-79: { - "gas_used": 1710807, + "gas_used": 1714614, "status": "Executed" } diff --git a/integration-tests/daospaceplugin/salary_gov_plugin.exp b/integration-tests/daospaceplugin/salary_gov_plugin.exp index ab2391e3..d2faf9bf 100644 --- a/integration-tests/daospaceplugin/salary_gov_plugin.exp +++ b/integration-tests/daospaceplugin/salary_gov_plugin.exp @@ -2,7 +2,7 @@ processed 21 tasks task 7 'run'. lines 252-264: { - "gas_used": 8187447, + "gas_used": 1723350, "status": "Executed" } diff --git a/integration-tests/package_txn_manager/cancel_upgrade_plan.exp b/integration-tests/package_txn_manager/cancel_upgrade_plan.exp index 79707e69..e3c6887d 100644 --- a/integration-tests/package_txn_manager/cancel_upgrade_plan.exp +++ b/integration-tests/package_txn_manager/cancel_upgrade_plan.exp @@ -30,7 +30,7 @@ task 5 'run'. lines 36-46: task 6 'run'. lines 48-57: { - "gas_used": 81198, + "gas_used": 65884, "status": "Executed" } diff --git a/integration-tests/package_txn_manager/override_upgrade_plan.exp b/integration-tests/package_txn_manager/override_upgrade_plan.exp index 0cac2f40..f9d06325 100644 --- a/integration-tests/package_txn_manager/override_upgrade_plan.exp +++ b/integration-tests/package_txn_manager/override_upgrade_plan.exp @@ -14,13 +14,13 @@ task 4 'run'. lines 19-31: task 5 'run'. lines 33-42: { - "gas_used": 81198, + "gas_used": 65884, "status": "Executed" } task 7 'run'. lines 46-55: { - "gas_used": 81198, + "gas_used": 65884, "status": "Executed" } diff --git a/integration-tests/package_txn_manager/package_txn_manager.exp b/integration-tests/package_txn_manager/package_txn_manager.exp index 24e4cf58..5d591f97 100644 --- a/integration-tests/package_txn_manager/package_txn_manager.exp +++ b/integration-tests/package_txn_manager/package_txn_manager.exp @@ -30,7 +30,7 @@ task 5 'run'. lines 36-46: task 6 'run'. lines 48-59: { - "gas_used": 81198, + "gas_used": 65884, "status": "Executed" } diff --git a/integration-tests/starcoin_dao/starcoin_upgrade_module.exp b/integration-tests/starcoin_dao/starcoin_upgrade_module.exp index 8c2fd68f..c9b2a556 100644 --- a/integration-tests/starcoin_dao/starcoin_upgrade_module.exp +++ b/integration-tests/starcoin_dao/starcoin_upgrade_module.exp @@ -47,20 +47,6 @@ task 21 'run'. lines 113-122: task 23 'run'. lines 126-138: { - "gas_used": 446524, - "status": { - "ExecutionFailure": { - "location": { - "Module": { - "address": "0x00000000000000000000000000000001", - "name": "PackageTxnManager" - } - }, - "function": 21, - "code_offset": 41 - } - } + "gas_used": 510063, + "status": "Executed" } - -task 26 'deploy'. lines 151-151: -Publish failure: Discard { status_code: StrView(2015), status_code_name: "UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION" } diff --git a/integration-tests/transaction_scripts/module_upgrade.exp b/integration-tests/transaction_scripts/module_upgrade.exp index 5e6921e0..4129506c 100644 --- a/integration-tests/transaction_scripts/module_upgrade.exp +++ b/integration-tests/transaction_scripts/module_upgrade.exp @@ -38,6 +38,6 @@ task 12 'run'. lines 113-126: task 14 'run'. lines 131-140: { - "gas_used": 118114, + "gas_used": 99099, "status": "Executed" } diff --git a/integration-tests/upgrade_module_dao_proposal/basic.exp b/integration-tests/upgrade_module_dao_proposal/basic.exp index d658735e..c6360bd2 100644 --- a/integration-tests/upgrade_module_dao_proposal/basic.exp +++ b/integration-tests/upgrade_module_dao_proposal/basic.exp @@ -83,6 +83,6 @@ task 16 'run'. lines 176-190: task 18 'run'. lines 194-207: { - "gas_used": 139768, + "gas_used": 120753, "status": "Executed" } diff --git a/sources/Account.move b/sources/Account.move index eb9e4de3..ffd79eaa 100644 --- a/sources/Account.move +++ b/sources/Account.move @@ -17,7 +17,6 @@ module Account { use StarcoinFramework::BCS; friend StarcoinFramework::StarcoinDAO; - friend StarcoinFramework::PackageTxnManagerUpgradeScripts; spec module { pragma verify = false; @@ -200,11 +199,6 @@ module Account { signer_cap } - public (friend) fun get_capability_for(addr: address): SignerCapability { - let signer_cap = SignerCapability { addr }; - signer_cap - } - public fun create_signer_with_cap(cap: &SignerCapability): signer { create_signer(cap.addr) } diff --git a/sources/PackageTxnManager.move b/sources/PackageTxnManager.move index fbb65130..f418fb84 100644 --- a/sources/PackageTxnManager.move +++ b/sources/PackageTxnManager.move @@ -31,7 +31,6 @@ address StarcoinFramework { const STRATEGY_NEW_MODULE: u8 = 2; const STRATEGY_FREEZE: u8 = 3; const ERR_INELIGIBALE_USER: u64 = 4; - const ERR_NOT_UPGRADE_YET: u64 = 5; const DEFAULT_MIN_TIME_LIMIT: u64 = 86400000;// one day /// arbitary stragegy @@ -245,6 +244,12 @@ address StarcoinFramework { acquires TwoPhaseUpgradeV2,UpgradePlanCapability,ModuleUpgradeStrategy,UpgradePlanEventHolder{ let account_address = Signer::address_of(account); let cap = borrow_global(account_address); + assert!(get_module_upgrade_strategy(cap.account_address) == STRATEGY_TWO_PHASE, Errors::invalid_argument(ESTRATEGY_NOT_TWO_PHASE)); + if (!exists(account_address)) { + move_to(account, UpgradePlanEventHolder { + upgrade_plan_event: Event::new_event_handle(account) + }) + }; submit_upgrade_plan_with_cap_v2(cap, package_hash, version, enforced); } @@ -257,7 +262,6 @@ address StarcoinFramework { public fun submit_upgrade_plan_with_cap_v2(cap: &UpgradePlanCapability, package_hash: vector, version: u64, enforced: bool) acquires TwoPhaseUpgradeV2, ModuleUpgradeStrategy, UpgradePlanEventHolder{ let package_address = cap.account_address; - assert!(exists(package_address), Errors::not_published(ERR_NOT_UPGRADE_YET)); assert!(get_module_upgrade_strategy(package_address) == STRATEGY_TWO_PHASE, Errors::invalid_argument(ESTRATEGY_NOT_TWO_PHASE)); let tpu = borrow_global_mut(package_address); @@ -265,11 +269,17 @@ address StarcoinFramework { let plan = UpgradePlanV2 { package_hash, active_after_time, version, enforced }; tpu.plan = Option::some(copy plan); - let event_holder = borrow_global_mut(package_address); - Event::emit_event(&mut event_holder.upgrade_plan_event, UpgradePlanEvent { - package_address, - plan - }); + // TODO + // if UpgradePlanCapability was delegated to DAO or contract, + // it's hard to upgrade the address to claim an UpgradePlanEventHolder. + // Try to fix this! + if (exists(package_address)) { + let event_holder = borrow_global_mut(package_address); + Event::emit_event(&mut event_holder.upgrade_plan_event, UpgradePlanEvent { + package_address, + plan + }); + } } spec submit_upgrade_plan_with_cap_v2 { pragma verify = false; diff --git a/sources/PackageTxnManagerUpgrade.move b/sources/PackageTxnManagerUpgrade.move deleted file mode 100644 index eb6904dd..00000000 --- a/sources/PackageTxnManagerUpgrade.move +++ /dev/null @@ -1,21 +0,0 @@ -module StarcoinFramework::PackageTxnManagerUpgradeScripts { - use StarcoinFramework::Account; - use StarcoinFramework::Errors; - use StarcoinFramework::PackageTxnManager::{Self, UpgradePlanCapability}; - - const ERR_ADDRESS_NOT_MATCH: u64 = 100; - - /// Used for - public fun claim_upgrade_plan_event_with_cap(account_address: address, cap: &UpgradePlanCapability) { - let addr_ref = PackageTxnManager::account_address(cap); - assert!(addr_ref == account_address, Errors::invalid_argument(ERR_ADDRESS_NOT_MATCH)); - let signer_cap = Account::get_capability_for(account_address); - let temp_signer = Account::create_signer_with_cap(&signer_cap); - PackageTxnManager::claim_upgrade_plan_event(&temp_signer); - Account::destroy_signer_cap(signer_cap); - } - - public(script) fun claim_upgrade_plan_event_entry(sender: signer) { - PackageTxnManager::claim_upgrade_plan_event(&sender); - } -} \ No newline at end of file