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

Include the signature length in the gas billing of the dry run. #3268

Merged
merged 3 commits into from
Feb 5, 2025
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
11 changes: 8 additions & 3 deletions crates/rooch-executor/src/actor/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use rooch_types::framework::ethereum::EthereumModule;
use rooch_types::framework::transaction_validator::TransactionValidator;
use rooch_types::framework::{system_post_execute_functions, system_pre_execute_functions};
use rooch_types::multichain_id::RoochMultiChainID;
use rooch_types::transaction::authenticator::AUTH_PAYLOAD_SIZE;
use rooch_types::transaction::{
AuthenticatorInfo, L1Block, L1BlockWithBody, L1Transaction, RoochTransaction,
RoochTransactionData,
Expand Down Expand Up @@ -365,18 +366,22 @@ impl ExecutorActor {
Ok(vm_result)
}

pub fn convert_to_verified_tx(
pub fn convert_to_verified_tx_for_dry_run(
&self,
tx_data: RoochTransactionData,
) -> Result<VerifiedMoveOSTransaction> {
let root = self.root.clone();

// The dry run supports unsigned transactions, but when calculating the transaction size,
// the length of the signature part needs to be included.
let tx_size = tx_data.tx_size() + AUTH_PAYLOAD_SIZE;

let mut tx_ctx = TxContext::new(
tx_data.sender.into(),
tx_data.sequence_number,
tx_data.max_gas_amount,
tx_data.tx_hash(),
tx_data.tx_size(),
tx_size,
);

let tx_metadata = TxMeta::new_from_move_action(&tx_data.action);
Expand Down Expand Up @@ -544,7 +549,7 @@ impl Handler<ConvertL2TransactionData> for ExecutorActor {
msg: ConvertL2TransactionData,
_ctx: &mut ActorContext,
) -> Result<VerifiedMoveOSTransaction> {
self.convert_to_verified_tx(msg.tx_data)
self.convert_to_verified_tx_for_dry_run(msg.tx_data)
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/rooch-types/src/transaction/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ use crate::{

use super::RoochTransactionData;

// The size of the signature data.
pub const AUTH_PAYLOAD_SIZE: u64 = 219;

/// A `Authenticator` is an abstraction of a account authenticator.
/// It is a part of `AccountAbstraction`

Expand Down
12 changes: 11 additions & 1 deletion crates/rooch/src/tx_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use moveos_types::move_std::option::MoveOption;
use moveos_types::moveos_std::gas_schedule::GasScheduleConfig;
use moveos_types::moveos_std::object::ObjectMeta;
use moveos_types::moveos_std::tx_context::TxContext;
use moveos_types::moveos_std::tx_meta::TxMeta;
use moveos_types::transaction::{
MoveAction, RawTransactionOutput, VMErrorInfo, VerifiedMoveAction, VerifiedMoveOSTransaction,
};
Expand All @@ -34,6 +35,7 @@ use rooch_rpc_client::{Client, ClientResolver};
use rooch_types::address::{BitcoinAddress, MultiChainAddress};
use rooch_types::framework::auth_validator::{BuiltinAuthValidator, TxValidateResult};
use rooch_types::framework::system_pre_execute_functions;
use rooch_types::transaction::authenticator::AUTH_PAYLOAD_SIZE;
use rooch_types::transaction::RoochTransactionData;
use std::rc::Rc;
use std::str::FromStr;
Expand All @@ -55,7 +57,12 @@ pub fn execute_tx_locally(
GasScheduleConfig::CLI_DEFAULT_MAX_GAS_AMOUNT,
true,
);
gas_meter.charge_io_write(tx.tx_size()).unwrap();

// The dry run supports unsigned transactions, but when calculating the transaction size,
// the length of the signature part needs to be included.
let tx_size = tx.tx_size() + AUTH_PAYLOAD_SIZE;

gas_meter.charge_io_write(tx_size).unwrap();

let mut moveos_session = MoveOSSession::new(
move_mv.inner(),
Expand Down Expand Up @@ -235,6 +242,9 @@ fn convert_to_verified_tx(
tx_data.tx_size(),
);

let tx_metadata = TxMeta::new_from_move_action(&tx_data.action);
tx_ctx.add(tx_metadata).unwrap();

let mut bitcoin_address = BitcoinAddress::from_str("18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX")?;

let user_multi_chain_address: MultiChainAddress = tx_data.sender.into();
Expand Down
Loading