From 7261a116ccf523cff8569cfc3c9e0383231279f0 Mon Sep 17 00:00:00 2001 From: simonjiao Date: Tue, 26 Nov 2024 13:29:43 +0800 Subject: [PATCH 1/2] add flexi_dag_config and empty_scripts scripts --- .../starcoin-framework/doc/empty_scripts.md | 50 +++++ .../doc/flexi_dag_config.md | 178 ++++++++++++++++++ .../sources/configs/flexi_dag_config.move | 49 +++++ .../sources/empty_scripts.move | 11 ++ .../tests/cases/arg_variable.move | 8 +- .../tests/cases/run_cmd.move | 2 +- vm/transaction-builder/src/lib.rs | 2 +- vm/types/src/transaction/script.rs | 2 +- 8 files changed, 295 insertions(+), 7 deletions(-) create mode 100644 vm/framework/starcoin-framework/doc/empty_scripts.md create mode 100644 vm/framework/starcoin-framework/doc/flexi_dag_config.md create mode 100644 vm/framework/starcoin-framework/sources/configs/flexi_dag_config.move create mode 100644 vm/framework/starcoin-framework/sources/empty_scripts.move diff --git a/vm/framework/starcoin-framework/doc/empty_scripts.md b/vm/framework/starcoin-framework/doc/empty_scripts.md new file mode 100644 index 0000000000..122ff74804 --- /dev/null +++ b/vm/framework/starcoin-framework/doc/empty_scripts.md @@ -0,0 +1,50 @@ + + + +# Module `0x1::empty_scripts` + + + +- [Function `empty_script`](#0x1_empty_scripts_empty_script) +- [Specification](#@Specification_0) + + +
+ + + + + +## Function `empty_script` + + + +
public entry fun empty_script()
+
+ + + +
+Implementation + + +
public entry fun empty_script() {}
+
+ + + +
+ + + +## Specification + + + +
pragma verify = false;
+pragma aborts_if_is_partial = false;
+pragma aborts_if_is_strict = false;
+
+ + +[move-book]: https://starcoin.dev/move/book/SUMMARY diff --git a/vm/framework/starcoin-framework/doc/flexi_dag_config.md b/vm/framework/starcoin-framework/doc/flexi_dag_config.md new file mode 100644 index 0000000000..bba446eaab --- /dev/null +++ b/vm/framework/starcoin-framework/doc/flexi_dag_config.md @@ -0,0 +1,178 @@ + + + +# Module `0x1::flexi_dag_config` + + + +- [Struct `FlexiDagConfig`](#0x1_flexi_dag_config_FlexiDagConfig) +- [Function `new_flexidag_config`](#0x1_flexi_dag_config_new_flexidag_config) +- [Function `initialize`](#0x1_flexi_dag_config_initialize) +- [Function `effective_height`](#0x1_flexi_dag_config_effective_height) +- [Specification](#@Specification_0) + - [Function `initialize`](#@Specification_0_initialize) + - [Function `effective_height`](#@Specification_0_effective_height) + + +
use 0x1::on_chain_config;
+use 0x1::system_addresses;
+
+ + + + + +## Struct `FlexiDagConfig` + +The struct to hold all config data needed for Flexidag. + + +
struct FlexiDagConfig has copy, drop, store
+
+ + + +
+Fields + + +
+
+effective_height: u64 +
+
+ +
+
+ + +
+ + + +## Function `new_flexidag_config` + +Create a new configuration for flexidag, mainly used in DAO. + + +
public fun new_flexidag_config(effective_height: u64): flexi_dag_config::FlexiDagConfig
+
+ + + +
+Implementation + + +
public fun new_flexidag_config(effective_height: u64): FlexiDagConfig {
+    FlexiDagConfig {
+        effective_height,
+    }
+}
+
+ + + +
+ + + +## Function `initialize` + + + +
public fun initialize(account: &signer, effective_height: u64)
+
+ + + +
+Implementation + + +
public fun initialize(account: &signer, effective_height: u64) {
+    system_addresses::assert_starcoin_framework(account);
+    on_chain_config::publish_new_config<FlexiDagConfig>(account, new_flexidag_config(effective_height));
+}
+
+ + + +
+ + + +## Function `effective_height` + + + +
public fun effective_height(account: address): u64
+
+ + + +
+Implementation + + +
public fun effective_height(account: address): u64 {
+    let flexi_dag_config = on_chain_config::get_by_address<FlexiDagConfig>(account);
+    flexi_dag_config.effective_height
+}
+
+ + + +
+ + + +## Specification + + + +
pragma verify = false;
+pragma aborts_if_is_strict;
+
+ + + + + +### Function `initialize` + + +
public fun initialize(account: &signer, effective_height: u64)
+
+ + + + +
aborts_if signer::address_of(account) != system_addresses::get_starcoin_framework();
+aborts_if exists<on_chain_config::Config<FlexiDagConfig>>(signer::address_of(account));
+aborts_if exists<on_chain_config::ModifyConfigCapabilityHolder<FlexiDagConfig>>(signer::address_of(account));
+ensures exists<on_chain_config::Config<FlexiDagConfig>>(signer::address_of(account));
+ensures
+    exists<on_chain_config::ModifyConfigCapabilityHolder<FlexiDagConfig>>(
+        signer::address_of(account),
+    );
+
+ + + + + +### Function `effective_height` + + +
public fun effective_height(account: address): u64
+
+ + + + +
include on_chain_config::AbortsIfConfigNotExist<FlexiDagConfig> { addr: account };
+
+ + +[move-book]: https://starcoin.dev/move/book/SUMMARY diff --git a/vm/framework/starcoin-framework/sources/configs/flexi_dag_config.move b/vm/framework/starcoin-framework/sources/configs/flexi_dag_config.move new file mode 100644 index 0000000000..76c34b0557 --- /dev/null +++ b/vm/framework/starcoin-framework/sources/configs/flexi_dag_config.move @@ -0,0 +1,49 @@ +module starcoin_framework::flexi_dag_config { + + use std::signer; + use starcoin_framework::system_addresses; + use starcoin_framework::on_chain_config; + + spec module { + pragma verify = false; + pragma aborts_if_is_strict; + } + + /// The struct to hold all config data needed for Flexidag. + struct FlexiDagConfig has copy, drop, store { + // the height of dag genesis block + effective_height: u64, + } + + /// Create a new configuration for flexidag, mainly used in DAO. + public fun new_flexidag_config(effective_height: u64): FlexiDagConfig { + FlexiDagConfig { + effective_height, + } + } + + public fun initialize(account: &signer, effective_height: u64) { + system_addresses::assert_starcoin_framework(account); + on_chain_config::publish_new_config(account, new_flexidag_config(effective_height)); + } + + spec initialize { + aborts_if signer::address_of(account) != system_addresses::get_starcoin_framework(); + aborts_if exists>(signer::address_of(account)); + aborts_if exists>(signer::address_of(account)); + ensures exists>(signer::address_of(account)); + ensures + exists>( + signer::address_of(account), + ); + } + + public fun effective_height(account: address): u64 { + let flexi_dag_config = on_chain_config::get_by_address(account); + flexi_dag_config.effective_height + } + + spec effective_height { + include on_chain_config::AbortsIfConfigNotExist { addr: account }; + } +} diff --git a/vm/framework/starcoin-framework/sources/empty_scripts.move b/vm/framework/starcoin-framework/sources/empty_scripts.move new file mode 100644 index 0000000000..3bf36c5e7f --- /dev/null +++ b/vm/framework/starcoin-framework/sources/empty_scripts.move @@ -0,0 +1,11 @@ +module starcoin_framework::empty_scripts { + // A empty scripts module for call a script but do nothing. + + spec module { + pragma verify = false; + pragma aborts_if_is_partial = false; + pragma aborts_if_is_strict = false; + } + + public entry fun empty_script() {} +} \ No newline at end of file diff --git a/vm/starcoin-transactional-test-harness/tests/cases/arg_variable.move b/vm/starcoin-transactional-test-harness/tests/cases/arg_variable.move index 7457e956f0..5b4b2720b6 100644 --- a/vm/starcoin-transactional-test-harness/tests/cases/arg_variable.move +++ b/vm/starcoin-transactional-test-harness/tests/cases/arg_variable.move @@ -4,13 +4,13 @@ //# block --author=creator -//# run --signers creator -- 0x1::EmptyScripts::empty_script +//# run --signers creator -- 0x1::empty_scripts::empty_script -//# view --address creator --resource 0x1::Account::Account +//# view --address creator --resource 0x1::account::Account //# run --signers creator --args {{$.block[0].number}} --args {{$.view[0].sequence_number}} -script{ - fun main(_sender: signer, block_number: u64, sequence_number: u64){ +script { + fun main(_sender: signer, block_number: u64, sequence_number: u64) { assert!(block_number == 2, 1000); assert!(sequence_number == 1, 1001); } diff --git a/vm/starcoin-transactional-test-harness/tests/cases/run_cmd.move b/vm/starcoin-transactional-test-harness/tests/cases/run_cmd.move index 50f1743a3f..9baed64f09 100644 --- a/vm/starcoin-transactional-test-harness/tests/cases/run_cmd.move +++ b/vm/starcoin-transactional-test-harness/tests/cases/run_cmd.move @@ -2,5 +2,5 @@ //# faucet --addr creator --amount 100000000000 -//# run --signers creator -- 0x1::EmptyScripts::empty_script +//# run --signers creator -- 0x1::empty_scripts::empty_script diff --git a/vm/transaction-builder/src/lib.rs b/vm/transaction-builder/src/lib.rs index 397574e642..4dbb18c728 100644 --- a/vm/transaction-builder/src/lib.rs +++ b/vm/transaction-builder/src/lib.rs @@ -601,7 +601,7 @@ pub fn build_empty_script() -> EntryFunction { EntryFunction::new( ModuleId::new( core_code_address(), - Identifier::new("EmptyScripts").unwrap(), + Identifier::new("empty_scripts").unwrap(), ), Identifier::new("empty_script").unwrap(), vec![], diff --git a/vm/types/src/transaction/script.rs b/vm/types/src/transaction/script.rs index 3afecc18da..d672e86464 100644 --- a/vm/types/src/transaction/script.rs +++ b/vm/types/src/transaction/script.rs @@ -125,7 +125,7 @@ impl Sample for EntryFunction { Self { module: ModuleId::new( core_code_address(), - Identifier::new("EmptyScripts").unwrap(), + Identifier::new("empty_scripts").unwrap(), ), function: Identifier::new("empty_script").unwrap(), ty_args: vec![], From 5dd7a963ca44953bface9fa25be9d48983ddacf5 Mon Sep 17 00:00:00 2001 From: simonjiao Date: Tue, 26 Nov 2024 14:46:41 +0800 Subject: [PATCH 2/2] fix flexidagconfig dao in testsuite --- testsuite/features/cmd.feature | 90 +++++++++---------- .../src/starcoin_framework_sdk_builder.rs | 87 ++++++++++++++++-- vm/framework/starcoin-framework/doc/dao.md | 1 + .../doc/on_chain_config_scripts.md | 48 ++++++++++ .../starcoin-framework/doc/overview.md | 2 + .../starcoin-framework/doc/stc_genesis.md | 8 +- .../starcoin-framework/sources/stc/dao.move | 1 - .../sources/stc/on_chain_config_scripts.move | 21 +++-- .../sources/stc/stc_genesis.move | 6 +- 9 files changed, 201 insertions(+), 63 deletions(-) diff --git a/testsuite/features/cmd.feature b/testsuite/features/cmd.feature index 6dea738776..459d3cc468 100644 --- a/testsuite/features/cmd.feature +++ b/testsuite/features/cmd.feature @@ -198,51 +198,51 @@ Feature: cmd integration test # | | # #flexidagconfig dao testing -# Scenario Outline: [cmd] starcoin flexidagconfig dao -# # 1. deposit to default account which is a proposer -# Then cmd: "dev get-coin -v 1000000" -# Then cmd: "account unlock" -# # 2. create FlexiDagConfig proposal with proposer account -# Then cmd: "account execute-function --function 0x1::OnChainConfigScripts::propose_update_flexi_dag_effective_height -s {{$.account[0].ok.address}} --arg 10000u64 --arg 0u64 -b" -# Then cmd: "dev sleep -t 60000" -# # 3. make sure proposal has been ACTIVE for voting -# Then cmd: "dev gen-block" -# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" -# Then assert: "{{$.dev[-1].ok[0]}} == 2" -# # 4. create a new account to vote, deposit enough tokens -# Then cmd: "account create -p 1234" -# Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}" -# Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}" -# Then cmd: "account unlock {{$.account[2].ok.address}} -p 1234" -# # 5. stake and cast vote with new account -# Then cmd: "account execute-function --function 0x1::DaoVoteScripts::cast_vote -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> -s {{$.account[2].ok.address}} --arg {{$.account[0].ok.address}} --arg 0 --arg true --arg 12740545600000000u128 -b" -# Then cmd: "dev sleep -t 3600000" -# # 6. switch to proposer account, make sure proposal has been AGREED -# Then cmd: "account unlock" -# Then cmd: "dev gen-block" -# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" -# Then assert: "{{$.dev[-1].ok[0]}} == 4" -# # 7. add proposal to execution queue with proposer account -# Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::Dao::queue_proposal_action -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0 -b" -# Then cmd: "dev sleep -t 3600000" -# # 8. make sure proposal is EXECUTABLE -# Then cmd: "dev gen-block" -# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" -# Then assert: "{{$.dev[-1].ok[0]}} == 6" -# # 9. execute proposal with proposer account -# Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::OnChainConfigScripts::execute_on_chain_config_proposal -t 0x1::FlexiDagConfig::FlexiDagConfig --arg 0 -b" -# # 10. make sure the proposal is EXTRACTED -# Then cmd: "dev gen-block" -# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" -# Then assert: "{{$.dev[-1].ok[0]}} == 7" -# # 11. clean up proposal -# Then cmd: "account execute-function --function 0x1::Dao::destroy_terminated_proposal -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0u64" -# # 12. check the latest flexidagconfig -# Then cmd: "state get resource 0x1 0x1::Config::Config<0x01::FlexiDagConfig::FlexiDagConfig>" -# Then assert: "{{$.state[0].ok.json.payload.effective_height}} == 10000" -# -# Examples: -# | | | + Scenario Outline: [cmd] starcoin flexidagconfig dao + # 1. deposit to default account which is a proposer + Then cmd: "dev get-coin -v 1000000" + Then cmd: "account unlock" + # 2. create FlexiDagConfig proposal with proposer account + Then cmd: "account execute-function --function 0x1::on_chain_config_scripts::propose_update_flexi_dag_effective_height -s {{$.account[0].ok.address}} --arg 10000u64 --arg 0u64 -b" + Then cmd: "dev sleep -t 60000" + # 3. make sure proposal has been ACTIVE for voting + Then cmd: "dev gen-block" + Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" + Then assert: "{{$.dev[-1].ok[0]}} == 2" + # 4. create a new account to vote, deposit enough tokens + Then cmd: "account create -p 1234" + Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}" + Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}" + Then cmd: "account unlock {{$.account[2].ok.address}} -p 1234" + # 5. stake and cast vote with new account + Then cmd: "account execute-function --function 0x1::dao_vote_scripts::cast_vote -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> -s {{$.account[2].ok.address}} --arg {{$.account[0].ok.address}} --arg 0 --arg true --arg 12740545600000000u128 -b" + Then cmd: "dev sleep -t 3600000" + # 6. switch to proposer account, make sure proposal has been AGREED + Then cmd: "account unlock" + Then cmd: "dev gen-block" + Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" + Then assert: "{{$.dev[-1].ok[0]}} == 4" + # 7. add proposal to execution queue with proposer account + Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::dao::queue_proposal_action -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0 -b" + Then cmd: "dev sleep -t 3600000" + # 8. make sure proposal is EXECUTABLE + Then cmd: "dev gen-block" + Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" + Then assert: "{{$.dev[-1].ok[0]}} == 6" + # 9. execute proposal with proposer account + Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::on_chain_config_scripts::execute_on_chain_config_proposal -t 0x1::flexi_dag_config::FlexiDagConfig --arg 0 -b" + # 10. make sure the proposal is EXTRACTED + Then cmd: "dev gen-block" + Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0" + Then assert: "{{$.dev[-1].ok[0]}} == 7" + # 11. clean up proposal + Then cmd: "account execute-function --function 0x1::dao::destroy_terminated_proposal -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0u64" + # 12. check the latest flexidagconfig + Then cmd: "state get resource 0x1 0x1::on_chain_config::Config<0x01::flexi_dag_config::FlexiDagConfig>" + Then assert: "{{$.state[0].ok.json.payload.effective_height}} == 10000" + + Examples: + | | | # #easy gas testing # Scenario Outline: starcoin easy gas test diff --git a/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs b/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs index 8149424fb5..1f3c419882 100644 --- a/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs +++ b/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs @@ -396,6 +396,8 @@ pub enum EntryFunctionCall { amount: u128, }, + EmptyScriptsEmptyScript {}, + /// Withdraw an `amount` of coin `CoinType` from `account` and burn it. ManagedCoinBurn { coin_type: TypeTag, @@ -673,6 +675,11 @@ pub enum EntryFunctionCall { exec_delay: u64, }, + OnChainConfigScriptsProposeUpdateFlexiDagEffectiveHeight { + new_height: u64, + exec_delay: u64, + }, + OnChainConfigScriptsProposeUpdateMoveLanguageVersion { new_version: u64, exec_delay: u64, @@ -1118,7 +1125,7 @@ pub enum EntryFunctionCall { voting_quorum_rate: u8, min_action_delay: u64, transaction_timeout: u64, - _dag_effective_height: u64, + dag_effective_height: u64, }, TransactionFeeConvertToStarcoinFaBurnRef {}, @@ -1510,6 +1517,7 @@ impl EntryFunctionCall { EasyGasScriptWithdrawGasFeeEntry { token_type, amount } => { easy_gas_script_withdraw_gas_fee_entry(token_type, amount) } + EmptyScriptsEmptyScript {} => empty_scripts_empty_script(), ManagedCoinBurn { coin_type, amount } => managed_coin_burn(coin_type, amount), ManagedCoinInitialize { coin_type, @@ -1721,6 +1729,12 @@ impl EntryFunctionCall { strategy, exec_delay, ), + OnChainConfigScriptsProposeUpdateFlexiDagEffectiveHeight { + new_height, + exec_delay, + } => on_chain_config_scripts_propose_update_flexi_dag_effective_height( + new_height, exec_delay, + ), OnChainConfigScriptsProposeUpdateMoveLanguageVersion { new_version, exec_delay, @@ -2024,7 +2038,7 @@ impl EntryFunctionCall { voting_quorum_rate, min_action_delay, transaction_timeout, - _dag_effective_height, + dag_effective_height, } => stc_genesis_initialize( stdlib_version, reward_delay, @@ -2056,7 +2070,7 @@ impl EntryFunctionCall { voting_quorum_rate, min_action_delay, transaction_timeout, - _dag_effective_height, + dag_effective_height, ), TransactionFeeConvertToStarcoinFaBurnRef {} => { transaction_fee_convert_to_starcoin_fa_burn_ref() @@ -3040,6 +3054,18 @@ pub fn easy_gas_script_withdraw_gas_fee_entry( )) } +pub fn empty_scripts_empty_script() -> TransactionPayload { + TransactionPayload::EntryFunction(EntryFunction::new( + ModuleId::new( + AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), + ident_str!("empty_scripts").to_owned(), + ), + ident_str!("empty_script").to_owned(), + vec![], + vec![], + )) +} + /// Withdraw an `amount` of coin `CoinType` from `account` and burn it. pub fn managed_coin_burn(coin_type: TypeTag, amount: u64) -> TransactionPayload { TransactionPayload::EntryFunction(EntryFunction::new( @@ -3734,6 +3760,24 @@ pub fn on_chain_config_scripts_propose_update_consensus_config( )) } +pub fn on_chain_config_scripts_propose_update_flexi_dag_effective_height( + new_height: u64, + exec_delay: u64, +) -> TransactionPayload { + TransactionPayload::EntryFunction(EntryFunction::new( + ModuleId::new( + AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), + ident_str!("on_chain_config_scripts").to_owned(), + ), + ident_str!("propose_update_flexi_dag_effective_height").to_owned(), + vec![], + vec![ + bcs::to_bytes(&new_height).unwrap(), + bcs::to_bytes(&exec_delay).unwrap(), + ], + )) +} + pub fn on_chain_config_scripts_propose_update_move_language_version( new_version: u64, exec_delay: u64, @@ -4900,7 +4944,7 @@ pub fn stc_genesis_initialize( voting_quorum_rate: u8, min_action_delay: u64, transaction_timeout: u64, - _dag_effective_height: u64, + dag_effective_height: u64, ) -> TransactionPayload { TransactionPayload::EntryFunction(EntryFunction::new( ModuleId::new( @@ -4940,7 +4984,7 @@ pub fn stc_genesis_initialize( bcs::to_bytes(&voting_quorum_rate).unwrap(), bcs::to_bytes(&min_action_delay).unwrap(), bcs::to_bytes(&transaction_timeout).unwrap(), - bcs::to_bytes(&_dag_effective_height).unwrap(), + bcs::to_bytes(&dag_effective_height).unwrap(), ], )) } @@ -5952,6 +5996,14 @@ mod decoder { } } + pub fn empty_scripts_empty_script(payload: &TransactionPayload) -> Option { + if let TransactionPayload::EntryFunction(_script) = payload { + Some(EntryFunctionCall::EmptyScriptsEmptyScript {}) + } else { + None + } + } + pub fn managed_coin_burn(payload: &TransactionPayload) -> Option { if let TransactionPayload::EntryFunction(script) = payload { Some(EntryFunctionCall::ManagedCoinBurn { @@ -6416,6 +6468,21 @@ mod decoder { } } + pub fn on_chain_config_scripts_propose_update_flexi_dag_effective_height( + payload: &TransactionPayload, + ) -> Option { + if let TransactionPayload::EntryFunction(script) = payload { + Some( + EntryFunctionCall::OnChainConfigScriptsProposeUpdateFlexiDagEffectiveHeight { + new_height: bcs::from_bytes(script.args().get(0)?).ok()?, + exec_delay: bcs::from_bytes(script.args().get(1)?).ok()?, + }, + ) + } else { + None + } + } + pub fn on_chain_config_scripts_propose_update_move_language_version( payload: &TransactionPayload, ) -> Option { @@ -7256,7 +7323,7 @@ mod decoder { voting_quorum_rate: bcs::from_bytes(script.args().get(27)?).ok()?, min_action_delay: bcs::from_bytes(script.args().get(28)?).ok()?, transaction_timeout: bcs::from_bytes(script.args().get(29)?).ok()?, - _dag_effective_height: bcs::from_bytes(script.args().get(30)?).ok()?, + dag_effective_height: bcs::from_bytes(script.args().get(30)?).ok()?, }) } else { None @@ -7753,6 +7820,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazyaddress, proposal_id: u64, ): ActionT acquires Proposal { + debug::print(&std::string::utf8(b"dao::extract_proposal_action | Entered")); // Only executable proposal's action can be extracted. assert!( proposal_state<TokenT, ActionT>(proposer_address, proposal_id) == EXECUTABLE, diff --git a/vm/framework/starcoin-framework/doc/on_chain_config_scripts.md b/vm/framework/starcoin-framework/doc/on_chain_config_scripts.md index ab43919d40..51c257e082 100644 --- a/vm/framework/starcoin-framework/doc/on_chain_config_scripts.md +++ b/vm/framework/starcoin-framework/doc/on_chain_config_scripts.md @@ -11,6 +11,7 @@ - [Function `propose_update_txn_timeout_config`](#0x1_on_chain_config_scripts_propose_update_txn_timeout_config) - [Function `propose_update_vm_config`](#0x1_on_chain_config_scripts_propose_update_vm_config) - [Function `propose_update_move_language_version`](#0x1_on_chain_config_scripts_propose_update_move_language_version) +- [Function `propose_update_flexi_dag_effective_height`](#0x1_on_chain_config_scripts_propose_update_flexi_dag_effective_height) - [Function `execute_on_chain_config_proposal`](#0x1_on_chain_config_scripts_execute_on_chain_config_proposal) - [Function `execute_on_chain_config_proposal_v2`](#0x1_on_chain_config_scripts_execute_on_chain_config_proposal_v2) - [Specification](#@Specification_0) @@ -20,12 +21,14 @@ - [Function `propose_update_txn_timeout_config`](#@Specification_0_propose_update_txn_timeout_config) - [Function `propose_update_vm_config`](#@Specification_0_propose_update_vm_config) - [Function `propose_update_move_language_version`](#@Specification_0_propose_update_move_language_version) + - [Function `propose_update_flexi_dag_effective_height`](#@Specification_0_propose_update_flexi_dag_effective_height) - [Function `execute_on_chain_config_proposal`](#@Specification_0_execute_on_chain_config_proposal) - [Function `execute_on_chain_config_proposal_v2`](#@Specification_0_execute_on_chain_config_proposal_v2)
use 0x1::block_reward_config;
 use 0x1::consensus_config;
+use 0x1::flexi_dag_config;
 use 0x1::on_chain_config_dao;
 use 0x1::signer;
 use 0x1::starcoin_coin;
@@ -251,6 +254,35 @@ Propose to update the VM configuration.
 
 
 
+
+
+
+
+## Function `propose_update_flexi_dag_effective_height`
+
+
+
+
public entry fun propose_update_flexi_dag_effective_height(account: signer, new_height: u64, exec_delay: u64)
+
+ + + +
+Implementation + + +
public entry fun propose_update_flexi_dag_effective_height(account: signer, new_height: u64, exec_delay: u64) {
+    let config = flexi_dag_config::new_flexidag_config(new_height);
+    on_chain_config_dao::propose_update<starcoin_coin::STC, flexi_dag_config::FlexiDagConfig>(
+        &account,
+        config,
+        exec_delay
+    );
+}
+
+ + +
@@ -400,6 +432,22 @@ Propose to update the VM configuration. +
pragma verify = false;
+
+ + + + + +### Function `propose_update_flexi_dag_effective_height` + + +
public entry fun propose_update_flexi_dag_effective_height(account: signer, new_height: u64, exec_delay: u64)
+
+ + + +
pragma verify = false;
 
diff --git a/vm/framework/starcoin-framework/doc/overview.md b/vm/framework/starcoin-framework/doc/overview.md index 0f3dd06fb2..1561f118ba 100644 --- a/vm/framework/starcoin-framework/doc/overview.md +++ b/vm/framework/starcoin-framework/doc/overview.md @@ -37,9 +37,11 @@ This is the reference documentation of the Starcoin framework. - [`0x1::dkg`](dkg.md#0x1_dkg) - [`0x1::easy_gas`](easy_gas.md#0x1_easy_gas) - [`0x1::easy_gas_script`](easy_gas_script.md#0x1_easy_gas_script) +- [`0x1::empty_scripts`](empty_scripts.md#0x1_empty_scripts) - [`0x1::epoch`](epoch.md#0x1_epoch) - [`0x1::event`](event.md#0x1_event) - [`0x1::execution_config`](execution_config.md#0x1_execution_config) +- [`0x1::flexi_dag_config`](flexi_dag_config.md#0x1_flexi_dag_config) - [`0x1::function_info`](function_info.md#0x1_function_info) - [`0x1::fungible_asset`](fungible_asset.md#0x1_fungible_asset) - [`0x1::gas_schedule`](gas_schedule.md#0x1_gas_schedule) diff --git a/vm/framework/starcoin-framework/doc/stc_genesis.md b/vm/framework/starcoin-framework/doc/stc_genesis.md index 61edb62f23..ba536b2bfc 100644 --- a/vm/framework/starcoin-framework/doc/stc_genesis.md +++ b/vm/framework/starcoin-framework/doc/stc_genesis.md @@ -27,6 +27,7 @@ The module for init Genesis use 0x1::dao_treasury_withdraw_proposal; use 0x1::debug; use 0x1::epoch; +use 0x1::flexi_dag_config; use 0x1::on_chain_config; use 0x1::on_chain_config_dao; use 0x1::option; @@ -56,7 +57,7 @@ The module for init Genesis -
public entry fun initialize(stdlib_version: u64, reward_delay: u64, total_stc_amount: u128, pre_mine_stc_amount: u128, time_mint_stc_amount: u128, time_mint_stc_period: u64, parent_hash: vector<u8>, association_auth_key: vector<u8>, genesis_auth_key: vector<u8>, chain_id: u8, _genesis_timestamp: u64, uncle_rate_target: u64, epoch_block_count: u64, base_block_time_target: u64, base_block_difficulty_window: u64, base_reward_per_block: u128, base_reward_per_uncle_percent: u64, min_block_time_target: u64, max_block_time_target: u64, base_max_uncles_per_block: u64, base_block_gas_limit: u64, strategy: u8, script_allowed: bool, module_publishing_allowed: bool, gas_schedule_blob: vector<u8>, voting_delay: u64, voting_period: u64, voting_quorum_rate: u8, min_action_delay: u64, transaction_timeout: u64, _dag_effective_height: u64)
+
public entry fun initialize(stdlib_version: u64, reward_delay: u64, total_stc_amount: u128, pre_mine_stc_amount: u128, time_mint_stc_amount: u128, time_mint_stc_period: u64, parent_hash: vector<u8>, association_auth_key: vector<u8>, genesis_auth_key: vector<u8>, chain_id: u8, _genesis_timestamp: u64, uncle_rate_target: u64, epoch_block_count: u64, base_block_time_target: u64, base_block_difficulty_window: u64, base_reward_per_block: u128, base_reward_per_uncle_percent: u64, min_block_time_target: u64, max_block_time_target: u64, base_max_uncles_per_block: u64, base_block_gas_limit: u64, strategy: u8, script_allowed: bool, module_publishing_allowed: bool, gas_schedule_blob: vector<u8>, voting_delay: u64, voting_period: u64, voting_quorum_rate: u8, min_action_delay: u64, transaction_timeout: u64, dag_effective_height: u64)
 
@@ -101,7 +102,7 @@ The module for init Genesis min_action_delay: u64, // transaction timeout config transaction_timeout: u64, - _dag_effective_height: u64, + dag_effective_height: u64, ) { debug::print(&std::string::utf8(b"stc_genesis::initialize Entered")); @@ -136,6 +137,8 @@ The module for init Genesis gas_schedule_blob, ); + flexi_dag_config::initialize(&starcoin_framework_account, dag_effective_height); + stc_transaction_timeout_config::initialize(&starcoin_framework_account, transaction_timeout); consensus_config::initialize( &starcoin_framework_account, @@ -325,6 +328,7 @@ The treasury will mint the total_stc_amount to the treasury. on_chain_config_dao::plugin<STC, consensus_config::ConsensusConfig>(starcoin_framework); on_chain_config_dao::plugin<STC, block_reward_config::RewardConfig>(starcoin_framework); on_chain_config_dao::plugin<STC, stc_transaction_timeout_config::TransactionTimeoutConfig>(starcoin_framework); + on_chain_config_dao::plugin<STC, flexi_dag_config::FlexiDagConfig>(starcoin_framework); // debug::print(&std::string::utf8(b"initialize_stc | Exited")); diff --git a/vm/framework/starcoin-framework/sources/stc/dao.move b/vm/framework/starcoin-framework/sources/stc/dao.move index 4fd69c2583..3f4906ff57 100644 --- a/vm/framework/starcoin-framework/sources/stc/dao.move +++ b/vm/framework/starcoin-framework/sources/stc/dao.move @@ -581,7 +581,6 @@ module starcoin_framework::dao { } - //// Helper functions //// Query functions diff --git a/vm/framework/starcoin-framework/sources/stc/on_chain_config_scripts.move b/vm/framework/starcoin-framework/sources/stc/on_chain_config_scripts.move index 19d1ef7fff..5b1535d4ab 100644 --- a/vm/framework/starcoin-framework/sources/stc/on_chain_config_scripts.move +++ b/vm/framework/starcoin-framework/sources/stc/on_chain_config_scripts.move @@ -1,6 +1,7 @@ module starcoin_framework::on_chain_config_scripts { use std::signer; + use starcoin_framework::starcoin_coin; use starcoin_framework::block_reward_config; use starcoin_framework::consensus_config; @@ -10,6 +11,7 @@ module starcoin_framework::on_chain_config_scripts { use starcoin_framework::stc_transaction_timeout_config; use starcoin_framework::transaction_publish_option; use starcoin_framework::vm_config; + use starcoin_framework::flexi_dag_config; public entry fun propose_update_consensus_config( account: signer, @@ -132,15 +134,18 @@ module starcoin_framework::on_chain_config_scripts { pragma verify = false; } - // TODO(BobOng): [framework compatible] To implement the following functions, we need to implement the `FlexiDagConfig` struct. - // public entry fun propose_update_flexi_dag_effective_height(account: signer, new_height: u64, exec_delay: u64) { - // let config = FlexiDagConfig::new_flexidag_config(new_height); - // OnChainConfigDao::propose_update(&account, config, exec_delay); - // } + public entry fun propose_update_flexi_dag_effective_height(account: signer, new_height: u64, exec_delay: u64) { + let config = flexi_dag_config::new_flexidag_config(new_height); + on_chain_config_dao::propose_update( + &account, + config, + exec_delay + ); + } - // spec propose_update_flexi_dag_effective_height { - // pragma verify = false; - // } + spec propose_update_flexi_dag_effective_height { + pragma verify = false; + } public entry fun execute_on_chain_config_proposal(account: signer, proposal_id: u64) { on_chain_config_dao::execute(signer::address_of(&account), proposal_id); diff --git a/vm/framework/starcoin-framework/sources/stc/stc_genesis.move b/vm/framework/starcoin-framework/sources/stc/stc_genesis.move index 1e09a0c75c..1530b5673c 100644 --- a/vm/framework/starcoin-framework/sources/stc/stc_genesis.move +++ b/vm/framework/starcoin-framework/sources/stc/stc_genesis.move @@ -3,6 +3,7 @@ module starcoin_framework::stc_genesis { use std::option; use std::vector; + use starcoin_framework::flexi_dag_config; use starcoin_framework::oracle_stc_usd; use starcoin_framework::dao_modify_config_proposal; @@ -77,7 +78,7 @@ module starcoin_framework::stc_genesis { min_action_delay: u64, // transaction timeout config transaction_timeout: u64, - _dag_effective_height: u64, + dag_effective_height: u64, ) { debug::print(&std::string::utf8(b"stc_genesis::initialize Entered")); @@ -112,6 +113,8 @@ module starcoin_framework::stc_genesis { gas_schedule_blob, ); + flexi_dag_config::initialize(&starcoin_framework_account, dag_effective_height); + stc_transaction_timeout_config::initialize(&starcoin_framework_account, transaction_timeout); consensus_config::initialize( &starcoin_framework_account, @@ -261,6 +264,7 @@ module starcoin_framework::stc_genesis { on_chain_config_dao::plugin(starcoin_framework); on_chain_config_dao::plugin(starcoin_framework); on_chain_config_dao::plugin(starcoin_framework); + on_chain_config_dao::plugin(starcoin_framework); // debug::print(&std::string::utf8(b"initialize_stc | Exited"));