Skip to content

Commit

Permalink
lazy evaluate genesis timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Mar 3, 2023
1 parent 15e4ee3 commit d57f68e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 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.

1 change: 1 addition & 0 deletions blockchain/state_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ lazy_static.workspace = true
lru.workspace = true
num-traits.workspace = true
num.workspace = true
once_cell.workspace = true
parking_lot.workspace = true
prometheus.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand Down
10 changes: 8 additions & 2 deletions blockchain/state_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use fvm_shared::clock::ChainEpoch;
use lru::LruCache;
use num::BigInt;
use num_traits::identities::Zero;
use once_cell::unsync::Lazy;
use parking_lot::Mutex as SyncMutex;
use serde::{Deserialize, Serialize};
use tokio::sync::{broadcast::error::RecvError, Mutex as TokioMutex, RwLock};
Expand Down Expand Up @@ -397,11 +398,16 @@ where
};

let mut parent_state = *p_state;
let genesis_timestamp = self.chain_store().genesis().unwrap().timestamp();
let genesis_timestamp = Lazy::new(|| {
self.chain_store()
.genesis()
.expect("could not find genesis block!")
.timestamp()
});

for epoch_i in parent_epoch..epoch {
if epoch_i > parent_epoch {
let timestamp = genesis_timestamp + ((EPOCH_DURATION_SECONDS * epoch_i) as u64);
let timestamp = *genesis_timestamp + ((EPOCH_DURATION_SECONDS * epoch_i) as u64);
let mut vm = create_vm(parent_state, epoch_i, timestamp)?;
// run cron for null rounds if any
if let Err(e) = vm.run_cron(epoch_i, callback.as_mut()) {
Expand Down

0 comments on commit d57f68e

Please sign in to comment.