Skip to content

Commit 6e05e71

Browse files
committed
Adds block lock back in
1 parent 7cfadd9 commit 6e05e71

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

synthesizer/src/vm/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub struct VM<N: Network, C: ConsensusStorage<N>> {
7474
store: ConsensusStore<N, C>,
7575
/// The lock to guarantee atomicity over calls to speculate and finalize.
7676
atomic_lock: Arc<Mutex<()>>,
77+
/// The lock for ensuring there is no concurrency when advancing blocks.
78+
block_lock: Arc<Mutex<()>>,
7779
}
7880

7981
impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
@@ -171,7 +173,12 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
171173
}
172174

173175
// Return the new VM.
174-
Ok(Self { process: Arc::new(RwLock::new(process)), store, atomic_lock: Arc::new(Mutex::new(())) })
176+
Ok(Self {
177+
process: Arc::new(RwLock::new(process)),
178+
store,
179+
atomic_lock: Arc::new(Mutex::new(())),
180+
block_lock: Arc::new(Mutex::new(())),
181+
})
175182
}
176183

177184
/// Returns `true` if a program with the given program ID exists.
@@ -312,6 +319,10 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
312319
/// Adds the given block into the VM.
313320
#[inline]
314321
pub fn add_next_block(&self, block: &Block<N>) -> Result<()> {
322+
// Acquire the block lock, which is needed to ensure this function is not called concurrently.
323+
// Note: This lock must be held for the entire scope of this function.
324+
let _block_lock = self.block_lock.lock();
325+
315326
// Construct the finalize state.
316327
let state = FinalizeGlobalState::new::<N>(
317328
block.round(),

0 commit comments

Comments
 (0)