Skip to content

Commit

Permalink
[rooch-networkgh-2458] return dry run result before executing txs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Aug 24, 2024
1 parent 616fbc1 commit 895cbce
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
36 changes: 36 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,17 @@ 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 +136,18 @@ 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: gas_used,
status,
}
}
}

impl From<TransactionExecutionInfo> for TransactionExecutionInfoView {
fn from(transaction_execution_info: TransactionExecutionInfo) -> Self {
Self {
Expand Down Expand Up @@ -211,6 +236,17 @@ 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.clone(), response.raw_output.status.clone()),
output: None,
error_info: Some(response),
}
}
}

impl From<ExecuteTransactionResponse> for ExecuteTransactionResponseView {
fn from(response: ExecuteTransactionResponse) -> Self {
Self {
Expand Down
12 changes: 6 additions & 6 deletions crates/rooch/src/commands/move_cli/commands/run_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use moveos_types::transaction::MoveAction;
use rooch_key::key_derive::verify_password;
use rooch_key::keystore::account_keystore::AccountKeystore;
use rooch_rpc_api::jsonrpc_types::{
ExecuteTransactionResponseView, HumanReadableDisplay, KeptVMStatusView,
DryRunTransactionResponseView, ExecuteTransactionResponseView, HumanReadableDisplay, KeptVMStatusView
};
use rooch_types::function_arg::parse_function_arg;
use rooch_types::{
Expand Down 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 895cbce

Please sign in to comment.