-
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-cmd): add cmds for packing DA batch (#3310)
## Summary 1. feat(rooch-da): add pack command to DA module Introduce the PackCommand to enable segmenting human-readable LedgerTransaction lists into chunk. Updated related DA module code and fixed some error-handling inconsistencies. 2. feat(rooch): add cmd for signing transaction order Introduces the `SignOrderCommand` to handle signing transaction orders with sequencer keys. Includes integration into the CLI, command routing, and dependencies on `rooch-sequencer`. 3. other fix/improvement
- Loading branch information
Showing
11 changed files
with
158 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,66 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::cli_types::WalletContextOptions; | ||
use crate::utils::get_sequencer_keypair; | ||
use clap::Parser; | ||
use rooch_types::da::batch::DABatch; | ||
use rooch_types::da::chunk::{Chunk, ChunkV0}; | ||
use rooch_types::error::RoochResult; | ||
use rooch_types::transaction::LedgerTransaction; | ||
use std::fs::File; | ||
use std::io::{BufRead, BufReader, Read, Write}; | ||
use std::path::PathBuf; | ||
|
||
const DEFAULT_MAX_SEGMENT_SIZE: usize = 4 * 1024 * 1024; | ||
|
||
/// Unpack human-readable LedgerTransaction List to segments. | ||
#[derive(Debug, Parser)] | ||
pub struct PackCommand { | ||
#[clap(long = "segment-dir")] | ||
pub segment_dir: PathBuf, | ||
#[clap(long = "batch-path")] | ||
pub batch_path: PathBuf, | ||
#[clap(long = "chunk-id")] | ||
pub chunk_id: u128, | ||
#[clap(long)] | ||
pub sequencer_account: Option<String>, | ||
#[clap(flatten)] | ||
pub context_options: WalletContextOptions, | ||
} | ||
|
||
impl PackCommand { | ||
pub fn execute(self) -> RoochResult<()> { | ||
let sequencer_keypair = | ||
get_sequencer_keypair(self.context_options, self.sequencer_account)?; | ||
|
||
let mut reader = BufReader::new(File::open(self.batch_path)?); | ||
let mut tx_list = Vec::new(); | ||
for line in reader.by_ref().lines() { | ||
let line = line?; | ||
let tx: LedgerTransaction = serde_json::from_str(&line)?; | ||
tx_list.push(tx); | ||
} | ||
let tx_order_start = tx_list.first().unwrap().sequence_info.tx_order; | ||
let tx_order_end = tx_list.last().unwrap().sequence_info.tx_order; | ||
|
||
let batch = DABatch::new( | ||
self.chunk_id, | ||
tx_order_start, | ||
tx_order_end, | ||
&tx_list, | ||
sequencer_keypair, | ||
); | ||
batch.verify(true)?; | ||
|
||
let segments = ChunkV0::from(batch).to_segments(DEFAULT_MAX_SEGMENT_SIZE); | ||
for segment in segments.iter() { | ||
let segment_path = self.segment_dir.join(segment.get_id().to_string()); | ||
let mut writer = File::create(segment_path)?; | ||
writer.write_all(&segment.to_bytes())?; | ||
writer.flush()?; | ||
} | ||
|
||
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
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
32 changes: 32 additions & 0 deletions
32
crates/rooch/src/commands/transaction/commands/sign_order.rs
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,32 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::cli_types::WalletContextOptions; | ||
use crate::utils::get_sequencer_keypair; | ||
use moveos_types::h256::H256; | ||
use rooch_sequencer::actor::sequencer::sign_tx_order; | ||
use rooch_types::error::RoochResult; | ||
|
||
/// Get transactions by hashes | ||
#[derive(Debug, clap::Parser)] | ||
pub struct SignOrderCommand { | ||
/// Transaction's hash | ||
#[clap(long)] | ||
pub tx_hash: H256, | ||
#[clap(long)] | ||
pub tx_order: u64, | ||
#[clap(long)] | ||
pub sequencer_account: Option<String>, | ||
#[clap(flatten)] | ||
pub(crate) context_options: WalletContextOptions, | ||
} | ||
|
||
impl SignOrderCommand { | ||
pub fn execute(self) -> RoochResult<String> { | ||
let sequencer_keypair = | ||
get_sequencer_keypair(self.context_options, self.sequencer_account)?; | ||
let tx_order_sign = sign_tx_order(self.tx_order, self.tx_hash, &sequencer_keypair); | ||
let tx_order_sign_str = serde_json::to_string(&tx_order_sign)?; | ||
Ok(tx_order_sign_str) | ||
} | ||
} |
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