/__w/smoldot/smoldot/repo/lib/src/sync/all_forks/pending_blocks.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Substrate-lite |
2 | | // Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. |
3 | | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 |
4 | | |
5 | | // This program is free software: you can redistribute it and/or modify |
6 | | // it under the terms of the GNU General Public License as published by |
7 | | // the Free Software Foundation, either version 3 of the License, or |
8 | | // (at your option) any later version. |
9 | | |
10 | | // This program is distributed in the hope that it will be useful, |
11 | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | // GNU General Public License for more details. |
14 | | |
15 | | // You should have received a copy of the GNU General Public License |
16 | | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | |
18 | | //! State machine managing the "disjoint" blocks, in other words blocks whose existence is known |
19 | | //! but which can't be verified yet. |
20 | | //! |
21 | | //! > **Example**: The local node knows about block 5. A peer announces block 7. Since the local |
22 | | //! > node doesn't know block 6, it has to store block 7 for later, then download |
23 | | //! > block 6. The container in this module is where block 7 is temporarily stored. |
24 | | //! |
25 | | //! In addition to a set of blocks, this data structure also stores a set of sources of blocks, |
26 | | //! and ongoing requests that related to these blocks. |
27 | | //! |
28 | | //! > **Note**: In the example above, it would store the request that asks for block 6 from the |
29 | | //! > network. |
30 | | //! |
31 | | //! # Sources |
32 | | //! |
33 | | //! The [`PendingBlocks`] collection stores a list of sources of blocks. |
34 | | //! |
35 | | //! Sources can be added by calling [`PendingBlocks::add_source`] and removed by calling |
36 | | //! [`PendingBlocks::remove_source`]. |
37 | | //! |
38 | | //! Each source has the following properties: |
39 | | //! |
40 | | //! - A [`SourceId`]. |
41 | | //! - A best block. |
42 | | //! - A list of non-finalized blocks known by this source. |
43 | | //! - An opaque user data, of type `TSrc`. |
44 | | //! |
45 | | //! # Unverified blocks |
46 | | //! |
47 | | //! The [`PendingBlocks`] collection also stores a list of unverified blocks. |
48 | | //! |
49 | | //! Note that unverified blocks are added/removed completely separately from blocks known by |
50 | | //! sources. |
51 | | //! |
52 | | //! Unverified blocks are expected to be added to this collection whenever this node hears about them |
53 | | //! from a source of blocks (such as a peer) and that it is not possible to verify them |
54 | | //! immediately (because their parent isn't known). |
55 | | //! |
56 | | //! Blocks can be added by calling [`PendingBlocks::insert_unverified_block`] and removed by |
57 | | //! calling [`PendingBlocks::remove_unverified_block`]. |
58 | | //! |
59 | | //! Each unverified block stored in this collection has the following properties associated to it: |
60 | | //! |
61 | | //! - A height. |
62 | | //! - A hash. |
63 | | //! - An optional parent block hash. |
64 | | //! - Whether the block is known to be bad. |
65 | | //! - A opaque user data decided by the user of type `TBl`. |
66 | | //! |
67 | | //! This data structure is only able to link parent and children together if the heights are |
68 | | //! linearly increasing. For example, if block A is the parent of block B, then the height of |
69 | | //! block B must be equal to the height of block A plus one. Otherwise, this data structure will |
70 | | //! not be able to detect the parent-child relationship. |
71 | | //! |
72 | | //! If a block is marked as bad, all its children (i.e. other blocks in the collection whose |
73 | | //! parent hash is the bad block) are automatically marked as bad as well. This process is |
74 | | //! recursive, such that not only direct children but all descendants of a bad block are |
75 | | //! automatically marked as bad. |
76 | | //! |
77 | | //! # Requests |
78 | | //! |
79 | | //! Call [`PendingBlocks::desired_requests`] or [`PendingBlocks::source_desired_requests`] to |
80 | | //! obtain the list of requests that should be started. |
81 | | //! |
82 | | //! Call [`PendingBlocks::add_request`] to allocate a new [`RequestId`] and add a new request. |
83 | | //! Call [`PendingBlocks::remove_request`] to destroy a request after it has finished or been |
84 | | //! canceled. Note that this method doesn't require to be passed the response to that request. |
85 | | //! The user is encouraged to update the state machine according to the response, but this must |
86 | | //! be done manually. |
87 | | //! |
88 | | |
89 | | #![allow(dead_code)] // TODO: remove this after `all.rs` implements full node; right now many methods here are useless because expected to be used only for full node code |
90 | | |
91 | | use super::{disjoint, sources}; |
92 | | |
93 | | use alloc::{collections::BTreeSet, vec::Vec}; |
94 | | use core::{ |
95 | | iter, |
96 | | num::{NonZeroU32, NonZeroU64}, |
97 | | ops, |
98 | | }; |
99 | | |
100 | | pub use disjoint::TreeRoot; |
101 | | pub use sources::SourceId; |
102 | | |
103 | | /// Configuration for the [`PendingBlocks`]. |
104 | | #[derive(Debug)] |
105 | | pub struct Config { |
106 | | /// Pre-allocated capacity for the number of blocks between the finalized block and the head |
107 | | /// of the chain. |
108 | | pub blocks_capacity: usize, |
109 | | |
110 | | /// Pre-allocated capacity for the number of sources that will be added to the collection. |
111 | | pub sources_capacity: usize, |
112 | | |
113 | | /// Height of the known finalized block. Can be lower than the actual value, and increased |
114 | | /// later. |
115 | | pub finalized_block_height: u64, |
116 | | |
117 | | /// If `true`, block bodies are downloaded and verified. If `false`, only headers are |
118 | | /// verified. |
119 | | pub download_bodies: bool, |
120 | | |
121 | | /// Maximum number of simultaneous pending requests made towards the same block. |
122 | | /// |
123 | | /// Should be set according to the failure rate of requests. For example if requests have an |
124 | | /// estimated `10%` chance of failing, then setting to value to `2` gives a `1%` chance that |
125 | | /// downloading this block will overall fail and has to be attempted again. |
126 | | /// |
127 | | /// Also keep in mind that sources might maliciously take a long time to answer requests. A |
128 | | /// higher value makes it possible to reduce the risks of the syncing taking a long time |
129 | | /// because of malicious sources. |
130 | | /// |
131 | | /// The higher the value, the more bandwidth is potentially wasted. |
132 | | pub max_requests_per_block: NonZeroU32, |
133 | | } |
134 | | |
135 | | /// State of a block in the data structure. |
136 | | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
137 | | pub enum UnverifiedBlockState { |
138 | | /// Only the height and hash of the block is known. |
139 | | HeightHash, |
140 | | /// The header of the block is known, but not its body. |
141 | | Header { |
142 | | /// Hash of the block that is parent of this one. |
143 | | parent_hash: [u8; 32], |
144 | | }, |
145 | | /// The header and body of the block are both known. The block is waiting to be verified. |
146 | | HeaderBody { |
147 | | /// Hash of the block that is parent of this one. |
148 | | parent_hash: [u8; 32], |
149 | | }, |
150 | | } |
151 | | |
152 | | impl UnverifiedBlockState { |
153 | | /// Returns the parent block hash stored in this instance, if any. |
154 | 0 | pub fn parent_hash(&self) -> Option<&[u8; 32]> { |
155 | 0 | match self { |
156 | 0 | UnverifiedBlockState::HeightHash => None, |
157 | 0 | UnverifiedBlockState::Header { parent_hash } => Some(parent_hash), |
158 | 0 | UnverifiedBlockState::HeaderBody { parent_hash } => Some(parent_hash), |
159 | | } |
160 | 0 | } Unexecuted instantiation: _RNvMNtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksNtB2_20UnverifiedBlockState11parent_hash Unexecuted instantiation: _RNvMNtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksNtB2_20UnverifiedBlockState11parent_hash |
161 | | } |
162 | | |
163 | | /// Identifier for a request in the [`super::AllForksSync`]. |
164 | | #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] |
165 | | pub struct RequestId(usize); |
166 | | |
167 | | /// Collection of pending blocks and requests. |
168 | | pub struct PendingBlocks<TBl, TRq, TSrc> { |
169 | | /// All sources in the collection. |
170 | | sources: sources::AllForksSources<Source<TSrc>>, |
171 | | |
172 | | /// Blocks whose validity couldn't be determined yet. |
173 | | blocks: disjoint::DisjointBlocks<UnverifiedBlock<TBl>>, |
174 | | |
175 | | /// See [`Config::download_bodies`]. |
176 | | download_bodies: bool, |
177 | | |
178 | | /// Set of `(block_height, block_hash, request_id)`. |
179 | | /// Contains the list of all requests, associated to their block. |
180 | | /// |
181 | | /// Note that this doesn't contain an exhaustive list of all blocks that are targeted by a |
182 | | /// request, for the simple reason that not all blocks might be known. |
183 | | /// |
184 | | /// The `request_id` is an index in [`PendingBlocks::requests`]. |
185 | | /// |
186 | | /// > **Note**: This is a more optimized way compared to adding a `Vec<RequestId>` in the |
187 | | /// > [`UnverifiedBlock`] struct. |
188 | | blocks_requests: BTreeSet<(u64, [u8; 32], RequestId)>, |
189 | | |
190 | | /// Set of `(request_id, block_height, block_hash)`. |
191 | | /// |
192 | | /// Contains the same entries as [`PendingBlocks::blocks_requests`], but ordered differently. |
193 | | requested_blocks: BTreeSet<(RequestId, u64, [u8; 32])>, |
194 | | |
195 | | /// Set of `(source_id, request_id)`. |
196 | | /// Contains the list of requests, associated to their source. |
197 | | /// |
198 | | /// The `request_id` is an index in [`PendingBlocks::requests`]. |
199 | | source_occupations: BTreeSet<(SourceId, RequestId)>, |
200 | | |
201 | | /// All ongoing requests. |
202 | | requests: slab::Slab<Request<TRq>>, |
203 | | |
204 | | /// See [`Config::max_requests_per_block`]. |
205 | | /// Since it is always compared with `usize`s, converted to `usize` ahead of time. |
206 | | max_requests_per_block: usize, |
207 | | } |
208 | | |
209 | | struct UnverifiedBlock<TBl> { |
210 | | state: UnverifiedBlockState, |
211 | | user_data: TBl, |
212 | | } |
213 | | |
214 | | struct Request<TRq> { |
215 | | detail: RequestParams, |
216 | | source_id: SourceId, |
217 | | user_data: TRq, |
218 | | } |
219 | | |
220 | | #[derive(Debug)] |
221 | | struct Source<TSrc> { |
222 | | /// Opaque object passed by the user. |
223 | | user_data: TSrc, |
224 | | } |
225 | | |
226 | | impl<TBl, TRq, TSrc> PendingBlocks<TBl, TRq, TSrc> { |
227 | | /// Initializes a new empty collection. |
228 | 21 | pub fn new(config: Config) -> Self { |
229 | 21 | PendingBlocks { |
230 | 21 | sources: sources::AllForksSources::new( |
231 | 21 | config.sources_capacity, |
232 | 21 | config.finalized_block_height, |
233 | 21 | ), |
234 | 21 | blocks: disjoint::DisjointBlocks::with_capacity(config.blocks_capacity), |
235 | 21 | download_bodies: config.download_bodies, |
236 | 21 | blocks_requests: Default::default(), |
237 | 21 | requested_blocks: Default::default(), |
238 | 21 | source_occupations: Default::default(), |
239 | 21 | requests: slab::Slab::with_capacity( |
240 | 21 | config.blocks_capacity |
241 | 21 | * usize::try_from(config.max_requests_per_block.get()).unwrap_or(usize::MAX), |
242 | 21 | ), |
243 | 21 | max_requests_per_block: usize::try_from(config.max_requests_per_block.get()) |
244 | 21 | .unwrap_or(usize::MAX), |
245 | 21 | } |
246 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE3newBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE3newCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE3newBa_ _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE3newCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 228 | 2 | pub fn new(config: Config) -> Self { | 229 | 2 | PendingBlocks { | 230 | 2 | sources: sources::AllForksSources::new( | 231 | 2 | config.sources_capacity, | 232 | 2 | config.finalized_block_height, | 233 | 2 | ), | 234 | 2 | blocks: disjoint::DisjointBlocks::with_capacity(config.blocks_capacity), | 235 | 2 | download_bodies: config.download_bodies, | 236 | 2 | blocks_requests: Default::default(), | 237 | 2 | requested_blocks: Default::default(), | 238 | 2 | source_occupations: Default::default(), | 239 | 2 | requests: slab::Slab::with_capacity( | 240 | 2 | config.blocks_capacity | 241 | 2 | * usize::try_from(config.max_requests_per_block.get()).unwrap_or(usize::MAX), | 242 | 2 | ), | 243 | 2 | max_requests_per_block: usize::try_from(config.max_requests_per_block.get()) | 244 | 2 | .unwrap_or(usize::MAX), | 245 | 2 | } | 246 | 2 | } |
Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE3newCscDgN54JpMGG_6author _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE3newCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 228 | 19 | pub fn new(config: Config) -> Self { | 229 | 19 | PendingBlocks { | 230 | 19 | sources: sources::AllForksSources::new( | 231 | 19 | config.sources_capacity, | 232 | 19 | config.finalized_block_height, | 233 | 19 | ), | 234 | 19 | blocks: disjoint::DisjointBlocks::with_capacity(config.blocks_capacity), | 235 | 19 | download_bodies: config.download_bodies, | 236 | 19 | blocks_requests: Default::default(), | 237 | 19 | requested_blocks: Default::default(), | 238 | 19 | source_occupations: Default::default(), | 239 | 19 | requests: slab::Slab::with_capacity( | 240 | 19 | config.blocks_capacity | 241 | 19 | * usize::try_from(config.max_requests_per_block.get()).unwrap_or(usize::MAX), | 242 | 19 | ), | 243 | 19 | max_requests_per_block: usize::try_from(config.max_requests_per_block.get()) | 244 | 19 | .unwrap_or(usize::MAX), | 245 | 19 | } | 246 | 19 | } |
|
247 | | |
248 | | /// Returns the value that was passed as [`Config::download_bodies`] |
249 | 0 | pub fn downloading_bodies(&self) -> bool { |
250 | 0 | self.download_bodies |
251 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE18downloading_bodiesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE18downloading_bodiesCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE18downloading_bodiesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE18downloading_bodiesCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE18downloading_bodiesCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE18downloading_bodiesCsibGXYHQB8Ea_25json_rpc_general_requests |
252 | | |
253 | | /// Add a new source to the container. |
254 | | /// |
255 | | /// The `user_data` parameter is opaque and decided entirely by the user. It can later be |
256 | | /// retrieved using the `Index` trait implementation of this container. |
257 | | /// |
258 | | /// Returns the newly-created source entry. |
259 | 21 | pub fn add_source( |
260 | 21 | &mut self, |
261 | 21 | user_data: TSrc, |
262 | 21 | best_block_number: u64, |
263 | 21 | best_block_hash: [u8; 32], |
264 | 21 | ) -> SourceId { |
265 | 21 | self.sources |
266 | 21 | .add_source(best_block_number, best_block_hash, Source { user_data }) |
267 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE10add_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE10add_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE10add_sourceBa_ _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE10add_sourceCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 259 | 2 | pub fn add_source( | 260 | 2 | &mut self, | 261 | 2 | user_data: TSrc, | 262 | 2 | best_block_number: u64, | 263 | 2 | best_block_hash: [u8; 32], | 264 | 2 | ) -> SourceId { | 265 | 2 | self.sources | 266 | 2 | .add_source(best_block_number, best_block_hash, Source { user_data }) | 267 | 2 | } |
Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE10add_sourceCscDgN54JpMGG_6author _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE10add_sourceCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 259 | 19 | pub fn add_source( | 260 | 19 | &mut self, | 261 | 19 | user_data: TSrc, | 262 | 19 | best_block_number: u64, | 263 | 19 | best_block_hash: [u8; 32], | 264 | 19 | ) -> SourceId { | 265 | 19 | self.sources | 266 | 19 | .add_source(best_block_number, best_block_hash, Source { user_data }) | 267 | 19 | } |
|
268 | | |
269 | | /// Removes the source from the [`PendingBlocks`]. |
270 | | /// |
271 | | /// Returns the user data that was originally passed to [`PendingBlocks::add_source`], plus |
272 | | /// a list of all the requests that were targeting this source. These request are now |
273 | | /// invalid. |
274 | | /// |
275 | | /// # Panic |
276 | | /// |
277 | | /// Panics if the [`SourceId`] is out of range. |
278 | | /// |
279 | 0 | pub fn remove_source( |
280 | 0 | &mut self, |
281 | 0 | source_id: SourceId, |
282 | 0 | ) -> (TSrc, impl Iterator<Item = (RequestId, RequestParams, TRq)>) { |
283 | 0 | let user_data = self.sources.remove(source_id); |
284 | 0 |
|
285 | 0 | let source_occupations_entries = self |
286 | 0 | .source_occupations |
287 | 0 | .range((source_id, RequestId(usize::MIN))..=(source_id, RequestId(usize::MAX))) |
288 | 0 | .copied() |
289 | 0 | .collect::<Vec<_>>(); |
290 | 0 |
|
291 | 0 | // TODO: optimize with a custom iterator? |
292 | 0 | let mut pending_requests = Vec::new(); |
293 | | |
294 | 0 | for (_source_id, pending_request_id) in source_occupations_entries { |
295 | 0 | debug_assert_eq!(source_id, _source_id); |
296 | | |
297 | 0 | debug_assert!(self.requests.contains(pending_request_id.0)); |
298 | 0 | let request = self.requests.remove(pending_request_id.0); |
299 | 0 |
|
300 | 0 | let _was_in = self |
301 | 0 | .source_occupations |
302 | 0 | .remove(&(source_id, pending_request_id)); |
303 | 0 | debug_assert!(_was_in); |
304 | | |
305 | 0 | let _was_in = self.blocks_requests.remove(&( |
306 | 0 | request.detail.first_block_height, |
307 | 0 | request.detail.first_block_hash, |
308 | 0 | pending_request_id, |
309 | 0 | )); |
310 | 0 | debug_assert!(_was_in); |
311 | | |
312 | 0 | let _was_in = self.requested_blocks.remove(&( |
313 | 0 | pending_request_id, |
314 | 0 | request.detail.first_block_height, |
315 | 0 | request.detail.first_block_hash, |
316 | 0 | )); |
317 | 0 | debug_assert!(_was_in); |
318 | | |
319 | 0 | pending_requests.push((pending_request_id, request.detail, request.user_data)); |
320 | | } |
321 | | |
322 | 0 | debug_assert_eq!(self.source_occupations.len(), self.requests.len()); |
323 | | |
324 | 0 | (user_data.user_data, pending_requests.into_iter()) |
325 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE13remove_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE13remove_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE13remove_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE13remove_sourceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE13remove_sourceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE13remove_sourceCsibGXYHQB8Ea_25json_rpc_general_requests |
326 | | |
327 | | /// Returns the list of sources in this state machine. |
328 | 21 | pub fn sources(&'_ self) -> impl ExactSizeIterator<Item = SourceId> + '_ { |
329 | 21 | self.sources.keys() |
330 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE7sourcesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE7sourcesCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE7sourcesBa_ _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE7sourcesCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 328 | 2 | pub fn sources(&'_ self) -> impl ExactSizeIterator<Item = SourceId> + '_ { | 329 | 2 | self.sources.keys() | 330 | 2 | } |
Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE7sourcesCscDgN54JpMGG_6author _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE7sourcesCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 328 | 19 | pub fn sources(&'_ self) -> impl ExactSizeIterator<Item = SourceId> + '_ { | 329 | 19 | self.sources.keys() | 330 | 19 | } |
|
331 | | |
332 | | /// Returns the list of all user datas of all sources. |
333 | 0 | pub fn sources_user_data_iter_mut( |
334 | 0 | &'_ mut self, |
335 | 0 | ) -> impl ExactSizeIterator<Item = &'_ mut TSrc> + '_ { |
336 | 0 | self.sources.user_data_iter_mut().map(|s| &mut s.user_data) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE26sources_user_data_iter_mut0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE26sources_user_data_iter_mut0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE26sources_user_data_iter_mut0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE26sources_user_data_iter_mut0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE26sources_user_data_iter_mut0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE26sources_user_data_iter_mut0CsibGXYHQB8Ea_25json_rpc_general_requests |
337 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26sources_user_data_iter_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE26sources_user_data_iter_mutCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26sources_user_data_iter_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26sources_user_data_iter_mutCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26sources_user_data_iter_mutCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26sources_user_data_iter_mutCsibGXYHQB8Ea_25json_rpc_general_requests |
338 | | |
339 | | /// Registers a new block that the source is aware of. |
340 | | /// |
341 | | /// Has no effect if `height` is inferior or equal to the finalized block height. |
342 | | /// |
343 | | /// The block does not need to be known by the data structure. |
344 | | /// |
345 | | /// # Panic |
346 | | /// |
347 | | /// Panics if the [`SourceId`] is out of range. |
348 | | /// |
349 | 0 | pub fn add_known_block_to_source(&mut self, source_id: SourceId, height: u64, hash: [u8; 32]) { |
350 | 0 | self.sources.add_known_block(source_id, height, hash); |
351 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25add_known_block_to_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE25add_known_block_to_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25add_known_block_to_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25add_known_block_to_sourceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25add_known_block_to_sourceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25add_known_block_to_sourceCsibGXYHQB8Ea_25json_rpc_general_requests |
352 | | |
353 | | /// Un-registers a new block that the source is aware of. |
354 | | /// |
355 | | /// Has no effect if the block wasn't marked as being known to this source. |
356 | | /// |
357 | | /// > **Note**: Use this function if for example a source is unable to serve a block that is |
358 | | /// > supposed to be known to it. |
359 | | /// |
360 | | /// # Panic |
361 | | /// |
362 | | /// Panics if the [`SourceId`] is out of range. |
363 | | /// |
364 | 0 | pub fn remove_known_block_of_source( |
365 | 0 | &mut self, |
366 | 0 | source_id: SourceId, |
367 | 0 | height: u64, |
368 | 0 | hash: &[u8; 32], |
369 | 0 | ) { |
370 | 0 | self.sources |
371 | 0 | .source_remove_known_block(source_id, height, hash); |
372 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28remove_known_block_of_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE28remove_known_block_of_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28remove_known_block_of_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28remove_known_block_of_sourceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28remove_known_block_of_sourceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28remove_known_block_of_sourceCsibGXYHQB8Ea_25json_rpc_general_requests |
373 | | |
374 | | /// Registers a new block that the source is aware of and sets it as its best block. |
375 | | /// |
376 | | /// If the block height is inferior or equal to the finalized block height, the block itself |
377 | | /// isn't kept in memory but is still set as the source's best block. |
378 | | /// |
379 | | /// The block does not need to be known by the data structure. |
380 | | /// |
381 | | /// # Panic |
382 | | /// |
383 | | /// Panics if the [`SourceId`] is out of range. |
384 | | /// |
385 | 0 | pub fn add_known_block_to_source_and_set_best( |
386 | 0 | &mut self, |
387 | 0 | source_id: SourceId, |
388 | 0 | height: u64, |
389 | 0 | hash: [u8; 32], |
390 | 0 | ) { |
391 | 0 | self.sources |
392 | 0 | .add_known_block_and_set_best(source_id, height, hash); |
393 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38add_known_block_to_source_and_set_bestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38add_known_block_to_source_and_set_bestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCsibGXYHQB8Ea_25json_rpc_general_requests |
394 | | |
395 | | /// Returns the current best block of the given source. |
396 | | /// |
397 | | /// This corresponds either the latest call to [`PendingBlocks::add_known_block_to_source_and_set_best`], |
398 | | /// or to the parameter passed to [`PendingBlocks::add_source`]. |
399 | | /// |
400 | | /// # Panic |
401 | | /// |
402 | | /// Panics if the [`SourceId`] is invalid. |
403 | | /// |
404 | 0 | pub fn source_best_block(&self, source_id: SourceId) -> (u64, &[u8; 32]) { |
405 | 0 | self.sources.best_block(source_id) |
406 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17source_best_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE17source_best_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17source_best_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17source_best_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17source_best_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17source_best_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
407 | | |
408 | | /// Returns the number of ongoing requests that concern this source. |
409 | | /// |
410 | | /// # Panic |
411 | | /// |
412 | | /// Panics if the [`SourceId`] is invalid. |
413 | | /// |
414 | 0 | pub fn source_num_ongoing_requests(&self, source_id: SourceId) -> usize { |
415 | 0 | self.source_occupations |
416 | 0 | .range((source_id, RequestId(usize::MIN))..=(source_id, RequestId(usize::MAX))) |
417 | 0 | .count() |
418 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE27source_num_ongoing_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE27source_num_ongoing_requestsBa_ |
419 | | |
420 | | /// Returns the list of sources for which [`PendingBlocks::source_knows_non_finalized_block`] |
421 | | /// would return `true`. |
422 | | /// |
423 | | /// # Panic |
424 | | /// |
425 | | /// Panics if `height` is inferior or equal to the finalized block height. Finalized blocks |
426 | | /// are intentionally not tracked by this data structure, and panicking when asking for a |
427 | | /// potentially-finalized block prevents potentially confusing or erroneous situations. |
428 | | /// |
429 | 0 | pub fn knows_non_finalized_block<'a>( |
430 | 0 | &'a self, |
431 | 0 | height: u64, |
432 | 0 | hash: &[u8; 32], |
433 | 0 | ) -> impl Iterator<Item = SourceId> + 'a { |
434 | 0 | self.sources.knows_non_finalized_block(height, hash) |
435 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25knows_non_finalized_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE25knows_non_finalized_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25knows_non_finalized_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25knows_non_finalized_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25knows_non_finalized_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25knows_non_finalized_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
436 | | |
437 | | /// Returns true if [`PendingBlocks::add_known_block_to_source`] or |
438 | | /// [`PendingBlocks::add_known_block_to_source_and_set_best`] has earlier been called on this |
439 | | /// source with this height and hash, or if the source was originally created (using |
440 | | /// [`PendingBlocks::add_source`]) with this height and hash. |
441 | | /// |
442 | | /// # Panic |
443 | | /// |
444 | | /// Panics if the [`SourceId`] is out of range. |
445 | | /// |
446 | | /// Panics if `height` is inferior or equal to the finalized block height. Finalized blocks |
447 | | /// are intentionally not tracked by this data structure, and panicking when asking for a |
448 | | /// potentially-finalized block prevents potentially confusing or erroneous situations. |
449 | | /// |
450 | 0 | pub fn source_knows_non_finalized_block( |
451 | 0 | &self, |
452 | 0 | source_id: SourceId, |
453 | 0 | height: u64, |
454 | 0 | hash: &[u8; 32], |
455 | 0 | ) -> bool { |
456 | 0 | self.sources |
457 | 0 | .source_knows_non_finalized_block(source_id, height, hash) |
458 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE32source_knows_non_finalized_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE32source_knows_non_finalized_blockBa_ |
459 | | |
460 | | /// Updates the height of the finalized block. |
461 | | /// |
462 | | /// This removes from the collection all blocks (both source-known and unverified) whose |
463 | | /// height is inferior or equal to this value. |
464 | | /// |
465 | | /// # Panic |
466 | | /// |
467 | | /// Panics if the new height is inferior to the previous value. |
468 | | /// |
469 | 0 | pub fn set_finalized_block_height( |
470 | 0 | &mut self, |
471 | 0 | height: u64, |
472 | 0 | ) -> impl ExactSizeIterator<Item = TBl> { |
473 | 0 | self.sources.set_finalized_block_height(height); |
474 | 0 | self.blocks |
475 | 0 | .remove_below_height(height + 1) |
476 | 0 | .map(|(_, _, bl)| bl.user_data) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE26set_finalized_block_height0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE26set_finalized_block_height0Bc_ |
477 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_finalized_block_heightBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE26set_finalized_block_heightCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_finalized_block_heightBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26set_finalized_block_heightCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26set_finalized_block_heightCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26set_finalized_block_heightCsibGXYHQB8Ea_25json_rpc_general_requests |
478 | | |
479 | | /// Inserts an unverified block in the collection. |
480 | | /// |
481 | | /// Returns the previous user data associated to this block, if any. |
482 | | /// |
483 | | /// > **Note**: You should probably also call [`PendingBlocks::add_known_block_to_source`] or |
484 | | /// > [`PendingBlocks::add_known_block_to_source_and_set_best`]. |
485 | 0 | pub fn insert_unverified_block( |
486 | 0 | &mut self, |
487 | 0 | height: u64, |
488 | 0 | hash: [u8; 32], |
489 | 0 | state: UnverifiedBlockState, |
490 | 0 | user_data: TBl, |
491 | 0 | ) -> Option<(TBl, UnverifiedBlockState)> { |
492 | 0 | if height <= self.sources.finalized_block_height() { |
493 | 0 | return None; |
494 | 0 | } |
495 | 0 |
|
496 | 0 | let parent_hash = state.parent_hash().copied(); |
497 | 0 | // TODO: is it ok to just override the UnverifiedBlockState? |
498 | 0 | self.blocks |
499 | 0 | .insert( |
500 | 0 | height, |
501 | 0 | hash, |
502 | 0 | parent_hash, |
503 | 0 | UnverifiedBlock { state, user_data }, |
504 | 0 | ) |
505 | 0 | .map(|b| (b.user_data, b.state)) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23insert_unverified_block0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE23insert_unverified_block0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23insert_unverified_block0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE23insert_unverified_block0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE23insert_unverified_block0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE23insert_unverified_block0CsibGXYHQB8Ea_25json_rpc_general_requests |
506 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23insert_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE23insert_unverified_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23insert_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23insert_unverified_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23insert_unverified_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23insert_unverified_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
507 | | |
508 | | /// Returns `true` if the block with the given height and hash is in the collection. |
509 | 0 | pub fn contains_unverified_block(&self, height: u64, hash: &[u8; 32]) -> bool { |
510 | 0 | self.blocks.contains(height, hash) |
511 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25contains_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE25contains_unverified_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25contains_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25contains_unverified_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25contains_unverified_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25contains_unverified_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
512 | | |
513 | | /// Gives access to the user data stored for this block. |
514 | | /// |
515 | | /// # Panic |
516 | | /// |
517 | | /// Panics if the block wasn't present in the data structure. |
518 | | /// |
519 | 0 | pub fn unverified_block_user_data(&self, height: u64, hash: &[u8; 32]) -> &TBl { |
520 | 0 | &self.blocks.user_data(height, hash).unwrap().user_data |
521 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26unverified_block_user_dataBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE26unverified_block_user_dataCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26unverified_block_user_dataBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26unverified_block_user_dataCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26unverified_block_user_dataCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26unverified_block_user_dataCsibGXYHQB8Ea_25json_rpc_general_requests |
522 | | |
523 | | /// Gives access to the user data stored for this block. |
524 | | /// |
525 | | /// # Panic |
526 | | /// |
527 | | /// Panics if the block wasn't present in the data structure. |
528 | | /// |
529 | 0 | pub fn unverified_block_user_data_mut(&mut self, height: u64, hash: &[u8; 32]) -> &mut TBl { |
530 | 0 | &mut self.blocks.user_data_mut(height, hash).unwrap().user_data |
531 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE30unverified_block_user_data_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE30unverified_block_user_data_mutCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE30unverified_block_user_data_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE30unverified_block_user_data_mutCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE30unverified_block_user_data_mutCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE30unverified_block_user_data_mutCsibGXYHQB8Ea_25json_rpc_general_requests |
532 | | |
533 | | /// Modifies the state of the given block. |
534 | | /// |
535 | | /// This influences the outcome of [`PendingBlocks::desired_requests`]. |
536 | | /// |
537 | | /// # Panic |
538 | | /// |
539 | | /// Panics if the block wasn't present in the data structure. |
540 | | /// |
541 | 0 | pub fn set_unverified_block_state( |
542 | 0 | &mut self, |
543 | 0 | height: u64, |
544 | 0 | hash: &[u8; 32], |
545 | 0 | state: UnverifiedBlockState, |
546 | 0 | ) { |
547 | 0 | if let Some(parent_hash) = state.parent_hash() { |
548 | 0 | self.blocks.set_parent_hash(height, hash, *parent_hash); |
549 | 0 | } |
550 | | |
551 | 0 | self.blocks.user_data_mut(height, hash).unwrap().state = state; |
552 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_unverified_block_stateBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_unverified_block_stateBa_ |
553 | | |
554 | | /// Modifies the state of the given block. This is a convenience around |
555 | | /// [`PendingBlocks::set_unverified_block_state`]. |
556 | | /// |
557 | | /// If the current block's state implies that the header isn't known yet, updates it to a |
558 | | /// state where the header is known. |
559 | | /// |
560 | | /// > **Note**: A user of this data structure is expected to manually add the parent block to |
561 | | /// this data structure as well in case it is unverified. |
562 | | /// |
563 | | /// # Panic |
564 | | /// |
565 | | /// Panics if the block wasn't present in the data structure. |
566 | | /// Panics if the block's header was already known and the its parent hash doesn't match |
567 | | /// the one passed as parameter. |
568 | | /// |
569 | 0 | pub fn set_unverified_block_header_known( |
570 | 0 | &mut self, |
571 | 0 | height: u64, |
572 | 0 | hash: &[u8; 32], |
573 | 0 | parent_hash: [u8; 32], |
574 | 0 | ) { |
575 | 0 | let curr = &mut self.blocks.user_data_mut(height, hash).unwrap().state; |
576 | | |
577 | 0 | match curr { |
578 | 0 | UnverifiedBlockState::Header { |
579 | 0 | parent_hash: cur_ph, |
580 | 0 | } |
581 | 0 | | UnverifiedBlockState::HeaderBody { |
582 | 0 | parent_hash: cur_ph, |
583 | 0 | } if *cur_ph == parent_hash => return, |
584 | | UnverifiedBlockState::Header { .. } | UnverifiedBlockState::HeaderBody { .. } => { |
585 | 0 | panic!() |
586 | | } |
587 | 0 | UnverifiedBlockState::HeightHash => {} |
588 | 0 | } |
589 | 0 |
|
590 | 0 | *curr = UnverifiedBlockState::Header { parent_hash }; |
591 | 0 | self.blocks.set_parent_hash(height, hash, parent_hash); |
592 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE33set_unverified_block_header_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE33set_unverified_block_header_knownCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE33set_unverified_block_header_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE33set_unverified_block_header_knownCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE33set_unverified_block_header_knownCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE33set_unverified_block_header_knownCsibGXYHQB8Ea_25json_rpc_general_requests |
593 | | |
594 | | /// Modifies the state of the given block. This is a convenience around |
595 | | /// [`PendingBlocks::set_unverified_block_state`]. |
596 | | /// |
597 | | /// If the current block's state implies that the header or body isn't known yet, updates it |
598 | | /// to a state where the header and body are known. |
599 | | /// |
600 | | /// > **Note**: A user of this data structure is expected to manually add the parent block to |
601 | | /// this data structure as well in case it is unverified. |
602 | | /// |
603 | | /// # Panic |
604 | | /// |
605 | | /// Panics if the block wasn't present in the data structure. |
606 | | /// Panics if the block's header was already known and the its parent hash doesn't match |
607 | | /// the one passed as parameter. |
608 | | /// |
609 | 0 | pub fn set_unverified_block_header_body_known( |
610 | 0 | &mut self, |
611 | 0 | height: u64, |
612 | 0 | hash: &[u8; 32], |
613 | 0 | parent_hash: [u8; 32], |
614 | 0 | ) { |
615 | 0 | let curr = &mut self.blocks.user_data_mut(height, hash).unwrap().state; |
616 | | |
617 | 0 | match curr { |
618 | 0 | UnverifiedBlockState::Header { |
619 | 0 | parent_hash: cur_ph, |
620 | 0 | } if *cur_ph == parent_hash => {} |
621 | | UnverifiedBlockState::HeaderBody { |
622 | 0 | parent_hash: cur_ph, |
623 | 0 | } if *cur_ph == parent_hash => return, |
624 | | UnverifiedBlockState::Header { .. } | UnverifiedBlockState::HeaderBody { .. } => { |
625 | 0 | panic!() |
626 | | } |
627 | 0 | UnverifiedBlockState::HeightHash => {} |
628 | | } |
629 | | |
630 | 0 | *curr = UnverifiedBlockState::HeaderBody { parent_hash }; |
631 | 0 | self.blocks.set_parent_hash(height, hash, parent_hash); |
632 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38set_unverified_block_header_body_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38set_unverified_block_header_body_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCsibGXYHQB8Ea_25json_rpc_general_requests |
633 | | |
634 | | /// Removes the given block from the list of known blocks of all from the sources. |
635 | | /// |
636 | | /// This is equivalent to calling [`PendingBlocks::remove_known_block_of_source`] for each |
637 | | /// source. |
638 | 0 | pub fn remove_sources_known_block(&mut self, height: u64, hash: &[u8; 32]) { |
639 | 0 | self.sources.remove_known_block(height, hash); |
640 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26remove_sources_known_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26remove_sources_known_blockBa_ |
641 | | |
642 | | /// Removes the given unverified block from the collection. |
643 | | /// |
644 | | /// > **Note**: Use this method after a block has been successfully verified, or in order to |
645 | | /// > remove uninteresting blocks if there are too many blocks in the collection. |
646 | | /// |
647 | | /// # Panic |
648 | | /// |
649 | | /// Panics if the block wasn't present in the data structure. |
650 | | /// |
651 | 0 | pub fn remove_unverified_block(&mut self, height: u64, hash: &[u8; 32]) -> TBl { |
652 | 0 | self.blocks.remove(height, hash).user_data |
653 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23remove_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE23remove_unverified_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23remove_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23remove_unverified_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23remove_unverified_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23remove_unverified_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
654 | | |
655 | | /// Marks the given unverified block and all its known children as "bad". |
656 | | /// |
657 | | /// If a child of this block is later added to the collection, it is also automatically |
658 | | /// marked as bad. |
659 | | /// |
660 | | /// # Panic |
661 | | /// |
662 | | /// Panics if the block wasn't present in the data structure. |
663 | | /// |
664 | | #[track_caller] |
665 | 0 | pub fn mark_unverified_block_as_bad(&mut self, height: u64, hash: &[u8; 32]) { |
666 | 0 | self.blocks.set_block_bad(height, hash); |
667 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28mark_unverified_block_as_badBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE28mark_unverified_block_as_badCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28mark_unverified_block_as_badBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28mark_unverified_block_as_badCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28mark_unverified_block_as_badCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28mark_unverified_block_as_badCsibGXYHQB8Ea_25json_rpc_general_requests |
668 | | |
669 | | /// Returns the number of unverified blocks stored in the data structure. |
670 | 0 | pub fn num_unverified_blocks(&self) -> usize { |
671 | 0 | self.blocks.len() |
672 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE21num_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE21num_unverified_blocksCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE21num_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE21num_unverified_blocksCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE21num_unverified_blocksCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE21num_unverified_blocksCsibGXYHQB8Ea_25json_rpc_general_requests |
673 | | |
674 | | /// Returns the list of blocks whose parent hash is known but absent from the list of disjoint |
675 | | /// blocks. These blocks can potentially be verified. |
676 | | /// |
677 | | /// All the returned block are guaranteed to be in a "header known" state. If |
678 | | /// [`Config::download_bodies`] if `true`, they they are also guaranteed to be in a "body known" |
679 | | /// state. |
680 | | /// |
681 | | /// > **Note**: The naming of this function assumes that all blocks that are referenced by |
682 | | /// > this data structure but absent from this data structure are known by the |
683 | | /// > API user. |
684 | 21 | pub fn unverified_leaves(&'_ self) -> impl Iterator<Item = TreeRoot> + '_ { |
685 | 21 | self.blocks.good_tree_roots().filter(move |pending| { |
686 | 0 | match self |
687 | 0 | .blocks |
688 | 0 | .user_data(pending.block_number, &pending.block_hash) |
689 | 0 | .unwrap() |
690 | 0 | .state |
691 | | { |
692 | 0 | UnverifiedBlockState::HeightHash => false, |
693 | 0 | UnverifiedBlockState::Header { .. } => !self.download_bodies, |
694 | 0 | UnverifiedBlockState::HeaderBody { .. } => true, |
695 | | } |
696 | 21 | }0 ) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17unverified_leaves0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE17unverified_leaves0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17unverified_leaves0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE17unverified_leaves0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE17unverified_leaves0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE17unverified_leaves0CsibGXYHQB8Ea_25json_rpc_general_requests |
697 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17unverified_leavesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE17unverified_leavesCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17unverified_leavesBa_ _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17unverified_leavesCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 684 | 2 | pub fn unverified_leaves(&'_ self) -> impl Iterator<Item = TreeRoot> + '_ { | 685 | 2 | self.blocks.good_tree_roots().filter(move |pending| { | 686 | | match self | 687 | | .blocks | 688 | | .user_data(pending.block_number, &pending.block_hash) | 689 | | .unwrap() | 690 | | .state | 691 | | { | 692 | | UnverifiedBlockState::HeightHash => false, | 693 | | UnverifiedBlockState::Header { .. } => !self.download_bodies, | 694 | | UnverifiedBlockState::HeaderBody { .. } => true, | 695 | | } | 696 | 2 | }) | 697 | 2 | } |
Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17unverified_leavesCscDgN54JpMGG_6author _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17unverified_leavesCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 684 | 19 | pub fn unverified_leaves(&'_ self) -> impl Iterator<Item = TreeRoot> + '_ { | 685 | 19 | self.blocks.good_tree_roots().filter(move |pending| { | 686 | | match self | 687 | | .blocks | 688 | | .user_data(pending.block_number, &pending.block_hash) | 689 | | .unwrap() | 690 | | .state | 691 | | { | 692 | | UnverifiedBlockState::HeightHash => false, | 693 | | UnverifiedBlockState::Header { .. } => !self.download_bodies, | 694 | | UnverifiedBlockState::HeaderBody { .. } => true, | 695 | | } | 696 | 19 | }) | 697 | 19 | } |
|
698 | | |
699 | | /// Returns an iterator to a list of unverified blocks in the data structure that aren't |
700 | | /// necessary to keep in order to complete the chain. |
701 | | /// |
702 | | /// The returned blocks are ordered by increasing order of importance. In other words, the |
703 | | /// earlier blocks are less useful. |
704 | | /// |
705 | | /// In details, this returns: |
706 | | /// |
707 | | /// - Blocks that have a bad parent and that aren't the best block of any given source. |
708 | | /// - Blocks whose parent is in the data structure and that aren't the best block of any given |
709 | | /// source. |
710 | | /// - Blocks that are bad and that aren't the best block of any given source. |
711 | | /// |
712 | | /// It is guaranteed that, even if you always immediately remove all the blocks provided by |
713 | | /// this iterator, the chain will eventually become fully synchronized (assuming that block |
714 | | /// requests eventually succeed). |
715 | | /// |
716 | | /// > **Note**: You are encouraged to use this method to remove blocks in order to prevent the |
717 | | /// > data structure from reaching unreasonable sizes. Please keep in mind, however, |
718 | | /// > that removing blocks will lead to redownloading these blocks later. In other |
719 | | /// > words, it is better to keep these blocks. |
720 | 0 | pub fn unnecessary_unverified_blocks( |
721 | 0 | &'_ self, |
722 | 0 | ) -> impl Iterator<Item = (u64, &'_ [u8; 32])> + '_ { |
723 | 0 | // TODO: this entire function is O(n) everywhere |
724 | 0 |
|
725 | 0 | // List of blocks that have a bad parent. |
726 | 0 | // If a block has a bad parent, it is also bad itself, hence why we use `bad_blocks()`. |
727 | 0 | let bad_parent_iter = self |
728 | 0 | .blocks |
729 | 0 | .iter() |
730 | 0 | .filter(|(height, hash, _)| self.blocks.is_parent_bad(*height, hash).unwrap_or(false)); Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blocks0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blocks0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blocks0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blocks0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blocks0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blocks0CsibGXYHQB8Ea_25json_rpc_general_requests |
731 | 0 |
|
732 | 0 | // List of blocks whose parent is in the data structure. |
733 | 0 | let parent_known_iter = self.blocks.iter().filter(|(height, hash, _)| { |
734 | 0 | match ( |
735 | 0 | height.checked_sub(1), |
736 | 0 | self.blocks.parent_hash(*height, hash), |
737 | | ) { |
738 | 0 | (Some(n), Some(h)) => self.blocks.contains(n, h), |
739 | 0 | _ => false, |
740 | | } |
741 | 0 | }); Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0CsibGXYHQB8Ea_25json_rpc_general_requests |
742 | 0 |
|
743 | 0 | // List of blocks that are bad but don't have a bad parent. |
744 | 0 | // This is the same as `bad_parent_iter`, but the filter is reversed. |
745 | 0 | let bad_iter = self |
746 | 0 | .blocks |
747 | 0 | .iter() |
748 | 0 | .filter(|(height, hash, _)| self.blocks.is_bad(*height, hash).unwrap()) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0CsibGXYHQB8Ea_25json_rpc_general_requests |
749 | 0 | .filter(|(height, hash, _)| !self.blocks.is_parent_bad(*height, hash).unwrap_or(false)); Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0CsibGXYHQB8Ea_25json_rpc_general_requests |
750 | 0 |
|
751 | 0 | // Never return any block that is the best block of a source. |
752 | 0 | bad_parent_iter |
753 | 0 | .chain(parent_known_iter) |
754 | 0 | .chain(bad_iter) |
755 | 0 | .map(|(height, hash, _)| (height, hash)) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0CsibGXYHQB8Ea_25json_rpc_general_requests |
756 | 0 | .filter(|(height, hash)| { |
757 | 0 | !self |
758 | 0 | .sources |
759 | 0 | .keys() |
760 | 0 | .any(|source_id| self.sources.best_block(source_id) == (*height, hash)) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE29unnecessary_unverified_blockss3_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE29unnecessary_unverified_blockss3_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00CsibGXYHQB8Ea_25json_rpc_general_requests |
761 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0CsibGXYHQB8Ea_25json_rpc_general_requests |
762 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE29unnecessary_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE29unnecessary_unverified_blocksCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE29unnecessary_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE29unnecessary_unverified_blocksCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE29unnecessary_unverified_blocksCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE29unnecessary_unverified_blocksCsibGXYHQB8Ea_25json_rpc_general_requests |
763 | | |
764 | | /// Inserts a new request in the data structure. |
765 | | /// |
766 | | /// > **Note**: The request doesn't necessarily have to match a request returned by |
767 | | /// > [`PendingBlocks::desired_requests`] or |
768 | | /// > [`PendingBlocks::source_desired_requests`]. Any arbitrary blocks request can |
769 | | /// > be added. |
770 | | /// |
771 | | /// # Panic |
772 | | /// |
773 | | /// Panics if the [`SourceId`] is out of range. |
774 | | /// |
775 | 0 | pub fn add_request( |
776 | 0 | &mut self, |
777 | 0 | source_id: SourceId, |
778 | 0 | detail: RequestParams, |
779 | 0 | user_data: TRq, |
780 | 0 | ) -> RequestId { |
781 | 0 | assert!(self.sources.contains(source_id)); |
782 | | |
783 | 0 | let request_id = RequestId(self.requests.insert(Request { |
784 | 0 | detail, |
785 | 0 | source_id, |
786 | 0 | user_data, |
787 | 0 | })); |
788 | 0 |
|
789 | 0 | let _was_inserted = self.source_occupations.insert((source_id, request_id)); |
790 | 0 | debug_assert!(_was_inserted); |
791 | | |
792 | 0 | debug_assert_eq!(self.source_occupations.len(), self.requests.len()); |
793 | | |
794 | | // Add in `blocks_requests` and `requested_blocks` an entry for each known block. |
795 | 0 | let mut iter = (detail.first_block_height, detail.first_block_hash); |
796 | 0 | loop { |
797 | 0 | self.blocks_requests.insert((iter.0, iter.1, request_id)); |
798 | 0 | self.requested_blocks.insert((request_id, iter.0, iter.1)); |
799 | 0 |
|
800 | 0 | match self.blocks.parent_hash(iter.0, &iter.1) { |
801 | 0 | Some(p) => iter = (iter.0 - 1, *p), |
802 | 0 | None => break, |
803 | 0 | } |
804 | 0 | } |
805 | 0 |
|
806 | 0 | request_id |
807 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE11add_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE11add_requestCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE11add_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE11add_requestCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE11add_requestCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE11add_requestCsibGXYHQB8Ea_25json_rpc_general_requests |
808 | | |
809 | | /// Removes a request from the state machine. |
810 | | /// |
811 | | /// Returns the parameters that were passed to [`PendingBlocks::add_request`]. |
812 | | /// |
813 | | /// Note that this function does nothing else but remove the given request from the state |
814 | | /// machine. Nothing in the state concerning sources or blocks is updated. |
815 | | /// |
816 | | /// The next call to [`PendingBlocks::desired_requests`] might return the same request again. |
817 | | /// In order to avoid that, you are encouraged to update the state of the sources and blocks |
818 | | /// in the container with the outcome of the request. |
819 | | /// |
820 | | /// # Panic |
821 | | /// |
822 | | /// Panics if the [`RequestId`] is invalid. |
823 | | /// |
824 | | #[track_caller] |
825 | 0 | pub fn remove_request(&mut self, request_id: RequestId) -> (RequestParams, SourceId, TRq) { |
826 | 0 | assert!(self.requests.contains(request_id.0)); |
827 | 0 | let request = self.requests.remove(request_id.0); |
828 | 0 |
|
829 | 0 | // Update `requested_blocks`. |
830 | 0 | let blocks_to_remove = self |
831 | 0 | .requested_blocks |
832 | 0 | .range((request_id, u64::MIN, [0; 32])..=(request_id, u64::MAX, [0xff; 32])) |
833 | 0 | .cloned() |
834 | 0 | .collect::<Vec<_>>(); |
835 | | |
836 | 0 | for (request_id, block_height, block_hash) in blocks_to_remove { |
837 | 0 | let _was_in = self |
838 | 0 | .blocks_requests |
839 | 0 | .remove(&(block_height, block_hash, request_id)); |
840 | 0 | debug_assert!(_was_in); |
841 | | |
842 | 0 | let _was_in = self |
843 | 0 | .requested_blocks |
844 | 0 | .remove(&(request_id, block_height, block_hash)); |
845 | 0 | debug_assert!(_was_in); |
846 | | } |
847 | | |
848 | 0 | let _was_in = self |
849 | 0 | .source_occupations |
850 | 0 | .remove(&(request.source_id, request_id)); |
851 | 0 | debug_assert!(_was_in); |
852 | | |
853 | 0 | debug_assert_eq!(self.source_occupations.len(), self.requests.len()); |
854 | 0 | debug_assert_eq!(self.blocks_requests.len(), self.requested_blocks.len()); |
855 | | |
856 | 0 | (request.detail, request.source_id, request.user_data) |
857 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE14remove_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE14remove_requestCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE14remove_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE14remove_requestCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE14remove_requestCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE14remove_requestCsibGXYHQB8Ea_25json_rpc_general_requests |
858 | | |
859 | | /// Returns the source that the given request is being performed on. |
860 | | /// |
861 | | /// # Panic |
862 | | /// |
863 | | /// Panics if the [`RequestId`] is invalid. |
864 | | /// |
865 | | #[track_caller] |
866 | 0 | pub fn request_source_id(&self, request_id: RequestId) -> SourceId { |
867 | 0 | self.requests.get(request_id.0).unwrap().source_id |
868 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17request_source_idBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17request_source_idBa_ |
869 | | |
870 | | /// Returns a list of requests that are considered obsolete and can be removed using |
871 | | /// [`PendingBlocks::remove_request`]. |
872 | | /// |
873 | | /// A request is considered obsolete if the state of the requested blocks changes in such a |
874 | | /// way that they don't need to be requested anymore. The request wouldn't be returned by |
875 | | /// [`PendingBlocks::desired_requests`]. |
876 | | /// |
877 | | /// > **Note**: It is in no way mandatory to actually call this function and cancel the |
878 | | /// > requests that are returned. |
879 | 0 | pub fn obsolete_requests(&'_ self) -> impl Iterator<Item = (RequestId, &'_ TRq)> + '_ { |
880 | 0 | // TODO: more than that? |
881 | 0 | self.requests |
882 | 0 | .iter() |
883 | 0 | .filter(move |(_, rq)| { |
884 | 0 | rq.detail.first_block_height <= self.sources.finalized_block_height() |
885 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requests0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE17obsolete_requests0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requests0Bc_ |
886 | 0 | .map(|(id, rq)| (RequestId(id), &rq.user_data)) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requestss_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE17obsolete_requestss_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requestss_0Bc_ |
887 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17obsolete_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE17obsolete_requestsCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17obsolete_requestsBa_ |
888 | | |
889 | | /// Returns a list of requests that should be started in order to learn about the missing |
890 | | /// unverified blocks. |
891 | | /// |
892 | | /// In details, the requests concern: |
893 | | /// |
894 | | /// - If [`Config::download_bodies`] was `true`, downloading the body of blocks whose body is |
895 | | /// unknown. |
896 | | /// - Downloading headers of blocks whose state is [`UnverifiedBlockState::HeightHash`]. |
897 | | /// |
898 | | /// Requests are ordered by increasing block height. In other words, the most important |
899 | | /// requests are returned first. |
900 | | /// |
901 | | /// This method doesn't modify the state machine in any way. [`PendingBlocks::add_request`] |
902 | | /// must be called in order for the request to actually be marked as started. Once a request |
903 | | /// has been started with [`PendingBlocks::add_request`] it will no longer be returned by this |
904 | | /// method. |
905 | | /// |
906 | | /// No request concerning the finalized block (as set using |
907 | | /// [`PendingBlocks::set_finalized_block_height`]) or below will ever be returned. |
908 | | /// |
909 | | /// > **Note**: The API user is encouraged to iterate over the requests until they find a |
910 | | /// > request that is appropriate, then stop iterating and start said request. |
911 | | /// |
912 | | /// > **Note**: This state machine does in no way enforce a limit to the number of simultaneous |
913 | | /// > requests per source, as this is out of scope of this module. However, there is |
914 | | /// > limit to the number of simultaneous requests per block. See |
915 | | /// > [`Config::max_requests_per_block`]. |
916 | 43 | pub fn desired_requests(&'_ self) -> impl Iterator<Item = DesiredRequest> + '_ { |
917 | 43 | self.desired_requests_inner(None) |
918 | 43 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE16desired_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE16desired_requestsCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE16desired_requestsBa_ _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE16desired_requestsCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 916 | 4 | pub fn desired_requests(&'_ self) -> impl Iterator<Item = DesiredRequest> + '_ { | 917 | 4 | self.desired_requests_inner(None) | 918 | 4 | } |
Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE16desired_requestsCscDgN54JpMGG_6author _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE16desired_requestsCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 916 | 39 | pub fn desired_requests(&'_ self) -> impl Iterator<Item = DesiredRequest> + '_ { | 917 | 39 | self.desired_requests_inner(None) | 918 | 39 | } |
|
919 | | |
920 | | /// Returns a list of requests that should be started in order to learn about the missing |
921 | | /// unverified blocks. |
922 | | /// |
923 | | /// This method is similar to [`PendingBlocks::desired_requests`], except that only requests |
924 | | /// concerning the given source will be returned. |
925 | | /// |
926 | | /// # Panic |
927 | | /// |
928 | | /// Panics if the [`SourceId`] is out of range. |
929 | | /// |
930 | 0 | pub fn source_desired_requests( |
931 | 0 | &'_ self, |
932 | 0 | source_id: SourceId, |
933 | 0 | ) -> impl Iterator<Item = RequestParams> + '_ { |
934 | 0 | self.desired_requests_inner(Some(source_id)).map(move |rq| { |
935 | 0 | debug_assert_eq!(rq.source_id, source_id); |
936 | 0 | rq.request_params |
937 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23source_desired_requests0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23source_desired_requests0Bc_ |
938 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23source_desired_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23source_desired_requestsBa_ |
939 | | |
940 | | /// Inner implementation of [`PendingBlocks::desired_requests`] and |
941 | | /// [`PendingBlocks::source_desired_requests`]. |
942 | | /// |
943 | | /// If `force_source` is `Some`, only the given source will be considered. |
944 | | /// |
945 | | /// # Panic |
946 | | /// |
947 | | /// Panics if the [`SourceId`] is out of range. |
948 | | /// |
949 | 43 | fn desired_requests_inner( |
950 | 43 | &'_ self, |
951 | 43 | force_source: Option<SourceId>, |
952 | 43 | ) -> impl Iterator<Item = DesiredRequest> + '_ { |
953 | | // TODO: could provide more optimized requests by avoiding potentially overlapping requests (e.g. if blocks #4 and #5 are unknown, ask for block #5 with num_blocks=2), but this is complicated because peers aren't obligated to respond with the given number of blocks |
954 | | |
955 | | // List of blocks whose header is known but not its body. |
956 | 43 | let unknown_body_iter = if self.download_bodies { |
957 | 43 | either::Left( |
958 | 43 | self.blocks |
959 | 43 | .iter() |
960 | 43 | .filter(move |(_, _, block_info)| {0 |
961 | 0 | matches!(&block_info.state, UnverifiedBlockState::Header { .. }) |
962 | 43 | }0 ) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inner0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inner0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inner0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inner0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inner0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inner0CsibGXYHQB8Ea_25json_rpc_general_requests |
963 | 43 | .map(|(height, hash, _)| (height, hash)0 ), Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners_0CsibGXYHQB8Ea_25json_rpc_general_requests |
964 | 43 | ) |
965 | | } else { |
966 | 0 | either::Right(iter::empty()) |
967 | | }; |
968 | | |
969 | | // List of blocks whose header isn't known. |
970 | 43 | let unknown_header_iter = self |
971 | 43 | .blocks |
972 | 43 | .unknown_blocks() |
973 | 43 | .filter(move |(unknown_block_height, _)| { |
974 | 0 | // Don't request the finalized block or below. |
975 | 0 | *unknown_block_height > self.sources.finalized_block_height() |
976 | 43 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners0_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners0_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners0_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners0_0CsibGXYHQB8Ea_25json_rpc_general_requests |
977 | 43 | .inspect(move |(unknown_block_height, unknown_block_hash)| { |
978 | 0 | // Sanity check. |
979 | 0 | debug_assert!(match self |
980 | 0 | .blocks |
981 | 0 | .user_data(*unknown_block_height, unknown_block_hash) |
982 | 0 | .map(|ud| &ud.state) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners1_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE22desired_requests_inners1_00CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners1_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners1_00CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners1_00CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners1_00CsibGXYHQB8Ea_25json_rpc_general_requests |
983 | | { |
984 | 0 | None | Some(UnverifiedBlockState::HeightHash) => true, |
985 | | Some( |
986 | | UnverifiedBlockState::Header { .. } |
987 | | | UnverifiedBlockState::HeaderBody { .. }, |
988 | 0 | ) => false, |
989 | | }); |
990 | 43 | }0 ); Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners1_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners1_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners1_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners1_0CsibGXYHQB8Ea_25json_rpc_general_requests |
991 | 43 | |
992 | 43 | // Combine the two block iterators and find sources. |
993 | 43 | // There isn't any overlap between the two iterators. |
994 | 43 | unknown_body_iter |
995 | 43 | .map(|(n, h)| (n, h, false)0 ) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners2_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners2_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners2_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners2_0CsibGXYHQB8Ea_25json_rpc_general_requests |
996 | 43 | .chain(unknown_header_iter.map(|(n, h)| (n, h, true)0 )) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners3_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners3_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners3_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners3_0CsibGXYHQB8Ea_25json_rpc_general_requests |
997 | 43 | .filter(move |(unknown_block_height, unknown_block_hash, _)| { |
998 | 0 | // Cap by `max_requests_per_block`. |
999 | 0 | // TODO: O(n)? |
1000 | 0 | let num_existing_requests = self |
1001 | 0 | .blocks_requests |
1002 | 0 | .range( |
1003 | 0 | ( |
1004 | 0 | *unknown_block_height, |
1005 | 0 | **unknown_block_hash, |
1006 | 0 | RequestId(usize::MIN), |
1007 | 0 | ) |
1008 | 0 | ..=( |
1009 | 0 | *unknown_block_height, |
1010 | 0 | **unknown_block_hash, |
1011 | 0 | RequestId(usize::MAX), |
1012 | 0 | ), |
1013 | 0 | ) |
1014 | 0 | .count(); |
1015 | 0 |
|
1016 | 0 | num_existing_requests < self.max_requests_per_block |
1017 | 43 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners4_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners4_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners4_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners4_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners4_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners4_0CsibGXYHQB8Ea_25json_rpc_general_requests |
1018 | 43 | .flat_map( |
1019 | 43 | move |(unknown_block_height, unknown_block_hash, download_many)| {0 |
1020 | | // Try to find all appropriate sources. |
1021 | 0 | let possible_sources = |
1022 | 0 | if let Some(force_source) = force_source { |
1023 | 0 | either::Left(iter::once(force_source).filter(move |id| { |
1024 | 0 | self.sources.source_knows_non_finalized_block( |
1025 | 0 | *id, |
1026 | 0 | unknown_block_height, |
1027 | 0 | unknown_block_hash, |
1028 | 0 | ) |
1029 | 0 | })) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE22desired_requests_inners5_00CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_00CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_00CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_00CsibGXYHQB8Ea_25json_rpc_general_requests |
1030 | | } else { |
1031 | 0 | either::Right(self.sources.knows_non_finalized_block( |
1032 | 0 | unknown_block_height, |
1033 | 0 | unknown_block_hash, |
1034 | 0 | )) |
1035 | | }; |
1036 | | |
1037 | 0 | possible_sources |
1038 | 0 | .filter(move |source_id| { |
1039 | 0 | // Don't start any request towards this source if there's another request |
1040 | 0 | // for the same block from the same source. |
1041 | 0 | // TODO: O(n)? |
1042 | 0 | !self |
1043 | 0 | .blocks_requests |
1044 | 0 | .range( |
1045 | 0 | ( |
1046 | 0 | unknown_block_height, |
1047 | 0 | *unknown_block_hash, |
1048 | 0 | RequestId(usize::MIN), |
1049 | 0 | ) |
1050 | 0 | ..=( |
1051 | 0 | unknown_block_height, |
1052 | 0 | *unknown_block_hash, |
1053 | 0 | RequestId(usize::MAX), |
1054 | 0 | ), |
1055 | 0 | ) |
1056 | 0 | .any(|(_, _, request_id)| { |
1057 | 0 | self.requests[request_id.0].source_id == *source_id |
1058 | 0 | }) Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlockspppE22desired_requests_inners5_0s_00Bg_ Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB2t_19AllForksSourceExtraEE22desired_requests_inners5_0s_00CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlockspppE22desired_requests_inners5_0s_00Bg_ Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB3F_19AllForksSourceExtraEE22desired_requests_inners5_0s_00CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB3F_19AllForksSourceExtraEE22desired_requests_inners5_0s_00CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB3F_19AllForksSourceExtraEE22desired_requests_inners5_0s_00CsibGXYHQB8Ea_25json_rpc_general_requests |
1059 | 0 | }) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE22desired_requests_inners5_0s_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s_0CsibGXYHQB8Ea_25json_rpc_general_requests |
1060 | 0 | .map(move |source_id| { |
1061 | 0 | debug_assert!(self.sources.source_knows_non_finalized_block( |
1062 | 0 | source_id, |
1063 | 0 | unknown_block_height, |
1064 | 0 | unknown_block_hash |
1065 | 0 | )); |
1066 | | |
1067 | | DesiredRequest { |
1068 | 0 | source_id, |
1069 | 0 | request_params: RequestParams { |
1070 | 0 | first_block_hash: *unknown_block_hash, |
1071 | 0 | first_block_height: unknown_block_height, |
1072 | 0 | num_blocks: NonZeroU64::new(if download_many { |
1073 | 0 | unknown_block_height - self.sources.finalized_block_height() |
1074 | | } else { |
1075 | 0 | 1 |
1076 | | }) |
1077 | 0 | .unwrap(), |
1078 | 0 | }, |
1079 | 0 | } |
1080 | 0 | }) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s0_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s0_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0CsibGXYHQB8Ea_25json_rpc_general_requests |
1081 | 43 | }, Unexecuted instantiation: _RNCNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners5_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners5_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners5_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners5_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners5_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners5_0CsibGXYHQB8Ea_25json_rpc_general_requests |
1082 | 43 | ) |
1083 | 43 | } Unexecuted instantiation: _RNvMs_NtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE22desired_requests_innerBa_ Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE22desired_requests_innerCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE22desired_requests_innerBa_ _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE22desired_requests_innerCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 949 | 4 | fn desired_requests_inner( | 950 | 4 | &'_ self, | 951 | 4 | force_source: Option<SourceId>, | 952 | 4 | ) -> impl Iterator<Item = DesiredRequest> + '_ { | 953 | | // TODO: could provide more optimized requests by avoiding potentially overlapping requests (e.g. if blocks #4 and #5 are unknown, ask for block #5 with num_blocks=2), but this is complicated because peers aren't obligated to respond with the given number of blocks | 954 | | | 955 | | // List of blocks whose header is known but not its body. | 956 | 4 | let unknown_body_iter = if self.download_bodies { | 957 | 4 | either::Left( | 958 | 4 | self.blocks | 959 | 4 | .iter() | 960 | 4 | .filter(move |(_, _, block_info)| { | 961 | | matches!(&block_info.state, UnverifiedBlockState::Header { .. }) | 962 | 4 | }) | 963 | 4 | .map(|(height, hash, _)| (height, hash)), | 964 | 4 | ) | 965 | | } else { | 966 | 0 | either::Right(iter::empty()) | 967 | | }; | 968 | | | 969 | | // List of blocks whose header isn't known. | 970 | 4 | let unknown_header_iter = self | 971 | 4 | .blocks | 972 | 4 | .unknown_blocks() | 973 | 4 | .filter(move |(unknown_block_height, _)| { | 974 | | // Don't request the finalized block or below. | 975 | | *unknown_block_height > self.sources.finalized_block_height() | 976 | 4 | }) | 977 | 4 | .inspect(move |(unknown_block_height, unknown_block_hash)| { | 978 | | // Sanity check. | 979 | | debug_assert!(match self | 980 | | .blocks | 981 | | .user_data(*unknown_block_height, unknown_block_hash) | 982 | | .map(|ud| &ud.state) | 983 | | { | 984 | | None | Some(UnverifiedBlockState::HeightHash) => true, | 985 | | Some( | 986 | | UnverifiedBlockState::Header { .. } | 987 | | | UnverifiedBlockState::HeaderBody { .. }, | 988 | | ) => false, | 989 | | }); | 990 | 4 | }); | 991 | 4 | | 992 | 4 | // Combine the two block iterators and find sources. | 993 | 4 | // There isn't any overlap between the two iterators. | 994 | 4 | unknown_body_iter | 995 | 4 | .map(|(n, h)| (n, h, false)) | 996 | 4 | .chain(unknown_header_iter.map(|(n, h)| (n, h, true))) | 997 | 4 | .filter(move |(unknown_block_height, unknown_block_hash, _)| { | 998 | | // Cap by `max_requests_per_block`. | 999 | | // TODO: O(n)? | 1000 | | let num_existing_requests = self | 1001 | | .blocks_requests | 1002 | | .range( | 1003 | | ( | 1004 | | *unknown_block_height, | 1005 | | **unknown_block_hash, | 1006 | | RequestId(usize::MIN), | 1007 | | ) | 1008 | | ..=( | 1009 | | *unknown_block_height, | 1010 | | **unknown_block_hash, | 1011 | | RequestId(usize::MAX), | 1012 | | ), | 1013 | | ) | 1014 | | .count(); | 1015 | | | 1016 | | num_existing_requests < self.max_requests_per_block | 1017 | 4 | }) | 1018 | 4 | .flat_map( | 1019 | 4 | move |(unknown_block_height, unknown_block_hash, download_many)| { | 1020 | | // Try to find all appropriate sources. | 1021 | | let possible_sources = | 1022 | | if let Some(force_source) = force_source { | 1023 | | either::Left(iter::once(force_source).filter(move |id| { | 1024 | | self.sources.source_knows_non_finalized_block( | 1025 | | *id, | 1026 | | unknown_block_height, | 1027 | | unknown_block_hash, | 1028 | | ) | 1029 | | })) | 1030 | | } else { | 1031 | | either::Right(self.sources.knows_non_finalized_block( | 1032 | | unknown_block_height, | 1033 | | unknown_block_hash, | 1034 | | )) | 1035 | | }; | 1036 | | | 1037 | | possible_sources | 1038 | | .filter(move |source_id| { | 1039 | | // Don't start any request towards this source if there's another request | 1040 | | // for the same block from the same source. | 1041 | | // TODO: O(n)? | 1042 | | !self | 1043 | | .blocks_requests | 1044 | | .range( | 1045 | | ( | 1046 | | unknown_block_height, | 1047 | | *unknown_block_hash, | 1048 | | RequestId(usize::MIN), | 1049 | | ) | 1050 | | ..=( | 1051 | | unknown_block_height, | 1052 | | *unknown_block_hash, | 1053 | | RequestId(usize::MAX), | 1054 | | ), | 1055 | | ) | 1056 | | .any(|(_, _, request_id)| { | 1057 | | self.requests[request_id.0].source_id == *source_id | 1058 | | }) | 1059 | | }) | 1060 | | .map(move |source_id| { | 1061 | | debug_assert!(self.sources.source_knows_non_finalized_block( | 1062 | | source_id, | 1063 | | unknown_block_height, | 1064 | | unknown_block_hash | 1065 | | )); | 1066 | | | 1067 | | DesiredRequest { | 1068 | | source_id, | 1069 | | request_params: RequestParams { | 1070 | | first_block_hash: *unknown_block_hash, | 1071 | | first_block_height: unknown_block_height, | 1072 | | num_blocks: NonZeroU64::new(if download_many { | 1073 | | unknown_block_height - self.sources.finalized_block_height() | 1074 | | } else { | 1075 | | 1 | 1076 | | }) | 1077 | | .unwrap(), | 1078 | | }, | 1079 | | } | 1080 | | }) | 1081 | 4 | }, | 1082 | 4 | ) | 1083 | 4 | } |
Unexecuted instantiation: _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE22desired_requests_innerCscDgN54JpMGG_6author _RNvMs_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE22desired_requests_innerCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 949 | 39 | fn desired_requests_inner( | 950 | 39 | &'_ self, | 951 | 39 | force_source: Option<SourceId>, | 952 | 39 | ) -> impl Iterator<Item = DesiredRequest> + '_ { | 953 | | // TODO: could provide more optimized requests by avoiding potentially overlapping requests (e.g. if blocks #4 and #5 are unknown, ask for block #5 with num_blocks=2), but this is complicated because peers aren't obligated to respond with the given number of blocks | 954 | | | 955 | | // List of blocks whose header is known but not its body. | 956 | 39 | let unknown_body_iter = if self.download_bodies { | 957 | 39 | either::Left( | 958 | 39 | self.blocks | 959 | 39 | .iter() | 960 | 39 | .filter(move |(_, _, block_info)| { | 961 | | matches!(&block_info.state, UnverifiedBlockState::Header { .. }) | 962 | 39 | }) | 963 | 39 | .map(|(height, hash, _)| (height, hash)), | 964 | 39 | ) | 965 | | } else { | 966 | 0 | either::Right(iter::empty()) | 967 | | }; | 968 | | | 969 | | // List of blocks whose header isn't known. | 970 | 39 | let unknown_header_iter = self | 971 | 39 | .blocks | 972 | 39 | .unknown_blocks() | 973 | 39 | .filter(move |(unknown_block_height, _)| { | 974 | | // Don't request the finalized block or below. | 975 | | *unknown_block_height > self.sources.finalized_block_height() | 976 | 39 | }) | 977 | 39 | .inspect(move |(unknown_block_height, unknown_block_hash)| { | 978 | | // Sanity check. | 979 | | debug_assert!(match self | 980 | | .blocks | 981 | | .user_data(*unknown_block_height, unknown_block_hash) | 982 | | .map(|ud| &ud.state) | 983 | | { | 984 | | None | Some(UnverifiedBlockState::HeightHash) => true, | 985 | | Some( | 986 | | UnverifiedBlockState::Header { .. } | 987 | | | UnverifiedBlockState::HeaderBody { .. }, | 988 | | ) => false, | 989 | | }); | 990 | 39 | }); | 991 | 39 | | 992 | 39 | // Combine the two block iterators and find sources. | 993 | 39 | // There isn't any overlap between the two iterators. | 994 | 39 | unknown_body_iter | 995 | 39 | .map(|(n, h)| (n, h, false)) | 996 | 39 | .chain(unknown_header_iter.map(|(n, h)| (n, h, true))) | 997 | 39 | .filter(move |(unknown_block_height, unknown_block_hash, _)| { | 998 | | // Cap by `max_requests_per_block`. | 999 | | // TODO: O(n)? | 1000 | | let num_existing_requests = self | 1001 | | .blocks_requests | 1002 | | .range( | 1003 | | ( | 1004 | | *unknown_block_height, | 1005 | | **unknown_block_hash, | 1006 | | RequestId(usize::MIN), | 1007 | | ) | 1008 | | ..=( | 1009 | | *unknown_block_height, | 1010 | | **unknown_block_hash, | 1011 | | RequestId(usize::MAX), | 1012 | | ), | 1013 | | ) | 1014 | | .count(); | 1015 | | | 1016 | | num_existing_requests < self.max_requests_per_block | 1017 | 39 | }) | 1018 | 39 | .flat_map( | 1019 | 39 | move |(unknown_block_height, unknown_block_hash, download_many)| { | 1020 | | // Try to find all appropriate sources. | 1021 | | let possible_sources = | 1022 | | if let Some(force_source) = force_source { | 1023 | | either::Left(iter::once(force_source).filter(move |id| { | 1024 | | self.sources.source_knows_non_finalized_block( | 1025 | | *id, | 1026 | | unknown_block_height, | 1027 | | unknown_block_hash, | 1028 | | ) | 1029 | | })) | 1030 | | } else { | 1031 | | either::Right(self.sources.knows_non_finalized_block( | 1032 | | unknown_block_height, | 1033 | | unknown_block_hash, | 1034 | | )) | 1035 | | }; | 1036 | | | 1037 | | possible_sources | 1038 | | .filter(move |source_id| { | 1039 | | // Don't start any request towards this source if there's another request | 1040 | | // for the same block from the same source. | 1041 | | // TODO: O(n)? | 1042 | | !self | 1043 | | .blocks_requests | 1044 | | .range( | 1045 | | ( | 1046 | | unknown_block_height, | 1047 | | *unknown_block_hash, | 1048 | | RequestId(usize::MIN), | 1049 | | ) | 1050 | | ..=( | 1051 | | unknown_block_height, | 1052 | | *unknown_block_hash, | 1053 | | RequestId(usize::MAX), | 1054 | | ), | 1055 | | ) | 1056 | | .any(|(_, _, request_id)| { | 1057 | | self.requests[request_id.0].source_id == *source_id | 1058 | | }) | 1059 | | }) | 1060 | | .map(move |source_id| { | 1061 | | debug_assert!(self.sources.source_knows_non_finalized_block( | 1062 | | source_id, | 1063 | | unknown_block_height, | 1064 | | unknown_block_hash | 1065 | | )); | 1066 | | | 1067 | | DesiredRequest { | 1068 | | source_id, | 1069 | | request_params: RequestParams { | 1070 | | first_block_hash: *unknown_block_hash, | 1071 | | first_block_height: unknown_block_height, | 1072 | | num_blocks: NonZeroU64::new(if download_many { | 1073 | | unknown_block_height - self.sources.finalized_block_height() | 1074 | | } else { | 1075 | | 1 | 1076 | | }) | 1077 | | .unwrap(), | 1078 | | }, | 1079 | | } | 1080 | | }) | 1081 | 39 | }, | 1082 | 39 | ) | 1083 | 39 | } |
|
1084 | | } |
1085 | | |
1086 | | impl<TBl, TRq, TSrc> ops::Index<SourceId> for PendingBlocks<TBl, TRq, TSrc> { |
1087 | | type Output = TSrc; |
1088 | | |
1089 | | #[track_caller] |
1090 | 21 | fn index(&self, id: SourceId) -> &TSrc { |
1091 | 21 | &self.sources[id].user_data |
1092 | 21 | } Unexecuted instantiation: _RNvXININtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blockss0_0pppEINtB5_13PendingBlockspppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexNtNtB7_7sources8SourceIdE5indexBb_ Unexecuted instantiation: _RNvXs0_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB2o_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvXININtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blockss0_0pppEINtB5_13PendingBlockspppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexNtNtB7_7sources8SourceIdE5indexBb_ _RNvXs0_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1090 | 2 | fn index(&self, id: SourceId) -> &TSrc { | 1091 | 2 | &self.sources[id].user_data | 1092 | 2 | } |
Unexecuted instantiation: _RNvXs0_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCscDgN54JpMGG_6author _RNvXs0_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1090 | 19 | fn index(&self, id: SourceId) -> &TSrc { | 1091 | 19 | &self.sources[id].user_data | 1092 | 19 | } |
|
1093 | | } |
1094 | | |
1095 | | impl<TBl, TRq, TSrc> ops::IndexMut<SourceId> for PendingBlocks<TBl, TRq, TSrc> { |
1096 | | #[track_caller] |
1097 | 0 | fn index_mut(&mut self, id: SourceId) -> &mut TSrc { |
1098 | 0 | &mut self.sources[id].user_data |
1099 | 0 | } Unexecuted instantiation: _RNvXININtNtNtCsN16ciHI6Qf_7smoldot4sync9all_forks14pending_blockss1_0pppEINtB5_13PendingBlockspppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutBb_ Unexecuted instantiation: _RNvXs1_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionuEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB2o_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvXININtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blockss1_0pppEINtB5_13PendingBlockspppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutBb_ Unexecuted instantiation: _RNvXs1_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvXs1_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCscDgN54JpMGG_6author Unexecuted instantiation: _RNvXs1_NtNtNtCseuYC0Zibziv_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCsibGXYHQB8Ea_25json_rpc_general_requests |
1100 | | } |
1101 | | |
1102 | | /// See [`PendingBlocks::desired_requests`]. |
1103 | | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1104 | | pub struct DesiredRequest { |
1105 | | /// Source onto which to start this request. |
1106 | | pub source_id: SourceId, |
1107 | | /// Details of the request. |
1108 | | pub request_params: RequestParams, |
1109 | | } |
1110 | | |
1111 | | /// Information about a blocks request to be performed on a source. |
1112 | | /// |
1113 | | /// The source should return information about the block indicated with |
1114 | | /// [`RequestParams::first_block_height`] and [`RequestParams::first_block_hash`] and its |
1115 | | /// ancestors. In total, [`RequestParams::num_blocks`] should be provided by the source. |
1116 | | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1117 | | pub struct RequestParams { |
1118 | | /// Height of the first block to request. |
1119 | | pub first_block_height: u64, |
1120 | | |
1121 | | /// Hash of the first block to request. |
1122 | | pub first_block_hash: [u8; 32], |
1123 | | |
1124 | | /// Number of blocks the request should return. |
1125 | | /// |
1126 | | /// Note that this is only an indication, and the source is free to give fewer blocks |
1127 | | /// than requested. |
1128 | | pub num_blocks: NonZeroU64, |
1129 | | } |