-
Notifications
You must be signed in to change notification settings - Fork 26
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
fc634d8
commit a25f4bd
Showing
5 changed files
with
66 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; | ||
|
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
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() { | ||
if self.contract_cache_manager.get_native_contract_executor(&class_hash).is_some() { | ||
// Skip the compilation if the contract class is already compiled. | ||
continue; | ||
} | ||
// TODO(Avi): Convert `sierra_contract_class` to | ||
// `cairo_lang_starknet_classes::contract_class::ContractClass` | ||
let compilation_result = | ||
self.command_line_compiler.compile_to_native(sierra_contract_class.into()); | ||
match compilation_result { | ||
Ok(contract_executor) => { | ||
self.contract_cache_manager | ||
.set_native_contract_executor(class_hash, Some(contract_executor)); | ||
} | ||
Err(err) => { | ||
eprintln!("Error compiling contract class: {}", err); | ||
self.contract_cache_manager.set_native_contract_executor(class_hash, None); | ||
} | ||
} | ||
} | ||
} | ||
} |