Skip to content

Commit 1c48136

Browse files
committed
add more log to indicate progress
1 parent af1d8a6 commit 1c48136

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

crates/client/src/state_dump.rs

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ fn prepare_state_db(
8080
conf: &mut Configuration, exit_cond_var: Arc<(Mutex<bool>, Condvar)>,
8181
config: &StateDumpConfig,
8282
) -> Result<(StateDbGeneric, H256), String> {
83-
println!(
84-
"[{}] Preparing state...",
85-
Utc::now().format("%Y-%m-%d %H:%M:%S")
86-
);
83+
println("Preparing state...");
8784
let (
8885
data_man,
8986
_,
@@ -149,10 +146,7 @@ fn prepare_state_db(
149146
fn export_space_accounts(
150147
state: &mut StateDbGeneric, space: Space, config: &StateDumpConfig,
151148
) -> Result<BTreeMap<Address, AccountState>, Box<dyn std::error::Error>> {
152-
println!(
153-
"[{}] Start to iterate state...",
154-
Utc::now().format("%Y-%m-%d %H:%M:%S")
155-
);
149+
println("Start to iterate state...");
156150
let empty_key = StorageKey::EmptyKey.with_space(space);
157151
let kv_pairs = state.read_all(empty_key, None)?;
158152

@@ -169,11 +163,7 @@ fn export_space_accounts(
169163
match storage_key_with_space.key {
170164
StorageKey::AccountKey(address_bytes) => {
171165
let address = Address::from_slice(address_bytes);
172-
println!(
173-
"[{}] Find account: {:?}",
174-
Utc::now().format("%Y-%m-%d %H:%M:%S"),
175-
address
176-
);
166+
println(&format!("Find account: {:?}", address));
177167
let account =
178168
Account::new_from_rlp(address, &Rlp::new(&value))?;
179169
accounts_map.insert(address, account);
@@ -225,24 +215,16 @@ fn export_space_accounts(
225215
codes_map.get(&address).cloned()
226216
} else {
227217
if let Some(code) = codes_map.get(&address) {
228-
println!(
229-
"[{}] no-contract account have code: {:?}",
230-
Utc::now().format("%Y-%m-%d %H:%M:%S"),
231-
code
232-
);
218+
println(&format!("no-contract account have code: {:?}", code));
233219
}
234220
None
235221
};
236222

237223
let storage = if is_contract {
238224
storage_map.get(&address).cloned()
239225
} else {
240-
if let Some(storage) = storage_map.get(&address) {
241-
println!(
242-
"[{}] no-contract account have storage: {:?}",
243-
Utc::now().format("%Y-%m-%d %H:%M:%S"),
244-
storage
245-
);
226+
if let Some(_storage) = storage_map.get(&address) {
227+
println(&format!("no-contract account have storage"));
246228
}
247229
None
248230
};
@@ -272,11 +254,10 @@ pub fn export_space_accounts_with_callback<F: Fn(AccountState)>(
272254
state: &mut StateDbGeneric, space: Space, config: &StateDumpConfig,
273255
callback: F,
274256
) -> Result<(), Box<dyn std::error::Error>> {
275-
println!(
276-
"[{}] Start to iterate state...",
277-
Utc::now().format("%Y-%m-%d %H:%M:%S")
278-
);
257+
println("Start to iterate state...");
279258
let mut found_accounts = 0;
259+
let mut core_space_key_count: u64 = 0;
260+
let mut total_key_count: u64 = 0;
280261

281262
for i in 0..=255 {
282263
let prefix = [i];
@@ -285,21 +266,25 @@ pub fn export_space_accounts_with_callback<F: Fn(AccountState)>(
285266
let mut account_states = BTreeMap::new();
286267

287268
let mut inner_callback = |(key, value): (Vec<u8>, Box<[u8]>)| {
269+
total_key_count += 1;
288270
let storage_key_with_space =
289271
StorageKeyWithSpace::from_key_bytes::<SkipInputCheck>(&key);
290272
if storage_key_with_space.space != space {
273+
core_space_key_count += 1;
274+
if core_space_key_count % 10000 == 0 {
275+
println(&format!(
276+
"total_key_count: {}, core_space_key_count: {}",
277+
total_key_count, core_space_key_count
278+
));
279+
}
291280
return;
292281
}
293282

294283
if let StorageKey::AccountKey(address_bytes) =
295284
storage_key_with_space.key
296285
{
297286
let address = Address::from_slice(address_bytes);
298-
println!(
299-
"[{}] Find account: {:?}",
300-
Utc::now().format("%Y-%m-%d %H:%M:%S"),
301-
address
302-
);
287+
println(&format!("Find account: {:?}", address));
303288
let account = Account::new_from_rlp(address, &Rlp::new(&value))
304289
.expect("Failed to decode account");
305290

@@ -310,10 +295,7 @@ pub fn export_space_accounts_with_callback<F: Fn(AccountState)>(
310295
state.read_all_with_callback(start_key, &mut inner_callback)?;
311296

312297
if account_states.len() > 0 {
313-
println!(
314-
"[{}] Start to read account code and storage data...",
315-
Utc::now().format("%Y-%m-%d %H:%M:%S")
316-
);
298+
println("Start to read account code and storage data...");
317299
}
318300

319301
for (_address, account) in account_states {
@@ -368,3 +350,7 @@ fn get_account_state(
368350
address_hash: Some(address_hash),
369351
})
370352
}
353+
354+
fn println(message: &str) {
355+
println!("[{}] {}", Utc::now().format("%Y-%m-%d %H:%M:%S"), message);
356+
}

0 commit comments

Comments
 (0)