diff --git a/rollup/src/lib.rs b/rollup/src/lib.rs index c901882..6f93ad7 100644 --- a/rollup/src/lib.rs +++ b/rollup/src/lib.rs @@ -1,4 +1,6 @@ mod transaction; +use std::time::Duration; + use transaction::WithdrawalTxData; pub use transaction::{SignedTransaction, Transaction}; @@ -18,5 +20,5 @@ use blockchain::Blockchain; mod address; pub use address::Address; -pub const BLOCK_PERIOD_MILLIS: u64 = 2000; +pub const BLOCK_PERIOD: Duration = Duration::from_secs(2); pub const CHAIN_ID: u64 = 83479; diff --git a/rollup/src/sequencer.rs b/rollup/src/sequencer.rs index aebb6a2..e80a71c 100644 --- a/rollup/src/sequencer.rs +++ b/rollup/src/sequencer.rs @@ -3,12 +3,11 @@ use std::{ pin::Pin, sync::{Arc, Mutex}, task::{Context, Poll}, - time::Duration, }; use crate::{ Block, BlockHeader, Blockchain, SignedBlockHeader, SignedTransaction, Signer, Transaction, - BLOCK_PERIOD_MILLIS, + BLOCK_PERIOD, }; /// Permissioned entity responsible for maintaining the canonical [Blockchain]. @@ -34,7 +33,7 @@ impl Sequencer { blockchain: Blockchain::default(), transactions_pool: vec![], withdrawals_pool: vec![], - block_timer: tokio::time::interval(Duration::from_millis(BLOCK_PERIOD_MILLIS)), + block_timer: tokio::time::interval(BLOCK_PERIOD), } } diff --git a/script/src/main.rs b/script/src/main.rs index b986e31..ef03563 100644 --- a/script/src/main.rs +++ b/script/src/main.rs @@ -1,4 +1,4 @@ -use rollup::{Block, SignedTransaction, Signer, Transaction, BLOCK_PERIOD_MILLIS}; +use rollup::{Block, SignedTransaction, Signer, Transaction, BLOCK_PERIOD}; use secp256k1::SecretKey; use tokio::process::Command; @@ -38,13 +38,13 @@ async fn handle_request_err(e: reqwest::Error) { } else { println!("Error sending transaction: {:?}", e); } - tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; + tokio::time::sleep(BLOCK_PERIOD).await; } /// Infinitely sends transactions to the sequencer. async fn tx_loop() { // Wait for the sequencer to start. - tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; + tokio::time::sleep(BLOCK_PERIOD).await; for i in 0.. { // Send a deposit transaction. let signer = Signer::random(); @@ -65,13 +65,13 @@ async fn tx_loop() { } // Wait before sending the next transactions. - tokio::time::sleep(tokio::time::Duration::from_millis(BLOCK_PERIOD_MILLIS / 4)).await; + tokio::time::sleep(BLOCK_PERIOD / 4).await; } } async fn head_loop() { // Wait for some blocks. - tokio::time::sleep(tokio::time::Duration::from_millis(BLOCK_PERIOD_MILLIS * 2)).await; + tokio::time::sleep(BLOCK_PERIOD * 2).await; loop { // Get the head block from the sequencer. match reqwest::get(&format!("http://{}/", SEQUENCER_URL)).await { @@ -92,7 +92,7 @@ async fn head_loop() { println!("Error getting head block: {:?}", e); } } - tokio::time::sleep(tokio::time::Duration::from_millis(BLOCK_PERIOD_MILLIS)).await; + tokio::time::sleep(BLOCK_PERIOD).await; } }