-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rooch-da): add verify command for segment order validation (#3339)
## Summary Introduce the `verify` command to validate transaction order in segments. This includes a new execution flow that checks expected vs. actual transaction orders and logs discrepancies. output ( block: `[0,374435]`) ``` expected_tx_order,actual_tx_order,tx_hash,block_number 84658122,84658124,0x4854d82441239cda0805b963b404a007ecbc6366ce3fd4c37572cdb692624430,373386 84659999,84660000,0x44955c646f81defdcd4db2d038fc52f50949e943b59dc02757587f05e14ef007,373386 84706263,84706267,0xbb3bf39a48f85413e43f09de8a16b90237379f33abd77a8e6ea3c19ca96f2bc0,373392 84706265,84706267,0xbb3bf39a48f85413e43f09de8a16b90237379f33abd77a8e6ea3c19ca96f2bc0,373392 84706266,84706267,0xbb3bf39a48f85413e43f09de8a16b90237379f33abd77a8e6ea3c19ca96f2bc0,373392 ```
- Loading branch information
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::commands::da::commands::LedgerTxGetter; | ||
use clap::Parser; | ||
use rooch_types::error::RoochResult; | ||
use std::path::PathBuf; | ||
|
||
/// Verify segments from segments directory. | ||
/// Output: {expected_tx_order},{actual_tx_order},{tx_hash},{block_number} | ||
#[derive(Debug, Parser)] | ||
pub struct VerifyCommand { | ||
#[clap(long = "segment-dir")] | ||
pub segment_dir: PathBuf, | ||
#[clap(long = "start-from", help = "Start from the specified block number")] | ||
pub start_from: Option<u128>, | ||
} | ||
|
||
impl VerifyCommand { | ||
pub async fn execute(self) -> RoochResult<()> { | ||
let segment_dir = self.segment_dir; | ||
let ledger_tx_loader = LedgerTxGetter::new(segment_dir)?; | ||
let stop_at = ledger_tx_loader.get_max_chunk_id(); | ||
let mut block_number = self.start_from.unwrap_or(0); | ||
|
||
let mut expected_tx_order = 0; | ||
|
||
while block_number <= stop_at { | ||
let tx_list = ledger_tx_loader | ||
.load_ledger_tx_list(block_number, true, false) | ||
.await?; | ||
let tx_list = tx_list.unwrap(); | ||
|
||
if expected_tx_order == 0 { | ||
expected_tx_order = tx_list.first().unwrap().sequence_info.tx_order; | ||
} | ||
|
||
for mut ledger_tx in tx_list { | ||
let tx_order = ledger_tx.sequence_info.tx_order; | ||
let tx_hash = ledger_tx.tx_hash(); | ||
if tx_order != expected_tx_order { | ||
println!( | ||
"{},{},{:?},{}", | ||
expected_tx_order, tx_order, tx_hash, block_number | ||
); | ||
} | ||
expected_tx_order += 1; | ||
} | ||
block_number += 1; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters