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

perf: remove intermediate contract deserialization #1050

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
66 changes: 55 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cairo-lang-runner = "2.1.0-rc4"
cairo-lang-sierra = "2.1.0-rc4"
cairo-lang-starknet = "2.1.0-rc4"
cairo-lang-utils = "2.1.0-rc4"
cairo-vm = { version = "0.8.5", features = ["cairo-1-hints"] }
cairo-vm = { version = "0.9.0", features = ["cairo-1-hints"] }
num-traits = "0.2.15"
starknet = "0.5.0"
starknet_api = "0.4.1"
Expand Down
4 changes: 3 additions & 1 deletion rpc_state_reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ thiserror = { workspace = true }
flate2 = "1.0.25"
serde_with = "3.0.0"
dotenv = "0.15.0"
cairo-vm = "0.8.5"
cairo-vm.workspace = true
# To create the `Program` in Blockifier's tests
cairo-vm-blockifier = { package = "cairo-vm", version = "0.8.7" }
blockifier = "0.2.0-rc0"
starknet_in_rust = { path = "../", version = "0.4.0" }

Expand Down
48 changes: 34 additions & 14 deletions rpc_state_reader/tests/blockifier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use blockifier::{
use cairo_lang_starknet::{
casm_contract_class::CasmContractClass, contract_class::ContractClass as SierraContractClass,
};
use cairo_vm::types::program::Program;
use cairo_vm_blockifier::types::program::Program;
use pretty_assertions_sorted::{assert_eq, assert_eq_sorted};
use rpc_state_reader::rpc_state::*;
use rpc_state_reader::utils;
Expand Down Expand Up @@ -217,14 +217,24 @@ fn blockifier_test_recent_tx() {
..
} = execute_call_info.unwrap();

let trace_resources = &trace
.function_invocation
.as_ref()
.unwrap()
.execution_resources;
assert_eq!(actual_fee.0, receipt.actual_fee);
assert_eq!(
vm_resources,
trace
.function_invocation
.as_ref()
.unwrap()
.execution_resources
// NOTE: had to check field by field due to version mismatch causing type errors
assert_eq_sorted!(
(
vm_resources.n_steps,
vm_resources.n_memory_holes,
&vm_resources.builtin_instance_counter
),
(
trace_resources.n_steps,
trace_resources.n_memory_holes,
&trace_resources.builtin_instance_counter
),
);
assert_eq!(
inner_calls.len(),
Expand Down Expand Up @@ -313,13 +323,23 @@ fn blockifier_test_case_tx(hash: &str, block_number: u64, chain: RpcChain) {
}
}

let trace_resources = &trace
.function_invocation
.as_ref()
.unwrap()
.execution_resources;
// NOTE: had to check field by field due to version mismatch causing type errors
assert_eq_sorted!(
vm_resources,
trace
.function_invocation
.as_ref()
.unwrap()
.execution_resources
(
vm_resources.n_steps,
vm_resources.n_memory_holes,
&vm_resources.builtin_instance_counter
),
(
trace_resources.n_steps,
trace_resources.n_memory_holes,
&trace_resources.builtin_instance_counter
),
);
assert_eq!(
inner_calls.len(),
Expand Down
19 changes: 7 additions & 12 deletions src/serde_structs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ struct Signature {
#[serde(default, rename = "stateMutability")]
state_mutability: Option<String>,
#[serde(rename = "type")]
type_name: String,
type_name: EntryPointType,
}

// We should should consider reading all the information from the abi in the future. Right now we are not considering:
// - type: "event"
// - type: "struct"
// We should should consider reading all the information from the abi in the future. Right now we
// are not considering:
// // - type: "event"
// // - type: "struct"
pub fn read_abi(abi_name: &PathBuf) -> HashMap<String, (usize, EntryPointType)> {
let abi: Vec<Signature> = serde_json::from_reader(&File::open(abi_name).unwrap()).unwrap();
let mut func_type_counter: HashMap<String, usize> = HashMap::new();
let mut func_type_counter: HashMap<EntryPointType, usize> = HashMap::new();
let mut result_hash_map: HashMap<String, (usize, EntryPointType)> = HashMap::new();

for function in abi {
Expand All @@ -29,14 +30,8 @@ pub fn read_abi(abi_name: &PathBuf) -> HashMap<String, (usize, EntryPointType)>
None => 0,
};

let entry_point_type = match &function.type_name {
type_name if type_name == "function" => EntryPointType::External,
type_name if type_name == "constructor" => EntryPointType::Constructor,
_ => EntryPointType::L1Handler,
};

func_type_counter.insert(function.type_name, function_address);
result_hash_map.insert(function.name, (function_address, entry_point_type));
result_hash_map.insert(function.name, (function_address, function.type_name));
}

result_hash_map
Expand Down
Loading