Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
creativcoder committed Jun 3, 2021
1 parent de1c56f commit 860e140
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
8 changes: 5 additions & 3 deletions blockchain/state_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,18 @@ where
)?;

// Apply tipset messages
let receipts = vm.apply_block_messages(messages, parent_epoch, epoch,buf_store.clone(), callback)?;
let receipts =
vm.apply_block_messages(messages, parent_epoch, epoch, buf_store.clone(), callback)?;

// Construct receipt root from receipts
let rect_root = Amt::new_from_iter(self.blockstore(), receipts)?;
// Flush changes to blockstore
let state_root = vm.flush()?;
// Persist changes connected to root
Arc::get_mut(&mut buf_store)
.expect("failed getting store reference")
.flush(&state_root).expect("buffered blockstore flush failed");
.expect("failed getting store reference")
.flush(&state_root)
.expect("buffered blockstore flush failed");

Ok((state_root, rect_root))
}
Expand Down
2 changes: 1 addition & 1 deletion ipld/blockstore/src/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use super::BlockStore;
use byteorder::{BigEndian, ByteOrder, ReadBytesExt};
use cid::{Cid, Code, DAG_CBOR};
use db::{Error, Store};
use std::borrow::Borrow;
use std::collections::HashMap;
use std::error::Error as StdError;
use std::io::{Read, Seek};
use std::{convert::TryFrom, io::Cursor};
use std::borrow::Borrow;

/// Wrapper around `BlockStore` to limit and have control over when values are written.
/// This type is not threadsafe and can only be used in synchronous contexts.
Expand Down
6 changes: 3 additions & 3 deletions vm/state_migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

[dependencies]
fil_types = {path="../../types"}
fil_types = { path="../../types" }
vm = { package = "forest_vm", version = "0.3.1" }
ipld_blockstore = "0.1"
address = { package = "forest_address", version = "0.3" }
Expand All @@ -20,9 +20,9 @@ forest_hash_utils = "0.1"
forest_json_utils = "0.1.1"
thiserror = "1.0"
futures = "0.3.14"
state_tree = { path="../state_tree" }
state_tree = { path = "../state_tree" }
async-std = "1.9.0"
actor_interface = {path = "../actor_interface"}
actor_interface = { path = "../actor_interface" }
crossbeam-utils = "0.8.4"
crossbeam-channel = "0.5.1"
rayon = "1.5"
Expand Down
9 changes: 6 additions & 3 deletions vm/state_migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
//! Each network upgrade / state migration code lives in their own module.
use address::Address;
use async_std::sync::Arc;
use cid::Cid;
use clock::ChainEpoch;
use ipld_blockstore::BlockStore;
use rayon::ThreadPoolBuildError;
use vm::{ActorState, TokenAmount};

use rayon::ThreadPoolBuildError;

use async_std::sync::Arc;

pub mod nv12;

pub type MigrationResult<T> = Result<T, MigrationError>;
Expand Down Expand Up @@ -120,7 +122,8 @@ fn nil_migrator_v4<BS: BlockStore + Send + Sync>(
) -> Arc<dyn ActorMigration<BS> + Send + Sync> {
Arc::new(NilMigrator(cid))
}
// Migrator which preserves the head CID and provides a fixed result code CID.

/// Migrator which preserves the head CID and provides a fixed result code CID.
pub(crate) struct NilMigrator(Cid);

impl<BS: BlockStore + Send + Sync> ActorMigration<BS> for NilMigrator {
Expand Down
31 changes: 23 additions & 8 deletions vm/state_migration/src/nv12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ pub fn migrate_state_tree<BS: BlockStore + Send + Sync>(

let cpus = num_cpus::get();
let chan_size = 2;
log::info!("Using {} CPUs for migration and channel size of {}", cpus, chan_size);
log::info!(
"Using {} CPUs for migration and channel size of {}",
cpus,
chan_size
);

let pool = rayon::ThreadPoolBuilder::new()
.thread_name(|id| format!("nv12 migration thread: {}", id))
Expand All @@ -107,10 +111,14 @@ pub fn migrate_state_tree<BS: BlockStore + Send + Sync>(
let store_clone = store.clone();

s.spawn(move |_| {
actors_in.for_each(|addr, state| {
state_tx.send((addr, state.clone())).expect("failed sending actor state through channel");
Ok(())
}).expect("Failed iterating over actor state");
actors_in
.for_each(|addr, state| {
state_tx
.send((addr, state.clone()))
.expect("failed sending actor state through channel");
Ok(())
})
.expect("Failed iterating over actor state");
});

s.spawn(move |scope| {
Expand All @@ -125,9 +133,13 @@ pub fn migrate_state_tree<BS: BlockStore + Send + Sync>(
actor_migration: migrator,
};

let job_output = job.run(store_clone, prior_epoch).expect(&format!("failed executing job for address: {}", addr));
let job_output = job
.run(store_clone, prior_epoch)
.expect(&format!("failed executing job for address: {}", addr));

job_tx.send(job_output).expect(&format!("failed sending job output for address: {}", addr));
job_tx
.send(job_output)
.expect(&format!("failed sending job output for address: {}", addr));
});
}
drop(job_tx);
Expand All @@ -136,7 +148,10 @@ pub fn migrate_state_tree<BS: BlockStore + Send + Sync>(
while let Ok(job_output) = job_rx.recv() {
actors_out
.set_actor(&job_output.address, job_output.actor_state)
.expect(&format!("Failed setting new actor state at given address: {}", job_output.address));
.expect(&format!(
"Failed setting new actor state at given address: {}",
job_output.address
));
}
});

Expand Down

0 comments on commit 860e140

Please sign in to comment.