Skip to content

Commit

Permalink
feat: first draft for sequencer (#104)
Browse files Browse the repository at this point in the history
* first draft for sequencer

* add rust doc

* comments + linting
  • Loading branch information
greged93 authored Sep 19, 2023
1 parent 6a0ca02 commit f36f9f8
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 1 deletion.
9 changes: 9 additions & 0 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
@@ -1,5 +1,5 @@
[workspace]
members = ["crates/ef-testing"]
members = ["crates/ef-testing", "crates/sequencer"]
resolver = "2"

[workspace.package]
Expand Down
20 changes: 20 additions & 0 deletions crates/sequencer/Cargo.toml
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"
1 change: 1 addition & 0 deletions crates/sequencer/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct SequencerConfig {}
3 changes: 3 additions & 0 deletions crates/sequencer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod config;
pub mod sequencer;
pub mod state;
17 changes: 17 additions & 0 deletions crates/sequencer/src/sequencer.rs
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 }
}
}
24 changes: 24 additions & 0 deletions crates/sequencer/src/state.rs
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>,
}

0 comments on commit f36f9f8

Please sign in to comment.