From 3c536d0d0e43d41b87ade7208479f64e5844f27c Mon Sep 17 00:00:00 2001 From: Austin Abell Date: Thu, 7 Jan 2021 15:46:41 -0500 Subject: [PATCH] Setup multiple network configurations and drand schedule (#915) * Base setup to allow supporting multiple networks * Fork handling logic * Update drand schedule * Move genesis to networks --- Cargo.lock | 16 +++ Cargo.toml | 1 + Makefile | 1 + blockchain/beacon/src/drand.rs | 115 ++++++++++++------ blockchain/beacon/src/lib.rs | 30 ----- blockchain/beacon/tests/drand.rs | 26 ++-- blockchain/blocks/src/header/mod.rs | 32 ++++- blockchain/chain_sync/Cargo.toml | 1 + blockchain/chain_sync/src/sync.rs | 13 +- blockchain/chain_sync/src/sync/peer_test.rs | 7 +- blockchain/chain_sync/src/sync_worker.rs | 16 ++- .../src/sync_worker/full_sync_test.rs | 15 +-- .../src/sync_worker/validate_block_test.rs | 15 +-- blockchain/state_manager/Cargo.toml | 1 + blockchain/state_manager/src/lib.rs | 14 +-- forest/Cargo.toml | 1 + forest/src/cli/config.rs | 7 +- forest/src/daemon.rs | 22 +--- node/forest_libp2p/Cargo.toml | 1 + node/forest_libp2p/src/config.rs | 19 +-- node/rpc/src/beacon_api.rs | 2 +- node/rpc/src/common_api.rs | 6 +- node/rpc/src/lib.rs | 4 +- node/rpc/src/sync_api.rs | 12 +- types/networks/Cargo.toml | 12 ++ types/networks/src/drand.rs | 15 +++ types/networks/src/lib.rs | 49 ++++++++ .../networks}/src/mainnet/genesis.car | Bin types/networks/src/mainnet/mod.rs | 107 ++++++++++++++++ types/src/build_version/mod.rs | 3 - types/src/version.rs | 8 -- utils/genesis/Cargo.toml | 1 + utils/genesis/src/{mainnet => }/export40.car | Bin utils/genesis/src/lib.rs | 6 +- 34 files changed, 390 insertions(+), 188 deletions(-) create mode 100644 types/networks/Cargo.toml create mode 100644 types/networks/src/drand.rs create mode 100644 types/networks/src/lib.rs rename {utils/genesis => types/networks}/src/mainnet/genesis.car (100%) create mode 100644 types/networks/src/mainnet/mod.rs rename utils/genesis/src/{mainnet => }/export40.car (100%) diff --git a/Cargo.lock b/Cargo.lock index d352d9e141ac..d7e86d346b4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -973,6 +973,7 @@ dependencies = [ "log", "lru", "message_pool", + "networks", "num-traits 0.2.14", "pretty_env_logger", "rand 0.7.3", @@ -2090,6 +2091,7 @@ dependencies = [ "log", "message_pool", "net_utils", + "networks", "paramfetch", "pretty_env_logger", "rpc", @@ -2375,6 +2377,7 @@ dependencies = [ "libp2p-bitswap", "libp2p-request-response", "log", + "networks", "serde", "smallvec", "tiny-cid", @@ -2671,6 +2674,7 @@ dependencies = [ "ipld_blockstore", "log", "net_utils", + "networks", "state_manager", "url", ] @@ -4194,6 +4198,17 @@ dependencies = [ "url", ] +[[package]] +name = "networks" +version = "0.1.0" +dependencies = [ + "beacon", + "fil_clock", + "fil_types", + "lazy_static", + "serde_json", +] + [[package]] name = "nix" version = "0.18.0" @@ -5779,6 +5794,7 @@ dependencies = [ "lazy_static", "lazycell", "log", + "networks", "num-traits 0.2.14", "serde", "state_tree", diff --git a/Cargo.toml b/Cargo.toml index d556972d3e3e..c5f5581f3163 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ members = [ "utils/statediff", "utils/hash_utils", "types", + "types/networks", "key_management", ] diff --git a/Makefile b/Makefile index 124e77d53337..a1823692020c 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ clean: @cargo clean -p genesis @cargo clean -p actor_interface @cargo clean -p forest_hash_utils + @cargo clean -p networks @echo "Done cleaning." lint: license clean diff --git a/blockchain/beacon/src/drand.rs b/blockchain/beacon/src/drand.rs index afe8f5a4b7e3..561eab8d7338 100644 --- a/blockchain/beacon/src/drand.rs +++ b/blockchain/beacon/src/drand.rs @@ -11,14 +11,9 @@ use clock::ChainEpoch; use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize}; use sha2::Digest; use std::borrow::Cow; -use std::convert::TryFrom; use std::error; use std::sync::Arc; -/// Default endpoint for the drand beacon node. -// TODO this URL is only valid until smoke fork, should setup schedule for drand upgrade -pub const DEFAULT_DRAND_URL: &str = "https://pl-us.incentinet.drand.sh"; - /// Enviromental Variable to ignore Drand. Lotus parallel is LOTUS_IGNORE_DRAND pub const IGNORE_DRAND_VAR: &str = "IGNORE_DRAND"; @@ -35,32 +30,72 @@ impl DrandPublic { } } -pub struct Schedule(pub Vec>); +#[derive(Clone)] +pub struct DrandConfig<'a> { + pub server: &'static str, + pub chain_info: ChainInfo<'a>, +} + +pub struct BeaconSchedule(pub Vec>); -impl Schedule +impl BeaconSchedule where T: Beacon, { - pub fn beacon_for_epoch(&self, e: ChainEpoch) -> Result<&T, Box> { - if let Some(beacon_point) = self + pub async fn beacon_entries_for_block( + &self, + epoch: ChainEpoch, + parent_epoch: ChainEpoch, + prev: &BeaconEntry, + ) -> Result, Box> { + let (cb_epoch, curr_beacon) = self.beacon_for_epoch(epoch)?; + let (pb_epoch, _) = self.beacon_for_epoch(parent_epoch)?; + if cb_epoch != pb_epoch { + // Fork logic + let round = curr_beacon.max_beacon_round_for_epoch(epoch); + let mut entries = Vec::with_capacity(2); + entries.push(curr_beacon.entry(round - 1).await?); + entries.push(curr_beacon.entry(round).await?); + return Ok(entries); + } + let max_round = curr_beacon.max_beacon_round_for_epoch(epoch); + if max_round == prev.round() { + return Ok(vec![]); + } + // TODO: this is a sketchy way to handle the genesis block not having a beacon entry + let prev_round = if prev.round() == 0 { + max_round - 1 + } else { + prev.round() + }; + + let mut cur = max_round; + let mut out = Vec::new(); + while cur > prev_round { + let entry = curr_beacon.entry(cur).await?; + cur = entry.round() - 1; + out.push(entry); + } + out.reverse(); + Ok(out) + } + + pub fn beacon_for_epoch( + &self, + epoch: ChainEpoch, + ) -> Result<(ChainEpoch, &T), Box> { + Ok(self .0 .iter() .rev() - .find(|beacon| beacon.start == e) - .map(|s| &s.beacon) - { - Ok(&*beacon_point) - } else { - self.0 - .first() - .map(|s| &*s.beacon) - .ok_or_else(|| Box::from("Could not get first_value of beacon in beacon_for_epoch")) - } + .find(|upgrade| epoch >= upgrade.height) + .map(|upgrade| (upgrade.height, upgrade.beacon.as_ref())) + .ok_or("Invalid beacon schedule, no valid beacon")?) } } pub struct BeaconPoint { - pub start: ChainEpoch, + pub height: ChainEpoch, pub beacon: Arc, } @@ -83,14 +118,14 @@ where fn max_beacon_round_for_epoch(&self, fil_epoch: ChainEpoch) -> u64; } -#[derive(SerdeDeserialize, SerdeSerialize, Debug, Clone)] -pub struct ChainInfo { - public_key: String, - period: i32, - genesis_time: i32, - hash: String, +#[derive(SerdeDeserialize, SerdeSerialize, Debug, Clone, PartialEq, Default)] +pub struct ChainInfo<'a> { + pub public_key: Cow<'a, str>, + pub period: i32, + pub genesis_time: i32, + pub hash: Cow<'a, str>, #[serde(rename = "groupHash")] - group_hash: String, + pub group_hash: Cow<'a, str>, } #[derive(SerdeDeserialize, SerdeSerialize, Debug, Clone)] @@ -102,7 +137,7 @@ pub struct BeaconEntryJson { } pub struct DrandBeacon { - url: Cow<'static, str>, + url: &'static str, pub_key: DrandPublic, /// Interval between beacons, in seconds. @@ -118,26 +153,28 @@ pub struct DrandBeacon { impl DrandBeacon { /// Construct a new DrandBeacon. pub async fn new( - url: impl Into>, - pub_key: DrandPublic, genesis_ts: u64, interval: u64, + config: &DrandConfig<'_>, ) -> Result> { if genesis_ts == 0 { panic!("Genesis timestamp cannot be 0") } - let url = url.into(); - let chain_info: ChainInfo = surf::get(&format!("{}/info", &url)).recv_json().await?; - let remote_pub_key = hex::decode(chain_info.public_key)?; - if remote_pub_key != pub_key.coefficient { - return Err(Box::try_from( - "Drand pub key from config is different than one on drand servers", - )?); + + let chain_info = &config.chain_info; + + if cfg!(debug_assertions) { + let remote_chain_info: ChainInfo = surf::get(&format!("{}/info", &config.server)) + .recv_json() + .await?; + debug_assert!(&remote_chain_info == chain_info); } Ok(Self { - url, - pub_key, + url: config.server, + pub_key: DrandPublic { + coefficient: hex::decode(chain_info.public_key.as_ref())?, + }, interval: chain_info.period as u64, drand_gen_time: chain_info.genesis_time as u64, fil_round_time: interval, diff --git a/blockchain/beacon/src/lib.rs b/blockchain/beacon/src/lib.rs index f50d71c0b46d..43bad5c991f8 100644 --- a/blockchain/beacon/src/lib.rs +++ b/blockchain/beacon/src/lib.rs @@ -8,33 +8,3 @@ mod mock_beacon; pub use beacon_entries::*; pub use drand::*; pub use mock_beacon::*; - -use clock::ChainEpoch; -use std::error::Error; - -pub async fn beacon_entries_for_block( - beacon: &B, - round: ChainEpoch, - prev: &BeaconEntry, -) -> Result, Box> { - let max_round = beacon.max_beacon_round_for_epoch(round); - if max_round == prev.round() { - return Ok(vec![]); - } - // TODO: this is a sketchy way to handle the genesis block not having a beacon entry - let prev_round = if prev.round() == 0 { - max_round - 1 - } else { - prev.round() - }; - - let mut cur = max_round; - let mut out = Vec::new(); - while cur > prev_round { - let entry = beacon.entry(cur).await?; - cur = entry.round() - 1; - out.push(entry); - } - out.reverse(); - Ok(out) -} diff --git a/blockchain/beacon/tests/drand.rs b/blockchain/beacon/tests/drand.rs index 8c497e1fce7c..0f69ede32e65 100644 --- a/blockchain/beacon/tests/drand.rs +++ b/blockchain/beacon/tests/drand.rs @@ -1,19 +1,25 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use beacon::{Beacon, DrandBeacon, DrandPublic, DEFAULT_DRAND_URL}; +use beacon::{Beacon, ChainInfo, DrandBeacon, DrandConfig}; use serde::{Deserialize, Serialize}; async fn new_beacon() -> DrandBeacon { - // Current public parameters, subject to change. - let coeffs = - hex::decode("922a2e93828ff83345bae533f5172669a26c02dc76d6bf59c80892e12ab1455c229211886f35bb56af6d5bea981024df").unwrap(); - let dist_pub = DrandPublic { - coefficient: coeffs, - }; - DrandBeacon::new(DEFAULT_DRAND_URL, dist_pub, 15904451751, 25) - .await - .unwrap() + DrandBeacon::new( + 15904451751, + 25, + // TODO this could maybe be referencing existing config + &DrandConfig { + server: "https://pl-us.incentinet.drand.sh", + chain_info: ChainInfo { + public_key: "922a2e93828ff83345bae533f5172669a26c02dc76d6bf59c80892e12ab1455c229211886f35bb56af6d5bea981024df" + .into(), + ..Default::default() + }, + }, + ) + .await + .unwrap() } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/blockchain/blocks/src/header/mod.rs b/blockchain/blocks/src/header/mod.rs index 42ecc1256fb1..238fa82e8b5b 100644 --- a/blockchain/blocks/src/header/mod.rs +++ b/blockchain/blocks/src/header/mod.rs @@ -3,7 +3,7 @@ use super::{ElectionProof, Error, Ticket, TipsetKeys}; use address::Address; -use beacon::{self, Beacon, BeaconEntry}; +use beacon::{self, Beacon, BeaconEntry, BeaconSchedule}; use cid::{Cid, Code::Blake2b256}; use clock::ChainEpoch; use crypto::Signature; @@ -341,11 +341,33 @@ impl BlockHeader { /// Validates if the current header's Beacon entries are valid to ensure randomness was generated correctly pub async fn validate_block_drand( &self, - beacon: &B, + b_schedule: &BeaconSchedule, + _parent_epoch: ChainEpoch, prev_entry: &BeaconEntry, ) -> Result<(), Error> { - // TODO validation may need to use the beacon schedule from `ChainSyncer`. Seems outdated - let max_round = beacon.max_beacon_round_for_epoch(self.epoch); + let (cb_epoch, curr_beacon) = b_schedule + .beacon_for_epoch(self.epoch) + .map_err(|e| Error::Validation(e.to_string()))?; + let (pb_epoch, _) = b_schedule + .beacon_for_epoch(self.epoch) + .map_err(|e| Error::Validation(e.to_string()))?; + + if cb_epoch != pb_epoch { + // Fork logic + if self.beacon_entries.len() != 2 { + return Err(Error::Validation(format!( + "Expected two beacon entries at beacon fork, got {}", + self.beacon_entries.len() + ))); + } + + curr_beacon + .verify_entry(&self.beacon_entries[1], &self.beacon_entries[0]) + .await + .map_err(|e| Error::Validation(e.to_string()))?; + } + + let max_round = curr_beacon.max_beacon_round_for_epoch(self.epoch); if max_round == prev_entry.round() { if !self.beacon_entries.is_empty() { return Err(Error::Validation(format!( @@ -367,7 +389,7 @@ impl BlockHeader { let mut prev = prev_entry; for curr in &self.beacon_entries { - if !beacon + if !curr_beacon .verify_entry(&curr, &prev) .await .map_err(|e| Error::Validation(e.to_string()))? diff --git a/blockchain/chain_sync/Cargo.toml b/blockchain/chain_sync/Cargo.toml index dc6a6fdab690..ebcf353e3e0e 100644 --- a/blockchain/chain_sync/Cargo.toml +++ b/blockchain/chain_sync/Cargo.toml @@ -40,6 +40,7 @@ smallvec = "1.1.0" actor = { package = "actor_interface", path = "../../vm/actor_interface" } interpreter = { path = "../../vm/interpreter/" } message_pool = { path = "../message_pool" } +networks = { path = "../../types/networks" } [dev-dependencies] test_utils = { version = "0.1.0", path = "../../utils/test_utils/", features = ["test_constructors"] } diff --git a/blockchain/chain_sync/src/sync.rs b/blockchain/chain_sync/src/sync.rs index f052d6113452..0cd27526cd10 100644 --- a/blockchain/chain_sync/src/sync.rs +++ b/blockchain/chain_sync/src/sync.rs @@ -12,7 +12,7 @@ use super::{Error, SyncNetworkContext}; use amt::Amt; use async_std::sync::{channel, Mutex, Receiver, RwLock, Sender}; use async_std::task::{self, JoinHandle}; -use beacon::Beacon; +use beacon::{Beacon, BeaconSchedule}; use blocks::{Block, FullTipset, GossipBlock, Tipset, TipsetKeys, TxMeta}; use chain::ChainStore; use cid::{Cid, Code::Blake2b256}; @@ -84,7 +84,7 @@ pub struct ChainSyncer { worker_state: WorkerState, /// Drand randomness beacon - beacon: Arc, + beacon: Arc>, /// manages retrieving and updates state objects state_manager: Arc>, @@ -128,7 +128,7 @@ where { pub fn new( state_manager: Arc>, - beacon: Arc, + beacon: Arc>, mpool: Arc>, network_send: Sender, network_rx: Receiver, @@ -579,7 +579,7 @@ mod tests { use async_std::sync::channel; use async_std::sync::Sender; use async_std::task; - use beacon::MockBeacon; + use beacon::{BeaconPoint, MockBeacon}; use db::MemoryDB; use fil_types::verifier::MockVerifier; use forest_libp2p::NetworkEvent; @@ -614,7 +614,10 @@ mod tests { let gen = construct_dummy_header(); chain_store.set_genesis(&gen).unwrap(); - let beacon = Arc::new(MockBeacon::new(Duration::from_secs(1))); + let beacon = Arc::new(BeaconSchedule(vec![BeaconPoint { + height: 0, + beacon: Arc::new(MockBeacon::new(Duration::from_secs(1))), + }])); let genesis_ts = Arc::new(Tipset::new(vec![gen]).unwrap()); ( diff --git a/blockchain/chain_sync/src/sync/peer_test.rs b/blockchain/chain_sync/src/sync/peer_test.rs index 58bd7f346538..e98c47129809 100644 --- a/blockchain/chain_sync/src/sync/peer_test.rs +++ b/blockchain/chain_sync/src/sync/peer_test.rs @@ -5,7 +5,7 @@ use super::*; use address::Address; use async_std::sync::channel; use async_std::task; -use beacon::MockBeacon; +use beacon::{BeaconPoint, MockBeacon}; use blocks::BlockHeader; use db::MemoryDB; use fil_types::verifier::MockVerifier; @@ -45,7 +45,10 @@ fn peer_manager_update() { let gen_hash = chain_store.set_genesis(&dummy_header).unwrap(); let genesis_ts = Arc::new(Tipset::new(vec![dummy_header]).unwrap()); - let beacon = Arc::new(MockBeacon::new(Duration::from_secs(1))); + let beacon = Arc::new(BeaconSchedule(vec![BeaconPoint { + height: 0, + beacon: Arc::new(MockBeacon::new(Duration::from_secs(1))), + }])); let state_manager = Arc::new(StateManager::new(chain_store)); let cs = ChainSyncer::<_, _, MockVerifier, TestApi>::new( state_manager, diff --git a/blockchain/chain_sync/src/sync_worker.rs b/blockchain/chain_sync/src/sync_worker.rs index 7b2a8d8ab051..992cdaf7c75d 100644 --- a/blockchain/chain_sync/src/sync_worker.rs +++ b/blockchain/chain_sync/src/sync_worker.rs @@ -14,7 +14,7 @@ use address::Address; use amt::Amt; use async_std::sync::{Mutex, Receiver, RwLock}; use async_std::task::{self, JoinHandle}; -use beacon::{Beacon, BeaconEntry, IGNORE_DRAND_VAR}; +use beacon::{Beacon, BeaconEntry, BeaconSchedule, IGNORE_DRAND_VAR}; use blocks::{Block, BlockHeader, FullTipset, Tipset, TipsetKeys, TxMeta}; use chain::{persist_objects, ChainStore}; use cid::{Cid, Code::Blake2b256}; @@ -45,7 +45,7 @@ pub(crate) struct SyncWorker { pub state: Arc>, /// Drand randomness beacon. - pub beacon: Arc, + pub beacon: Arc>, /// manages retrieving and updates state objects. pub state_manager: Arc>, @@ -424,7 +424,7 @@ where /// Returns the block cid (for marking bad) and `Error` if invalid (`Err`). async fn validate_block( sm: Arc>, - bc: Arc, + bc: Arc>, block: Arc, ) -> Result, (Cid, Error)> { debug!( @@ -666,10 +666,11 @@ where // * Beacon values check if std::env::var(IGNORE_DRAND_VAR) != Ok("1".to_owned()) { let block_cloned = Arc::clone(&block); + let parent_epoch = base_ts.epoch(); validations.push(task::spawn(async move { block_cloned .header() - .validate_block_drand(bc.as_ref(), &p_beacon) + .validate_block_drand(bc.as_ref(), parent_epoch, &p_beacon) .await .map_err(|e| { Error::Validation(format!( @@ -1018,7 +1019,7 @@ fn cids_from_messages(messages: &[T]) -> Result, EncodingError mod tests { use super::*; use async_std::sync::channel; - use beacon::MockBeacon; + use beacon::{BeaconPoint, MockBeacon}; use db::MemoryDB; use fil_types::verifier::MockVerifier; use forest_libp2p::NetworkMessage; @@ -1040,7 +1041,10 @@ mod tests { let gen = construct_dummy_header(); chain_store.set_genesis(&gen).unwrap(); - let beacon = Arc::new(MockBeacon::new(Duration::from_secs(1))); + let beacon = Arc::new(BeaconSchedule(vec![BeaconPoint { + height: 0, + beacon: Arc::new(MockBeacon::new(Duration::from_secs(1))), + }])); let genesis_ts = Arc::new(Tipset::new(vec![gen]).unwrap()); ( diff --git a/blockchain/chain_sync/src/sync_worker/full_sync_test.rs b/blockchain/chain_sync/src/sync_worker/full_sync_test.rs index 0f9421552c1d..a87616556880 100644 --- a/blockchain/chain_sync/src/sync_worker/full_sync_test.rs +++ b/blockchain/chain_sync/src/sync_worker/full_sync_test.rs @@ -3,10 +3,8 @@ use super::*; use crate::peer_manager::PeerManager; -use actor::EPOCH_DURATION_SECONDS; use async_std::sync::channel; use async_std::task; -use beacon::{DrandBeacon, DrandPublic}; use db::MemoryDB; use fil_types::verifier::FullVerifier; use forest_car::load_car; @@ -51,14 +49,11 @@ async fn space_race_full_sync() { let (genesis, _) = initialize_genesis(None, &state_manager).await.unwrap(); let genesis = Arc::new(genesis); - let beacon = Arc::new(DrandBeacon::new( - "https://pl-us.incentinet.drand.sh", - DrandPublic{coefficient: hex::decode("8cad0c72c606ab27d36ee06de1d5b2db1faf92e447025ca37575ab3a8aac2eaae83192f846fc9e158bc738423753d000").unwrap()}, - genesis.blocks()[0].timestamp(), - EPOCH_DURATION_SECONDS as u64, - ) - .await - .unwrap()); + let beacon = Arc::new( + networks::beacon_schedule_default(genesis.min_timestamp()) + .await + .unwrap(), + ); let peer = PeerId::random(); let peer_manager = PeerManager::default(); diff --git a/blockchain/chain_sync/src/sync_worker/validate_block_test.rs b/blockchain/chain_sync/src/sync_worker/validate_block_test.rs index 0130027d60c9..d235d3b5c0a9 100644 --- a/blockchain/chain_sync/src/sync_worker/validate_block_test.rs +++ b/blockchain/chain_sync/src/sync_worker/validate_block_test.rs @@ -2,9 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT use super::*; -use actor::EPOCH_DURATION_SECONDS; use async_std::task; -use beacon::{DrandBeacon, DrandPublic}; use clock::ChainEpoch; use db::MemoryDB; use fil_types::verifier::FullVerifier; @@ -32,14 +30,11 @@ async fn validate_specific_block() { let (genesis, _) = initialize_genesis(None, &state_manager).await.unwrap(); let genesis = Arc::new(genesis); - let beacon = Arc::new(DrandBeacon::new( - "https://pl-us.incentinet.drand.sh", - DrandPublic{coefficient: hex::decode("8cad0c72c606ab27d36ee06de1d5b2db1faf92e447025ca37575ab3a8aac2eaae83192f846fc9e158bc738423753d000").unwrap()}, - genesis.blocks()[0].timestamp(), - EPOCH_DURATION_SECONDS as u64, - ) - .await - .unwrap()); + let beacon = Arc::new( + networks::beacon_schedule_default(genesis.min_timestamp()) + .await + .unwrap(), + ); let mut ts = chain_store .tipset_from_keys(&TipsetKeys::new(cids)) diff --git a/blockchain/state_manager/Cargo.toml b/blockchain/state_manager/Cargo.toml index 57ff6de8add0..0527f9d505a9 100644 --- a/blockchain/state_manager/Cargo.toml +++ b/blockchain/state_manager/Cargo.toml @@ -36,3 +36,4 @@ runtime = { package = "forest_runtime", version = "0.1" } lazy_static = "1.4" lazycell = "1.2.1" forest_crypto = { version = "0.4" } +networks = { path = "../../types/networks" } diff --git a/blockchain/state_manager/src/lib.rs b/blockchain/state_manager/src/lib.rs index e9314afa357a..a2ea98515a84 100644 --- a/blockchain/state_manager/src/lib.rs +++ b/blockchain/state_manager/src/lib.rs @@ -16,8 +16,7 @@ use actor::*; use address::{Address, BLSPublicKey, Payload, Protocol, BLS_PUB_LEN}; use async_log::span; use async_std::{sync::RwLock, task}; -use beacon::BeaconEntry; -use beacon::{Beacon, Schedule, IGNORE_DRAND_VAR}; +use beacon::{Beacon, BeaconEntry, BeaconSchedule, IGNORE_DRAND_VAR}; use blockstore::BlockStore; use blockstore::BufferedBlockStore; use chain::{draw_randomness, ChainStore, HeadChange}; @@ -611,7 +610,7 @@ where /// gets associated miner base info based pub async fn miner_get_base_info( self: &Arc, - schedule: &Schedule, + beacon: &BeaconSchedule, key: &TipsetKeys, round: ChainEpoch, address: Address, @@ -621,8 +620,8 @@ where Ok(prev) => prev, Err(err) => { if std::env::var(IGNORE_DRAND_VAR) - .map(|e| e == "1") - .unwrap_or_default() + .map(|e| e != "1") + .unwrap_or(true) { return Err(Box::from(format!( "failed to get latest beacon entry: {:?}", @@ -632,8 +631,9 @@ where beacon::BeaconEntry::default() } }; - let beacon = schedule.beacon_for_epoch(round)?; - let entries = beacon::beacon_entries_for_block(beacon, round, &prev).await?; + let entries = beacon + .beacon_entries_for_block(round, tipset.epoch(), &prev) + .await?; let rbase = entries.iter().last().unwrap_or(&prev); let (lbts, lbst) = self .get_lookback_tipset_for_round::(tipset.clone(), round) diff --git a/forest/Cargo.toml b/forest/Cargo.toml index bffc0b417dde..cc3ee1c93e2e 100644 --- a/forest/Cargo.toml +++ b/forest/Cargo.toml @@ -43,6 +43,7 @@ actor = { package = "actor_interface", path = "../vm/actor_interface" } genesis = { path = "../utils/genesis" } paramfetch = { path = "../utils/paramfetch" } encoding = { package = "forest_encoding", version = "0.2.1" } +networks = { path = "../types/networks" } [features] default = ["rocksdb"] diff --git a/forest/src/cli/config.rs b/forest/src/cli/config.rs index 6a6e1e6cfa51..249328bc7fce 100644 --- a/forest/src/cli/config.rs +++ b/forest/src/cli/config.rs @@ -1,7 +1,6 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use beacon::DrandPublic; use chain_sync::SyncConfig; use forest_libp2p::Libp2pConfig; use serde::Deserialize; @@ -12,7 +11,6 @@ pub struct Config { pub network: Libp2pConfig, pub data_dir: String, pub genesis_file: Option, - pub drand_public: DrandPublic, pub enable_rpc: bool, pub rpc_port: String, /// If this is true, then we do not validate the imported snapshot. @@ -28,12 +26,11 @@ impl Default for Config { network: Libp2pConfig::default(), data_dir: get_home_dir() + "/.forest", genesis_file: None, - drand_public: DrandPublic{coefficient: hex::decode("8cad0c72c606ab27d36ee06de1d5b2db1faf92e447025ca37575ab3a8aac2eaae83192f846fc9e158bc738423753d000").unwrap()}, - enable_rpc : true, + enable_rpc: true, rpc_port: "1234".to_string(), snapshot_path: None, snapshot: false, - sync: SyncConfig::default() + sync: SyncConfig::default(), } } } diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index 6b798d978b7a..e0c2458588c8 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -2,14 +2,11 @@ // SPDX-License-Identifier: Apache-2.0, MIT use super::cli::{block_until_sigint, Config}; -use actor::EPOCH_DURATION_SECONDS; use async_std::{ sync::{channel, RwLock}, task, }; use auth::{generate_priv_key, JWT_IDENTIFIER}; -use beacon::{BeaconPoint, Schedule}; -use beacon::{DrandBeacon, DEFAULT_DRAND_URL}; use chain::ChainStore; use chain_sync::ChainSyncer; use fil_types::verifier::FullVerifier; @@ -111,21 +108,14 @@ pub(super) async fn start(config: Config) { .unwrap(), ); - // Get Drand Coefficients - let coeff = config.drand_public; - - let beacon = DrandBeacon::new( - DEFAULT_DRAND_URL, - coeff, - genesis.blocks()[0].timestamp(), - EPOCH_DURATION_SECONDS as u64, - ) - .await - .unwrap(); + let beacon = Arc::new( + networks::beacon_schedule_default(genesis.min_timestamp()) + .await + .unwrap(), + ); // Initialize ChainSyncer // TODO allow for configuring validation strategy (defaulting to full validation) - let beacon = Arc::new(beacon); let chain_syncer = ChainSyncer::<_, _, FullVerifier, _>::new( Arc::clone(&state_manager), beacon.clone(), @@ -163,7 +153,7 @@ pub(super) async fn start(config: Config) { network_send, network_name, events_pubsub: Arc::new(RwLock::new(Publisher::new(1000))), - beacon: Schedule(vec![BeaconPoint { start: 0, beacon }]), + beacon, chain_store, new_mined_block_tx: worker_tx, }, diff --git a/node/forest_libp2p/Cargo.toml b/node/forest_libp2p/Cargo.toml index 4a9a818ab068..c8b4ab07acf5 100644 --- a/node/forest_libp2p/Cargo.toml +++ b/node/forest_libp2p/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" [dependencies] utils = { path = "../utils" } +networks = { path = "../../types/networks" } libp2p = { version = "0.24", default-features = false, features = [ "gossipsub", "kad", diff --git a/node/forest_libp2p/src/config.rs b/node/forest_libp2p/src/config.rs index 9c79dae9717e..4dabc70840dc 100644 --- a/node/forest_libp2p/src/config.rs +++ b/node/forest_libp2p/src/config.rs @@ -2,26 +2,9 @@ // SPDX-License-Identifier: Apache-2.0, MIT use libp2p::Multiaddr; +use networks::DEFAULT_BOOTSTRAP; use serde::Deserialize; -const DEFAULT_BOOTSTRAP: &[&str] = &[ - "/dns4/bootstrap-0.mainnet.filops.net/tcp/1347/p2p/12D3KooWCVe8MmsEMes2FzgTpt9fXtmCY7wrq91GRiaC8PHSCCBj", - "/dns4/bootstrap-1.mainnet.filops.net/tcp/1347/p2p/12D3KooWCwevHg1yLCvktf2nvLu7L9894mcrJR4MsBCcm4syShVc", - "/dns4/bootstrap-2.mainnet.filops.net/tcp/1347/p2p/12D3KooWEWVwHGn2yR36gKLozmb4YjDJGerotAPGxmdWZx2nxMC4", - "/dns4/bootstrap-3.mainnet.filops.net/tcp/1347/p2p/12D3KooWKhgq8c7NQ9iGjbyK7v7phXvG6492HQfiDaGHLHLQjk7R", - "/dns4/bootstrap-4.mainnet.filops.net/tcp/1347/p2p/12D3KooWL6PsFNPhYftrJzGgF5U18hFoaVhfGk7xwzD8yVrHJ3Uc", - "/dns4/bootstrap-5.mainnet.filops.net/tcp/1347/p2p/12D3KooWLFynvDQiUpXoHroV1YxKHhPJgysQGH2k3ZGwtWzR4dFH", - "/dns4/bootstrap-6.mainnet.filops.net/tcp/1347/p2p/12D3KooWP5MwCiqdMETF9ub1P3MbCvQCcfconnYHbWg6sUJcDRQQ", - "/dns4/bootstrap-7.mainnet.filops.net/tcp/1347/p2p/12D3KooWRs3aY1p3juFjPy8gPN95PEQChm2QKGUCAdcDCC4EBMKf", - "/dns4/bootstrap-8.mainnet.filops.net/tcp/1347/p2p/12D3KooWScFR7385LTyR4zU1bYdzSiiAb5rnNABfVahPvVSzyTkR", - "/dns4/lotus-bootstrap.forceup.cn/tcp/41778/p2p/12D3KooWFQsv3nRMUevZNWWsY1Wu6NUzUbawnWU5NcRhgKuJA37C", - "/dns4/bootstrap-0.starpool.in/tcp/12757/p2p/12D3KooWGHpBMeZbestVEWkfdnC9u7p6uFHXL1n7m1ZBqsEmiUzz", - "/dns4/bootstrap-1.starpool.in/tcp/12757/p2p/12D3KooWQZrGH1PxSNZPum99M1zNvjNFM33d1AAu5DcvdHptuU7u", - "/dns4/node.glif.io/tcp/1235/p2p/12D3KooWBF8cpp65hp2u9LK5mh19x67ftAam84z9LsfaquTDSBpt", - "/dns4/bootstrap-0.ipfsmain.cn/tcp/34721/p2p/12D3KooWQnwEGNqcM2nAcPtRR9rAX8Hrg4k9kJLCHoTR5chJfz6d", - "/dns4/bootstrap-1.ipfsmain.cn/tcp/34723/p2p/12D3KooWMKxMkD5DMpSWsW7dBddKxKT7L2GgbNuckz9otxvkvByP", -]; - #[derive(Debug, Deserialize)] #[serde(default)] pub struct Libp2pConfig { diff --git a/node/rpc/src/beacon_api.rs b/node/rpc/src/beacon_api.rs index a157a639a215..a6d47f5a76dc 100644 --- a/node/rpc/src/beacon_api.rs +++ b/node/rpc/src/beacon_api.rs @@ -24,7 +24,7 @@ where let first = params .first() .ok_or_else(|| "Empty vec given for beacon".to_string())?; - let beacon = data.beacon.beacon_for_epoch(*first)?; + let (_, beacon) = data.beacon.beacon_for_epoch(*first)?; let rr = beacon.max_beacon_round_for_epoch(*first); let e = beacon.entry(rr).await?; Ok(BeaconEntryJson(e)) diff --git a/node/rpc/src/common_api.rs b/node/rpc/src/common_api.rs index dff9ddf9e970..38106ec49cba 100644 --- a/node/rpc/src/common_api.rs +++ b/node/rpc/src/common_api.rs @@ -1,11 +1,11 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use fil_types::build_version::{ - user_version, APIVersion, Version, BLOCK_DELAY_SECS, RUNNING_NODE_TYPE, -}; +use fil_types::build_version::{user_version, APIVersion, Version, RUNNING_NODE_TYPE}; +use fil_types::BLOCK_DELAY_SECS; use jsonrpc_v2::Error as JsonRpcError; use std::convert::TryInto; + pub(crate) async fn version() -> Result { let v: Version = (&*RUNNING_NODE_TYPE.read().await).try_into()?; Ok(APIVersion { diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 5a852a0b1ebc..bbb4955360a5 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -21,7 +21,7 @@ use async_tungstenite::{ tungstenite::handshake::server::Request, tungstenite::Message, WebSocketStream, }; use auth::{has_perms, Error as AuthError, JWT_IDENTIFIER, WRITE_ACCESS}; -use beacon::{Beacon, Schedule}; +use beacon::{Beacon, BeaconSchedule}; use blocks::Tipset; use blockstore::BlockStore; use chain::ChainStore; @@ -71,7 +71,7 @@ where pub new_mined_block_tx: Sender>, pub network_name: String, pub chain_store: Arc>, - pub beacon: Schedule, + pub beacon: Arc>, } pub async fn start_rpc(state: RpcState, rpc_endpoint: &str) diff --git a/node/rpc/src/sync_api.rs b/node/rpc/src/sync_api.rs index 36371fe2ea00..49e041a5ff0d 100644 --- a/node/rpc/src/sync_api.rs +++ b/node/rpc/src/sync_api.rs @@ -122,7 +122,7 @@ mod tests { use super::*; use async_std::sync::{channel, Receiver, RwLock}; use async_std::task; - use beacon::{BeaconPoint, MockBeacon, Schedule}; + use beacon::{BeaconPoint, BeaconSchedule, MockBeacon}; use blocks::{BlockHeader, Tipset}; use chain::ChainStore; use chain_sync::SyncStage; @@ -132,7 +132,7 @@ mod tests { use message_pool::{MessagePool, MpoolRpcProvider}; use serde_json::from_str; use state_manager::StateManager; - use std::sync::Arc; + use std::{sync::Arc, time::Duration}; use wallet::MemKeyStore; const TEST_NET_NAME: &str = "test"; @@ -141,7 +141,10 @@ mod tests { Arc>, Receiver, ) { - let beacon = MockBeacon::new(std::time::Duration::from_secs(2)); + let beacon = Arc::new(BeaconSchedule(vec![BeaconPoint { + height: 0, + beacon: Arc::new(MockBeacon::new(Duration::from_secs(1))), + }])); let (network_send, network_rx) = channel(5); let db = Arc::new(MemoryDB::default()); @@ -178,7 +181,6 @@ mod tests { .unwrap() }); let (new_mined_block_tx, _) = channel(5); - let beacon = Arc::new(beacon); let state = Arc::new(RpcState { state_manager, keystore: Arc::new(RwLock::new(wallet::MemKeyStore::new())), @@ -189,7 +191,7 @@ mod tests { network_name: TEST_NET_NAME.to_owned(), events_pubsub: Arc::new(RwLock::new(Publisher::new(1000))), chain_store: cs_for_chain, - beacon: Schedule(vec![BeaconPoint { start: 0, beacon }]), + beacon, new_mined_block_tx, }); (state, network_rx) diff --git a/types/networks/Cargo.toml b/types/networks/Cargo.toml new file mode 100644 index 000000000000..af5fb38c6aa9 --- /dev/null +++ b/types/networks/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "networks" +version = "0.1.0" +authors = ["ChainSafe Systems "] +edition = "2018" + +[dependencies] +fil_types = { path = "../../types" } +clock = { package = "fil_clock", path = "../../node/clock", version = "0.1" } +lazy_static = "1.4" +beacon = { path = "../../blockchain/beacon" } +serde_json = "1.0" diff --git a/types/networks/src/drand.rs b/types/networks/src/drand.rs new file mode 100644 index 000000000000..d1dc2c73a209 --- /dev/null +++ b/types/networks/src/drand.rs @@ -0,0 +1,15 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use beacon::DrandConfig; + +lazy_static! { + pub(super) static ref DRAND_MAINNET: DrandConfig<'static> = DrandConfig { + server: "https://api.drand.sh", + chain_info: serde_json::from_str(r#"{"public_key":"868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31","period":30,"genesis_time":1595431050,"hash":"8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce","groupHash":"176f93498eac9ca337150b46d21dd58673ea4e3581185f869672e59fa4cb390a"}"#).unwrap() + }; + pub(super) static ref DRAND_INCENTINET: DrandConfig<'static> = DrandConfig { + server: "https://pl-us.incentinet.drand.sh", + chain_info: serde_json::from_str(r#"{"public_key":"8cad0c72c606ab27d36ee06de1d5b2db1faf92e447025ca37575ab3a8aac2eaae83192f846fc9e158bc738423753d000","period":30,"genesis_time":1595873820,"hash":"80c8b872c714f4c00fdd3daa465d5514049f457f01f85a4caf68cdcd394ba039","groupHash":"d9406aaed487f7af71851b4399448e311f2328923d454e971536c05398ce2d9b"}"#).unwrap() + }; +} diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs new file mode 100644 index 000000000000..52503c420520 --- /dev/null +++ b/types/networks/src/lib.rs @@ -0,0 +1,49 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +#[macro_use] +extern crate lazy_static; + +use beacon::{BeaconPoint, BeaconSchedule, DrandBeacon, DrandConfig}; +use clock::ChainEpoch; +use fil_types::{NetworkVersion, BLOCK_DELAY_SECS}; +use std::{error::Error, sync::Arc}; + +mod drand; + +mod mainnet; +pub use self::mainnet::*; + +struct Upgrade { + height: ChainEpoch, + network: NetworkVersion, +} + +struct DrandPoint<'a> { + pub height: ChainEpoch, + pub config: &'a DrandConfig<'a>, +} + +/// Gets network version from epoch using default Mainnet schedule +pub fn get_network_version_default(epoch: ChainEpoch) -> NetworkVersion { + VERSION_SCHEDULE + .iter() + .rev() + .find(|upgrade| epoch > upgrade.height) + .map(|upgrade| upgrade.network) + .unwrap_or(NetworkVersion::V0) +} + +/// Constructs a drand beacon schedule based on the build config. +pub async fn beacon_schedule_default( + genesis_ts: u64, +) -> Result, Box> { + let mut points = BeaconSchedule(Vec::with_capacity(DRAND_SCHEDULE.len())); + for dc in DRAND_SCHEDULE.iter() { + points.0.push(BeaconPoint { + height: dc.height, + beacon: Arc::new(DrandBeacon::new(genesis_ts, BLOCK_DELAY_SECS, dc.config).await?), + }); + } + Ok(points) +} diff --git a/utils/genesis/src/mainnet/genesis.car b/types/networks/src/mainnet/genesis.car similarity index 100% rename from utils/genesis/src/mainnet/genesis.car rename to types/networks/src/mainnet/genesis.car diff --git a/types/networks/src/mainnet/mod.rs b/types/networks/src/mainnet/mod.rs new file mode 100644 index 000000000000..7e6fe66a4900 --- /dev/null +++ b/types/networks/src/mainnet/mod.rs @@ -0,0 +1,107 @@ +// Copyright 2020 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use super::{ + drand::{DRAND_INCENTINET, DRAND_MAINNET}, + DrandPoint, Upgrade, +}; +use clock::ChainEpoch; +use fil_types::NetworkVersion; + +/// Default genesis car file bytes. +pub const DEFAULT_GENESIS: &[u8] = include_bytes!("genesis.car"); + +/// V1 network upgrade +pub const UPGRADE_BREEZE_HEIGHT: ChainEpoch = 41280; +/// V2 network upgrade +pub const UPGRADE_SMOKE_HEIGHT: ChainEpoch = 51000; +/// V3 network upgrade +pub const UPGRADE_IGNITION_HEIGHT: ChainEpoch = 94000; +/// V4 network upgrade +pub const UPGRADE_ACTORS_V2_HEIGHT: ChainEpoch = 138720; +/// V5 network upgrade +pub const UPGRADE_TAPE_HEIGHT: ChainEpoch = 140760; +/// Switching to mainnet network name +pub const UPGRADE_LIFTOFF_HEIGHT: i64 = 148888; +/// V6 network upgrade +pub const UPGRADE_KUMQUAT_HEIGHT: ChainEpoch = 170000; +/// V7 network upgrade +pub const UPGRADE_CALICO_HEIGHT: ChainEpoch = 265200; +/// V8 network upgrade +pub const UPGRADE_PERSIAN_HEIGHT: ChainEpoch = 272400; +/// V9 network upgrade +pub const UPGRADE_ORANGE_HEIGHT: ChainEpoch = 336458; +/// Remove burn on window PoSt fork +// TODO implement updates for height https://github.com/ChainSafe/forest/issues/905 +pub const UPGRADE_CLAUS_HEIGHT: ChainEpoch = 343200; + +pub(super) const VERSION_SCHEDULE: [Upgrade; 9] = [ + Upgrade { + height: UPGRADE_BREEZE_HEIGHT, + network: NetworkVersion::V1, + }, + Upgrade { + height: UPGRADE_SMOKE_HEIGHT, + network: NetworkVersion::V2, + }, + Upgrade { + height: UPGRADE_IGNITION_HEIGHT, + network: NetworkVersion::V3, + }, + Upgrade { + height: UPGRADE_ACTORS_V2_HEIGHT, + network: NetworkVersion::V4, + }, + Upgrade { + height: UPGRADE_TAPE_HEIGHT, + network: NetworkVersion::V5, + }, + Upgrade { + height: UPGRADE_KUMQUAT_HEIGHT, + network: NetworkVersion::V6, + }, + Upgrade { + height: UPGRADE_CALICO_HEIGHT, + network: NetworkVersion::V7, + }, + Upgrade { + height: UPGRADE_PERSIAN_HEIGHT, + network: NetworkVersion::V8, + }, + Upgrade { + height: UPGRADE_ORANGE_HEIGHT, + network: NetworkVersion::V9, + }, +]; + +/// Bootstrap peer ids +pub const DEFAULT_BOOTSTRAP: &[&str] = &[ + "/dns4/bootstrap-0.mainnet.filops.net/tcp/1347/p2p/12D3KooWCVe8MmsEMes2FzgTpt9fXtmCY7wrq91GRiaC8PHSCCBj", + "/dns4/bootstrap-1.mainnet.filops.net/tcp/1347/p2p/12D3KooWCwevHg1yLCvktf2nvLu7L9894mcrJR4MsBCcm4syShVc", + "/dns4/bootstrap-2.mainnet.filops.net/tcp/1347/p2p/12D3KooWEWVwHGn2yR36gKLozmb4YjDJGerotAPGxmdWZx2nxMC4", + "/dns4/bootstrap-3.mainnet.filops.net/tcp/1347/p2p/12D3KooWKhgq8c7NQ9iGjbyK7v7phXvG6492HQfiDaGHLHLQjk7R", + "/dns4/bootstrap-4.mainnet.filops.net/tcp/1347/p2p/12D3KooWL6PsFNPhYftrJzGgF5U18hFoaVhfGk7xwzD8yVrHJ3Uc", + "/dns4/bootstrap-5.mainnet.filops.net/tcp/1347/p2p/12D3KooWLFynvDQiUpXoHroV1YxKHhPJgysQGH2k3ZGwtWzR4dFH", + "/dns4/bootstrap-6.mainnet.filops.net/tcp/1347/p2p/12D3KooWP5MwCiqdMETF9ub1P3MbCvQCcfconnYHbWg6sUJcDRQQ", + "/dns4/bootstrap-7.mainnet.filops.net/tcp/1347/p2p/12D3KooWRs3aY1p3juFjPy8gPN95PEQChm2QKGUCAdcDCC4EBMKf", + "/dns4/bootstrap-8.mainnet.filops.net/tcp/1347/p2p/12D3KooWScFR7385LTyR4zU1bYdzSiiAb5rnNABfVahPvVSzyTkR", + "/dns4/lotus-bootstrap.forceup.cn/tcp/41778/p2p/12D3KooWFQsv3nRMUevZNWWsY1Wu6NUzUbawnWU5NcRhgKuJA37C", + "/dns4/bootstrap-0.starpool.in/tcp/12757/p2p/12D3KooWGHpBMeZbestVEWkfdnC9u7p6uFHXL1n7m1ZBqsEmiUzz", + "/dns4/bootstrap-1.starpool.in/tcp/12757/p2p/12D3KooWQZrGH1PxSNZPum99M1zNvjNFM33d1AAu5DcvdHptuU7u", + "/dns4/node.glif.io/tcp/1235/p2p/12D3KooWBF8cpp65hp2u9LK5mh19x67ftAam84z9LsfaquTDSBpt", + "/dns4/bootstrap-0.ipfsmain.cn/tcp/34721/p2p/12D3KooWQnwEGNqcM2nAcPtRR9rAX8Hrg4k9kJLCHoTR5chJfz6d", + "/dns4/bootstrap-1.ipfsmain.cn/tcp/34723/p2p/12D3KooWMKxMkD5DMpSWsW7dBddKxKT7L2GgbNuckz9otxvkvByP", +]; + +lazy_static! { + pub(super) static ref DRAND_SCHEDULE: [DrandPoint<'static>; 2] = [ + DrandPoint { + height: 0, + config: &*DRAND_INCENTINET, + }, + DrandPoint { + height: UPGRADE_SMOKE_HEIGHT, + config: &*DRAND_MAINNET, + }, + ]; +} diff --git a/types/src/build_version/mod.rs b/types/src/build_version/mod.rs index 67fd10bfc78f..dedd5de2c1c2 100644 --- a/types/src/build_version/mod.rs +++ b/types/src/build_version/mod.rs @@ -22,9 +22,6 @@ const FULL_API_VERSION: Version = new_version(1, 0, 0); const MINER_API_VERSION: Version = new_version(0, 15, 0); const WORKER_API_VERSION: Version = new_version(0, 15, 0); -/// a constant for the block delay process in seconds -pub const BLOCK_DELAY_SECS: u64 = 4; - lazy_static! { static ref CURRENT_COMMIT: String = { let output = Command::new("git") diff --git a/types/src/version.rs b/types/src/version.rs index 3775b00108df..96de46794a13 100644 --- a/types/src/version.rs +++ b/types/src/version.rs @@ -102,14 +102,6 @@ pub enum NetworkVersion { V11, } -/// this function helps us check if we shoudl be getting the newest network -pub fn use_newest_network() -> bool { - if UPGRADE_BREEZE_HEIGHT <= 0 && UPGRADE_SMOKE_HEIGHT <= 0 { - return true; - } - false -} - /// Gets network version from epoch using default Mainnet schedule pub fn get_network_version_default(epoch: ChainEpoch) -> NetworkVersion { MAINNET_SCHEDULE diff --git a/utils/genesis/Cargo.toml b/utils/genesis/Cargo.toml index 2d733fd83f01..3b0f4a298f52 100644 --- a/utils/genesis/Cargo.toml +++ b/utils/genesis/Cargo.toml @@ -21,3 +21,4 @@ encoding = { package = "forest_encoding", version = "0.2.1" } net_utils = { path = "../net_utils" } url = "2.1.1" futures = "0.3.5" +networks = { path = "../../types/networks" } diff --git a/utils/genesis/src/mainnet/export40.car b/utils/genesis/src/export40.car similarity index 100% rename from utils/genesis/src/mainnet/export40.car rename to utils/genesis/src/export40.car diff --git a/utils/genesis/src/lib.rs b/utils/genesis/src/lib.rs index c6fc7943a952..ca36e750fc07 100644 --- a/utils/genesis/src/lib.rs +++ b/utils/genesis/src/lib.rs @@ -13,6 +13,7 @@ use futures::AsyncRead; use ipld_blockstore::BlockStore; use log::{debug, info}; use net_utils::FetchProgress; +use networks::DEFAULT_GENESIS; use state_manager::StateManager; use std::convert::TryFrom; use std::error::Error as StdError; @@ -21,7 +22,7 @@ use std::sync::Arc; use url::Url; #[cfg(feature = "testing")] -pub const EXPORT_SR_40: &[u8; 1226395] = include_bytes!("mainnet/export40.car"); +pub const EXPORT_SR_40: &[u8] = include_bytes!("export40.car"); /// Uses an optional file path or the default genesis to parse the genesis and determine if /// chain store has existing data for the given genesis. @@ -40,8 +41,7 @@ where } None => { debug!("No specified genesis in config. Using default genesis."); - let bz = include_bytes!("mainnet/genesis.car"); - let reader = BufReader::<&[u8]>::new(bz.as_ref()); + let reader = BufReader::<&[u8]>::new(DEFAULT_GENESIS); process_car(reader, state_manager.chain_store()).await? } };