fix import  snapshot bug
* add export_snapshot special block number
* 1.add export_snapshot special block number for debug
2.fix apply_snapshot on barnard
* remove unused code
MODIFY
cmd/db-exporter/src/main.rs
cmd/db-exporter/src/main.rs
@@ -346,6 +346,9 @@ pub struct ExportSnapshotOptions {
#[clap(long, short = 't')]
/// enable increment export snapshot
pub increment: Option<bool>,
+ #[clap(long, short = 'b')]
+ /// special block_num for debug usage
+ pub special_block_num: Option<BlockNumber>,
}
#[derive(Debug, Parser)]
@@ -479,7 +482,13 @@ fn main() -> anyhow::Result<()> {
}
if let Cmd::ExportSnapshot(option) = cmd {
- let result = export_snapshot(option.db_path, option.output, option.net, option.increment);
+ let result = export_snapshot(
+ option.db_path,
+ option.output,
+ option.net,
+ option.increment,
+ option.special_block_num,
+ );
return result;
}
@@ -1038,6 +1047,7 @@ pub fn export_snapshot(
output: PathBuf,
network: BuiltinNetworkID,
increment: Option<bool>,
+ special_block_num: Option<BlockNumber>,
) -> anyhow::Result<()> {
let start_time = SystemTime::now();
let net = ChainNetwork::new_builtin(network);
@@ -1064,11 +1074,16 @@ pub fn export_snapshot(
)
.expect("create block chain should success.");
let block_num = chain.status().head().number();
- let cur_num = if block_num <= SNAP_GAP {
+ let mut cur_num = if block_num <= SNAP_GAP {
block_num
} else {
block_num - SNAP_GAP
};
+ if let Some(special_num) = special_block_num {
+ if special_num <= cur_num {
+ cur_num = special_num;
+ }
+ }
let cur_block = chain
.get_block_by_number(cur_num)?
.ok_or_else(|| format_err!("get block by number {} error", cur_num))?;

MODIFY
state/statedb/src/lib.rs
state/statedb/src/lib.rs
@@ -458,45 +458,21 @@ impl ChainStateWriter for ChainStateDB {
fn apply(&self, chain_state_set: ChainStateSet) -> Result<()> {
for (address, account_state_set) in chain_state_set.state_sets() {
- let (code_root, resource_root) = match self.get_account_state(address)? {
- Some(account_state) => (
- account_state.code_root(),
- Some(account_state.resource_root()),
- ),
- None => (None, None),
- };
- let code_root = match (code_root, account_state_set.code_set()) {
- (Some(storage_root), Some(state_set)) => {
- let state_tree = self.new_state_tree::<ModuleName>(storage_root);
- state_tree.apply(state_set.clone())?;
- state_tree.flush()?;
- Some(state_tree.root_hash())
- }
- (Some(storage_root), None) => Some(storage_root),
- (None, Some(state_set)) => {
+ let code_root = if let Some(state_set) = account_state_set.code_set() {
let state_tree = StateTree::<ModuleName>::new(self.store.clone(), None);
state_tree.apply(state_set.clone())?;
state_tree.flush()?;
Some(state_tree.root_hash())
- }
- (None, None) => None,
+ } else {
+ None
};
-
- let resource_root = match (resource_root, account_state_set.resource_set()) {
- (Some(storage_root), Some(state_set)) => {
- let state_tree = self.new_state_tree::<StructTag>(storage_root);
- state_tree.apply(state_set.clone())?;
- state_tree.flush()?;
- state_tree.root_hash()
- }
- (Some(storage_root), None) => storage_root,
- (None, Some(state_set)) => {
+ let resource_root = if let Some(state_set) = account_state_set.resource_set() {
let state_tree = StateTree::<StructTag>::new(self.store.clone(), None);
state_tree.apply(state_set.clone())?;
state_tree.flush()?;
state_tree.root_hash()
- }
- (None, None) => unreachable!("this should never happened"),
+ } else {
+ unreachable!("this should never happened")
};
let new_account_state = AccountState::new(code_root, resource_root);
self.state_tree.put(*address, new_account_state.try_into()?);

fix import  snapshot bug (#3425)

* add export_snapshot special block number

* 1.add export_snapshot special block number for debug
2.fix apply_snapshot on barnard

* remove unused code