Skip to content

Commit

Permalink
update_module_upgrade_strategy support set min_time_limit (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 authored and sanlee42 committed Mar 16, 2023
1 parent 2cbdb88 commit be7f3a9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 55FD31A7EE545AD6C249CA3C06160B3B905B41CC3EB014362C9A1182E3CB0922
source_digest: 8F6E813CD88BBC53CEA97F77E661925153A65506614CD35E03D223A5A6470CFC
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/ModuleUpgradeScripts.mv
Binary file not shown.
58 changes: 56 additions & 2 deletions build/StarcoinFramework/docs/ModuleUpgradeScripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@



- [Constants](#@Constants_0)
- [Function `propose_module_upgrade_v2`](#0x1_ModuleUpgradeScripts_propose_module_upgrade_v2)
- [Function `update_module_upgrade_strategy`](#0x1_ModuleUpgradeScripts_update_module_upgrade_strategy)
- [Function `update_module_upgrade_strategy_with_min_time`](#0x1_ModuleUpgradeScripts_update_module_upgrade_strategy_with_min_time)
- [Function `submit_module_upgrade_plan`](#0x1_ModuleUpgradeScripts_submit_module_upgrade_plan)
- [Function `execute_module_upgrade_plan_propose`](#0x1_ModuleUpgradeScripts_execute_module_upgrade_plan_propose)
- [Function `submit_upgrade_plan`](#0x1_ModuleUpgradeScripts_submit_upgrade_plan)
- [Function `cancel_upgrade_plan`](#0x1_ModuleUpgradeScripts_cancel_upgrade_plan)
- [Module Specification](#@Module_Specification_0)
- [Module Specification](#@Module_Specification_1)


<pre><code><b>use</b> <a href="Config.md#0x1_Config">0x1::Config</a>;
<b>use</b> <a href="Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="Option.md#0x1_Option">0x1::Option</a>;
<b>use</b> <a href="PackageTxnManager.md#0x1_PackageTxnManager">0x1::PackageTxnManager</a>;
<b>use</b> <a href="Signer.md#0x1_Signer">0x1::Signer</a>;
Expand All @@ -24,6 +27,20 @@



<a name="@Constants_0"></a>

## Constants


<a name="0x1_ModuleUpgradeScripts_ERR_WRONG_UPGRADE_STRATEGY"></a>



<pre><code><b>const</b> <a href="ModuleUpgradeScripts.md#0x1_ModuleUpgradeScripts_ERR_WRONG_UPGRADE_STRATEGY">ERR_WRONG_UPGRADE_STRATEGY</a>: u64 = 100;
</code></pre>



<a name="0x1_ModuleUpgradeScripts_propose_module_upgrade_v2"></a>

## Function `propose_module_upgrade_v2`
Expand Down Expand Up @@ -100,6 +117,43 @@ Update <code>sender</code>'s module upgrade strategy to <code>strategy</code>



</details>

<a name="0x1_ModuleUpgradeScripts_update_module_upgrade_strategy_with_min_time"></a>

## Function `update_module_upgrade_strategy_with_min_time`

Update <code>sender</code>'s module upgrade strategy to <code>strategy</code> with min_time_limit.
This can only be invoked when strategy is STRATEGY_TWO_PHASE.


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ModuleUpgradeScripts.md#0x1_ModuleUpgradeScripts_update_module_upgrade_strategy_with_min_time">update_module_upgrade_strategy_with_min_time</a>(sender: signer, strategy: u8, min_time_limit: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ModuleUpgradeScripts.md#0x1_ModuleUpgradeScripts_update_module_upgrade_strategy_with_min_time">update_module_upgrade_strategy_with_min_time</a>(
sender: signer,
strategy: u8,
min_time_limit: u64,
){
// 1. check version
<b>assert</b>!(strategy == <a href="PackageTxnManager.md#0x1_PackageTxnManager_get_strategy_two_phase">PackageTxnManager::get_strategy_two_phase</a>(), <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="ModuleUpgradeScripts.md#0x1_ModuleUpgradeScripts_ERR_WRONG_UPGRADE_STRATEGY">ERR_WRONG_UPGRADE_STRATEGY</a>));
// 2. <b>update</b> strategy
<a href="PackageTxnManager.md#0x1_PackageTxnManager_update_module_upgrade_strategy">PackageTxnManager::update_module_upgrade_strategy</a>(
&sender,
strategy,
<a href="Option.md#0x1_Option_some">Option::some</a>&lt;u64&gt;(min_time_limit),
);
}
</code></pre>



</details>

<a name="0x1_ModuleUpgradeScripts_submit_module_upgrade_plan"></a>
Expand Down Expand Up @@ -248,7 +302,7 @@ Cancel current upgrade plan, the <code>sender</code> must have <code>UpgradePlan

</details>

<a name="@Module_Specification_0"></a>
<a name="@Module_Specification_1"></a>

## Module Specification

Expand Down
Binary file modified build/StarcoinFramework/source_maps/ModuleUpgradeScripts.mvsm
Binary file not shown.
20 changes: 20 additions & 0 deletions sources/ModuleUpgradeScripts.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module ModuleUpgradeScripts {
use StarcoinFramework::Version;
use StarcoinFramework::Option;
use StarcoinFramework::UpgradeModuleDaoProposal;
use StarcoinFramework::Errors;

const ERR_WRONG_UPGRADE_STRATEGY: u64 = 100;

spec module {
pragma verify = false; // break after enabling v2 compilation scheme
Expand Down Expand Up @@ -51,6 +54,23 @@ module ModuleUpgradeScripts {
);
}

/// Update `sender`'s module upgrade strategy to `strategy` with min_time_limit.
/// This can only be invoked when strategy is STRATEGY_TWO_PHASE.
public(script) fun update_module_upgrade_strategy_with_min_time(
sender: signer,
strategy: u8,
min_time_limit: u64,
){
// 1. check version
assert!(strategy == PackageTxnManager::get_strategy_two_phase(), Errors::invalid_argument(ERR_WRONG_UPGRADE_STRATEGY));
// 2. update strategy
PackageTxnManager::update_module_upgrade_strategy(
&sender,
strategy,
Option::some<u64>(min_time_limit),
);
}

/// a alias of execute_module_upgrade_plan_propose, will deprecated in the future.
public(script) fun submit_module_upgrade_plan<Token: copy + drop + store>(
sender: signer,
Expand Down

0 comments on commit be7f3a9

Please sign in to comment.