Skip to content

Commit

Permalink
Add and make local network as default chainid (#853)
Browse files Browse the repository at this point in the history
* new and make local network as default chainid

* change all dev to local chain id for integration test and other tests

* opt sequencer order check error when server start

* remove sequencer order check

* fixup sdk test case

* Revert "new and make local network as default chainid"

This reverts commit af6f2ec.

* fixup chain id and dev timestamp

* fixup chain id and dev timestamp

* modify default env alias

* make local as default chain for env
  • Loading branch information
baichuan3 authored Sep 25, 2023
1 parent 0daecbb commit 8cbd965
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 60 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ better_any = "0.1.1"
bitcoin = "0.30.1"
bip32 = "0.4.0"
byteorder = "1.4.3"
clap = { version = "3.2.17", features = ["derive"] }
clap = { version = "3.2.23", features = ["derive"] }
chrono = "0.4.23"
coerce = "0.8"
datatest-stable = "0.1.3"
Expand Down
10 changes: 5 additions & 5 deletions crates/rooch-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct RoochOpt {
/// Path to data dir, this dir is base dir, the final data_dir is base_dir/chain_network_name
pub base_data_dir: Option<PathBuf>,

/// If dev chainid, start the service with a temporary data store.
/// If local chainid, start the service with a temporary data store.
/// All data will be deleted when the service is stopped.
#[serde(skip_serializing_if = "Option::is_none")]
#[clap(long, short = 'n', help = R_OPT_NET_HELP)]
Expand Down Expand Up @@ -98,7 +98,7 @@ impl RoochOpt {
pub fn new_with_temp_store() -> Self {
RoochOpt {
base_data_dir: None,
chain_id: Some(RoochChainID::DEV),
chain_id: Some(RoochChainID::LOCAL),
store: StoreConfig::default(),
port: None,
eth_rpc_url: None,
Expand All @@ -119,14 +119,14 @@ impl BaseConfig {
let base_data_dir = match opt.base_data_dir.clone() {
Some(base_data_dir) if base_data_dir.to_str() == Some("TMP") => temp_dir(),
Some(base_data_dir) => DataDirPath::PathBuf(base_data_dir),
// only dev mode use temp store dir
None if chain_id.is_dev() => temp_dir(),
// only local network use temp store dir
None if chain_id.is_local() => temp_dir(),
None => DataDirPath::PathBuf(R_DEFAULT_BASE_DATA_DIR.to_path_buf()),
};

let data_dir = base_data_dir.as_ref().join(chain_id.dir_name());
if !data_dir.exists() {
create_dir_all(data_dir.as_path())?;
create_dir_all(data_dir.as_path())?
}

Ok(Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-framework-tests/src/binding_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl RustBindingTest {
let moveos_store = MoveOSStore::mock_moveos_store()?;
let rooch_store = RoochStore::mock_rooch_store()?;
let executor =
ExecutorActor::new(RoochChainID::DEV.genesis_ctx(), moveos_store, rooch_store)?;
ExecutorActor::new(RoochChainID::LOCAL.genesis_ctx(), moveos_store, rooch_store)?;
Ok(Self { executor })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn test_session_key_rooch() {

// test session key expired
let update_time_action =
TimestampModule::create_fast_forward_seconds_for_dev_action(max_inactive_interval + 1);
TimestampModule::create_fast_forward_seconds_for_local_action(max_inactive_interval + 1);
// because previous transaction is failed, so the sequence number is not increased.
let tx_data =
RoochTransactionData::new_for_test(sender, sequence_number + 2, update_time_action);
Expand Down
34 changes: 34 additions & 0 deletions crates/rooch-framework/doc/chain_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Constants](#@Constants_0)
- [Function `genesis_init`](#0x3_chain_id_genesis_init)
- [Function `chain_id`](#0x3_chain_id_chain_id)
- [Function `is_local`](#0x3_chain_id_is_local)
- [Function `is_dev`](#0x3_chain_id_is_dev)
- [Function `is_test`](#0x3_chain_id_is_test)
- [Function `is_main`](#0x3_chain_id_is_main)
Expand Down Expand Up @@ -62,6 +63,15 @@ The ChainID in the global storage



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



<pre><code><b>const</b> <a href="chain_id.md#0x3_chain_id_CHAIN_ID_LOCAL">CHAIN_ID_LOCAL</a>: u64 = 20230104;
</code></pre>



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


Expand Down Expand Up @@ -130,6 +140,30 @@ The ChainID in the global storage



</details>

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

## Function `is_local`



<pre><code><b>public</b> <b>fun</b> <a href="chain_id.md#0x3_chain_id_is_local">is_local</a>(ctx: &<a href="_StorageContext">storage_context::StorageContext</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="chain_id.md#0x3_chain_id_is_local">is_local</a>(ctx: &StorageContext) : bool {
<a href="chain_id.md#0x3_chain_id">chain_id</a>(ctx) == <a href="chain_id.md#0x3_chain_id_CHAIN_ID_LOCAL">CHAIN_ID_LOCAL</a>
}
</code></pre>



</details>

<a name="0x3_chain_id_is_dev"></a>
Expand Down
14 changes: 7 additions & 7 deletions crates/rooch-framework/doc/timestamp.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It interacts with the other modules in the following ways:
- [Function `now_microseconds`](#0x3_timestamp_now_microseconds)
- [Function `now_seconds`](#0x3_timestamp_now_seconds)
- [Function `seconds_to_microseconds`](#0x3_timestamp_seconds_to_microseconds)
- [Function `fast_forward_seconds_for_dev`](#0x3_timestamp_fast_forward_seconds_for_dev)
- [Function `fast_forward_seconds_for_local`](#0x3_timestamp_fast_forward_seconds_for_local)


<pre><code><b>use</b> <a href="">0x1::error</a>;
Expand Down Expand Up @@ -241,14 +241,14 @@ Gets the current time in seconds.

</details>

<a name="0x3_timestamp_fast_forward_seconds_for_dev"></a>
<a name="0x3_timestamp_fast_forward_seconds_for_local"></a>

## Function `fast_forward_seconds_for_dev`
## Function `fast_forward_seconds_for_local`

Fast forwards the clock by the given number of seconds, but only if the chain is in dev mode.
Fast forwards the clock by the given number of seconds, but only if the chain is in local mode.


<pre><code><b>public</b> entry <b>fun</b> <a href="timestamp.md#0x3_timestamp_fast_forward_seconds_for_dev">fast_forward_seconds_for_dev</a>(ctx: &<b>mut</b> <a href="_StorageContext">storage_context::StorageContext</a>, timestamp_seconds: u64)
<pre><code><b>public</b> entry <b>fun</b> <a href="timestamp.md#0x3_timestamp_fast_forward_seconds_for_local">fast_forward_seconds_for_local</a>(ctx: &<b>mut</b> <a href="_StorageContext">storage_context::StorageContext</a>, timestamp_seconds: u64)
</code></pre>


Expand All @@ -257,8 +257,8 @@ Fast forwards the clock by the given number of seconds, but only if the chain is
<summary>Implementation</summary>


<pre><code><b>public</b> entry <b>fun</b> <a href="timestamp.md#0x3_timestamp_fast_forward_seconds_for_dev">fast_forward_seconds_for_dev</a>(ctx: &<b>mut</b> StorageContext, timestamp_seconds: u64) {
<b>assert</b>!(rooch_framework::chain_id::is_dev(ctx), <a href="_invalid_argument">error::invalid_argument</a>(<a href="timestamp.md#0x3_timestamp_ErrorInvalidTimestamp">ErrorInvalidTimestamp</a>));
<pre><code><b>public</b> entry <b>fun</b> <a href="timestamp.md#0x3_timestamp_fast_forward_seconds_for_local">fast_forward_seconds_for_local</a>(ctx: &<b>mut</b> StorageContext, timestamp_seconds: u64) {
<b>assert</b>!(rooch_framework::chain_id::is_local(ctx), <a href="_invalid_argument">error::invalid_argument</a>(<a href="timestamp.md#0x3_timestamp_ErrorInvalidTimestamp">ErrorInvalidTimestamp</a>));
<a href="timestamp.md#0x3_timestamp_fast_forward_seconds">fast_forward_seconds</a>(ctx, timestamp_seconds);
}
</code></pre>
Expand Down
5 changes: 5 additions & 0 deletions crates/rooch-framework/sources/chain_id.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module rooch_framework::chain_id {

friend rooch_framework::genesis;

const CHAIN_ID_LOCAL: u64 = 20230104;
const CHAIN_ID_DEV: u64 = 20230103;
const CHAIN_ID_TEST: u64 = 20230102;
const CHAIN_ID_MAIN: u64 = 20230101;
Expand All @@ -26,6 +27,10 @@ module rooch_framework::chain_id {
chain_id.id
}

public fun is_local(ctx: &StorageContext) : bool {
chain_id(ctx) == CHAIN_ID_LOCAL
}

public fun is_dev(ctx: &StorageContext) : bool {
chain_id(ctx) == CHAIN_ID_DEV
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rooch-framework/sources/timestamp.move
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ module rooch_framework::timestamp {
update_global_time(ctx, now_microseconds + (timestamp_seconds * MICRO_CONVERSION_FACTOR));
}

/// Fast forwards the clock by the given number of seconds, but only if the chain is in dev mode.
//TODO find a better way to do this, maybe some module that is only available in dev chain?
public entry fun fast_forward_seconds_for_dev(ctx: &mut StorageContext, timestamp_seconds: u64) {
assert!(rooch_framework::chain_id::is_dev(ctx), error::invalid_argument(ErrorInvalidTimestamp));
/// Fast forwards the clock by the given number of seconds, but only if the chain is in local mode.
//TODO find a better way to do this, maybe some module that is only available in local chain?
public entry fun fast_forward_seconds_for_local(ctx: &mut StorageContext, timestamp_seconds: u64) {
assert!(rooch_framework::chain_id::is_local(ctx), error::invalid_argument(ErrorInvalidTimestamp));
fast_forward_seconds(ctx, timestamp_seconds);
}
}
6 changes: 3 additions & 3 deletions crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ use std::{
path::{Path, PathBuf},
};

pub static ROOCH_DEV_GENESIS: Lazy<RoochGenesis> = Lazy::new(|| {
pub static ROOCH_LOCAL_GENESIS: Lazy<RoochGenesis> = Lazy::new(|| {
// genesis for integration test, we need to build the stdlib every time for `private_generic` check
// see moveos/moveos-verifier/src/metadata.rs#L27-L30
RoochGenesis::build_with_option(RoochChainID::DEV.genesis_ctx(), BuildOption::Fresh)
RoochGenesis::build_with_option(RoochChainID::LOCAL.genesis_ctx(), BuildOption::Fresh)
.expect("build rooch genesis failed")
});

Expand Down Expand Up @@ -264,7 +264,7 @@ mod tests {
#[test]
fn test_genesis_init() {
let genesis = super::RoochGenesis::build_with_option(
RoochChainID::DEV.genesis_ctx(),
RoochChainID::LOCAL.genesis_ctx(),
crate::BuildOption::Fresh,
)
.expect("build rooch framework failed");
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-integration-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> MoveOSTestAdapter<'a> for MoveOSTestRunner<'a> {

let moveos_store = MoveOSStore::mock_moveos_store().unwrap();

let genesis: &RoochGenesis = &rooch_genesis::ROOCH_DEV_GENESIS;
let genesis: &RoochGenesis = &rooch_genesis::ROOCH_LOCAL_GENESIS;
let mut moveos = MoveOS::new(
moveos_store,
genesis.all_natives(),
Expand Down
20 changes: 15 additions & 5 deletions crates/rooch-rpc-client/src/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use serde_with::serde_as;
use std::fmt::{Display, Formatter, Write};

pub const DEFAULT_EXPIRATION_SECS: u64 = 30;
pub const ROOCH_TEST_NET_URL: &str = "https://dev-seed.rooch.network/";
pub const ROOCH_DEV_NET_URL: &str = "https://dev-seed.rooch.network/";
pub const ROOCH_TEST_NET_URL: &str = "https://test-seed.rooch.network/";

#[serde_as]
#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -91,10 +92,19 @@ impl Env {
builder.build(&self.rpc).await
}

pub fn testnet() -> Self {
pub fn new_dev_env() -> Self {
Self {
chain_id: RoochChainID::DEV.chain_id().id(),
alias: RoochChainID::DEV.chain_name().to_lowercase(),
rpc: ROOCH_DEV_NET_URL.into(),
ws: None,
}
}

pub fn new_test_env() -> Self {
Self {
chain_id: RoochChainID::TEST.chain_id().id(),
alias: "test".to_string(),
alias: RoochChainID::TEST.chain_name().to_lowercase(),
rpc: ROOCH_TEST_NET_URL.into(),
ws: None,
}
Expand All @@ -104,8 +114,8 @@ impl Env {
impl Default for Env {
fn default() -> Self {
Env {
chain_id: RoochChainID::DEV.chain_id().id(),
alias: "default".to_string(),
chain_id: RoochChainID::LOCAL.chain_id().id(),
alias: RoochChainID::LOCAL.chain_name().to_lowercase(),
rpc: ServerConfig::default().url(false),
ws: None,
}
Expand Down
1 change: 1 addition & 0 deletions crates/rooch-sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tracing-subscriber = { workspace = true }
schemars = { workspace = true }
serde_with = { workspace = true }
parking_lot = { workspace = true }
log = { workspace = true }

move-core-types = { workspace = true }
move-resource-viewer = { workspace = true }
Expand Down
13 changes: 5 additions & 8 deletions crates/rooch-sequencer/src/actor/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rooch_types::{
transaction::{TransactionSequenceInfo, TypedTransaction},
H256,
};
use tracing::info;

pub struct SequencerActor {
last_order: u128,
Expand All @@ -33,18 +34,14 @@ impl SequencerActor {
pub fn new(
sequencer_key: RoochKeyPair,
rooch_store: RoochStore,
is_genesis: bool,
_is_genesis: bool,
) -> Result<Self> {
let last_order = rooch_store
let last_order_opt = rooch_store
.get_meta_store()
.get_sequencer_order()?
.map(|order| order.last_order);
let last_order = if is_genesis {
last_order.unwrap_or(0u128)
} else {
last_order.expect("Invalid sequencer order")
};

let last_order = last_order_opt.unwrap_or(0u128);
info!("Load latest sequencer order {:?}", last_order);
Ok(Self {
last_order,
sequencer_key,
Expand Down
Loading

0 comments on commit 8cbd965

Please sign in to comment.