Skip to content

Commit d34544b

Browse files
committed
ethereum: Remove needless Mutex in block stream
1 parent 2e534c1 commit d34544b

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

chain/ethereum/src/block_stream.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::cmp;
22
use std::collections::{HashMap, VecDeque};
33
use std::mem;
4-
use std::sync::Mutex;
54
use std::time::Duration;
65

76
use graph::components::ethereum::{
@@ -122,7 +121,7 @@ impl<S, C> Clone for BlockStreamContext<S, C> {
122121
}
123122

124123
pub struct BlockStream<S, C> {
125-
state: Mutex<BlockStreamState>,
124+
state: BlockStreamState,
126125
consecutive_err_count: u32,
127126
chain_head_update_stream: ChainHeadUpdateStream,
128127
ctx: BlockStreamContext<S, C>,
@@ -159,7 +158,7 @@ where
159158
metrics: Arc<BlockStreamMetrics>,
160159
) -> Self {
161160
BlockStream {
162-
state: Mutex::new(BlockStreamState::BeginReconciliation),
161+
state: BlockStreamState::BeginReconciliation,
163162
consecutive_err_count: 0,
164163
chain_head_update_stream: chain_store.chain_head_updates(),
165164
ctx: BlockStreamContext {
@@ -563,11 +562,8 @@ impl<S: Store, C: ChainStore> Stream for BlockStream<S, C> {
563562
type Error = Error;
564563

565564
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
566-
// Lock Mutex to perform a state transition
567-
let mut state_lock = self.state.lock().unwrap();
568-
569565
let mut state = BlockStreamState::Transition;
570-
mem::swap(&mut *state_lock, &mut state);
566+
mem::swap(&mut self.state, &mut state);
571567

572568
let result = loop {
573569
match state {
@@ -717,7 +713,7 @@ impl<S: Store, C: ChainStore> Stream for BlockStream<S, C> {
717713
}
718714
};
719715

720-
*state_lock = state;
716+
self.state = state;
721717

722718
result
723719
}

0 commit comments

Comments
 (0)