Skip to content

Commit

Permalink
Add counters for not found UTXOs and addresses (#2428)
Browse files Browse the repository at this point in the history
Extended the `genesis_verify` script to track and display counters for not found UTXOs and addresses, in addition to mismatched counts. Updated logging statements to include this information, improving diagnostic capabilities.
  • Loading branch information
popcnt1 authored Aug 13, 2024
1 parent 33fc9f5 commit 14d256c
Showing 1 changed file with 55 additions and 24 deletions.
79 changes: 55 additions & 24 deletions crates/rooch/src/commands/statedb/commands/genesis_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ fn verify_utxo(
let mut utxo_total: u32 = 0;
let mut utxo_checked_count: u32 = 0;
let mut utxo_mismatched_count: u32 = 0;
let mut utxo_not_found_count: u32 = 0;

let mut address_checked_count: u32 = 0;
let mut address_mismatched_count: u32 = 0;
let mut address_not_found_count: u32 = 0;

for line in reader.by_ref().lines() {
let line = line.unwrap();
Expand All @@ -193,11 +195,13 @@ fn verify_utxo(
utxo_total += 1;
if utxo_total % 1_000_000 == 0 {
println!(
"utxo checking: total: {}. (mismatched/checked): utxo: ({}/{}); address: ({}/{}). cost: {:?}",
"utxo checking: total: {}. (mismatched(not_found)/checked): utxo: ({}({})/{}); address: ({}({})/{}). cost: {:?}",
utxo_total,
utxo_mismatched_count,
utxo_not_found_count,
utxo_checked_count,
address_mismatched_count,
address_not_found_count,
address_checked_count,
start_time.elapsed()
);
Expand All @@ -213,30 +217,38 @@ fn verify_utxo(
let act_utxo_state = resolver
.get_field_at(utxo_store_state_root, &exp_utxo_key)
.unwrap();
if write_mismatched_state_output::<UTXO>(
let (mismatched, not_found) = write_mismatched_state_output::<UTXO>(
&mut output_writer,
"[utxo]",
exp_utxo_state,
act_utxo_state.clone(),
) {
);
if mismatched {
utxo_mismatched_count += 1;
}
if not_found {
utxo_not_found_count += 1;
}
// check address

if addr_updates.is_some() {
address_checked_count += 1;
let (exp_addr_key, exp_addr_state) = addr_updates.unwrap();
let act_address_state = resolver
.get_field_at(address_mapping_state_root, &exp_addr_key)
.unwrap();
if write_mismatched_state_output::<DynamicField<AccountAddress, BitcoinAddress>>(
&mut output_writer,
"[address_mapping]",
exp_addr_state,
act_address_state.clone(),
) {
let (mismatched, not_found) =
write_mismatched_state_output::<DynamicField<AccountAddress, BitcoinAddress>>(
&mut output_writer,
"[address_mapping]",
exp_addr_state,
act_address_state.clone(),
);
if mismatched {
address_mismatched_count += 1;
}
if not_found {
address_not_found_count += 1;
}
}
}
output_writer.flush().expect("Unable to flush writer");
Expand Down Expand Up @@ -264,12 +276,14 @@ fn verify_utxo(
}
println!("------------{}----------------", result);
println!(
"utxo check {}. total: {}. (mismatched/checked): utxo: ({}/{}); address: ({}/{}). cost: {:?}",
"utxo check {}. total: {}. (mismatched(not_found)/checked): utxo: ({}({})/{}); address: ({}({})/{}). cost: {:?}",
result,
utxo_total,
utxo_mismatched_count,
utxo_not_found_count,
utxo_checked_count,
address_mismatched_count,
address_not_found_count,
address_checked_count,
start_time.elapsed()
);
Expand Down Expand Up @@ -312,7 +326,9 @@ fn verify_inscription(

let mut checked_count: u32 = 0;
let mut mismatched_count: u32 = 0;
let mut not_found_count: u32 = 0;
let mut mismatched_inscription_id_count: u32 = 0;
let mut not_found_inscription_id_count: u32 = 0;

let inscription_store_state_root = act_inscription_store_state.metadata.state_root.unwrap();
for line in src_reader.by_ref().lines() {
Expand All @@ -336,11 +352,13 @@ fn verify_inscription(
total += 1;
if total % 1_000_000 == 0 {
println!(
"inscription checking: total: {}. (mismatched/checked): inscription: ({}/{}); inscription_id: ({}/{}). cost: {:?}",
"inscription checking: total: {}. (mismatched(not_found)/checked): inscription: ({}({})/{}); inscription_id: ({}({})/{}). cost: {:?}",
total,
mismatched_count,
not_found_count,
checked_count,
mismatched_inscription_id_count,
not_found_inscription_id_count,
checked_count,
start_time.elapsed()
);
Expand All @@ -355,28 +373,37 @@ fn verify_inscription(
let act_inscription_state = resolver
.get_field_at(inscription_store_state_root, &exp_key)
.unwrap();
if write_mismatched_state_output::<Inscription>(
let (mismatched, not_found) = write_mismatched_state_output::<Inscription>(
&mut output_writer,
"[inscription]",
exp_state,
act_inscription_state.clone(),
) {
);
if mismatched {
mismatched_count += 1;
}
if not_found {
not_found_count += 1;
}
// check inscription_id
let (exp_inscription_id_key, exp_inscription_id_state) =
gen_inscription_id_update(total - 1, exp_inscription_id.clone());
let act_inscription_id_state = resolver
.get_field_at(inscription_store_state_root, &exp_inscription_id_key)
.unwrap();
if write_mismatched_state_output::<DynamicField<u32, InscriptionID>>(
&mut output_writer,
"[inscription_id]",
exp_inscription_id_state,
act_inscription_id_state.clone(),
) {
let (mismatched, not_found) =
write_mismatched_state_output::<DynamicField<u32, InscriptionID>>(
&mut output_writer,
"[inscription_id]",
exp_inscription_id_state,
act_inscription_id_state.clone(),
);
if mismatched {
mismatched_inscription_id_count += 1;
}
if not_found {
not_found_inscription_id_count += 1;
}
}

output_writer.flush().expect("Unable to flush writer");
Expand Down Expand Up @@ -407,12 +434,14 @@ fn verify_inscription(

println!("-----------{}-----------------", result);
println!(
"inscription check {}. total: {}. (mismatched/checked): inscription: ({}/{}); inscription_id: ({}/{}). cost: {:?}",
"inscription check {}. total: {}. (mismatched(not_found)/checked): inscription: ({}({})/{}); inscription_id: ({}({})/{}). cost: {:?}",
result,
total,
mismatched_count,
not_found_count,
checked_count,
mismatched_inscription_id_count,
not_found_inscription_id_count,
checked_count,
start_time.elapsed()
);
Expand All @@ -431,8 +460,9 @@ fn write_mismatched_state_output<T: MoveStructState + std::fmt::Debug>(
prefix: &str,
exp: ObjectState,
act: Option<ObjectState>,
) -> bool {
) -> (bool, bool) {
let mut mismatched = false;
let mut not_found = false;
let (act_str, exp_str) = match act {
Some(act) => {
let mut act = act;
Expand All @@ -451,12 +481,13 @@ fn write_mismatched_state_output<T: MoveStructState + std::fmt::Debug>(
}
None => {
mismatched = true;
not_found = true;
let exp_decoded: Result<T, _> = T::from_bytes(&exp.value);
("None".to_string(), format!("{:?}", exp_decoded.unwrap()))
}
};
if !mismatched {
return false;
return (false, false);
}

writeln!(
Expand All @@ -466,5 +497,5 @@ fn write_mismatched_state_output<T: MoveStructState + std::fmt::Debug>(
)
.expect("Unable to write line");
writeln!(output_writer, "--------------------------------").expect("Unable to write line");
true
(mismatched, not_found)
}

0 comments on commit 14d256c

Please sign in to comment.