//! The sequential reference executor. This is the ORACLE: the definition of the //! correct answer. Block-STM's output must equal this, byte for byte, for every //! batch. It simply applies transactions in index order against a live map. use crate::types::{Key, StateMap, Txn, Value}; use crate::vm::{execute_txn, VmView}; struct SeqView<'a> { state: &'a mut StateMap, } impl<'a> VmView for SeqView<'a> { fn read(&mut self, key: Key) -> Option { Some(*self.state.get(&key).unwrap_or(&0)) } fn write(&mut self, key: Key, value: Value) { self.state.insert(key, value); } } /// Execute `txns` in order starting from `base`, returning the final state. pub fn execute_block_sequential(base: &StateMap, txns: &[Txn]) -> StateMap { let mut state = base.clone(); for txn in txns { let mut view = SeqView { state: &mut state }; // Sequential execution never aborts (no ESTIMATE), so this is always Some. let _ = execute_txn(txn, &mut view); } state }