Skip to content

Commit

Permalink
[gh-2458] return dry run result before executing txs. (#2498)
Browse files Browse the repository at this point in the history
* [gh-2458] return dry run result before executing txs.

* [gh-2458] format code.

* [gh-2458] fix code lint issues.

---------

Co-authored-by: Feliciss <10203-feliciss@users.noreply.0xacab.org>
  • Loading branch information
feliciss and Feliciss committed Aug 24, 2024
1 parent 616fbc1 commit c7eb08f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
58 changes: 58 additions & 0 deletions crates/rooch-rpc-api/src/jsonrpc_types/execute_tx_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::BytesView;
use super::{HumanReadableDisplay, ModuleIdView, StateChangeSetView, StrView};
use crate::jsonrpc_types::event_view::EventView;
use crate::jsonrpc_types::H256View;
use ethers::types::H256;
use move_core_types::vm_status::{AbortLocation, KeptVMStatus};
use moveos_types::transaction::TransactionOutput;
use moveos_types::transaction::{TransactionExecutionInfo, VMErrorInfo};
Expand All @@ -13,6 +14,7 @@ use rooch_types::transaction::{authenticator::Authenticator, TransactionSequence
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use std::u64;

pub type AbortLocationView = StrView<AbortLocation>;

Expand Down Expand Up @@ -103,6 +105,22 @@ pub struct TransactionSequenceInfoView {
pub tx_timestamp: StrView<u64>,
}

impl TransactionSequenceInfoView {
fn new(
tx_order: u64,
tx_order_signature: Vec<u8>,
tx_accumulator_root: H256,
tx_timestamp: u64,
) -> Self {
Self {
tx_order: StrView(tx_order),
tx_order_signature: tx_order_signature.into(),
tx_accumulator_root: tx_accumulator_root.into(),
tx_timestamp: StrView(tx_timestamp),
}
}
}

impl From<TransactionSequenceInfo> for TransactionSequenceInfoView {
fn from(transaction_sequence_info: TransactionSequenceInfo) -> Self {
Self {
Expand All @@ -123,6 +141,24 @@ pub struct TransactionExecutionInfoView {
pub status: KeptVMStatusView,
}

impl TransactionExecutionInfoView {
fn new(
tx_hash: H256,
state_root: H256,
event_root: H256,
gas_used: StrView<u64>,
status: KeptVMStatusView,
) -> Self {
Self {
tx_hash: tx_hash.into(),
state_root: state_root.into(),
event_root: event_root.into(),
gas_used,
status,
}
}
}

impl From<TransactionExecutionInfo> for TransactionExecutionInfoView {
fn from(transaction_execution_info: TransactionExecutionInfo) -> Self {
Self {
Expand Down Expand Up @@ -211,6 +247,28 @@ impl ExecuteTransactionResponseView {
}
}

impl From<DryRunTransactionResponseView> for ExecuteTransactionResponseView {
fn from(response: DryRunTransactionResponseView) -> Self {
Self {
sequence_info: TransactionSequenceInfoView::new(
u64::MIN,
Vec::new(),
H256::random(),
u64::MIN,
),
execution_info: TransactionExecutionInfoView::new(
H256::random(),
H256::random(),
H256::random(),
response.raw_output.gas_used,
response.raw_output.status.clone(),
),
output: None,
error_info: Some(response),
}
}
}

impl From<ExecuteTransactionResponse> for ExecuteTransactionResponseView {
fn from(response: ExecuteTransactionResponse) -> Self {
Self {
Expand Down
10 changes: 5 additions & 5 deletions crates/rooch/src/commands/move_cli/commands/run_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ impl CommandAction<ExecuteTransactionResponseView> for RunFunction {
)
.await?;

let mut result = match (self.tx_options.authenticator, self.tx_options.session_key) {
if dry_run_result.raw_output.status != KeptVMStatusView::Executed {
return Ok(dry_run_result.into());
};

let result = match (self.tx_options.authenticator, self.tx_options.session_key) {
(Some(authenticator), _) => {
let tx_data = context
.build_tx_data(sender, action, max_gas_amount)
Expand Down Expand Up @@ -163,10 +167,6 @@ impl CommandAction<ExecuteTransactionResponseView> for RunFunction {
}
};

if dry_run_result.raw_output.status != KeptVMStatusView::Executed {
result.error_info = Some(dry_run_result);
}

Ok(result)
}

Expand Down

0 comments on commit c7eb08f

Please sign in to comment.