-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first draft for sequencer (#104)
* first draft for sequencer * add rust doc * comments + linting
- Loading branch information
Showing
7 changed files
with
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "sequencer" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
description.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
license.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
# Starknet | ||
blockifier = { git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" } | ||
starknet_api = { workspace = true } | ||
|
||
# Other | ||
rustc-hash = "1.1.0" |
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 @@ | ||
pub struct SequencerConfig {} |
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,3 @@ | ||
pub mod config; | ||
pub mod sequencer; | ||
pub mod state; |
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,17 @@ | ||
use crate::config::SequencerConfig; | ||
use blockifier::state::state_api::{State, StateReader}; | ||
|
||
/// Sequencer is the main struct of the sequencer crate. | ||
/// Using a trait bound for the state allows for better | ||
/// speed, as the type of the state is known at compile time. | ||
pub struct Sequencer<S: State + StateReader> { | ||
pub config: SequencerConfig, | ||
pub state: S, | ||
} | ||
|
||
impl<S: State + StateReader> Sequencer<S> { | ||
/// Creates a new Sequencer instance. | ||
pub fn new(config: SequencerConfig, state: S) -> Self { | ||
Self { config, state } | ||
} | ||
} |
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,24 @@ | ||
use blockifier::{ | ||
execution::contract_class::ContractClass, state::cached_state::ContractStorageKey, | ||
}; | ||
use rustc_hash::FxHashMap; | ||
use starknet_api::core::CompiledClassHash; | ||
use starknet_api::{ | ||
core::{ClassHash, ContractAddress, Nonce}, | ||
hash::StarkFelt, | ||
}; | ||
|
||
/// Generic state structure for the sequencer. | ||
/// The use of FxHashMap allows for a better performance. | ||
/// This hash map is used by rustc. It uses a non cryptographic hash function | ||
/// which is faster than the default hash function. Think about changing | ||
/// if the test sequencer is used for tests outside of ef-tests. | ||
/// See [rustc-hash](https://crates.io/crates/rustc-hash) for more information. | ||
#[derive(Default)] | ||
pub struct State { | ||
pub classes: FxHashMap<ClassHash, ContractClass>, | ||
pub compiled_classes: FxHashMap<ClassHash, CompiledClassHash>, | ||
pub contracts: FxHashMap<ContractAddress, ClassHash>, | ||
pub storage: FxHashMap<ContractStorageKey, StarkFelt>, | ||
pub nonces: FxHashMap<ContractAddress, Nonce>, | ||
} |