-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cairo_native): add batcher compiler struct
- Loading branch information
1 parent
271aa9b
commit 6e8b104
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod batcher_compiler; | ||
pub mod contract_class; | ||
pub mod entry_point_execution; | ||
pub mod syscall_handler; | ||
|
68 changes: 68 additions & 0 deletions
68
crates/blockifier/src/execution/native/batcher_compiler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::sync::Arc; | ||
|
||
use crossbeam_channel::Receiver; | ||
use starknet_api::core::ClassHash; | ||
use starknet_api::state::ContractClass as SierraContractClass; | ||
use starknet_sierra_compile::command_line_compiler::CommandLineCompiler; | ||
use starknet_sierra_compile::SierraToNativeCompiler; | ||
|
||
use crate::execution::native::contract_class::NativeContractClassV1; | ||
use crate::state::global_cache::GlobalContractCacheManager; | ||
|
||
type CompilationRequest = (ClassHash, Arc<SierraContractClass>); | ||
|
||
struct BatcherCompiler { | ||
contract_cache_manager: GlobalContractCacheManager, | ||
compilation_request_receiver: Receiver<CompilationRequest>, | ||
command_line_compiler: CommandLineCompiler, | ||
} | ||
|
||
impl BatcherCompiler { | ||
pub fn new( | ||
contract_cache_manager: GlobalContractCacheManager, | ||
compilation_request_receiver: Receiver<CompilationRequest>, | ||
command_line_compiler: CommandLineCompiler, | ||
) -> Self { | ||
Self { contract_cache_manager, compilation_request_receiver, command_line_compiler } | ||
} | ||
pub fn run(&self) { | ||
for (class_hash, sierra_contract_class) in self.compilation_request_receiver.iter() { | ||
// TODO(Avi): Convert `sierra_contract_class` to | ||
// `cairo_lang_starknet_classes::contract_class::ContractClass` | ||
if self | ||
.contract_cache_manager | ||
.cairo_native_contract_class_cache | ||
.get(&class_hash) | ||
.is_none() | ||
{ | ||
// Skip the compilation if the contract class is already compiled. | ||
continue; | ||
} | ||
let casm_contract_class = self | ||
.contract_cache_manager | ||
.casm_contract_class_cache | ||
.get(&class_hash) | ||
.expect("Casm not found in cache."); | ||
let compilation_result = | ||
self.command_line_compiler.compile_to_native(sierra_contract_class.into()); | ||
match compilation_result { | ||
Ok(contract_executor) => { | ||
let native_contract_class = NativeContractClassV1::new( | ||
contract_executor, | ||
sierra_contract_class, | ||
casm_contract_class, | ||
); | ||
self.contract_cache_manager | ||
.cairo_native_contract_class_cache | ||
.set(class_hash, Some(native_contract_class)); | ||
} | ||
Err(err) => { | ||
eprintln!("Error compiling contract class: {}", err); | ||
self.contract_cache_manager | ||
.cairo_native_contract_class_cache | ||
.set(class_hash, None); | ||
} | ||
} | ||
} | ||
} | ||
} |