Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit feaa783

Browse files
committed
Bugfix
1 parent 4bb91a4 commit feaa783

File tree

7 files changed

+48
-28
lines changed

7 files changed

+48
-28
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc_state_reader/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,4 +929,19 @@ mod transaction_tests {
929929
// dbg!(&result.call_info.clone().unwrap().execution_resources);
930930
// dbg!(&result.call_info.unwrap().internal_calls.len());
931931
// }
932+
933+
#[test]
934+
fn test_0x00164bfc80755f62de97ae7c98c9d67c1767259427bcf4ccfcc9683d44d54676() {
935+
let result = test_tx(
936+
"0x00164bfc80755f62de97ae7c98c9d67c1767259427bcf4ccfcc9683d44d54676",
937+
RpcChain::MainNet,
938+
197000,
939+
11367671039,
940+
);
941+
942+
dbg!(&result.actual_resources);
943+
dbg!(&result.actual_fee); // test=6361070805216, explorer=47292465953700, diff=5888146145679 (0.13%)
944+
//dbg!(&result.call_info.clone().unwrap().execution_resources); // Ok with explorer
945+
//dbg!(&result.call_info.unwrap().internal_calls.len()); // Ok with explorer
946+
}
932947
}

rpc_state_reader_sn_api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ flate2 = "1.0.25"
2121
serde_with = "3.0.0"
2222
dotenv = "0.15.0"
2323
cairo-vm = "0.8.5"
24-
blockifier = "0.2.0-rc0"
24+
blockifier = { path = "../../blockifier/crates/blockifier" }
2525
starknet_in_rust = { path = "../", version = "0.3.1" }

rpc_state_reader_sn_api/src/lib.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,24 @@ mod blockifier_transaction_tests {
10421042
.len()
10431043
);
10441044
}
1045+
1046+
#[test]
1047+
fn test_recent_tx_pato_bloc() {
1048+
let (tx_info, trace, receipt) = execute_tx(
1049+
"0x00164bfc80755f62de97ae7c98c9d67c1767259427bcf4ccfcc9683d44d54676",
1050+
RpcChain::MainNet,
1051+
BlockNumber(197000),
1052+
);
1053+
1054+
let TransactionExecutionInfo {
1055+
actual_fee,
1056+
actual_resources,
1057+
..
1058+
} = tx_info;
1059+
1060+
dbg!(actual_resources);
1061+
dbg!(actual_fee);
1062+
}
10451063
}
10461064
}
10471065

@@ -1145,7 +1163,7 @@ mod starknet_in_rust_transaction_tests {
11451163
// Instantiate the RPC StateReader and the CachedState
11461164
let rpc_reader = RpcStateReader(RpcState::new(network, block_number.into()));
11471165
let gas_price = rpc_reader.0.get_gas_price(block_number.0).unwrap();
1148-
1166+
dbg!(gas_price);
11491167
// Get values for block context before giving ownership of the reader
11501168
let chain_id = match rpc_reader.0.chain {
11511169
RpcChain::MainNet => StarknetChainId::MainNet,
@@ -1225,17 +1243,17 @@ mod starknet_in_rust_transaction_tests {
12251243
}
12261244

12271245
#[test]
1228-
#[ignore = "working on fixes"]
1229-
fn test_recent_tx() {
1246+
fn test_recent_tx_pato_sn() {
12301247
let (tx_info, trace, receipt) = execute_tx(
1231-
"0x05d200ef175ba15d676a68b36f7a7b72c17c17604eda4c1efc2ed5e4973e2c91",
1248+
"0x00164bfc80755f62de97ae7c98c9d67c1767259427bcf4ccfcc9683d44d54676",
12321249
RpcChain::MainNet,
1233-
BlockNumber(169928),
1250+
BlockNumber(197000),
12341251
);
12351252

12361253
let TransactionExecutionInfo {
12371254
call_info,
12381255
actual_fee,
1256+
actual_resources,
12391257
..
12401258
} = tx_info;
12411259

@@ -1262,8 +1280,8 @@ mod starknet_in_rust_transaction_tests {
12621280
.internal_calls
12631281
.len()
12641282
);
1265-
1266-
assert_eq!(actual_fee, receipt.actual_fee);
1283+
dbg!(actual_resources);
1284+
dbg!(actual_fee);
12671285
}
12681286
}
12691287
}

src/definitions/constants.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ pub(crate) const N_DEFAULT_TOPICS: usize = 1; // Events have one default topic.
1414
pub(crate) const CONSUMED_MSG_TO_L2_ENCODED_DATA_SIZE: usize =
1515
(L1_TO_L2_MSG_HEADER_SIZE + 1) - CONSUMED_MSG_TO_L2_N_TOPICS;
1616

17-
/// Sender and sequencer balance updates.
18-
pub(crate) const FEE_TRANSFER_N_STORAGE_CHANGES: usize = 2;
19-
20-
/// Exclude the sequencer balance update, since it's charged once throught the batch.
21-
pub(crate) const FEE_TRANSFER_N_STORAGE_CHANGES_TO_CHARGE: usize =
22-
FEE_TRANSFER_N_STORAGE_CHANGES - 1;
23-
2417
lazy_static! {
2518
pub(crate) static ref QUERY_VERSION_BASE: Felt252 =
2619
felt_str!("340282366920938463463374607431768211456");

src/state/cached_state.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ impl<T: StateReader> State for CachedState<T> {
265265
self.cache.storage_initial_values.clone(),
266266
);
267267

268-
let n_modified_contracts = {
269268
let storage_unique_updates = storage_updates.keys().map(|k| k.0.clone());
270269

271270
let class_hash_updates: Vec<_> = subtract_mappings(
@@ -289,9 +288,6 @@ impl<T: StateReader> State for CachedState<T> {
289288
modified_contracts.extend(class_hash_updates);
290289
modified_contracts.extend(nonce_updates);
291290

292-
modified_contracts.len()
293-
};
294-
295291
// Add fee transfer storage update before actually charging it, as it needs to be included in the
296292
// calculation of the final fee.
297293
if let Some((fee_token_address, sender_address)) = fee_token_and_sender_address {
@@ -300,9 +296,10 @@ impl<T: StateReader> State for CachedState<T> {
300296
(fee_token_address.clone(), sender_low_key),
301297
Felt252::default(),
302298
);
299+
modified_contracts.remove(fee_token_address);
303300
}
304301

305-
Ok((n_modified_contracts, storage_updates.len()))
302+
Ok((modified_contracts.len(), storage_updates.len()))
306303
}
307304

308305
fn get_class_hash_at(&mut self, contract_address: &Address) -> Result<ClassHash, StateError> {

src/utils.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::core::errors::hash_errors::HashError;
2-
use crate::definitions::constants::FEE_TRANSFER_N_STORAGE_CHANGES_TO_CHARGE;
32
use crate::services::api::contract_classes::deprecated_contract_class::EntryPointType;
43
use crate::state::state_api::State;
54
use crate::{
@@ -186,11 +185,11 @@ pub fn calculate_tx_resources(
186185
}
187186

188187
let l1_gas_usage = calculate_tx_gas_usage(
189-
l2_to_l1_messages,
190-
n_modified_contracts,
191-
n_storage_changes + FEE_TRANSFER_N_STORAGE_CHANGES_TO_CHARGE,
192-
l1_handler_payload_size,
193-
n_deployments,
188+
dbg!(l2_to_l1_messages),
189+
dbg!(n_modified_contracts),
190+
dbg!(n_storage_changes),
191+
dbg!(l1_handler_payload_size),
192+
dbg!(n_deployments),
194193
);
195194

196195
let cairo_usage = resources_manager.cairo_usage.clone();

0 commit comments

Comments
 (0)