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

add framework entry function in on_chain_config_scripts.move #4295

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
462 changes: 462 additions & 0 deletions vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs

Large diffs are not rendered by default.

439 changes: 439 additions & 0 deletions vm/framework/starcoin-framework/doc/on_chain_config_scripts.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions vm/framework/starcoin-framework/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ This is the reference documentation of the Starcoin framework.
- [`0x1::object_code_deployment`](object_code_deployment.md#0x1_object_code_deployment)
- [`0x1::on_chain_config`](on_chain_config.md#0x1_on_chain_config)
- [`0x1::on_chain_config_dao`](on_chain_config_dao.md#0x1_on_chain_config_dao)
- [`0x1::on_chain_config_scripts`](on_chain_config_scripts.md#0x1_on_chain_config_scripts)
- [`0x1::optional_aggregator`](optional_aggregator.md#0x1_optional_aggregator)
- [`0x1::oracle`](oracle.md#0x1_oracle)
- [`0x1::oracle_aggregator`](oracle_aggregator.md#0x1_oracle_aggregator)
Expand Down
10 changes: 4 additions & 6 deletions vm/framework/starcoin-framework/doc/stc_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ Get the hash of the parents block, used for DAG
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_parents_hash">get_parents_hash</a>(): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
// *&<b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).parent_hash
<a href="../../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>()
<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_parents_hash">get_parents_hash</a>(): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; <b>acquires</b> <a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a> {
*&<b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).parents_hash
}
</code></pre>

Expand All @@ -357,9 +356,8 @@ Gets the address of the author of the current block
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_current_author">get_current_author</a>(): <b>address</b> {
// <b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).author
@0x1
<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_current_author">get_current_author</a>(): <b>address</b> <b>acquires</b> <a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a> {
<b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).author
}
</code></pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@



<a id="0x1_stc_transaction_validation_EPROLOGUE_BAD_CHAIN_ID"></a>
<a id="0x1_stc_transaction_validation_EPROLOGUE_ACCOUNT_DOES_NOT_EXIST"></a>



<pre><code><b>const</b> <a href="stc_transaction_validation.md#0x1_stc_transaction_validation_EPROLOGUE_BAD_CHAIN_ID">EPROLOGUE_BAD_CHAIN_ID</a>: u64 = 6;
<pre><code><b>const</b> <a href="stc_transaction_validation.md#0x1_stc_transaction_validation_EPROLOGUE_ACCOUNT_DOES_NOT_EXIST">EPROLOGUE_ACCOUNT_DOES_NOT_EXIST</a>: u64 = 0;
</code></pre>



<a id="0x1_stc_transaction_validation_EPROLOGUE_ACCOUNT_DOES_NOT_EXIST"></a>
<a id="0x1_stc_transaction_validation_EPROLOGUE_BAD_CHAIN_ID"></a>



<pre><code><b>const</b> <a href="stc_transaction_validation.md#0x1_stc_transaction_validation_EPROLOGUE_ACCOUNT_DOES_NOT_EXIST">EPROLOGUE_ACCOUNT_DOES_NOT_EXIST</a>: u64 = 0;
<pre><code><b>const</b> <a href="stc_transaction_validation.md#0x1_stc_transaction_validation_EPROLOGUE_BAD_CHAIN_ID">EPROLOGUE_BAD_CHAIN_ID</a>: u64 = 6;
</code></pre>


Expand Down
25 changes: 25 additions & 0 deletions vm/framework/starcoin-framework/doc/vm_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- [Struct `VMConfig`](#0x1_vm_config_VMConfig)
- [Function `initialize`](#0x1_vm_config_initialize)
- [Function `new_from_blob`](#0x1_vm_config_new_from_blob)
- [Specification](#@Specification_0)
- [Function `initialize`](#@Specification_0_initialize)

Expand Down Expand Up @@ -83,6 +84,30 @@ Initialize the table under the genesis account



</details>

<a id="0x1_vm_config_new_from_blob"></a>

## Function `new_from_blob`



<pre><code><b>public</b> <b>fun</b> <a href="vm_config.md#0x1_vm_config_new_from_blob">new_from_blob</a>(gas_schedule_blob: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="vm_config.md#0x1_vm_config_VMConfig">vm_config::VMConfig</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="vm_config.md#0x1_vm_config_new_from_blob">new_from_blob</a>(gas_schedule_blob: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="vm_config.md#0x1_vm_config_VMConfig">VMConfig</a> {
<a href="util.md#0x1_util_from_bytes">util::from_bytes</a>&lt;<a href="vm_config.md#0x1_vm_config_VMConfig">VMConfig</a>&gt;(gas_schedule_blob)
}
</code></pre>



</details>

<a id="@Specification_0"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,61 @@ processed 21 tasks

task 4 'run'. lines 9-21:
{
"gas_used": 1763221,
"gas_used": 1860054,
"status": "Executed"
}

task 5 'run'. lines 24-33:
{
"gas_used": 1100997,
"gas_used": 1175537,
"status": "Executed"
}

task 6 'run'. lines 36-59:
{
"gas_used": 49947,
"gas_used": 57071,
"status": "Executed"
}

task 8 'run'. lines 64-82:
{
"gas_used": 1143976,
"gas_used": 1184064,
"status": "Executed"
}

task 9 'run'. lines 85-102:
{
"gas_used": 1136908,
"gas_used": 1176362,
"status": "Executed"
}

task 11 'run'. lines 107-126:
{
"gas_used": 348880,
"gas_used": 381844,
"status": "Executed"
}

task 12 'run'. lines 129-149:
{
"gas_used": 1148394,
"gas_used": 1190440,
"status": "Executed"
}

task 13 'run'. lines 152-191:
{
"gas_used": 2739806,
"gas_used": 2863362,
"status": "Executed"
}

task 15 'run'. lines 197-219:
{
"gas_used": 252843,
"gas_used": 281364,
"status": "Executed"
}

task 17 'run'. lines 225-240:
{
"gas_used": 41583,
"gas_used": 48712,
"status": {
"MoveAbort": {
"location": {
Expand All @@ -72,12 +72,12 @@ task 17 'run'. lines 225-240:

task 18 'run'. lines 243-267:
{
"gas_used": 306887,
"gas_used": 348210,
"status": "Executed"
}

task 20 'run'. lines 273-285:
{
"gas_used": 58675,
"gas_used": 69700,
"status": "Executed"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
module starcoin_framework::on_chain_config_scripts {

use std::signer;
use starcoin_framework::block_reward_config;
use starcoin_framework::stc_language_version;
use starcoin_framework::vm_config;
use starcoin_framework::stc_transaction_timeout_config;
use starcoin_framework::transaction_publish_option;
use starcoin_framework::starcoin_coin::STC;
use starcoin_framework::on_chain_config_dao;
use starcoin_framework::consensus_config;

public entry fun propose_update_consensus_config(
account: signer,
uncle_rate_target: u64,
base_block_time_target: u64,
base_reward_per_block: u128,
base_reward_per_uncle_percent: u64,
epoch_block_count: u64,
base_block_difficulty_window: u64,
min_block_time_target: u64,
max_block_time_target: u64,
base_max_uncles_per_block: u64,
base_block_gas_limit: u64,
strategy: u8,
exec_delay: u64
) {
let consensus_config = consensus_config::new_consensus_config(
uncle_rate_target,
base_block_time_target,
base_reward_per_block,
base_reward_per_uncle_percent,
epoch_block_count,
base_block_difficulty_window,
min_block_time_target,
max_block_time_target,
base_max_uncles_per_block,
base_block_gas_limit,
strategy
);

on_chain_config_dao::propose_update<STC, consensus_config::ConsensusConfig>(
&account,
consensus_config,
exec_delay
);
}

spec propose_update_consensus_config {
pragma verify = false;
}

public entry fun propose_update_reward_config(
account: signer,
reward_delay: u64,
exec_delay: u64
) {
let reward_config = block_reward_config::new_reward_config(reward_delay);
on_chain_config_dao::propose_update<STC, block_reward_config::RewardConfig>(
&account,
reward_config,
exec_delay
);
}

spec propose_update_reward_config {
pragma verify = false;
}

/// Propose to update the transaction publish option.
///
public entry fun propose_update_txn_publish_option(
account: signer,
script_allowed: bool,
module_publishing_allowed: bool,
exec_delay: u64
) {
let txn_publish_option = transaction_publish_option::new_transaction_publish_option(
script_allowed,
module_publishing_allowed
);
on_chain_config_dao::propose_update<STC, transaction_publish_option::TransactionPublishOption>(
&account,
txn_publish_option,
exec_delay
);
}

spec propose_update_txn_publish_option {
pragma verify = false;
}

/// Propose to update the transaction timeout configuration.
public entry fun propose_update_txn_timeout_config(
account: signer,
duration_seconds: u64,
exec_delay: u64
) {
let txn_timeout_config = stc_transaction_timeout_config::new_transaction_timeout_config(duration_seconds);
on_chain_config_dao::propose_update<STC, stc_transaction_timeout_config::TransactionTimeoutConfig>(
&account,
txn_timeout_config,
exec_delay
);
}

spec propose_update_txn_timeout_config {
pragma verify = false;
}

/// Propose to update the VM configuration.
public entry fun propose_update_vm_config(account: signer, new_config: vector<u8>, exec_delay: u64) {
let new_config = vm_config::new_from_blob(new_config);
on_chain_config_dao::propose_update<STC, vm_config::VMConfig>(&account, new_config, exec_delay);
}

spec propose_update_vm_config {
pragma verify = false;
}

public entry fun propose_update_move_language_version(account: signer, new_version: u64, exec_delay: u64) {
let lang_version = stc_language_version::new(new_version);
on_chain_config_dao::propose_update<STC, stc_language_version::LanguageVersion>(
&account,
lang_version,
exec_delay
);
}

spec propose_update_move_language_version {
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<STC::STC, FlexiDagConfig::FlexiDagConfig>(&account, config, exec_delay);
// }

// spec propose_update_flexi_dag_effective_height {
// pragma verify = false;
// }

public entry fun execute_on_chain_config_proposal<ConfigT: copy + drop + store>(account: signer, proposal_id: u64) {
on_chain_config_dao::execute<STC, ConfigT>(signer::address_of(&account), proposal_id);
}

spec execute_on_chain_config_proposal {
pragma verify = false;
}

public entry fun execute_on_chain_config_proposal_v2<TokenType, ConfigT: copy + drop + store>(
proposer_address: address,
proposal_id: u64
) {
on_chain_config_dao::execute<TokenType, ConfigT>(proposer_address, proposal_id);
}

spec execute_on_chain_config_proposal_v2 {
pragma verify = false;
}
}
5 changes: 5 additions & 0 deletions vm/framework/starcoin-framework/sources/stc/vm_config.move
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// `VMConfig` keep track of VM related configuration, like gas schedule.
module starcoin_framework::vm_config {
use starcoin_framework::storage_gas::GasCurve;
use starcoin_framework::gas_schedule::GasScheduleV2;
use starcoin_framework::system_addresses;
use starcoin_framework::on_chain_config;
Expand Down Expand Up @@ -32,6 +33,10 @@ module starcoin_framework::vm_config {
);
}

public fun new_from_blob(gas_schedule_blob: vector<u8>): VMConfig {
util::from_bytes<VMConfig>(gas_schedule_blob)
}

spec initialize {
use std::signer;
use starcoin_framework::on_chain_config;
Expand Down
Loading