Skip to content

Commit

Permalink
[compiler-v2] fixed genesis timestamp (#4381)
Browse files Browse the repository at this point in the history
* [compiler-v2] Fixed genesis timestamp

* [compiler-v2] rebuild genesis files

* update proxima timestamp

---------

Co-authored-by: nk_ysg <[email protected]>
  • Loading branch information
welbon and nkysg authored Jan 26, 2025
1 parent c59ff57 commit 0870220
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 42 deletions.
2 changes: 1 addition & 1 deletion config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ pub static G_PROXIMA_CONFIG: Lazy<GenesisConfig> = Lazy::new(|| {
GenesisConfig {
genesis_block_parameter: GenesisBlockParameterConfig::Static(GenesisBlockParameter {
parent_hash: HashValue::sha3_256_of(b"starcoin_proxima"),
timestamp: 1661944080000,
timestamp: 1737879796000,
difficulty: 100.into(),
}),
version: Version { major: 1 },
Expand Down
Binary file modified genesis/generated/barnard/genesis
Binary file not shown.
Binary file modified genesis/generated/halley/genesis
Binary file not shown.
Binary file modified genesis/generated/main/genesis
Binary file not shown.
Binary file modified genesis/generated/proxima/genesis
Binary file not shown.
Binary file modified genesis/generated/vega/genesis
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub enum EntryFunctionCall {
association_auth_key: Vec<u8>,
genesis_auth_key: Vec<u8>,
chain_id: u8,
_genesis_timestamp: u64,
genesis_timestamp: u64,
uncle_rate_target: u64,
epoch_block_count: u64,
base_block_time_target: u64,
Expand Down Expand Up @@ -908,7 +908,7 @@ impl EntryFunctionCall {
association_auth_key,
genesis_auth_key,
chain_id,
_genesis_timestamp,
genesis_timestamp,
uncle_rate_target,
epoch_block_count,
base_block_time_target,
Expand Down Expand Up @@ -941,7 +941,7 @@ impl EntryFunctionCall {
association_auth_key,
genesis_auth_key,
chain_id,
_genesis_timestamp,
genesis_timestamp,
uncle_rate_target,
epoch_block_count,
base_block_time_target,
Expand Down Expand Up @@ -2170,7 +2170,7 @@ pub fn stc_genesis_initialize(
association_auth_key: Vec<u8>,
genesis_auth_key: Vec<u8>,
chain_id: u8,
_genesis_timestamp: u64,
genesis_timestamp: u64,
uncle_rate_target: u64,
epoch_block_count: u64,
base_block_time_target: u64,
Expand Down Expand Up @@ -2211,7 +2211,7 @@ pub fn stc_genesis_initialize(
bcs::to_bytes(&association_auth_key).unwrap(),
bcs::to_bytes(&genesis_auth_key).unwrap(),
bcs::to_bytes(&chain_id).unwrap(),
bcs::to_bytes(&_genesis_timestamp).unwrap(),
bcs::to_bytes(&genesis_timestamp).unwrap(),
bcs::to_bytes(&uncle_rate_target).unwrap(),
bcs::to_bytes(&epoch_block_count).unwrap(),
bcs::to_bytes(&base_block_time_target).unwrap(),
Expand Down Expand Up @@ -3211,7 +3211,7 @@ mod decoder {
association_auth_key: bcs::from_bytes(script.args().get(7)?).ok()?,
genesis_auth_key: bcs::from_bytes(script.args().get(8)?).ok()?,
chain_id: bcs::from_bytes(script.args().get(9)?).ok()?,
_genesis_timestamp: bcs::from_bytes(script.args().get(10)?).ok()?,
genesis_timestamp: bcs::from_bytes(script.args().get(10)?).ok()?,
uncle_rate_target: bcs::from_bytes(script.args().get(11)?).ok()?,
epoch_block_count: bcs::from_bytes(script.args().get(12)?).ok()?,
base_block_time_target: bcs::from_bytes(script.args().get(13)?).ok()?,
Expand Down
3 changes: 1 addition & 2 deletions vm/framework/starcoin-framework/doc/stc_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Block module provide metadata for generated blocks.
<b>use</b> <a href="epoch.md#0x1_epoch">0x1::epoch</a>;
<b>use</b> <a href="../../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
<b>use</b> <a href="event.md#0x1_event">0x1::event</a>;
<b>use</b> <a href="../../move-stdlib/doc/signer.md#0x1_signer">0x1::signer</a>;
<b>use</b> <a href="starcoin_coin.md#0x1_starcoin_coin">0x1::starcoin_coin</a>;
<b>use</b> <a href="stc_transaction_fee.md#0x1_stc_transaction_fee">0x1::stc_transaction_fee</a>;
<b>use</b> <a href="../../move-stdlib/doc/string.md#0x1_string">0x1::string</a>;
Expand Down Expand Up @@ -392,7 +391,7 @@ The runtime always runs this before executing the transactions in a block.
// then deal <b>with</b> current block.
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"<a href="stc_block.md#0x1_stc_block_block_prologue">stc_block::block_prologue</a> | <a href="timestamp.md#0x1_timestamp_update_global_time">timestamp::update_global_time</a>"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="timestamp.md#0x1_timestamp">timestamp</a>);
<a href="timestamp.md#0x1_timestamp_update_global_time">timestamp::update_global_time</a>(&<a href="account.md#0x1_account">account</a>, <a href="../../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(&<a href="account.md#0x1_account">account</a>), <a href="timestamp.md#0x1_timestamp">timestamp</a> * 1000);
<a href="timestamp.md#0x1_timestamp_update_global_time">timestamp::update_global_time</a>(&<a href="account.md#0x1_account">account</a>, <a href="timestamp.md#0x1_timestamp">timestamp</a> * 1000);

<a href="stc_block.md#0x1_stc_block_process_block_metadata">process_block_metadata</a>(
&<a href="account.md#0x1_account">account</a>,
Expand Down
6 changes: 3 additions & 3 deletions vm/framework/starcoin-framework/doc/stc_genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The module for init Genesis



<pre><code><b>public</b> entry <b>fun</b> <a href="stc_genesis.md#0x1_stc_genesis_initialize">initialize</a>(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: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, association_auth_key: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, genesis_auth_key: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, <a href="chain_id.md#0x1_chain_id">chain_id</a>: 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: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, voting_delay: u64, voting_period: u64, voting_quorum_rate: u8, min_action_delay: u64, transaction_timeout: u64, dag_effective_height: u64, <a href="../../move-stdlib/doc/features.md#0x1_features">features</a>: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;)
<pre><code><b>public</b> entry <b>fun</b> <a href="stc_genesis.md#0x1_stc_genesis_initialize">initialize</a>(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: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, association_auth_key: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, genesis_auth_key: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, <a href="chain_id.md#0x1_chain_id">chain_id</a>: 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: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, voting_delay: u64, voting_period: u64, voting_quorum_rate: u8, min_action_delay: u64, transaction_timeout: u64, dag_effective_height: u64, <a href="../../move-stdlib/doc/features.md#0x1_features">features</a>: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;)
</code></pre>


Expand All @@ -80,7 +80,7 @@ The module for init Genesis
association_auth_key: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;,
genesis_auth_key: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;,
<a href="chain_id.md#0x1_chain_id">chain_id</a>: u8,
_genesis_timestamp: u64,
genesis_timestamp: u64,
//consensus config
uncle_rate_target: u64,
epoch_block_count: u64,
Expand Down Expand Up @@ -127,7 +127,7 @@ The module for init Genesis
<a href="aggregator_factory.md#0x1_aggregator_factory_initialize_aggregator_factory">aggregator_factory::initialize_aggregator_factory</a>(&starcoin_framework_account);

// Init <b>global</b> time
<a href="timestamp.md#0x1_timestamp_set_time_has_started">timestamp::set_time_has_started</a>(&starcoin_framework_account);
<a href="timestamp.md#0x1_timestamp_set_time_has_started">timestamp::set_time_has_started</a>(&starcoin_framework_account, genesis_timestamp * 1000);

<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"<a href="stc_genesis.md#0x1_stc_genesis_initialize">stc_genesis::initialize</a> | <a href="chain_id.md#0x1_chain_id">chain_id</a>: "));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="chain_id.md#0x1_chain_id">chain_id</a>);
Expand Down
19 changes: 5 additions & 14 deletions vm/framework/starcoin-framework/doc/timestamp.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Conversion factor between seconds and microseconds
Marks that time has started. This can only be called from genesis and with the starcoin framework account.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="timestamp.md#0x1_timestamp_set_time_has_started">set_time_has_started</a>(starcoin_framework: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="timestamp.md#0x1_timestamp_set_time_has_started">set_time_has_started</a>(starcoin_framework: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, microseconds: u64)
</code></pre>


Expand All @@ -119,9 +119,9 @@ Marks that time has started. This can only be called from genesis and with the s
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="timestamp.md#0x1_timestamp_set_time_has_started">set_time_has_started</a>(starcoin_framework: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>) {
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="timestamp.md#0x1_timestamp_set_time_has_started">set_time_has_started</a>(starcoin_framework: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, microseconds: u64) {
<a href="system_addresses.md#0x1_system_addresses_assert_starcoin_framework">system_addresses::assert_starcoin_framework</a>(starcoin_framework);
<b>let</b> timer = <a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">CurrentTimeMicroseconds</a> { microseconds: 0 };
<b>let</b> timer = <a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">CurrentTimeMicroseconds</a> { microseconds };
<b>move_to</b>(starcoin_framework, timer);
}
</code></pre>
Expand All @@ -137,7 +137,7 @@ Marks that time has started. This can only be called from genesis and with the s
Updates the wall clock time by consensus. Requires VM privilege and will be invoked during block prologue.


<pre><code><b>public</b> <b>fun</b> <a href="timestamp.md#0x1_timestamp_update_global_time">update_global_time</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, _proposer: <b>address</b>, <a href="timestamp.md#0x1_timestamp">timestamp</a>: u64)
<pre><code><b>public</b> <b>fun</b> <a href="timestamp.md#0x1_timestamp_update_global_time">update_global_time</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, <a href="timestamp.md#0x1_timestamp">timestamp</a>: u64)
</code></pre>


Expand All @@ -148,7 +148,6 @@ Updates the wall clock time by consensus. Requires VM privilege and will be invo

<pre><code><b>public</b> <b>fun</b> <a href="timestamp.md#0x1_timestamp_update_global_time">update_global_time</a>(
<a href="account.md#0x1_account">account</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
_proposer: <b>address</b>,
<a href="timestamp.md#0x1_timestamp">timestamp</a>: u64
) <b>acquires</b> <a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">CurrentTimeMicroseconds</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"<a href="timestamp.md#0x1_timestamp_update_global_time">timestamp::update_global_time</a> | Entered"));
Expand All @@ -159,17 +158,11 @@ Updates the wall clock time by consensus. Requires VM privilege and will be invo
<a href="system_addresses.md#0x1_system_addresses_assert_starcoin_framework">system_addresses::assert_starcoin_framework</a>(<a href="account.md#0x1_account">account</a>);

<b>let</b> global_timer = <b>borrow_global_mut</b>&lt;<a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">CurrentTimeMicroseconds</a>&gt;(@starcoin_framework);
//<b>let</b> now = global_timer.microseconds;
// <b>if</b> (proposer == @starcoin_framework) {
// // NIL block <b>with</b> null <b>address</b> <b>as</b> proposer. Timestamp must be equal.
// <b>assert</b>!(now == <a href="timestamp.md#0x1_timestamp">timestamp</a>, <a href="../../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="timestamp.md#0x1_timestamp_EINVALID_TIMESTAMP">EINVALID_TIMESTAMP</a>));
// } <b>else</b> {
// Normal block. Time must advance
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"<a href="timestamp.md#0x1_timestamp_update_global_time">timestamp::update_global_time</a> | Current <b>global</b> time: "));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&global_timer.microseconds);
<b>assert</b>!(global_timer.microseconds &lt; <a href="timestamp.md#0x1_timestamp">timestamp</a>, <a href="../../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="timestamp.md#0x1_timestamp_EINVALID_TIMESTAMP">EINVALID_TIMESTAMP</a>));
global_timer.microseconds = <a href="timestamp.md#0x1_timestamp">timestamp</a>;
//};

<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"<a href="timestamp.md#0x1_timestamp_update_global_time">timestamp::update_global_time</a> | Exited"));
}
Expand Down Expand Up @@ -326,15 +319,13 @@ Gets the current time in seconds.
### Function `update_global_time`


<pre><code><b>public</b> <b>fun</b> <a href="timestamp.md#0x1_timestamp_update_global_time">update_global_time</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, _proposer: <b>address</b>, <a href="timestamp.md#0x1_timestamp">timestamp</a>: u64)
<pre><code><b>public</b> <b>fun</b> <a href="timestamp.md#0x1_timestamp_update_global_time">update_global_time</a>(<a href="account.md#0x1_account">account</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, <a href="timestamp.md#0x1_timestamp">timestamp</a>: u64)
</code></pre>




<pre><code><b>requires</b> <a href="chain_status.md#0x1_chain_status_is_operating">chain_status::is_operating</a>();
<b>include</b> <a href="timestamp.md#0x1_timestamp_UpdateGlobalTimeAbortsIf">UpdateGlobalTimeAbortsIf</a>;
<b>ensures</b> (_proposer != @vm_reserved) ==&gt; (<a href="timestamp.md#0x1_timestamp_spec_now_microseconds">spec_now_microseconds</a>() == <a href="timestamp.md#0x1_timestamp">timestamp</a>);
</code></pre>


Expand Down
3 changes: 1 addition & 2 deletions vm/framework/starcoin-framework/sources/stc/stc_block.move
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Block module provide metadata for generated blocks.
module starcoin_framework::stc_block {
use std::error;
use std::signer;
use std::vector;

use starcoin_framework::account;
Expand Down Expand Up @@ -146,7 +145,7 @@ module starcoin_framework::stc_block {
// then deal with current block.
debug::print(&std::string::utf8(b"stc_block::block_prologue | timestamp::update_global_time"));
debug::print(&timestamp);
timestamp::update_global_time(&account, signer::address_of(&account), timestamp * 1000);
timestamp::update_global_time(&account, timestamp * 1000);

process_block_metadata(
&account,
Expand Down
4 changes: 2 additions & 2 deletions vm/framework/starcoin-framework/sources/stc/stc_genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module starcoin_framework::stc_genesis {
association_auth_key: vector<u8>,
genesis_auth_key: vector<u8>,
chain_id: u8,
_genesis_timestamp: u64,
genesis_timestamp: u64,
//consensus config
uncle_rate_target: u64,
epoch_block_count: u64,
Expand Down Expand Up @@ -103,7 +103,7 @@ module starcoin_framework::stc_genesis {
aggregator_factory::initialize_aggregator_factory(&starcoin_framework_account);

// Init global time
timestamp::set_time_has_started(&starcoin_framework_account);
timestamp::set_time_has_started(&starcoin_framework_account, genesis_timestamp * 1000);

debug::print(&std::string::utf8(b"stc_genesis::initialize | chain_id: "));
debug::print(&chain_id);
Expand Down
13 changes: 3 additions & 10 deletions vm/framework/starcoin-framework/sources/timestamp.move
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ module starcoin_framework::timestamp {
const EINVALID_TIMESTAMP: u64 = 1014;

/// Marks that time has started. This can only be called from genesis and with the starcoin framework account.
public(friend) fun set_time_has_started(starcoin_framework: &signer) {
public(friend) fun set_time_has_started(starcoin_framework: &signer, microseconds: u64) {
system_addresses::assert_starcoin_framework(starcoin_framework);
let timer = CurrentTimeMicroseconds { microseconds: 0 };
let timer = CurrentTimeMicroseconds { microseconds };
move_to(starcoin_framework, timer);
}

/// Updates the wall clock time by consensus. Requires VM privilege and will be invoked during block prologue.
public fun update_global_time(
account: &signer,
_proposer: address,
timestamp: u64
) acquires CurrentTimeMicroseconds {
debug::print(&std::string::utf8(b"timestamp::update_global_time | Entered"));
Expand All @@ -48,25 +47,19 @@ module starcoin_framework::timestamp {
system_addresses::assert_starcoin_framework(account);

let global_timer = borrow_global_mut<CurrentTimeMicroseconds>(@starcoin_framework);
//let now = global_timer.microseconds;
// if (proposer == @starcoin_framework) {
// // NIL block with null address as proposer. Timestamp must be equal.
// assert!(now == timestamp, error::invalid_argument(EINVALID_TIMESTAMP));
// } else {
// Normal block. Time must advance
debug::print(&std::string::utf8(b"timestamp::update_global_time | Current global time: "));
debug::print(&global_timer.microseconds);
assert!(global_timer.microseconds < timestamp, error::invalid_argument(EINVALID_TIMESTAMP));
global_timer.microseconds = timestamp;
//};

debug::print(&std::string::utf8(b"timestamp::update_global_time | Exited"));
}

#[test_only]
public fun set_time_has_started_for_testing(account: &signer) {
if (!exists<CurrentTimeMicroseconds>(@starcoin_framework)) {
set_time_has_started(account);
set_time_has_started(account, 0);
};
}

Expand Down
4 changes: 2 additions & 2 deletions vm/framework/starcoin-framework/sources/timestamp.spec.move
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ spec starcoin_framework::timestamp {
spec update_global_time {
use starcoin_framework::chain_status;
requires chain_status::is_operating();
include UpdateGlobalTimeAbortsIf;
ensures (_proposer != @vm_reserved) ==> (spec_now_microseconds() == timestamp);
// include UpdateGlobalTimeAbortsIf;
//ensures (_proposer != @vm_reserved) ==> (spec_now_microseconds() == timestamp);
}

spec schema UpdateGlobalTimeAbortsIf {
Expand Down
Binary file modified vm/stdlib/compiled/latest/stdlib/034_timestamp.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/108_stc_block.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/109_stc_genesis.mv
Binary file not shown.

0 comments on commit 0870220

Please sign in to comment.