-
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
0459bde
commit b22a7d5
Showing
6 changed files
with
84 additions
and
6 deletions.
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
63 changes: 63 additions & 0 deletions
63
crates/blockifier/src/execution/native/contract_class_manager.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,63 @@ | ||
use std::sync::Arc; | ||
|
||
use crossbeam_channel::{Receiver, Sender, TrySendError}; | ||
use log::error; | ||
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::contract_class::ContractClassV1; | ||
use crate::execution::native::contract_class::NativeContractClassV1; | ||
use crate::state::global_cache::{CachedCairoNative, ContractClassCaches}; | ||
|
||
type CompilationRequest = (ClassHash, Arc<SierraContractClass>, ContractClassV1); | ||
|
||
struct ContractClassManager { | ||
contract_class_caches: ContractClassCaches, | ||
sender: Sender<CompilationRequest>, | ||
receiver: Receiver<CompilationRequest>, | ||
compiler: CommandLineCompiler, | ||
} | ||
|
||
impl ContractClassManager { | ||
pub fn new( | ||
contract_class_caches: ContractClassCaches, | ||
sender: Sender<CompilationRequest>, | ||
receiver: Receiver<CompilationRequest>, | ||
compiler: CommandLineCompiler, | ||
) -> Self { | ||
Self { contract_class_caches, sender, receiver, compiler } | ||
} | ||
|
||
pub fn process_compilation_requests_continuously(&self) { | ||
for (class_hash, sierra, casm) in self.receiver.iter() { | ||
if self.contract_class_caches.get_native(&class_hash).is_some() { | ||
// The contract class is already compiled to native - skip the compilation. | ||
continue; | ||
} | ||
// TODO(Avi): Convert `sierra_contract_class` to | ||
// `cairo_lang_starknet_classes::contract_class::ContractClass` | ||
let compilation_result = self.compiler.compile_to_native(sierra.into()); | ||
match compilation_result { | ||
Ok(executor) => { | ||
let native_contract_class = NativeContractClassV1::new(executor, casm); | ||
self.contract_class_caches | ||
.set_native(class_hash, CachedCairoNative::Compiled(native_contract_class)); | ||
} | ||
Err(err) => { | ||
error!("Error compiling contract class: {}", err); | ||
self.contract_class_caches | ||
.set_native(class_hash, CachedCairoNative::CompilationFailed); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn try_send_compilation_request( | ||
&self, | ||
compilation_request: CompilationRequest, | ||
) -> Result<(), TrySendError<CompilationRequest>> { | ||
Ok(self.sender.try_send(compilation_request)?) | ||
} | ||
} |
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