Skip to content

Commit

Permalink
fix estimate message fee error
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Oct 16, 2024
1 parent 8e9a50e commit 9bf31c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
10 changes: 8 additions & 2 deletions crates/katana/rpc/rpc-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ impl MsgFromL1 {
// for the `estimateMessageFee` RPC.
let nonce = Felt::ZERO;

// When executing a l1 handler tx, blockifier just assert that the paid_fee_on_l1 is
// anything but 0. See: https://github.com/dojoengine/sequencer/blob/d6951f24fc2082c7aa89cdbc063648915b131d74/crates/blockifier/src/transaction/transaction_execution.rs#L140-L145
//
// For fee estimation, this value is basically irrelevant.
let paid_fee_on_l1 = 1u128;

let message_hash = compute_l2_to_l1_message_hash(
// This conversion will never fail bcs `from_address` is 20 bytes and the it will only
// fail if the slice is > 32 bytes
Expand All @@ -25,9 +31,9 @@ impl MsgFromL1 {
nonce,
chain_id,
message_hash,
calldata: self.0.payload,
paid_fee_on_l1,
version: Felt::ZERO,
paid_fee_on_l1: Default::default(),
calldata: self.0.payload,
contract_address: self.0.to_address.into(),
entry_point_selector: self.0.entry_point_selector,
}
Expand Down
17 changes: 6 additions & 11 deletions crates/katana/rpc/rpc/tests/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use katana_rpc_types::receipt::ReceiptBlock;
use rand::Rng;
use starknet::accounts::{Account, ConnectedAccount};
use starknet::contract::ContractFactory;
use starknet::core::types::MsgFromL1;
use starknet::core::types::{
BlockId, BlockTag, ContractClass, Felt, Hash256, Transaction, TransactionFinalityStatus,
TransactionReceipt,
BlockId, BlockTag, ContractClass, Felt, Hash256, MsgFromL1, Transaction,
TransactionFinalityStatus, TransactionReceipt,
};
use starknet::core::utils::get_contract_address;
use starknet::macros::selector;
Expand Down Expand Up @@ -331,8 +330,10 @@ async fn estimate_message_fee() -> Result<()> {
// Compute the contract address of the l1 handler contract
let l1handler_address = get_contract_address(Felt::ZERO, class_hash, &[], Felt::ZERO);

// Attempt to estimate the cost of calling a #[l1handler] function

let entry_point_selector = selector!("msg_handler_value");
let payload = vec![felt!("0x123"), felt!("123")];
let payload = vec![felt!("0x123"), felt!("123")]; // function arguments
let from_address = felt!("0x1337");
let to_address = l1handler_address;

Expand All @@ -344,13 +345,7 @@ async fn estimate_message_fee() -> Result<()> {
};

let result = provider.estimate_message_fee(msg, BlockId::Tag(BlockTag::Pending)).await;

match result {
Ok(_) => {}
Err(e) => {
dbg!(e);
}
}
assert!(result.is_ok());

Ok(())
}

0 comments on commit 9bf31c6

Please sign in to comment.