|
1 | 1 | use crate::object_mappings::ObjectMappings; |
2 | 2 | use crate::rpc_client::RpcClient; |
3 | | -use futures::{SinkExt, StreamExt}; |
4 | | -use std::time::Duration; |
5 | 3 | use subspace_archiving::archiver::ArchivedSegment; |
6 | 4 | use subspace_core_primitives::objects::{GlobalObject, PieceObject, PieceObjectMapping}; |
7 | 5 | use subspace_core_primitives::{FlatPieces, Sha256Hash}; |
8 | 6 | use subspace_rpc_primitives::FarmerMetadata; |
9 | 7 | use thiserror::Error; |
10 | 8 | use tokio::sync::oneshot; |
11 | 9 | use tokio::task::JoinHandle; |
12 | | -use tracing::{debug, error, info, warn}; |
13 | | - |
14 | | -const BEST_BLOCK_REQUEST_TIMEOUT: Duration = Duration::from_secs(60); |
| 10 | +use tracing::{debug, error, info}; |
15 | 11 |
|
16 | 12 | #[derive(Debug, Error)] |
17 | 13 | pub enum ArchivingError { |
@@ -52,7 +48,6 @@ impl Archiving { |
52 | 48 | farmer_metadata: FarmerMetadata, |
53 | 49 | object_mappings: ObjectMappings, |
54 | 50 | client: Client, |
55 | | - best_block_number_check_interval: Duration, |
56 | 51 | mut on_pieces_to_plot: OPTP, |
57 | 52 | ) -> Result<Archiving, ArchivingError> |
58 | 53 | where |
@@ -126,38 +121,6 @@ impl Archiving { |
126 | 121 | .await |
127 | 122 | .map_err(ArchivingError::RpcError)?; |
128 | 123 |
|
129 | | - let (mut best_block_number_sender, mut best_block_number_receiver) = |
130 | | - futures::channel::mpsc::channel(1); |
131 | | - |
132 | | - tokio::spawn({ |
133 | | - let client = client.clone(); |
134 | | - |
135 | | - async move { |
136 | | - loop { |
137 | | - tokio::time::sleep(best_block_number_check_interval).await; |
138 | | - |
139 | | - // In case connection dies, we need to disconnect from the node |
140 | | - let best_block_number_result = tokio::time::timeout( |
141 | | - BEST_BLOCK_REQUEST_TIMEOUT, |
142 | | - client.best_block_number(), |
143 | | - ) |
144 | | - .await; |
145 | | - |
146 | | - let is_error = !matches!(best_block_number_result, Ok(Ok(_))); |
147 | | - // Result doesn't matter here |
148 | | - let _ = best_block_number_sender |
149 | | - .send(best_block_number_result) |
150 | | - .await; |
151 | | - |
152 | | - if is_error { |
153 | | - break; |
154 | | - } |
155 | | - } |
156 | | - } |
157 | | - }); |
158 | | - |
159 | | - let mut last_best_block_number_error = false; |
160 | | - |
161 | 124 | let archiving_handle = tokio::spawn(async move { |
162 | 125 | // Listen for new blocks produced on the network |
163 | 126 | loop { |
@@ -189,36 +152,6 @@ impl Archiving { |
189 | 152 | } |
190 | 153 | } |
191 | 154 | } |
192 | | - maybe_result = best_block_number_receiver.next() => { |
193 | | - match maybe_result { |
194 | | - Some(Ok(Ok(best_block_number))) => { |
195 | | - debug!(best_block_number); |
196 | | - last_best_block_number_error = false; |
197 | | - } |
198 | | - Some(Ok(Err(error))) => { |
199 | | - if last_best_block_number_error { |
200 | | - error!(%error, "Request to get new best block failed second time"); |
201 | | - break; |
202 | | - } else { |
203 | | - warn!(%error, "Request to get new best block failed"); |
204 | | - last_best_block_number_error = true; |
205 | | - } |
206 | | - } |
207 | | - Some(Err(_error)) => { |
208 | | - if last_best_block_number_error { |
209 | | - error!("Request to get new best block timed out second time"); |
210 | | - break; |
211 | | - } else { |
212 | | - warn!("Request to get new best block timed out"); |
213 | | - last_best_block_number_error = true; |
214 | | - } |
215 | | - } |
216 | | - None => { |
217 | | - debug!("Best block number channel closed!"); |
218 | | - break; |
219 | | - } |
220 | | - } |
221 | | - } |
222 | 155 | } |
223 | 156 | } |
224 | 157 | }); |
|
0 commit comments