From f0768034b2824823a48139dbfdce34e2d0a9b149 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 21 Sep 2023 11:19:38 +0700 Subject: [PATCH] update from comments --- crates/sequencer/src/sequencer.rs | 3 +++ crates/sequencer/src/state.rs | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index 7e579c2f..46b7a34c 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -4,6 +4,9 @@ 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. +/// We bound S such that a mutable reference to S (&'a mut S) +/// must implement State and StateReader. The `for` keyword +/// indicates that the bound must hold for any lifetime 'a. pub struct Sequencer where for<'a> &'a mut S: State + StateReader, diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index b5a41828..3d36acaf 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -31,7 +31,7 @@ pub struct 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. -impl<'a> BlockifierState for &'a mut State { +impl BlockifierState for &mut State { fn set_storage_at( &mut self, contract_address: ContractAddress, @@ -90,8 +90,8 @@ impl<'a> BlockifierState for &'a mut State { } } -impl<'a> BlockifierStateReader for &'a mut State { - /// Default: 0 for an uninitialized contract address. +impl BlockifierStateReader for &mut State { + /// Default: 0 for an uninitialized contract address or key. fn get_storage_at( &mut self, contract_address: ContractAddress, @@ -113,7 +113,7 @@ impl<'a> BlockifierStateReader for &'a mut State { .unwrap_or_default()) } - /// Default: 0 (uninitialized class hash) for an uninitialized contract address. + /// Default: 0 for an uninitialized contract address. fn get_class_hash_at(&mut self, contract_address: ContractAddress) -> StateResult { Ok(self .contracts @@ -122,7 +122,9 @@ impl<'a> BlockifierStateReader for &'a mut State { .unwrap_or_default()) } - /// Errors if the compiled class is not declared. + /// # Errors + /// + /// If the compiled class is not declared. fn get_compiled_contract_class( &mut self, class_hash: &ClassHash, @@ -133,7 +135,9 @@ impl<'a> BlockifierStateReader for &'a mut State { .ok_or_else(|| StateError::UndeclaredClassHash(class_hash.to_owned())) } - /// Errors if the compiled class hash is not declared. + /// # Errors + /// + /// If the compiled class hash is not declared. fn get_compiled_class_hash(&mut self, class_hash: ClassHash) -> StateResult { self.compiled_class_hashes .get(&class_hash)