|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | 4 | use std::{ |
| 5 | + collections::HashMap, |
5 | 6 | future::{Future, IntoFuture}, |
6 | | - time::Duration, |
| 7 | + time::{Duration, Instant}, |
7 | 8 | }; |
8 | 9 |
|
| 10 | +use linera_base::crypto::CryptoHash; |
9 | 11 | use linera_execution::committee::Committee; |
10 | 12 | use linera_service::config::DestinationId; |
11 | 13 | use linera_storage::Storage; |
|
27 | 29 | storage: BlockProcessorStorage<T>, |
28 | 30 | new_block_queue: NewBlockQueue, |
29 | 31 | committee_destination_update: bool, |
| 32 | + // Temporary solution. |
| 33 | + // Tracks certificates that failed to be read from storage |
| 34 | + // along with the time of the failure to avoid retrying for too long. |
| 35 | + retried_certs: HashMap<CryptoHash, (u8, Instant)>, |
30 | 36 | } |
31 | 37 |
|
32 | 38 | impl<S, T> BlockProcessor<S, T> |
|
46 | 52 | exporters_tracker, |
47 | 53 | committee_destination_update, |
48 | 54 | new_block_queue, |
| 55 | + retried_certs: HashMap::new(), |
49 | 56 | } |
50 | 57 | } |
51 | 58 |
|
@@ -120,6 +127,30 @@ where |
120 | 127 | self.new_block_queue.push_back(next_block_notification); |
121 | 128 | }, |
122 | 129 |
|
| 130 | + Err(ExporterError::ReadCertificateError(hash)) => { |
| 131 | + match self.retried_certs.remove(&hash) { |
| 132 | + // We retry only if the time elapsed since the first attempt is |
| 133 | + // less than 1 second. The assumption is that Scylla cannot |
| 134 | + // be inconsistent for too long. |
| 135 | + Some((retries, first_attempt)) => { |
| 136 | + let elapsed = Instant::now().duration_since(first_attempt); |
| 137 | + if retries < 3 || elapsed < Duration::from_secs(1) { |
| 138 | + tracing::warn!(?hash, retry=retries+1, "retrying to read certificate"); |
| 139 | + self.retried_certs.insert(hash, (retries + 1, first_attempt)); |
| 140 | + self.new_block_queue.push_back(next_block_notification); |
| 141 | + } else { |
| 142 | + tracing::error!(?hash, "certificate is missing from the database"); |
| 143 | + return Err(ExporterError::ReadCertificateError(hash)); |
| 144 | + } |
| 145 | + }, |
| 146 | + None => { |
| 147 | + tracing::warn!(?hash, retry=1, "retrying to read certificate"); |
| 148 | + self.retried_certs.insert(hash, (1, Instant::now())); |
| 149 | + self.new_block_queue.push_back(next_block_notification); |
| 150 | + } |
| 151 | + } |
| 152 | + }, |
| 153 | + |
123 | 154 | Err(e @ (ExporterError::UnprocessedChain |
124 | 155 | | ExporterError::BadInitialization |
125 | 156 | | ExporterError::ChainAlreadyExists(_)) |
|
0 commit comments