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

feat(rooch-da): add rollback for exec cmd #3066

Merged
merged 6 commits into from
Dec 19, 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
59 changes: 59 additions & 0 deletions crates/rooch/src/commands/da/commands/dump_tx_order_hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::commands::da::commands::{LedgerTxGetter, TxOrderHashBlock};
use rooch_types::error::{RoochError, RoochResult};
use std::fs::File;
use std::io::BufWriter;
use std::io::Write;
use std::path::PathBuf;

/// Dump tx_order:tx_hash:block_number to a file from segments
#[derive(Debug, clap::Parser)]
pub struct DumpTxOrderHashCommand {
#[clap(long = "segment-dir")]
pub segment_dir: PathBuf,
#[clap(long = "output")]
pub output: PathBuf,
}

impl DumpTxOrderHashCommand {
pub fn execute(self) -> RoochResult<()> {
let ledger_tx_loader = LedgerTxGetter::new(self.segment_dir)?;
let mut block_number = ledger_tx_loader.get_min_chunk_id();
let mut expected_tx_order = 0;
let file = File::create(self.output.clone())?;
let mut writer = BufWriter::with_capacity(8 * 1024 * 1024, file.try_clone().unwrap());

loop {
if block_number > ledger_tx_loader.get_max_chunk_id() {
break;
}
let tx_list = ledger_tx_loader.load_ledger_tx_list(block_number, true)?;
let tx_list = tx_list.unwrap();
for mut ledger_tx in tx_list {
let tx_order = ledger_tx.sequence_info.tx_order;
let tx_hash = ledger_tx.tx_hash();
if expected_tx_order == 0 {
expected_tx_order = tx_order;
} else if tx_order != expected_tx_order {
return Err(RoochError::from(anyhow::anyhow!(
"tx_order mismatch: expected {}, got {}",
expected_tx_order,
tx_order
)));
}
writeln!(
writer,
"{}",
TxOrderHashBlock::new(tx_order, tx_hash, block_number)
)?;
expected_tx_order += 1;
}
block_number += 1;
}
writer.flush()?;
file.sync_data()?;
Ok(())
}
}
Loading
Loading