Skip to content

Commit 52bc527

Browse files
authored
fix: call make_idle if the adapter is idle initially (#2278)
Before #2178, make_idle was called at server startup if there have been no relevant transactions. After #2178, make_idle is not called anymore, meaning that the blockchain_manager and the connection_manager will stay in a "non idle" state forever for subnets that don't run the bitcoin adapter.
1 parent 71f3b76 commit 52bc527

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

rs/bitcoin/adapter/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ impl AdapterState {
208208
})
209209
.await;
210210
}
211+
212+
/// Returns whether the adapter is idle.
213+
pub fn is_idle(&self) -> bool {
214+
match *self.last_received_rx.borrow() {
215+
Some(last) => last.elapsed().as_secs() >= self.idle_seconds,
216+
// Nothing received yet still in idle from startup.
217+
None => true,
218+
}
219+
}
211220
}
212221

213222
/// Starts the gRPC server and the router for handling incoming requests.

rs/bitcoin/adapter/src/router.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ pub fn start_main_event_loop(
4949

5050
tokio::task::spawn(async move {
5151
let mut tick_interval = interval(Duration::from_millis(100));
52+
5253
loop {
53-
adapter_state.active().await;
54+
if adapter_state.is_idle() {
55+
connection_manager.make_idle();
56+
blockchain_manager.make_idle();
57+
adapter_state.active().await;
58+
}
5459

5560
// We do a select over tokio::sync::mpsc::Receiver::recv, tokio::sync::mpsc::UnboundedReceiver::recv,
5661
// tokio::time::Interval::tick which are all cancellation safe.
@@ -109,8 +114,6 @@ pub fn start_main_event_loop(
109114
}
110115
};
111116
}
112-
connection_manager.make_idle();
113-
blockchain_manager.make_idle();
114117
}
115118
});
116119
}

0 commit comments

Comments
 (0)