Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

update_module_upgrade_strategy support set min_time_limit #127

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: E084083B9449F396039B8495E0E69BE4F2537E6F6E63F8187394FFDA78F1A9B2
source_digest: 5E08A2774FAADBD05F5E98290A4B05E6D4D5AA4DB5123B79F6015AC8574B75F8
build_flags:
dev_mode: false
test_mode: false
Expand Down
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是以后都把 script 都改成 xx_entry 保存到原 Module 中,这样比较容易记。 @WGB5445

Copy link
Collaborator

@WGB5445 WGB5445 Sep 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DAOSpace 之后做的都是这样的风格,我觉得也是在原 Module 较好,不然每次要找实现了这个函数的 script 方法再调用比较麻烦

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以前的 module 更新的时候,保持原有风格也是一种选项。改成 entry 的话最好是逐步的统一进行。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种接口如果按照原有风格提供,后续只能增加新的接口并 abort 或者完全不动
不如新增加都按照新的风格来? @jolestar

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种接口如果按照原有风格提供,后续只能增加新的接口并 abort 或者完全不动 不如新增加都按照新的风格来? @jolestar

旧的不动,新增就可以。像这种旧 module 的新 script 留两个入口也可以。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

记录了一个 issue 追踪这个 #129

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