Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(statedb/genesis-verify): Enhance state mismatch debugging #2448

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions crates/rooch/src/commands/statedb/commands/genesis_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use move_core_types::account_address::AccountAddress;
use move_vm_types::values::Value;
use rustc_hash::FxHashSet;

use bitcoin_move::natives::ord::inscription_id::InscriptionId;
use moveos_store::MoveOSStore;
use moveos_types::moveos_std::object::{DynamicField, ObjectMeta};
use moveos_types::state::{MoveState, MoveStructState, ObjectState};
Expand All @@ -31,7 +32,7 @@ use rooch_types::rooch_network::RoochChainID;
use crate::commands::statedb::commands::inscription::{
gen_inscription_id_update, InscriptionSource,
};
use crate::commands::statedb::commands::utxo::UTXORawData;
use crate::commands::statedb::commands::utxo::{AddressMappingData, UTXORawData};
use crate::commands::statedb::commands::{init_job, OutpointInscriptionsMap};

/// Import BTC ordinals & UTXO for genesis
Expand Down Expand Up @@ -296,11 +297,12 @@ fn verify_utxo(
let act_utxo_state = resolver
.get_field_at(utxo_store_state_root, &exp_utxo_key)
.unwrap();
let (mismatched, not_found) = write_mismatched_state_output::<UTXO>(
let (mismatched, not_found) = write_mismatched_state_output::<UTXO, UTXORawData>(
&mut output_writer,
"[utxo]",
exp_utxo_state,
act_utxo_state.clone(),
Some(utxo_raw.clone()),
);
if mismatched {
utxo_mismatched_count += 1;
Expand All @@ -315,13 +317,16 @@ fn verify_utxo(
let act_address_state = resolver
.get_field_at(address_mapping_state_root, &exp_addr_key)
.unwrap();
let (mismatched, not_found) =
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>,
AddressMappingData,
>(
&mut output_writer,
"[address_mapping]",
exp_addr_state,
act_address_state.clone(),
None,
);
if mismatched {
address_mismatched_count += 1;
}
Expand Down Expand Up @@ -457,11 +462,12 @@ fn verify_inscription(
let act_inscription_state = resolver
.get_field_at(inscription_store_state_root, &exp_key)
.unwrap();
let (mismatched, not_found) = write_mismatched_state_output::<Inscription>(
let (mismatched, not_found) = write_mismatched_state_output::<Inscription, InscriptionSource>(
&mut output_writer,
"[inscription]",
exp_state,
act_inscription_state.clone(),
Some(source.clone()),
);
if mismatched {
mismatched_count += 1;
Expand All @@ -476,11 +482,12 @@ fn verify_inscription(
.get_field_at(inscription_store_state_root, &exp_inscription_id_key)
.unwrap();
let (mismatched, not_found) =
write_mismatched_state_output::<DynamicField<u32, InscriptionID>>(
write_mismatched_state_output::<DynamicField<u32, InscriptionID>, InscriptionId>(
&mut output_writer,
"[inscription_id]",
exp_inscription_id_state,
act_inscription_id_state.clone(),
Some(source.id),
);
if mismatched {
mismatched_inscription_id_count += 1;
Expand Down Expand Up @@ -538,12 +545,13 @@ fn clear_metadata(state: &mut ObjectState) {
state.metadata.updated_at = 0;
}

// if mismatched return true & write output
fn write_mismatched_state_output<T: MoveStructState + std::fmt::Debug>(
// if mismatched, return true & write output
fn write_mismatched_state_output<T: MoveStructState + std::fmt::Debug, R: std::fmt::Debug>(
output_writer: &mut BufWriter<File>,
prefix: &str,
exp: ObjectState,
act: Option<ObjectState>,
src_data: Option<R>, // write source data to output if mismatched for debug
) -> (bool, bool) {
let mut mismatched = false;
let mut not_found = false;
Expand Down Expand Up @@ -576,8 +584,8 @@ fn write_mismatched_state_output<T: MoveStructState + std::fmt::Debug>(

writeln!(
output_writer,
"{} mismatched: exp: {:?}, act: {:?}",
prefix, exp_str, act_str
"{} mismatched: exp: {:?}, act: {:?}, src_data: {:?}",
prefix, exp_str, act_str, src_data
)
.expect("Unable to write line");
writeln!(output_writer, "--------------------------------").expect("Unable to write line");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct InscriptionSource {
pub sequence_number: u32,
pub inscription_number: i32,
pub id: InscriptionId,
// ord crate has different version of bitcoin dependency, using string for compatibility
// ord crate has a different version of bitcoin dependency, using string for compatibility
pub satpoint_outpoint: String, // txid:vout
pub satpoint_offset: u64,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
Loading