Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rustfmt crates and remove unecessary functions (#3914)
  • Loading branch information
simonjiao committed Jun 21, 2023
1 parent 26e54a7 commit 62f2b39
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 118 deletions.
10 changes: 6 additions & 4 deletions cmd/db-exporter/src/cmd_batch_execution.rs
@@ -1,10 +1,12 @@
use anyhow::bail;
use indicatif::{ProgressBar, ProgressStyle};
use rayon::prelude::*;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::time::SystemTime;
use std::{
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
time::SystemTime,
};

pub struct CmdBatchExecution {
name: String,
Expand Down
134 changes: 63 additions & 71 deletions cmd/db-exporter/src/main.rs
Expand Up @@ -2,74 +2,71 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::{bail, format_err, Result};
use bcs_ext::BCSCodec;
use bcs_ext::Sample;
use clap::IntoApp;
use clap::Parser;
use bcs_ext::{BCSCodec, Sample};
use clap::{IntoApp, Parser};
use csv::Writer;
use db_exporter::verify_header::{verify_header_via_export_file, VerifyHeaderOptions};
use db_exporter::verify_module::{verify_modules_via_export_file, VerifyModuleOptions};
use db_exporter::{
verify_header::{verify_header_via_export_file, VerifyHeaderOptions},
verify_module::{verify_modules_via_export_file, VerifyModuleOptions},
};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
use serde::{ser::SerializeMap, Serialize, Serializer};
use starcoin_account_api::AccountInfo;
use starcoin_accumulator::node::AccumulatorStoreType;
use starcoin_accumulator::{Accumulator, MerkleAccumulator};
use starcoin_chain::verifier::{
BasicVerifier, ConsensusVerifier, FullVerifier, NoneVerifier, Verifier,
use starcoin_accumulator::{node::AccumulatorStoreType, Accumulator, MerkleAccumulator};
use starcoin_chain::{
verifier::{BasicVerifier, ConsensusVerifier, FullVerifier, NoneVerifier, Verifier},
BlockChain, ChainReader, ChainWriter,
};
use starcoin_chain::{BlockChain, ChainReader, ChainWriter};
use starcoin_config::{BuiltinNetworkID, ChainNetwork, RocksdbConfig};
use starcoin_consensus::Consensus;
use starcoin_crypto::HashValue;
use starcoin_genesis::Genesis;
use starcoin_resource_viewer::{AnnotatedMoveStruct, AnnotatedMoveValue, MoveValueAnnotator};
use starcoin_statedb::ChainStateDB;
use starcoin_statedb::ChainStateReader;
use starcoin_statedb::ChainStateWriter;
use starcoin_storage::block::FailedBlock;
use starcoin_storage::block_info::BlockInfoStore;
use starcoin_storage::cache_storage::CacheStorage;
use starcoin_storage::db_storage::DBStorage;
use starcoin_storage::storage::StorageInstance;
use starcoin_storage::storage::ValueCodec;
use starcoin_storage::storage::{ColumnFamilyName, InnerStore};
use starcoin_statedb::{ChainStateDB, ChainStateReader, ChainStateWriter};
use starcoin_storage::{
block::FailedBlock,
block_info::BlockInfoStore,
cache_storage::CacheStorage,
db_storage::DBStorage,
storage::{ColumnFamilyName, InnerStore, StorageInstance, ValueCodec},
BlockStore, Storage, StorageVersion, Store, BLOCK_ACCUMULATOR_NODE_PREFIX_NAME,
BLOCK_HEADER_PREFIX_NAME, BLOCK_INFO_PREFIX_NAME, BLOCK_PREFIX_NAME, FAILED_BLOCK_PREFIX_NAME,
STATE_NODE_PREFIX_NAME, STATE_NODE_PREFIX_NAME_PREV, TRANSACTION_ACCUMULATOR_NODE_PREFIX_NAME,
};
use starcoin_transaction_builder::{
build_signed_empty_txn, create_signed_txn_with_association_account, DEFAULT_MAX_GAS_AMOUNT,
};
use starcoin_types::account::peer_to_peer_txn;
use starcoin_types::account::Account;
use starcoin_types::account::DEFAULT_EXPIRATION_TIME;
use starcoin_types::account_address::AccountAddress;
use starcoin_types::block::{Block, BlockHeader, BlockInfo, BlockNumber};
use starcoin_types::language_storage::{StructTag, TypeTag};
use starcoin_types::startup_info::{SnapshotRange, StartupInfo};
use starcoin_types::state_set::{AccountStateSet, ChainStateSet};
use starcoin_types::transaction::Transaction;
use starcoin_vm_types::account_config::stc_type_tag;
use starcoin_vm_types::genesis_config::ConsensusStrategy;
use starcoin_vm_types::identifier::Identifier;
use starcoin_vm_types::language_storage::ModuleId;
use starcoin_vm_types::parser::parse_type_tag;
use starcoin_vm_types::transaction::{ScriptFunction, SignedUserTransaction, TransactionPayload};
use std::collections::HashMap;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::{BufRead, BufReader, Write};
use std::path::Path;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use std::time::SystemTime;
use std::{thread, thread::JoinHandle};
use starcoin_types::{
account::{peer_to_peer_txn, Account, DEFAULT_EXPIRATION_TIME},
account_address::AccountAddress,
block::{Block, BlockHeader, BlockInfo, BlockNumber},
startup_info::{SnapshotRange, StartupInfo},
state_set::{AccountStateSet, ChainStateSet},
transaction::Transaction,
};
use starcoin_vm_types::{
account_config::stc_type_tag,
genesis_config::ConsensusStrategy,
identifier::Identifier,
language_storage::{ModuleId, StructTag},
parser::parse_struct_tag,
transaction::{ScriptFunction, SignedUserTransaction, TransactionPayload},
};
use std::{
collections::HashMap,
fmt::{Debug, Formatter},
fs::{File, OpenOptions},
io::{BufRead, BufReader, Write},
path::{Path, PathBuf},
str::FromStr,
sync::{
atomic::{AtomicU64, Ordering},
Arc,
},
thread,
thread::JoinHandle,
time::SystemTime,
};

const BLOCK_GAP: u64 = 1000;
const BACK_SIZE: u64 = 10000;
Expand Down Expand Up @@ -1065,6 +1062,18 @@ pub fn execute_transaction_with_fixed_account(
Ok(())
}

fn handle_block_cf<T>(file: &mut File, blocks: Vec<Option<T>>, ids: &[HashValue]) -> Result<()>
where
T: serde::Serialize,
{
for (i, block) in blocks.into_iter().enumerate() {
let block =
block.ok_or_else(|| format_err!("get block by hash {} error", ids.get(i).unwrap()))?;
writeln!(file, "{}", serde_json::to_string(&block)?)?;
}
Ok(())
}

fn export_column(
storage: Arc<Storage>,
accumulator: MerkleAccumulator,
Expand Down Expand Up @@ -1104,23 +1113,13 @@ fn export_column(
// will cache ids
let ids = accumulator.get_leaves(start_index + start_num, false, max_size)?;
let blocks = storage.get_blocks(ids.clone())?;
for (i, block) in blocks.into_iter().enumerate() {
let block = block.ok_or_else(|| {
format_err!("get block by hash {} error", ids.get(i).unwrap())
})?;
writeln!(file, "{}", serde_json::to_string(&block)?)?;
}
handle_block_cf(&mut file, blocks, &ids)?;
}
BLOCK_INFO_PREFIX_NAME => {
// will cache ids
let ids = accumulator.get_leaves(start_index + start_num, false, max_size)?;
let block_infos = storage.get_block_infos(ids.clone())?;
for (i, block_info) in block_infos.into_iter().enumerate() {
let block_info = block_info.ok_or_else(|| {
format_err!("get block by hash {} error", ids.get(i).unwrap())
})?;
writeln!(file, "{}", serde_json::to_string(&block_info)?)?;
}
handle_block_cf(&mut file, block_infos, &ids)?;
}
_ => {
println!("{} not process", column);
Expand Down Expand Up @@ -1182,6 +1181,7 @@ pub fn export_snapshot(
} else {
block_num - SNAP_GAP
};
// For debug purpose
if let Some(special_num) = special_block_num {
if special_num <= cur_num {
cur_num = special_num;
Expand Down Expand Up @@ -1832,11 +1832,3 @@ impl serde::Serialize for MoveValue {
}
}
}
fn parse_struct_tag(input: &str) -> anyhow::Result<StructTag> {
match parse_type_tag(input)? {
TypeTag::Struct(s) => Ok(*s),
_ => {
anyhow::bail!("invalid struct tag")
}
}
}
9 changes: 3 additions & 6 deletions cmd/db-exporter/src/verify_module.rs
@@ -1,12 +1,9 @@
use clap::Parser;
use move_binary_format::errors::Location;
use starcoin_crypto::HashValue;
use starcoin_types::block::Block;
use starcoin_types::transaction::TransactionPayload;
use starcoin_vm_types::errors::VMError;
use starcoin_vm_types::file_format::CompiledModule;
use std::fmt::Debug;
use std::path::PathBuf;
use starcoin_types::{block::Block, transaction::TransactionPayload};
use starcoin_vm_types::{errors::VMError, file_format::CompiledModule};
use std::{fmt::Debug, path::PathBuf};
//use starcoin_accumulator::node::AccumulatorStoreType::Block;
use crate::cmd_batch_execution::{BatchCmdExec, CmdBatchExecution};

Expand Down
37 changes: 14 additions & 23 deletions cmd/resource-exporter/src/main.rs
@@ -1,22 +1,22 @@
use clap::Parser;
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
use serde::{ser::SerializeMap, Serialize, Serializer};
use starcoin_crypto::HashValue;
use starcoin_resource_viewer::{AnnotatedMoveStruct, AnnotatedMoveValue, MoveValueAnnotator};
use starcoin_state_tree::StateTree;
use starcoin_statedb::ChainStateDB;
use starcoin_storage::db_storage::DBStorage;
use starcoin_storage::storage::StorageInstance;
use starcoin_storage::{BlockStore, Storage, StorageVersion};
use starcoin_types::access_path::DataType;
use starcoin_types::account_state::AccountState;
use starcoin_types::language_storage::{StructTag, TypeTag};
use starcoin_vm_types::account_address::AccountAddress;
use starcoin_vm_types::parser::parse_type_tag;
use std::convert::TryInto;
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use starcoin_storage::{
db_storage::DBStorage, storage::StorageInstance, BlockStore, Storage, StorageVersion,
};
use starcoin_types::{
access_path::DataType, account_state::AccountState, language_storage::StructTag,
};
use starcoin_vm_types::{account_address::AccountAddress, parser::parse_struct_tag};
use std::{
convert::TryInto,
fmt::Debug,
path::{Path, PathBuf},
sync::Arc,
};

#[derive(Serialize, Debug)]
pub struct AccountData<R: Serialize> {
Expand Down Expand Up @@ -149,15 +149,6 @@ impl serde::Serialize for MoveValue {
}
}

fn parse_struct_tag(input: &str) -> anyhow::Result<StructTag> {
match parse_type_tag(input)? {
TypeTag::Struct(s) => Ok(*s),
_ => {
anyhow::bail!("invalid struct tag")
}
}
}

#[derive(Debug, Clone, Parser)]
#[clap(name = "resource-exporter", about = "onchain resource exporter")]
pub struct ExporterOptions {
Expand Down
16 changes: 2 additions & 14 deletions vm/types/src/lib.rs
Expand Up @@ -15,8 +15,7 @@ pub mod identifier {
}

pub mod language_storage {
pub use crate::language_storage_ext::parse_module_id;
pub use crate::language_storage_ext::FunctionId;
pub use crate::language_storage_ext::{parse_module_id, FunctionId};
pub use move_core_types::language_storage::{
ModuleId, ResourceKey, StructTag, TypeTag, CODE_TAG, CORE_CODE_ADDRESS, RESOURCE_TAG,
};
Expand Down Expand Up @@ -149,20 +148,9 @@ pub mod transaction_argument {
}

pub mod parser {
use crate::language_storage::TypeTag;
use anyhow::{bail, Result};
use move_core_types::language_storage::StructTag;
pub use move_core_types::parser::{
parse_transaction_argument, parse_type_tag, parse_type_tags,
parse_struct_tag, parse_transaction_argument, parse_type_tag, parse_type_tags,
};

pub fn parse_struct_tag(s: &str) -> Result<StructTag> {
let type_tag = parse_type_tag(s)?;
match type_tag {
TypeTag::Struct(st) => Ok(*st),
t => bail!("expect a struct tag, found: {:?}", t),
}
}
}

#[cfg(any(test, feature = "fuzzing"))]
Expand Down

0 comments on commit 62f2b39

Please sign in to comment.