Skip to content

Commit

Permalink
refactor committer
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 committed Sep 21, 2023
1 parent 41c994b commit 2301d5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions crates/sequencer/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use blockifier::state::{
state_api::{State as BlockifierState, StateReader as BlockifierStateReader},
};

pub trait Committer: BlockifierState + BlockifierStateReader {
fn commit<S>(cached_state: &mut CachedState<&mut S>)
where
for<'a> &'a mut S: BlockifierState + BlockifierStateReader,
{
pub trait Committer<S>
where
for<'a> &'a mut S: BlockifierState + BlockifierStateReader,
{
fn commit(cached_state: &mut CachedState<&mut S>) {
let diff = cached_state.to_state_diff();
for (address, class_hash) in diff.address_to_class_hash {
let _ = cached_state.state.set_class_hash_at(address, class_hash);
Expand Down
6 changes: 3 additions & 3 deletions crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ use tracing::{trace, warn};
/// For more details, check out https://doc.rust-lang.org/nomicon/hrtb.html
pub struct Sequencer<S>
where
for<'a> &'a mut S: State + StateReader + Committer,
for<'a> &'a mut S: State + StateReader,
{
pub context: BlockContext,
pub state: S,
}

impl<S> Sequencer<S>
where
for<'a> &'a mut S: State + StateReader + Committer,
for<'a> &'a mut S: State + StateReader,
{
/// Creates a new Sequencer instance.
pub fn new(context: BlockContext, state: S) -> Self {
Expand All @@ -39,7 +39,7 @@ where

impl<S> Execution for Sequencer<S>
where
for<'a> &'a mut S: State + StateReader + Committer,
for<'a> &'a mut S: State + StateReader + Committer<S>,
{
fn execute(&mut self, transaction: Transaction) -> Result<(), TransactionExecutionError> {
let mut cached_state = CachedState::new(&mut self.state);
Expand Down
2 changes: 1 addition & 1 deletion crates/sequencer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct State {
nonces: FxHashMap<ContractAddress, Nonce>,
}

impl Committer for &mut State {}
impl Committer<State> for &mut State {}

/// State implementation for the sequencer. We use a mutable reference to the state
/// because this is what will be available during the implementation of the execution.
Expand Down

0 comments on commit 2301d5f

Please sign in to comment.