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

skip epochs at the beginning #70

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion Node/Cargo.lock

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

1 change: 1 addition & 0 deletions Node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ chrono = "0.4"
p2p-network = { path = "../p2pNode/p2pNetwork" }
bincode = "1.3"
serde_bytes = "0.11"
fs2 = "0.4"

[dev-dependencies]
mockito = "1.4"
6 changes: 6 additions & 0 deletions Node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const MESSAGE_QUEUE_SIZE: usize = 100;
async fn main() -> Result<(), Error> {
init_logging();
let config = utils::config::Config::read_env_variables();
let state_file = utils::state_file::State::read_state_file(&config.state_file_path)
.map_err(|e| anyhow::anyhow!(format!("reading state file: {}", e)))?;

if !state_file.registered {
return Err(anyhow::anyhow!("Node is not registered, exiting"));
}

let (node_to_p2p_tx, node_to_p2p_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
let (p2p_to_node_tx, p2p_to_node_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
Expand Down
3 changes: 2 additions & 1 deletion Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Node {
gas_used: 0,
ethereum_l1,
_mev_boost: mev_boost,
epoch: Epoch::MAX, // it'll be updated in the first preconfirmation loop
epoch: Epoch::MAX, // it'll be updated in the first preconfirmation loop step
lookahead: vec![],
l2_slot_duration_sec,
validator_pubkey,
Expand Down Expand Up @@ -169,6 +169,7 @@ impl Node {
current_epoch
);
self.epoch = current_epoch;

self.current_slot_to_preconf = self.next_slot_to_preconf;
self.lookahead = self
.ethereum_l1
Expand Down
7 changes: 7 additions & 0 deletions Node/src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Config {
pub preconf_registry_expiry_sec: u64,
pub contract_addresses: ContractAddresses,
pub p2p_network_config: P2PNetworkConfig,
pub state_file_path: String,
}

#[derive(Debug)]
Expand Down Expand Up @@ -195,6 +196,9 @@ impl Config {
boot_nodes,
};

let state_file_path =
std::env::var("STATE_FILE_PATH").unwrap_or("/tmp/avs_node_state.json".to_string());

let config = Self {
taiko_proposer_url: std::env::var("TAIKO_PROPOSER_URL")
.unwrap_or("http://127.0.0.1:1234".to_string()),
Expand All @@ -214,6 +218,7 @@ impl Config {
preconf_registry_expiry_sec,
contract_addresses,
p2p_network_config,
state_file_path,
};

info!(
Expand All @@ -231,6 +236,7 @@ Block proposed receiver timeout: {}
Preconf registry expiry seconds: {}
Contract addresses: {:#?}
p2p_network_config: {}
State file path: {}
"#,
config.taiko_proposer_url,
config.taiko_driver_url,
Expand All @@ -244,6 +250,7 @@ p2p_network_config: {}
config.preconf_registry_expiry_sec,
config.contract_addresses,
config.p2p_network_config,
config.state_file_path,
);

config
Expand Down
31 changes: 31 additions & 0 deletions Node/src/utils/file_lock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use anyhow::Error;
use fs2::FileExt;
use std::fs::File;

pub struct FileLock {
file: File,
}

impl FileLock {
pub fn new_shared(path: &str) -> Result<Self, Error> {
let file = File::open(path)?;
file.lock_shared()?;
Ok(FileLock { file })
}

#[allow(dead_code)] //TODO: remove when used from the CLI
pub fn new_exclusive(file: File) -> Result<Self, Error> {
file.lock_exclusive()?;
Ok(FileLock { file })
}

pub fn get_file(&self) -> &File {
&self.file
}
}

impl Drop for FileLock {
fn drop(&mut self) {
let _ = self.file.unlock();
}
}
2 changes: 2 additions & 0 deletions Node/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ pub mod block;
pub mod block_proposed;
pub mod commit;
pub mod config;
mod file_lock;
pub mod rpc_client;
pub mod rpc_server;
pub mod state_file;
16 changes: 16 additions & 0 deletions Node/src/utils/state_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use super::file_lock::FileLock;
use anyhow::Error;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct State {
pub registered: bool,
}

impl State {
pub fn read_state_file(path: &str) -> Result<Self, Error> {
let file_lock = FileLock::new_shared(path)?;
let state: State = serde_json::from_reader(file_lock.get_file())?;
Ok(state)
}
}