/__w/smoldot/smoldot/repo/lib/src/sync/all_forks/pending_blocks.rs
Line | Count | Source |
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::{iter, num::NonZero, ops}; |
95 | | |
96 | | pub use disjoint::TreeRoot; |
97 | | pub use sources::SourceId; |
98 | | |
99 | | /// Configuration for the [`PendingBlocks`]. |
100 | | #[derive(Debug)] |
101 | | pub struct Config { |
102 | | /// Pre-allocated capacity for the number of blocks between the finalized block and the head |
103 | | /// of the chain. |
104 | | pub blocks_capacity: usize, |
105 | | |
106 | | /// Pre-allocated capacity for the number of sources that will be added to the collection. |
107 | | pub sources_capacity: usize, |
108 | | |
109 | | /// Height of the known finalized block. Can be lower than the actual value, and increased |
110 | | /// later. |
111 | | pub finalized_block_height: u64, |
112 | | |
113 | | /// If `true`, block bodies are downloaded and verified. If `false`, only headers are |
114 | | /// verified. |
115 | | pub download_bodies: bool, |
116 | | |
117 | | /// Maximum number of simultaneous pending requests made towards the same block. |
118 | | /// |
119 | | /// Should be set according to the failure rate of requests. For example if requests have an |
120 | | /// estimated `10%` chance of failing, then setting to value to `2` gives a `1%` chance that |
121 | | /// downloading this block will overall fail and has to be attempted again. |
122 | | /// |
123 | | /// Also keep in mind that sources might maliciously take a long time to answer requests. A |
124 | | /// higher value makes it possible to reduce the risks of the syncing taking a long time |
125 | | /// because of malicious sources. |
126 | | /// |
127 | | /// The higher the value, the more bandwidth is potentially wasted. |
128 | | pub max_requests_per_block: NonZero<u32>, |
129 | | } |
130 | | |
131 | | /// State of a block in the data structure. |
132 | | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
133 | | pub enum UnverifiedBlockState { |
134 | | /// Only the height and hash of the block is known. |
135 | | HeightHash, |
136 | | /// The header of the block is known, but not its body. |
137 | | Header { |
138 | | /// Hash of the block that is parent of this one. |
139 | | parent_hash: [u8; 32], |
140 | | }, |
141 | | /// The header and body of the block are both known. The block is waiting to be verified. |
142 | | HeaderBody { |
143 | | /// Hash of the block that is parent of this one. |
144 | | parent_hash: [u8; 32], |
145 | | }, |
146 | | } |
147 | | |
148 | | impl UnverifiedBlockState { |
149 | | /// Returns the parent block hash stored in this instance, if any. |
150 | 0 | pub fn parent_hash(&self) -> Option<&[u8; 32]> { |
151 | 0 | match self { |
152 | 0 | UnverifiedBlockState::HeightHash => None, |
153 | 0 | UnverifiedBlockState::Header { parent_hash } => Some(parent_hash), |
154 | 0 | UnverifiedBlockState::HeaderBody { parent_hash } => Some(parent_hash), |
155 | | } |
156 | 0 | } Unexecuted instantiation: _RNvMNtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksNtB2_20UnverifiedBlockState11parent_hash Unexecuted instantiation: _RNvMNtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksNtB2_20UnverifiedBlockState11parent_hash |
157 | | } |
158 | | |
159 | | /// Identifier for a request in the [`super::AllForksSync`]. |
160 | | #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] |
161 | | pub struct RequestId(usize); |
162 | | |
163 | | /// Collection of pending blocks and requests. |
164 | | pub struct PendingBlocks<TBl, TRq, TSrc> { |
165 | | /// All sources in the collection. |
166 | | sources: sources::AllForksSources<Source<TSrc>>, |
167 | | |
168 | | /// Blocks whose validity couldn't be determined yet. |
169 | | blocks: disjoint::DisjointBlocks<UnverifiedBlock<TBl>>, |
170 | | |
171 | | /// See [`Config::download_bodies`]. |
172 | | download_bodies: bool, |
173 | | |
174 | | /// Set of `(block_height, block_hash, request_id)`. |
175 | | /// Contains the list of all requests, associated to their block. |
176 | | /// |
177 | | /// Note that this doesn't contain an exhaustive list of all blocks that are targeted by a |
178 | | /// request, for the simple reason that not all blocks might be known. |
179 | | /// |
180 | | /// The `request_id` is an index in [`PendingBlocks::requests`]. |
181 | | /// |
182 | | /// > **Note**: This is a more optimized way compared to adding a `Vec<RequestId>` in the |
183 | | /// > [`UnverifiedBlock`] struct. |
184 | | blocks_requests: BTreeSet<(u64, [u8; 32], RequestId)>, |
185 | | |
186 | | /// Set of `(request_id, block_height, block_hash)`. |
187 | | /// |
188 | | /// Contains the same entries as [`PendingBlocks::blocks_requests`], but ordered differently. |
189 | | requested_blocks: BTreeSet<(RequestId, u64, [u8; 32])>, |
190 | | |
191 | | /// Set of `(source_id, request_id)`. |
192 | | /// Contains the list of requests, associated to their source. |
193 | | /// |
194 | | /// The `request_id` is an index in [`PendingBlocks::requests`]. |
195 | | source_occupations: BTreeSet<(SourceId, RequestId)>, |
196 | | |
197 | | /// All ongoing requests. |
198 | | requests: slab::Slab<Request<TRq>>, |
199 | | |
200 | | /// See [`Config::max_requests_per_block`]. |
201 | | /// Since it is always compared with `usize`s, converted to `usize` ahead of time. |
202 | | max_requests_per_block: usize, |
203 | | } |
204 | | |
205 | | struct UnverifiedBlock<TBl> { |
206 | | state: UnverifiedBlockState, |
207 | | user_data: TBl, |
208 | | } |
209 | | |
210 | | struct Request<TRq> { |
211 | | detail: RequestParams, |
212 | | source_id: SourceId, |
213 | | user_data: TRq, |
214 | | } |
215 | | |
216 | | #[derive(Debug)] |
217 | | struct Source<TSrc> { |
218 | | /// Opaque object passed by the user. |
219 | | user_data: TSrc, |
220 | | } |
221 | | |
222 | | impl<TBl, TRq, TSrc> PendingBlocks<TBl, TRq, TSrc> { |
223 | | /// Initializes a new empty collection. |
224 | 21 | pub fn new(config: Config) -> Self { |
225 | 21 | PendingBlocks { |
226 | 21 | sources: sources::AllForksSources::new( |
227 | 21 | config.sources_capacity, |
228 | 21 | config.finalized_block_height, |
229 | 21 | ), |
230 | 21 | blocks: disjoint::DisjointBlocks::with_capacity(config.blocks_capacity), |
231 | 21 | download_bodies: config.download_bodies, |
232 | 21 | blocks_requests: Default::default(), |
233 | 21 | requested_blocks: Default::default(), |
234 | 21 | source_occupations: Default::default(), |
235 | 21 | requests: slab::Slab::with_capacity( |
236 | 21 | config.blocks_capacity |
237 | 21 | * usize::try_from(config.max_requests_per_block.get()).unwrap_or(usize::MAX), |
238 | 21 | ), |
239 | 21 | max_requests_per_block: usize::try_from(config.max_requests_per_block.get()) |
240 | 21 | .unwrap_or(usize::MAX), |
241 | 21 | } |
242 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE3newBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE3newCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE3newBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE3newCs7snhGEhbuap_18smoldot_light_wasm _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE3newCsjyNE3yDMkgA_14json_rpc_basic Line | Count | Source | 224 | 2 | pub fn new(config: Config) -> Self { | 225 | 2 | PendingBlocks { | 226 | 2 | sources: sources::AllForksSources::new( | 227 | 2 | config.sources_capacity, | 228 | 2 | config.finalized_block_height, | 229 | 2 | ), | 230 | 2 | blocks: disjoint::DisjointBlocks::with_capacity(config.blocks_capacity), | 231 | 2 | download_bodies: config.download_bodies, | 232 | 2 | blocks_requests: Default::default(), | 233 | 2 | requested_blocks: Default::default(), | 234 | 2 | source_occupations: Default::default(), | 235 | 2 | requests: slab::Slab::with_capacity( | 236 | 2 | config.blocks_capacity | 237 | 2 | * usize::try_from(config.max_requests_per_block.get()).unwrap_or(usize::MAX), | 238 | 2 | ), | 239 | 2 | max_requests_per_block: usize::try_from(config.max_requests_per_block.get()) | 240 | 2 | .unwrap_or(usize::MAX), | 241 | 2 | } | 242 | 2 | } |
_RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE3newCs4VrkfB1pvQ3_25json_rpc_general_requests Line | Count | Source | 224 | 19 | pub fn new(config: Config) -> Self { | 225 | 19 | PendingBlocks { | 226 | 19 | sources: sources::AllForksSources::new( | 227 | 19 | config.sources_capacity, | 228 | 19 | config.finalized_block_height, | 229 | 19 | ), | 230 | 19 | blocks: disjoint::DisjointBlocks::with_capacity(config.blocks_capacity), | 231 | 19 | download_bodies: config.download_bodies, | 232 | 19 | blocks_requests: Default::default(), | 233 | 19 | requested_blocks: Default::default(), | 234 | 19 | source_occupations: Default::default(), | 235 | 19 | requests: slab::Slab::with_capacity( | 236 | 19 | config.blocks_capacity | 237 | 19 | * usize::try_from(config.max_requests_per_block.get()).unwrap_or(usize::MAX), | 238 | 19 | ), | 239 | 19 | max_requests_per_block: usize::try_from(config.max_requests_per_block.get()) | 240 | 19 | .unwrap_or(usize::MAX), | 241 | 19 | } | 242 | 19 | } |
|
243 | | |
244 | | /// Returns the value that was passed as [`Config::download_bodies`] |
245 | 0 | pub fn downloading_bodies(&self) -> bool { |
246 | 0 | self.download_bodies |
247 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE18downloading_bodiesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE18downloading_bodiesCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE18downloading_bodiesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE18downloading_bodiesCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE18downloading_bodiesCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE18downloading_bodiesCs4VrkfB1pvQ3_25json_rpc_general_requests |
248 | | |
249 | | /// Add a new source to the container. |
250 | | /// |
251 | | /// The `user_data` parameter is opaque and decided entirely by the user. It can later be |
252 | | /// retrieved using the `Index` trait implementation of this container. |
253 | | /// |
254 | | /// Returns the newly-created source entry. |
255 | 21 | pub fn add_source( |
256 | 21 | &mut self, |
257 | 21 | user_data: TSrc, |
258 | 21 | best_block_number: u64, |
259 | 21 | best_block_hash: [u8; 32], |
260 | 21 | ) -> SourceId { |
261 | 21 | self.sources |
262 | 21 | .add_source(best_block_number, best_block_hash, Source { user_data }) |
263 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE10add_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE10add_sourceCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE10add_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE10add_sourceCs7snhGEhbuap_18smoldot_light_wasm _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE10add_sourceCsjyNE3yDMkgA_14json_rpc_basic Line | Count | Source | 255 | 2 | pub fn add_source( | 256 | 2 | &mut self, | 257 | 2 | user_data: TSrc, | 258 | 2 | best_block_number: u64, | 259 | 2 | best_block_hash: [u8; 32], | 260 | 2 | ) -> SourceId { | 261 | 2 | self.sources | 262 | 2 | .add_source(best_block_number, best_block_hash, Source { user_data }) | 263 | 2 | } |
_RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE10add_sourceCs4VrkfB1pvQ3_25json_rpc_general_requests Line | Count | Source | 255 | 19 | pub fn add_source( | 256 | 19 | &mut self, | 257 | 19 | user_data: TSrc, | 258 | 19 | best_block_number: u64, | 259 | 19 | best_block_hash: [u8; 32], | 260 | 19 | ) -> SourceId { | 261 | 19 | self.sources | 262 | 19 | .add_source(best_block_number, best_block_hash, Source { user_data }) | 263 | 19 | } |
|
264 | | |
265 | | /// Removes the source from the [`PendingBlocks`]. |
266 | | /// |
267 | | /// Returns the user data that was originally passed to [`PendingBlocks::add_source`], plus |
268 | | /// a list of all the requests that were targeting this source. These request are now |
269 | | /// invalid. |
270 | | /// |
271 | | /// # Panic |
272 | | /// |
273 | | /// Panics if the [`SourceId`] is out of range. |
274 | | /// |
275 | 0 | pub fn remove_source( |
276 | 0 | &mut self, |
277 | 0 | source_id: SourceId, |
278 | 0 | ) -> (TSrc, impl Iterator<Item = (RequestId, RequestParams, TRq)>) { |
279 | 0 | let user_data = self.sources.remove(source_id); |
280 | | |
281 | 0 | let source_occupations_entries = self |
282 | 0 | .source_occupations |
283 | 0 | .range((source_id, RequestId(usize::MIN))..=(source_id, RequestId(usize::MAX))) |
284 | 0 | .copied() |
285 | 0 | .collect::<Vec<_>>(); |
286 | | |
287 | | // TODO: optimize with a custom iterator? |
288 | 0 | let mut pending_requests = Vec::new(); |
289 | | |
290 | 0 | for (_source_id, pending_request_id) in source_occupations_entries { |
291 | 0 | debug_assert_eq!(source_id, _source_id); |
292 | | |
293 | 0 | debug_assert!(self.requests.contains(pending_request_id.0)); |
294 | 0 | let request = self.requests.remove(pending_request_id.0); |
295 | | |
296 | 0 | let _was_in = self |
297 | 0 | .source_occupations |
298 | 0 | .remove(&(source_id, pending_request_id)); |
299 | 0 | debug_assert!(_was_in); |
300 | | |
301 | 0 | let _was_in = self.blocks_requests.remove(&( |
302 | 0 | request.detail.first_block_height, |
303 | 0 | request.detail.first_block_hash, |
304 | 0 | pending_request_id, |
305 | 0 | )); |
306 | 0 | debug_assert!(_was_in); |
307 | | |
308 | 0 | let _was_in = self.requested_blocks.remove(&( |
309 | 0 | pending_request_id, |
310 | 0 | request.detail.first_block_height, |
311 | 0 | request.detail.first_block_hash, |
312 | 0 | )); |
313 | 0 | debug_assert!(_was_in); |
314 | | |
315 | 0 | pending_requests.push((pending_request_id, request.detail, request.user_data)); |
316 | | } |
317 | | |
318 | 0 | debug_assert_eq!(self.source_occupations.len(), self.requests.len()); |
319 | | |
320 | 0 | (user_data.user_data, pending_requests.into_iter()) |
321 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE13remove_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE13remove_sourceCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE13remove_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE13remove_sourceCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE13remove_sourceCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE13remove_sourceCs4VrkfB1pvQ3_25json_rpc_general_requests |
322 | | |
323 | | /// Returns the list of sources in this state machine. |
324 | 21 | pub fn sources(&self) -> impl ExactSizeIterator<Item = SourceId> { |
325 | 21 | self.sources.keys() |
326 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE7sourcesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE7sourcesCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE7sourcesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE7sourcesCs7snhGEhbuap_18smoldot_light_wasm _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE7sourcesCsjyNE3yDMkgA_14json_rpc_basic Line | Count | Source | 324 | 2 | pub fn sources(&self) -> impl ExactSizeIterator<Item = SourceId> { | 325 | 2 | self.sources.keys() | 326 | 2 | } |
_RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE7sourcesCs4VrkfB1pvQ3_25json_rpc_general_requests Line | Count | Source | 324 | 19 | pub fn sources(&self) -> impl ExactSizeIterator<Item = SourceId> { | 325 | 19 | self.sources.keys() | 326 | 19 | } |
|
327 | | |
328 | | /// Returns the list of all user datas of all sources. |
329 | 0 | pub fn sources_user_data_iter_mut(&mut self) -> impl ExactSizeIterator<Item = &mut TSrc> { |
330 | 0 | self.sources.user_data_iter_mut().map(|s| &mut s.user_data) |
331 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26sources_user_data_iter_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26sources_user_data_iter_mutCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26sources_user_data_iter_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE26sources_user_data_iter_mutCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26sources_user_data_iter_mutCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26sources_user_data_iter_mutCs4VrkfB1pvQ3_25json_rpc_general_requests |
332 | | |
333 | | /// Registers a new block that the source is aware of. |
334 | | /// |
335 | | /// Has no effect if `height` is inferior or equal to the finalized block height. |
336 | | /// |
337 | | /// The block does not need to be known by the data structure. |
338 | | /// |
339 | | /// # Panic |
340 | | /// |
341 | | /// Panics if the [`SourceId`] is out of range. |
342 | | /// |
343 | 0 | pub fn add_known_block_to_source(&mut self, source_id: SourceId, height: u64, hash: [u8; 32]) { |
344 | 0 | self.sources.add_known_block(source_id, height, hash); |
345 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25add_known_block_to_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25add_known_block_to_sourceCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25add_known_block_to_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE25add_known_block_to_sourceCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25add_known_block_to_sourceCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25add_known_block_to_sourceCs4VrkfB1pvQ3_25json_rpc_general_requests |
346 | | |
347 | | /// Un-registers a new block that the source is aware of. |
348 | | /// |
349 | | /// Has no effect if the block wasn't marked as being known to this source. |
350 | | /// |
351 | | /// > **Note**: Use this function if for example a source is unable to serve a block that is |
352 | | /// > supposed to be known to it. |
353 | | /// |
354 | | /// # Panic |
355 | | /// |
356 | | /// Panics if the [`SourceId`] is out of range. |
357 | | /// |
358 | 0 | pub fn remove_known_block_of_source( |
359 | 0 | &mut self, |
360 | 0 | source_id: SourceId, |
361 | 0 | height: u64, |
362 | 0 | hash: &[u8; 32], |
363 | 0 | ) { |
364 | 0 | self.sources |
365 | 0 | .source_remove_known_block(source_id, height, hash); |
366 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28remove_known_block_of_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28remove_known_block_of_sourceCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28remove_known_block_of_sourceBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE28remove_known_block_of_sourceCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28remove_known_block_of_sourceCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28remove_known_block_of_sourceCs4VrkfB1pvQ3_25json_rpc_general_requests |
367 | | |
368 | | /// Registers a new block that the source is aware of and sets it as its best block. |
369 | | /// |
370 | | /// If the block height is inferior or equal to the finalized block height, the block itself |
371 | | /// isn't kept in memory but is still set as the source's best block. |
372 | | /// |
373 | | /// The block does not need to be known by the data structure. |
374 | | /// |
375 | | /// # Panic |
376 | | /// |
377 | | /// Panics if the [`SourceId`] is out of range. |
378 | | /// |
379 | 0 | pub fn add_known_block_to_source_and_set_best( |
380 | 0 | &mut self, |
381 | 0 | source_id: SourceId, |
382 | 0 | height: u64, |
383 | 0 | hash: [u8; 32], |
384 | 0 | ) { |
385 | 0 | self.sources |
386 | 0 | .add_known_block_and_set_best(source_id, height, hash); |
387 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38add_known_block_to_source_and_set_bestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38add_known_block_to_source_and_set_bestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38add_known_block_to_source_and_set_bestCs4VrkfB1pvQ3_25json_rpc_general_requests |
388 | | |
389 | | /// Returns the current best block of the given source. |
390 | | /// |
391 | | /// This corresponds either the latest call to [`PendingBlocks::add_known_block_to_source_and_set_best`], |
392 | | /// or to the parameter passed to [`PendingBlocks::add_source`]. |
393 | | /// |
394 | | /// # Panic |
395 | | /// |
396 | | /// Panics if the [`SourceId`] is invalid. |
397 | | /// |
398 | 0 | pub fn source_best_block(&self, source_id: SourceId) -> (u64, &[u8; 32]) { |
399 | 0 | self.sources.best_block(source_id) |
400 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17source_best_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17source_best_blockCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17source_best_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE17source_best_blockCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17source_best_blockCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17source_best_blockCs4VrkfB1pvQ3_25json_rpc_general_requests |
401 | | |
402 | | /// Returns the number of ongoing requests that concern this source. |
403 | | /// |
404 | | /// # Panic |
405 | | /// |
406 | | /// Panics if the [`SourceId`] is invalid. |
407 | | /// |
408 | 0 | pub fn source_num_ongoing_requests(&self, source_id: SourceId) -> usize { |
409 | 0 | self.source_occupations |
410 | 0 | .range((source_id, RequestId(usize::MIN))..=(source_id, RequestId(usize::MAX))) |
411 | 0 | .count() |
412 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE27source_num_ongoing_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE27source_num_ongoing_requestsBa_ |
413 | | |
414 | | /// Returns the list of sources for which [`PendingBlocks::source_knows_non_finalized_block`] |
415 | | /// would return `true`. |
416 | | /// |
417 | | /// # Panic |
418 | | /// |
419 | | /// Panics if `height` is inferior or equal to the finalized block height. Finalized blocks |
420 | | /// are intentionally not tracked by this data structure, and panicking when asking for a |
421 | | /// potentially-finalized block prevents potentially confusing or erroneous situations. |
422 | | /// |
423 | 0 | pub fn knows_non_finalized_block<'a>( |
424 | 0 | &'a self, |
425 | 0 | height: u64, |
426 | 0 | hash: &[u8; 32], |
427 | 0 | ) -> impl Iterator<Item = SourceId> + use<'a, TBl, TRq, TSrc> { |
428 | 0 | self.sources.knows_non_finalized_block(height, hash) |
429 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25knows_non_finalized_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25knows_non_finalized_blockCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25knows_non_finalized_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE25knows_non_finalized_blockCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25knows_non_finalized_blockCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25knows_non_finalized_blockCs4VrkfB1pvQ3_25json_rpc_general_requests |
430 | | |
431 | | /// Returns true if [`PendingBlocks::add_known_block_to_source`] or |
432 | | /// [`PendingBlocks::add_known_block_to_source_and_set_best`] has earlier been called on this |
433 | | /// source with this height and hash, or if the source was originally created (using |
434 | | /// [`PendingBlocks::add_source`]) with this height and hash. |
435 | | /// |
436 | | /// # Panic |
437 | | /// |
438 | | /// Panics if the [`SourceId`] is out of range. |
439 | | /// |
440 | | /// Panics if `height` is inferior or equal to the finalized block height. Finalized blocks |
441 | | /// are intentionally not tracked by this data structure, and panicking when asking for a |
442 | | /// potentially-finalized block prevents potentially confusing or erroneous situations. |
443 | | /// |
444 | 0 | pub fn source_knows_non_finalized_block( |
445 | 0 | &self, |
446 | 0 | source_id: SourceId, |
447 | 0 | height: u64, |
448 | 0 | hash: &[u8; 32], |
449 | 0 | ) -> bool { |
450 | 0 | self.sources |
451 | 0 | .source_knows_non_finalized_block(source_id, height, hash) |
452 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE32source_knows_non_finalized_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE32source_knows_non_finalized_blockBa_ |
453 | | |
454 | | /// Updates the height of the finalized block. |
455 | | /// |
456 | | /// This removes from the collection all blocks (both source-known and unverified) whose |
457 | | /// height is inferior or equal to this value. |
458 | | /// |
459 | | /// # Panic |
460 | | /// |
461 | | /// Panics if the new height is inferior to the previous value. |
462 | | /// |
463 | 0 | pub fn set_finalized_block_height( |
464 | 0 | &mut self, |
465 | 0 | height: u64, |
466 | 0 | ) -> impl ExactSizeIterator<Item = TBl> + use<TBl, TRq, TSrc> { |
467 | 0 | self.sources.set_finalized_block_height(height); |
468 | 0 | self.blocks |
469 | 0 | .remove_below_height(height + 1) |
470 | 0 | .map(|(_, _, bl)| bl.user_data) |
471 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_finalized_block_heightBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26set_finalized_block_heightCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_finalized_block_heightBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE26set_finalized_block_heightCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26set_finalized_block_heightCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26set_finalized_block_heightCs4VrkfB1pvQ3_25json_rpc_general_requests |
472 | | |
473 | | /// Inserts an unverified block in the collection. |
474 | | /// |
475 | | /// Returns the previous user data associated to this block, if any. |
476 | | /// |
477 | | /// > **Note**: You should probably also call [`PendingBlocks::add_known_block_to_source`] or |
478 | | /// > [`PendingBlocks::add_known_block_to_source_and_set_best`]. |
479 | 0 | pub fn insert_unverified_block( |
480 | 0 | &mut self, |
481 | 0 | height: u64, |
482 | 0 | hash: [u8; 32], |
483 | 0 | state: UnverifiedBlockState, |
484 | 0 | user_data: TBl, |
485 | 0 | ) -> Option<(TBl, UnverifiedBlockState)> { |
486 | 0 | if height <= self.sources.finalized_block_height() { |
487 | 0 | return None; |
488 | 0 | } |
489 | | |
490 | 0 | let parent_hash = state.parent_hash().copied(); |
491 | | // TODO: is it ok to just override the UnverifiedBlockState? |
492 | 0 | self.blocks |
493 | 0 | .insert( |
494 | 0 | height, |
495 | 0 | hash, |
496 | 0 | parent_hash, |
497 | 0 | UnverifiedBlock { state, user_data }, |
498 | | ) |
499 | 0 | .map(|b| (b.user_data, b.state)) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23insert_unverified_block0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE23insert_unverified_block0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23insert_unverified_block0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE23insert_unverified_block0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE23insert_unverified_block0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE23insert_unverified_block0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
500 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23insert_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23insert_unverified_blockCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23insert_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE23insert_unverified_blockCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23insert_unverified_blockCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23insert_unverified_blockCs4VrkfB1pvQ3_25json_rpc_general_requests |
501 | | |
502 | | /// Returns `true` if the block with the given height and hash is in the collection. |
503 | 0 | pub fn contains_unverified_block(&self, height: u64, hash: &[u8; 32]) -> bool { |
504 | 0 | self.blocks.contains(height, hash) |
505 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25contains_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25contains_unverified_blockCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE25contains_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE25contains_unverified_blockCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25contains_unverified_blockCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE25contains_unverified_blockCs4VrkfB1pvQ3_25json_rpc_general_requests |
506 | | |
507 | | /// Gives access to the user data stored for this block. |
508 | | /// |
509 | | /// # Panic |
510 | | /// |
511 | | /// Panics if the block wasn't present in the data structure. |
512 | | /// |
513 | 0 | pub fn unverified_block_user_data(&self, height: u64, hash: &[u8; 32]) -> &TBl { |
514 | 0 | &self.blocks.user_data(height, hash).unwrap().user_data |
515 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26unverified_block_user_dataBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26unverified_block_user_dataCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26unverified_block_user_dataBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE26unverified_block_user_dataCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26unverified_block_user_dataCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE26unverified_block_user_dataCs4VrkfB1pvQ3_25json_rpc_general_requests |
516 | | |
517 | | /// Gives access to the user data stored for this block. |
518 | | /// |
519 | | /// # Panic |
520 | | /// |
521 | | /// Panics if the block wasn't present in the data structure. |
522 | | /// |
523 | 0 | pub fn unverified_block_user_data_mut(&mut self, height: u64, hash: &[u8; 32]) -> &mut TBl { |
524 | 0 | &mut self.blocks.user_data_mut(height, hash).unwrap().user_data |
525 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE30unverified_block_user_data_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE30unverified_block_user_data_mutCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE30unverified_block_user_data_mutBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE30unverified_block_user_data_mutCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE30unverified_block_user_data_mutCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE30unverified_block_user_data_mutCs4VrkfB1pvQ3_25json_rpc_general_requests |
526 | | |
527 | | /// Modifies the state of the given block. |
528 | | /// |
529 | | /// This influences the outcome of [`PendingBlocks::desired_requests`]. |
530 | | /// |
531 | | /// # Panic |
532 | | /// |
533 | | /// Panics if the block wasn't present in the data structure. |
534 | | /// |
535 | 0 | pub fn set_unverified_block_state( |
536 | 0 | &mut self, |
537 | 0 | height: u64, |
538 | 0 | hash: &[u8; 32], |
539 | 0 | state: UnverifiedBlockState, |
540 | 0 | ) { |
541 | 0 | if let Some(parent_hash) = state.parent_hash() { |
542 | 0 | self.blocks.set_parent_hash(height, hash, *parent_hash); |
543 | 0 | } |
544 | | |
545 | 0 | self.blocks.user_data_mut(height, hash).unwrap().state = state; |
546 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_unverified_block_stateBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26set_unverified_block_stateBa_ |
547 | | |
548 | | /// Modifies the state of the given block. This is a convenience around |
549 | | /// [`PendingBlocks::set_unverified_block_state`]. |
550 | | /// |
551 | | /// If the current block's state implies that the header isn't known yet, updates it to a |
552 | | /// state where the header is known. |
553 | | /// |
554 | | /// > **Note**: A user of this data structure is expected to manually add the parent block to |
555 | | /// this data structure as well in case it is unverified. |
556 | | /// |
557 | | /// # Panic |
558 | | /// |
559 | | /// Panics if the block wasn't present in the data structure. |
560 | | /// Panics if the block's header was already known and the its parent hash doesn't match |
561 | | /// the one passed as parameter. |
562 | | /// |
563 | 0 | pub fn set_unverified_block_header_known( |
564 | 0 | &mut self, |
565 | 0 | height: u64, |
566 | 0 | hash: &[u8; 32], |
567 | 0 | parent_hash: [u8; 32], |
568 | 0 | ) { |
569 | 0 | let curr = &mut self.blocks.user_data_mut(height, hash).unwrap().state; |
570 | | |
571 | 0 | match curr { |
572 | | UnverifiedBlockState::Header { |
573 | 0 | parent_hash: cur_ph, |
574 | | } |
575 | | | UnverifiedBlockState::HeaderBody { |
576 | 0 | parent_hash: cur_ph, |
577 | 0 | } if *cur_ph == parent_hash => return, |
578 | | UnverifiedBlockState::Header { .. } | UnverifiedBlockState::HeaderBody { .. } => { |
579 | 0 | panic!() |
580 | | } |
581 | 0 | UnverifiedBlockState::HeightHash => {} |
582 | | } |
583 | | |
584 | 0 | *curr = UnverifiedBlockState::Header { parent_hash }; |
585 | 0 | self.blocks.set_parent_hash(height, hash, parent_hash); |
586 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE33set_unverified_block_header_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE33set_unverified_block_header_knownCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE33set_unverified_block_header_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE33set_unverified_block_header_knownCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE33set_unverified_block_header_knownCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE33set_unverified_block_header_knownCs4VrkfB1pvQ3_25json_rpc_general_requests |
587 | | |
588 | | /// Modifies the state of the given block. This is a convenience around |
589 | | /// [`PendingBlocks::set_unverified_block_state`]. |
590 | | /// |
591 | | /// If the current block's state implies that the header or body isn't known yet, updates it |
592 | | /// to a state where the header and body are known. |
593 | | /// |
594 | | /// > **Note**: A user of this data structure is expected to manually add the parent block to |
595 | | /// this data structure as well in case it is unverified. |
596 | | /// |
597 | | /// # Panic |
598 | | /// |
599 | | /// Panics if the block wasn't present in the data structure. |
600 | | /// Panics if the block's header was already known and the its parent hash doesn't match |
601 | | /// the one passed as parameter. |
602 | | /// |
603 | 0 | pub fn set_unverified_block_header_body_known( |
604 | 0 | &mut self, |
605 | 0 | height: u64, |
606 | 0 | hash: &[u8; 32], |
607 | 0 | parent_hash: [u8; 32], |
608 | 0 | ) { |
609 | 0 | let curr = &mut self.blocks.user_data_mut(height, hash).unwrap().state; |
610 | | |
611 | 0 | match curr { |
612 | | UnverifiedBlockState::Header { |
613 | 0 | parent_hash: cur_ph, |
614 | 0 | } if *cur_ph == parent_hash => {} |
615 | | UnverifiedBlockState::HeaderBody { |
616 | 0 | parent_hash: cur_ph, |
617 | 0 | } if *cur_ph == parent_hash => return, |
618 | | UnverifiedBlockState::Header { .. } | UnverifiedBlockState::HeaderBody { .. } => { |
619 | 0 | panic!() |
620 | | } |
621 | 0 | UnverifiedBlockState::HeightHash => {} |
622 | | } |
623 | | |
624 | 0 | *curr = UnverifiedBlockState::HeaderBody { parent_hash }; |
625 | 0 | self.blocks.set_parent_hash(height, hash, parent_hash); |
626 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38set_unverified_block_header_body_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE38set_unverified_block_header_body_knownBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE38set_unverified_block_header_body_knownCs4VrkfB1pvQ3_25json_rpc_general_requests |
627 | | |
628 | | /// Removes the given block from the list of known blocks of all from the sources. |
629 | | /// |
630 | | /// This is equivalent to calling [`PendingBlocks::remove_known_block_of_source`] for each |
631 | | /// source. |
632 | 0 | pub fn remove_sources_known_block(&mut self, height: u64, hash: &[u8; 32]) { |
633 | 0 | self.sources.remove_known_block(height, hash); |
634 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26remove_sources_known_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE26remove_sources_known_blockBa_ |
635 | | |
636 | | /// Removes the given unverified block from the collection. |
637 | | /// |
638 | | /// > **Note**: Use this method after a block has been successfully verified, or in order to |
639 | | /// > remove uninteresting blocks if there are too many blocks in the collection. |
640 | | /// |
641 | | /// # Panic |
642 | | /// |
643 | | /// Panics if the block wasn't present in the data structure. |
644 | | /// |
645 | 0 | pub fn remove_unverified_block(&mut self, height: u64, hash: &[u8; 32]) -> TBl { |
646 | 0 | self.blocks.remove(height, hash).user_data |
647 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23remove_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23remove_unverified_blockCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23remove_unverified_blockBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE23remove_unverified_blockCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23remove_unverified_blockCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE23remove_unverified_blockCs4VrkfB1pvQ3_25json_rpc_general_requests |
648 | | |
649 | | /// Marks the given unverified block and all its known children as "bad". |
650 | | /// |
651 | | /// If a child of this block is later added to the collection, it is also automatically |
652 | | /// marked as bad. |
653 | | /// |
654 | | /// # Panic |
655 | | /// |
656 | | /// Panics if the block wasn't present in the data structure. |
657 | | /// |
658 | | #[track_caller] |
659 | 0 | pub fn mark_unverified_block_as_bad(&mut self, height: u64, hash: &[u8; 32]) { |
660 | 0 | self.blocks.set_block_bad(height, hash); |
661 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28mark_unverified_block_as_badBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28mark_unverified_block_as_badCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE28mark_unverified_block_as_badBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE28mark_unverified_block_as_badCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28mark_unverified_block_as_badCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE28mark_unverified_block_as_badCs4VrkfB1pvQ3_25json_rpc_general_requests |
662 | | |
663 | | /// Returns the number of unverified blocks stored in the data structure. |
664 | 0 | pub fn num_unverified_blocks(&self) -> usize { |
665 | 0 | self.blocks.len() |
666 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE21num_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE21num_unverified_blocksCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE21num_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE21num_unverified_blocksCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE21num_unverified_blocksCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE21num_unverified_blocksCs4VrkfB1pvQ3_25json_rpc_general_requests |
667 | | |
668 | | /// Returns the list of blocks whose parent hash is known but absent from the list of disjoint |
669 | | /// blocks. These blocks can potentially be verified. |
670 | | /// |
671 | | /// All the returned block are guaranteed to be in a "header known" state. If |
672 | | /// [`Config::download_bodies`] if `true`, they they are also guaranteed to be in a "body known" |
673 | | /// state. |
674 | | /// |
675 | | /// > **Note**: The naming of this function assumes that all blocks that are referenced by |
676 | | /// > this data structure but absent from this data structure are known by the |
677 | | /// > API user. |
678 | 21 | pub fn unverified_leaves(&self) -> impl Iterator<Item = TreeRoot> { |
679 | 21 | self.blocks.good_tree_roots().filter(move |pending| {0 |
680 | 0 | match self |
681 | 0 | .blocks |
682 | 0 | .user_data(pending.block_number, &pending.block_hash) |
683 | 0 | .unwrap() |
684 | 0 | .state |
685 | | { |
686 | 0 | UnverifiedBlockState::HeightHash => false, |
687 | 0 | UnverifiedBlockState::Header { .. } => !self.download_bodies, |
688 | 0 | UnverifiedBlockState::HeaderBody { .. } => true, |
689 | | } |
690 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17unverified_leaves0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE17unverified_leaves0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17unverified_leaves0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE17unverified_leaves0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE17unverified_leaves0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE17unverified_leaves0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
691 | 21 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17unverified_leavesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17unverified_leavesCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17unverified_leavesBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE17unverified_leavesCs7snhGEhbuap_18smoldot_light_wasm _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17unverified_leavesCsjyNE3yDMkgA_14json_rpc_basic Line | Count | Source | 678 | 2 | pub fn unverified_leaves(&self) -> impl Iterator<Item = TreeRoot> { | 679 | 2 | self.blocks.good_tree_roots().filter(move |pending| { | 680 | | match self | 681 | | .blocks | 682 | | .user_data(pending.block_number, &pending.block_hash) | 683 | | .unwrap() | 684 | | .state | 685 | | { | 686 | | UnverifiedBlockState::HeightHash => false, | 687 | | UnverifiedBlockState::Header { .. } => !self.download_bodies, | 688 | | UnverifiedBlockState::HeaderBody { .. } => true, | 689 | | } | 690 | | }) | 691 | 2 | } |
_RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE17unverified_leavesCs4VrkfB1pvQ3_25json_rpc_general_requests Line | Count | Source | 678 | 19 | pub fn unverified_leaves(&self) -> impl Iterator<Item = TreeRoot> { | 679 | 19 | self.blocks.good_tree_roots().filter(move |pending| { | 680 | | match self | 681 | | .blocks | 682 | | .user_data(pending.block_number, &pending.block_hash) | 683 | | .unwrap() | 684 | | .state | 685 | | { | 686 | | UnverifiedBlockState::HeightHash => false, | 687 | | UnverifiedBlockState::Header { .. } => !self.download_bodies, | 688 | | UnverifiedBlockState::HeaderBody { .. } => true, | 689 | | } | 690 | | }) | 691 | 19 | } |
|
692 | | |
693 | | /// Returns an iterator to a list of unverified blocks in the data structure that aren't |
694 | | /// necessary to keep in order to complete the chain. |
695 | | /// |
696 | | /// The returned blocks are ordered by increasing order of importance. In other words, the |
697 | | /// earlier blocks are less useful. |
698 | | /// |
699 | | /// In details, this returns: |
700 | | /// |
701 | | /// - Blocks that have a bad parent and that aren't the best block of any given source. |
702 | | /// - Blocks whose parent is in the data structure and that aren't the best block of any given |
703 | | /// source. |
704 | | /// - Blocks that are bad and that aren't the best block of any given source. |
705 | | /// |
706 | | /// It is guaranteed that, even if you always immediately remove all the blocks provided by |
707 | | /// this iterator, the chain will eventually become fully synchronized (assuming that block |
708 | | /// requests eventually succeed). |
709 | | /// |
710 | | /// > **Note**: You are encouraged to use this method to remove blocks in order to prevent the |
711 | | /// > data structure from reaching unreasonable sizes. Please keep in mind, however, |
712 | | /// > that removing blocks will lead to redownloading these blocks later. In other |
713 | | /// > words, it is better to keep these blocks. |
714 | 0 | pub fn unnecessary_unverified_blocks(&self) -> impl Iterator<Item = (u64, &[u8; 32])> { |
715 | | // TODO: this entire function is O(n) everywhere |
716 | | |
717 | | // List of blocks that have a bad parent. |
718 | | // If a block has a bad parent, it is also bad itself, hence why we use `bad_blocks()`. |
719 | 0 | let bad_parent_iter = self |
720 | 0 | .blocks |
721 | 0 | .iter() |
722 | 0 | .filter(|(height, hash, _)| self.blocks.is_parent_bad(*height, hash).unwrap_or(false)); Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blocks0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blocks0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blocks0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blocks0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blocks0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blocks0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
723 | | |
724 | | // List of blocks whose parent is in the data structure. |
725 | 0 | let parent_known_iter = self.blocks.iter().filter(|(height, hash, _)| { |
726 | | match ( |
727 | 0 | height.checked_sub(1), |
728 | 0 | self.blocks.parent_hash(*height, hash), |
729 | | ) { |
730 | 0 | (Some(n), Some(h)) => self.blocks.contains(n, h), |
731 | 0 | _ => false, |
732 | | } |
733 | 0 | }); Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
734 | | |
735 | | // List of blocks that are bad but don't have a bad parent. |
736 | | // This is the same as `bad_parent_iter`, but the filter is reversed. |
737 | 0 | let bad_iter = self |
738 | 0 | .blocks |
739 | 0 | .iter() |
740 | 0 | .filter(|(height, hash, _)| self.blocks.is_bad(*height, hash).unwrap()) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss0_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
741 | 0 | .filter(|(height, hash, _)| !self.blocks.is_parent_bad(*height, hash).unwrap_or(false)); Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss1_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
742 | | |
743 | | // Never return any block that is the best block of a source. |
744 | 0 | bad_parent_iter |
745 | 0 | .chain(parent_known_iter) |
746 | 0 | .chain(bad_iter) |
747 | 0 | .map(|(height, hash, _)| (height, hash)) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss2_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
748 | 0 | .filter(|(height, hash)| { |
749 | 0 | !self |
750 | 0 | .sources |
751 | 0 | .keys() |
752 | 0 | .any(|source_id| self.sources.best_block(source_id) == (*height, hash)) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE29unnecessary_unverified_blockss3_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00CscoAnRPySggw_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE29unnecessary_unverified_blockss3_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_00Cs4VrkfB1pvQ3_25json_rpc_general_requests |
753 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE29unnecessary_unverified_blockss3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE29unnecessary_unverified_blockss3_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
754 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE29unnecessary_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE29unnecessary_unverified_blocksCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE29unnecessary_unverified_blocksBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE29unnecessary_unverified_blocksCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE29unnecessary_unverified_blocksCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE29unnecessary_unverified_blocksCs4VrkfB1pvQ3_25json_rpc_general_requests |
755 | | |
756 | | /// Inserts a new request in the data structure. |
757 | | /// |
758 | | /// > **Note**: The request doesn't necessarily have to match a request returned by |
759 | | /// > [`PendingBlocks::desired_requests`] or |
760 | | /// > [`PendingBlocks::source_desired_requests`]. Any arbitrary blocks request can |
761 | | /// > be added. |
762 | | /// |
763 | | /// # Panic |
764 | | /// |
765 | | /// Panics if the [`SourceId`] is out of range. |
766 | | /// |
767 | 0 | pub fn add_request( |
768 | 0 | &mut self, |
769 | 0 | source_id: SourceId, |
770 | 0 | detail: RequestParams, |
771 | 0 | user_data: TRq, |
772 | 0 | ) -> RequestId { |
773 | 0 | assert!(self.sources.contains(source_id)); |
774 | | |
775 | 0 | let request_id = RequestId(self.requests.insert(Request { |
776 | 0 | detail, |
777 | 0 | source_id, |
778 | 0 | user_data, |
779 | 0 | })); |
780 | | |
781 | 0 | let _was_inserted = self.source_occupations.insert((source_id, request_id)); |
782 | 0 | debug_assert!(_was_inserted); |
783 | | |
784 | 0 | debug_assert_eq!(self.source_occupations.len(), self.requests.len()); |
785 | | |
786 | | // Add in `blocks_requests` and `requested_blocks` an entry for each known block. |
787 | 0 | let mut iter = (detail.first_block_height, detail.first_block_hash); |
788 | | loop { |
789 | 0 | self.blocks_requests.insert((iter.0, iter.1, request_id)); |
790 | 0 | self.requested_blocks.insert((request_id, iter.0, iter.1)); |
791 | | |
792 | 0 | match self.blocks.parent_hash(iter.0, &iter.1) { |
793 | 0 | Some(p) => iter = (iter.0 - 1, *p), |
794 | 0 | None => break, |
795 | | } |
796 | | } |
797 | | |
798 | 0 | request_id |
799 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE11add_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE11add_requestCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE11add_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE11add_requestCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE11add_requestCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE11add_requestCs4VrkfB1pvQ3_25json_rpc_general_requests |
800 | | |
801 | | /// Removes a request from the state machine. |
802 | | /// |
803 | | /// Returns the parameters that were passed to [`PendingBlocks::add_request`]. |
804 | | /// |
805 | | /// Note that this function does nothing else but remove the given request from the state |
806 | | /// machine. Nothing in the state concerning sources or blocks is updated. |
807 | | /// |
808 | | /// The next call to [`PendingBlocks::desired_requests`] might return the same request again. |
809 | | /// In order to avoid that, you are encouraged to update the state of the sources and blocks |
810 | | /// in the container with the outcome of the request. |
811 | | /// |
812 | | /// # Panic |
813 | | /// |
814 | | /// Panics if the [`RequestId`] is invalid. |
815 | | /// |
816 | | #[track_caller] |
817 | 0 | pub fn remove_request(&mut self, request_id: RequestId) -> (RequestParams, SourceId, TRq) { |
818 | 0 | assert!(self.requests.contains(request_id.0)); |
819 | 0 | let request = self.requests.remove(request_id.0); |
820 | | |
821 | | // Update `requested_blocks`. |
822 | 0 | let blocks_to_remove = self |
823 | 0 | .requested_blocks |
824 | 0 | .range((request_id, u64::MIN, [0; 32])..=(request_id, u64::MAX, [0xff; 32])) |
825 | 0 | .cloned() |
826 | 0 | .collect::<Vec<_>>(); |
827 | | |
828 | 0 | for (request_id, block_height, block_hash) in blocks_to_remove { |
829 | 0 | let _was_in = self |
830 | 0 | .blocks_requests |
831 | 0 | .remove(&(block_height, block_hash, request_id)); |
832 | 0 | debug_assert!(_was_in); |
833 | | |
834 | 0 | let _was_in = self |
835 | 0 | .requested_blocks |
836 | 0 | .remove(&(request_id, block_height, block_hash)); |
837 | 0 | debug_assert!(_was_in); |
838 | | } |
839 | | |
840 | 0 | let _was_in = self |
841 | 0 | .source_occupations |
842 | 0 | .remove(&(request.source_id, request_id)); |
843 | 0 | debug_assert!(_was_in); |
844 | | |
845 | 0 | debug_assert_eq!(self.source_occupations.len(), self.requests.len()); |
846 | 0 | debug_assert_eq!(self.blocks_requests.len(), self.requested_blocks.len()); |
847 | | |
848 | 0 | (request.detail, request.source_id, request.user_data) |
849 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE14remove_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE14remove_requestCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE14remove_requestBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE14remove_requestCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE14remove_requestCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE14remove_requestCs4VrkfB1pvQ3_25json_rpc_general_requests |
850 | | |
851 | | /// Returns the source that the given request is being performed on. |
852 | | /// |
853 | | /// # Panic |
854 | | /// |
855 | | /// Panics if the [`RequestId`] is invalid. |
856 | | /// |
857 | | #[track_caller] |
858 | 0 | pub fn request_source_id(&self, request_id: RequestId) -> SourceId { |
859 | 0 | self.requests.get(request_id.0).unwrap().source_id |
860 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17request_source_idBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17request_source_idBa_ |
861 | | |
862 | | /// Returns a list of requests that are considered obsolete and can be removed using |
863 | | /// [`PendingBlocks::remove_request`]. |
864 | | /// |
865 | | /// A request is considered obsolete if the state of the requested blocks changes in such a |
866 | | /// way that they don't need to be requested anymore. The request wouldn't be returned by |
867 | | /// [`PendingBlocks::desired_requests`]. |
868 | | /// |
869 | | /// > **Note**: It is in no way mandatory to actually call this function and cancel the |
870 | | /// > requests that are returned. |
871 | 0 | pub fn obsolete_requests(&self) -> impl Iterator<Item = (RequestId, &TRq)> { |
872 | | // TODO: more than that? |
873 | 0 | self.requests |
874 | 0 | .iter() |
875 | 0 | .filter(move |(_, rq)| { |
876 | 0 | rq.detail.first_block_height <= self.sources.finalized_block_height() |
877 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requests0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requests0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE17obsolete_requests0Cs7snhGEhbuap_18smoldot_light_wasm |
878 | 0 | .map(|(id, rq)| (RequestId(id), &rq.user_data)) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requestss_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE17obsolete_requestss_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE17obsolete_requestss_0Cs7snhGEhbuap_18smoldot_light_wasm |
879 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17obsolete_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE17obsolete_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE17obsolete_requestsCs7snhGEhbuap_18smoldot_light_wasm |
880 | | |
881 | | /// Returns a list of requests that should be started in order to learn about the missing |
882 | | /// unverified blocks. |
883 | | /// |
884 | | /// In details, the requests concern: |
885 | | /// |
886 | | /// - If [`Config::download_bodies`] was `true`, downloading the body of blocks whose body is |
887 | | /// unknown. |
888 | | /// - Downloading headers of blocks whose state is [`UnverifiedBlockState::HeightHash`]. |
889 | | /// |
890 | | /// Requests are ordered by increasing block height. In other words, the most important |
891 | | /// requests are returned first. |
892 | | /// |
893 | | /// This method doesn't modify the state machine in any way. [`PendingBlocks::add_request`] |
894 | | /// must be called in order for the request to actually be marked as started. Once a request |
895 | | /// has been started with [`PendingBlocks::add_request`] it will no longer be returned by this |
896 | | /// method. |
897 | | /// |
898 | | /// No request concerning the finalized block (as set using |
899 | | /// [`PendingBlocks::set_finalized_block_height`]) or below will ever be returned. |
900 | | /// |
901 | | /// > **Note**: The API user is encouraged to iterate over the requests until they find a |
902 | | /// > request that is appropriate, then stop iterating and start said request. |
903 | | /// |
904 | | /// > **Note**: This state machine does in no way enforce a limit to the number of simultaneous |
905 | | /// > requests per source, as this is out of scope of this module. However, there is |
906 | | /// > limit to the number of simultaneous requests per block. See |
907 | | /// > [`Config::max_requests_per_block`]. |
908 | 43 | pub fn desired_requests(&self) -> impl Iterator<Item = DesiredRequest> { |
909 | 43 | self.desired_requests_inner(None) |
910 | 43 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE16desired_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE16desired_requestsCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE16desired_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE16desired_requestsCs7snhGEhbuap_18smoldot_light_wasm _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE16desired_requestsCsjyNE3yDMkgA_14json_rpc_basic Line | Count | Source | 908 | 4 | pub fn desired_requests(&self) -> impl Iterator<Item = DesiredRequest> { | 909 | 4 | self.desired_requests_inner(None) | 910 | 4 | } |
_RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE16desired_requestsCs4VrkfB1pvQ3_25json_rpc_general_requests Line | Count | Source | 908 | 39 | pub fn desired_requests(&self) -> impl Iterator<Item = DesiredRequest> { | 909 | 39 | self.desired_requests_inner(None) | 910 | 39 | } |
|
911 | | |
912 | | /// Returns a list of requests that should be started in order to learn about the missing |
913 | | /// unverified blocks. |
914 | | /// |
915 | | /// This method is similar to [`PendingBlocks::desired_requests`], except that only requests |
916 | | /// concerning the given source will be returned. |
917 | | /// |
918 | | /// # Panic |
919 | | /// |
920 | | /// Panics if the [`SourceId`] is out of range. |
921 | | /// |
922 | 0 | pub fn source_desired_requests( |
923 | 0 | &self, |
924 | 0 | source_id: SourceId, |
925 | 0 | ) -> impl Iterator<Item = RequestParams> { |
926 | 0 | self.desired_requests_inner(Some(source_id)).map(move |rq| { |
927 | 0 | debug_assert_eq!(rq.source_id, source_id); |
928 | 0 | rq.request_params |
929 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23source_desired_requests0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE23source_desired_requests0Bc_ |
930 | 0 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23source_desired_requestsBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE23source_desired_requestsBa_ |
931 | | |
932 | | /// Inner implementation of [`PendingBlocks::desired_requests`] and |
933 | | /// [`PendingBlocks::source_desired_requests`]. |
934 | | /// |
935 | | /// If `force_source` is `Some`, only the given source will be considered. |
936 | | /// |
937 | | /// # Panic |
938 | | /// |
939 | | /// Panics if the [`SourceId`] is out of range. |
940 | | /// |
941 | 43 | fn desired_requests_inner( |
942 | 43 | &self, |
943 | 43 | force_source: Option<SourceId>, |
944 | 43 | ) -> impl Iterator<Item = DesiredRequest> { |
945 | | // 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 |
946 | | |
947 | | // List of blocks whose header is known but not its body. |
948 | 43 | let unknown_body_iter = if self.download_bodies { |
949 | | either::Left( |
950 | 43 | self.blocks |
951 | 43 | .iter() |
952 | 43 | .filter(move |(_, _, block_info)| {0 |
953 | 0 | matches!(&block_info.state, UnverifiedBlockState::Header { .. }) |
954 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inner0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inner0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inner0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inner0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inner0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inner0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
955 | 43 | .map(|(height, hash, _)| (height0 , hash0 )), Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
956 | | ) |
957 | | } else { |
958 | 0 | either::Right(iter::empty()) |
959 | | }; |
960 | | |
961 | | // List of blocks whose header isn't known. |
962 | 43 | let unknown_header_iter = self |
963 | 43 | .blocks |
964 | 43 | .unknown_blocks() |
965 | 43 | .filter(move |(unknown_block_height, _)| {0 |
966 | | // Don't request the finalized block or below. |
967 | 0 | *unknown_block_height > self.sources.finalized_block_height() |
968 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners0_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners0_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners0_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners0_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners0_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
969 | 43 | .inspect(move |(unknown_block_height, unknown_block_hash)| {0 |
970 | | // Sanity check. |
971 | 0 | debug_assert!(match self |
972 | 0 | .blocks |
973 | 0 | .user_data(*unknown_block_height, unknown_block_hash) |
974 | 0 | .map(|ud| &ud.state) |
975 | | { |
976 | 0 | None | Some(UnverifiedBlockState::HeightHash) => true, |
977 | | Some( |
978 | | UnverifiedBlockState::Header { .. } |
979 | | | UnverifiedBlockState::HeaderBody { .. }, |
980 | 0 | ) => false, |
981 | | }); |
982 | 0 | }); Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners1_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners1_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners1_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners1_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners1_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
983 | | |
984 | | // Combine the two block iterators and find sources. |
985 | | // There isn't any overlap between the two iterators. |
986 | 43 | unknown_body_iter |
987 | 43 | .map(|(n, h)| (n0 , h0 , false)) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners2_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners2_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners2_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners2_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners2_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
988 | 43 | .chain(unknown_header_iter.map(|(n, h)| (n0 , h0 , true))) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners3_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners3_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners3_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners3_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners3_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
989 | 43 | .filter(move |(unknown_block_height, unknown_block_hash, _)| {0 |
990 | | // Cap by `max_requests_per_block`. |
991 | | // TODO: O(n)? |
992 | 0 | let num_existing_requests = self |
993 | 0 | .blocks_requests |
994 | 0 | .range( |
995 | 0 | ( |
996 | 0 | *unknown_block_height, |
997 | 0 | **unknown_block_hash, |
998 | 0 | RequestId(usize::MIN), |
999 | 0 | ) |
1000 | 0 | ..=( |
1001 | 0 | *unknown_block_height, |
1002 | 0 | **unknown_block_hash, |
1003 | 0 | RequestId(usize::MAX), |
1004 | 0 | ), |
1005 | | ) |
1006 | 0 | .count(); |
1007 | | |
1008 | 0 | num_existing_requests < self.max_requests_per_block |
1009 | 0 | }) Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners4_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners4_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners4_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners4_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners4_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners4_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
1010 | 43 | .flat_map( |
1011 | 0 | move |(unknown_block_height, unknown_block_hash, download_many)| { |
1012 | | // Try to find all appropriate sources. |
1013 | 0 | let possible_sources = |
1014 | 0 | if let Some(force_source) = force_source { |
1015 | 0 | either::Left(iter::once(force_source).filter(move |id| { |
1016 | 0 | self.sources.source_knows_non_finalized_block( |
1017 | 0 | *id, |
1018 | 0 | unknown_block_height, |
1019 | 0 | unknown_block_hash, |
1020 | | ) |
1021 | 0 | })) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_00CscoAnRPySggw_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_00Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE22desired_requests_inners5_00Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_00CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_00Cs4VrkfB1pvQ3_25json_rpc_general_requests |
1022 | | } else { |
1023 | 0 | either::Right(self.sources.knows_non_finalized_block( |
1024 | 0 | unknown_block_height, |
1025 | 0 | unknown_block_hash, |
1026 | 0 | )) |
1027 | | }; |
1028 | | |
1029 | 0 | possible_sources |
1030 | 0 | .filter(move |source_id| { |
1031 | | // Don't start any request towards this source if there's another request |
1032 | | // for the same block from the same source. |
1033 | | // TODO: O(n)? |
1034 | 0 | !self |
1035 | 0 | .blocks_requests |
1036 | 0 | .range( |
1037 | 0 | ( |
1038 | 0 | unknown_block_height, |
1039 | 0 | *unknown_block_hash, |
1040 | 0 | RequestId(usize::MIN), |
1041 | 0 | ) |
1042 | 0 | ..=( |
1043 | 0 | unknown_block_height, |
1044 | 0 | *unknown_block_hash, |
1045 | 0 | RequestId(usize::MAX), |
1046 | 0 | ), |
1047 | 0 | ) |
1048 | 0 | .any(|(_, _, request_id)| { |
1049 | 0 | self.requests[request_id.0].source_id == *source_id |
1050 | 0 | }) Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlockspppE22desired_requests_inners5_0s_00Bg_ Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB3F_19AllForksSourceExtraEE22desired_requests_inners5_0s_00CscoAnRPySggw_6author Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlockspppE22desired_requests_inners5_0s_00Bg_ Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB2t_19AllForksSourceExtraEE22desired_requests_inners5_0s_00Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB3F_19AllForksSourceExtraEE22desired_requests_inners5_0s_00CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtBa_13PendingBlocksINtBc_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBe_3all20AllForksRequestExtraINtBc_6SourceNtB3F_19AllForksSourceExtraEE22desired_requests_inners5_0s_00Cs4VrkfB1pvQ3_25json_rpc_general_requests |
1051 | 0 | }) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE22desired_requests_inners5_0s_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
1052 | 0 | .map(move |source_id| { |
1053 | 0 | debug_assert!(self.sources.source_knows_non_finalized_block( |
1054 | 0 | source_id, |
1055 | 0 | unknown_block_height, |
1056 | 0 | unknown_block_hash |
1057 | | )); |
1058 | | |
1059 | | DesiredRequest { |
1060 | 0 | source_id, |
1061 | | request_params: RequestParams { |
1062 | 0 | first_block_hash: *unknown_block_hash, |
1063 | 0 | first_block_height: unknown_block_height, |
1064 | 0 | num_blocks: NonZero::<u64>::new(if download_many { |
1065 | 0 | unknown_block_height - self.sources.finalized_block_height() |
1066 | | } else { |
1067 | 0 | 1 |
1068 | | }) |
1069 | 0 | .unwrap(), |
1070 | | }, |
1071 | | } |
1072 | 0 | }) Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s0_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlockspppE22desired_requests_inners5_0s0_0Be_ Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB2r_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB8_13PendingBlocksINtBa_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBc_3all20AllForksRequestExtraINtBa_6SourceNtB3D_19AllForksSourceExtraEE22desired_requests_inners5_0s0_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
1073 | 0 | }, Unexecuted instantiation: _RNCNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners5_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners5_0CscoAnRPySggw_6author Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlockspppE22desired_requests_inners5_0Bc_ Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB2p_19AllForksSourceExtraEE22desired_requests_inners5_0Cs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners5_0CsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNCNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB6_13PendingBlocksINtB8_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtBa_3all20AllForksRequestExtraINtB8_6SourceNtB3B_19AllForksSourceExtraEE22desired_requests_inners5_0Cs4VrkfB1pvQ3_25json_rpc_general_requests |
1074 | | ) |
1075 | 43 | } Unexecuted instantiation: _RNvMs_NtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE22desired_requests_innerBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE22desired_requests_innerCscoAnRPySggw_6author Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlockspppE22desired_requests_innerBa_ Unexecuted instantiation: _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB2n_19AllForksSourceExtraEE22desired_requests_innerCs7snhGEhbuap_18smoldot_light_wasm _RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE22desired_requests_innerCsjyNE3yDMkgA_14json_rpc_basic Line | Count | Source | 941 | 4 | fn desired_requests_inner( | 942 | 4 | &self, | 943 | 4 | force_source: Option<SourceId>, | 944 | 4 | ) -> impl Iterator<Item = DesiredRequest> { | 945 | | // 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 | 946 | | | 947 | | // List of blocks whose header is known but not its body. | 948 | 4 | let unknown_body_iter = if self.download_bodies { | 949 | | either::Left( | 950 | 4 | self.blocks | 951 | 4 | .iter() | 952 | 4 | .filter(move |(_, _, block_info)| { | 953 | | matches!(&block_info.state, UnverifiedBlockState::Header { .. }) | 954 | | }) | 955 | 4 | .map(|(height, hash, _)| (height, hash)), | 956 | | ) | 957 | | } else { | 958 | 0 | either::Right(iter::empty()) | 959 | | }; | 960 | | | 961 | | // List of blocks whose header isn't known. | 962 | 4 | let unknown_header_iter = self | 963 | 4 | .blocks | 964 | 4 | .unknown_blocks() | 965 | 4 | .filter(move |(unknown_block_height, _)| { | 966 | | // Don't request the finalized block or below. | 967 | | *unknown_block_height > self.sources.finalized_block_height() | 968 | | }) | 969 | 4 | .inspect(move |(unknown_block_height, unknown_block_hash)| { | 970 | | // Sanity check. | 971 | | debug_assert!(match self | 972 | | .blocks | 973 | | .user_data(*unknown_block_height, unknown_block_hash) | 974 | | .map(|ud| &ud.state) | 975 | | { | 976 | | None | Some(UnverifiedBlockState::HeightHash) => true, | 977 | | Some( | 978 | | UnverifiedBlockState::Header { .. } | 979 | | | UnverifiedBlockState::HeaderBody { .. }, | 980 | | ) => false, | 981 | | }); | 982 | | }); | 983 | | | 984 | | // Combine the two block iterators and find sources. | 985 | | // There isn't any overlap between the two iterators. | 986 | 4 | unknown_body_iter | 987 | 4 | .map(|(n, h)| (n, h, false)) | 988 | 4 | .chain(unknown_header_iter.map(|(n, h)| (n, h, true))) | 989 | 4 | .filter(move |(unknown_block_height, unknown_block_hash, _)| { | 990 | | // Cap by `max_requests_per_block`. | 991 | | // TODO: O(n)? | 992 | | let num_existing_requests = self | 993 | | .blocks_requests | 994 | | .range( | 995 | | ( | 996 | | *unknown_block_height, | 997 | | **unknown_block_hash, | 998 | | RequestId(usize::MIN), | 999 | | ) | 1000 | | ..=( | 1001 | | *unknown_block_height, | 1002 | | **unknown_block_hash, | 1003 | | RequestId(usize::MAX), | 1004 | | ), | 1005 | | ) | 1006 | | .count(); | 1007 | | | 1008 | | num_existing_requests < self.max_requests_per_block | 1009 | | }) | 1010 | 4 | .flat_map( | 1011 | | move |(unknown_block_height, unknown_block_hash, download_many)| { | 1012 | | // Try to find all appropriate sources. | 1013 | | let possible_sources = | 1014 | | if let Some(force_source) = force_source { | 1015 | | either::Left(iter::once(force_source).filter(move |id| { | 1016 | | self.sources.source_knows_non_finalized_block( | 1017 | | *id, | 1018 | | unknown_block_height, | 1019 | | unknown_block_hash, | 1020 | | ) | 1021 | | })) | 1022 | | } else { | 1023 | | either::Right(self.sources.knows_non_finalized_block( | 1024 | | unknown_block_height, | 1025 | | unknown_block_hash, | 1026 | | )) | 1027 | | }; | 1028 | | | 1029 | | possible_sources | 1030 | | .filter(move |source_id| { | 1031 | | // Don't start any request towards this source if there's another request | 1032 | | // for the same block from the same source. | 1033 | | // TODO: O(n)? | 1034 | | !self | 1035 | | .blocks_requests | 1036 | | .range( | 1037 | | ( | 1038 | | unknown_block_height, | 1039 | | *unknown_block_hash, | 1040 | | RequestId(usize::MIN), | 1041 | | ) | 1042 | | ..=( | 1043 | | unknown_block_height, | 1044 | | *unknown_block_hash, | 1045 | | RequestId(usize::MAX), | 1046 | | ), | 1047 | | ) | 1048 | | .any(|(_, _, request_id)| { | 1049 | | self.requests[request_id.0].source_id == *source_id | 1050 | | }) | 1051 | | }) | 1052 | | .map(move |source_id| { | 1053 | | debug_assert!(self.sources.source_knows_non_finalized_block( | 1054 | | source_id, | 1055 | | unknown_block_height, | 1056 | | unknown_block_hash | 1057 | | )); | 1058 | | | 1059 | | DesiredRequest { | 1060 | | source_id, | 1061 | | request_params: RequestParams { | 1062 | | first_block_hash: *unknown_block_hash, | 1063 | | first_block_height: unknown_block_height, | 1064 | | num_blocks: NonZero::<u64>::new(if download_many { | 1065 | | unknown_block_height - self.sources.finalized_block_height() | 1066 | | } else { | 1067 | | 1 | 1068 | | }) | 1069 | | .unwrap(), | 1070 | | }, | 1071 | | } | 1072 | | }) | 1073 | | }, | 1074 | | ) | 1075 | 4 | } |
_RNvMs_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB4_13PendingBlocksINtB6_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB8_3all20AllForksRequestExtraINtB6_6SourceNtB3z_19AllForksSourceExtraEE22desired_requests_innerCs4VrkfB1pvQ3_25json_rpc_general_requests Line | Count | Source | 941 | 39 | fn desired_requests_inner( | 942 | 39 | &self, | 943 | 39 | force_source: Option<SourceId>, | 944 | 39 | ) -> impl Iterator<Item = DesiredRequest> { | 945 | | // 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 | 946 | | | 947 | | // List of blocks whose header is known but not its body. | 948 | 39 | let unknown_body_iter = if self.download_bodies { | 949 | | either::Left( | 950 | 39 | self.blocks | 951 | 39 | .iter() | 952 | 39 | .filter(move |(_, _, block_info)| { | 953 | | matches!(&block_info.state, UnverifiedBlockState::Header { .. }) | 954 | | }) | 955 | 39 | .map(|(height, hash, _)| (height, hash)), | 956 | | ) | 957 | | } else { | 958 | 0 | either::Right(iter::empty()) | 959 | | }; | 960 | | | 961 | | // List of blocks whose header isn't known. | 962 | 39 | let unknown_header_iter = self | 963 | 39 | .blocks | 964 | 39 | .unknown_blocks() | 965 | 39 | .filter(move |(unknown_block_height, _)| { | 966 | | // Don't request the finalized block or below. | 967 | | *unknown_block_height > self.sources.finalized_block_height() | 968 | | }) | 969 | 39 | .inspect(move |(unknown_block_height, unknown_block_hash)| { | 970 | | // Sanity check. | 971 | | debug_assert!(match self | 972 | | .blocks | 973 | | .user_data(*unknown_block_height, unknown_block_hash) | 974 | | .map(|ud| &ud.state) | 975 | | { | 976 | | None | Some(UnverifiedBlockState::HeightHash) => true, | 977 | | Some( | 978 | | UnverifiedBlockState::Header { .. } | 979 | | | UnverifiedBlockState::HeaderBody { .. }, | 980 | | ) => false, | 981 | | }); | 982 | | }); | 983 | | | 984 | | // Combine the two block iterators and find sources. | 985 | | // There isn't any overlap between the two iterators. | 986 | 39 | unknown_body_iter | 987 | 39 | .map(|(n, h)| (n, h, false)) | 988 | 39 | .chain(unknown_header_iter.map(|(n, h)| (n, h, true))) | 989 | 39 | .filter(move |(unknown_block_height, unknown_block_hash, _)| { | 990 | | // Cap by `max_requests_per_block`. | 991 | | // TODO: O(n)? | 992 | | let num_existing_requests = self | 993 | | .blocks_requests | 994 | | .range( | 995 | | ( | 996 | | *unknown_block_height, | 997 | | **unknown_block_hash, | 998 | | RequestId(usize::MIN), | 999 | | ) | 1000 | | ..=( | 1001 | | *unknown_block_height, | 1002 | | **unknown_block_hash, | 1003 | | RequestId(usize::MAX), | 1004 | | ), | 1005 | | ) | 1006 | | .count(); | 1007 | | | 1008 | | num_existing_requests < self.max_requests_per_block | 1009 | | }) | 1010 | 39 | .flat_map( | 1011 | | move |(unknown_block_height, unknown_block_hash, download_many)| { | 1012 | | // Try to find all appropriate sources. | 1013 | | let possible_sources = | 1014 | | if let Some(force_source) = force_source { | 1015 | | either::Left(iter::once(force_source).filter(move |id| { | 1016 | | self.sources.source_knows_non_finalized_block( | 1017 | | *id, | 1018 | | unknown_block_height, | 1019 | | unknown_block_hash, | 1020 | | ) | 1021 | | })) | 1022 | | } else { | 1023 | | either::Right(self.sources.knows_non_finalized_block( | 1024 | | unknown_block_height, | 1025 | | unknown_block_hash, | 1026 | | )) | 1027 | | }; | 1028 | | | 1029 | | possible_sources | 1030 | | .filter(move |source_id| { | 1031 | | // Don't start any request towards this source if there's another request | 1032 | | // for the same block from the same source. | 1033 | | // TODO: O(n)? | 1034 | | !self | 1035 | | .blocks_requests | 1036 | | .range( | 1037 | | ( | 1038 | | unknown_block_height, | 1039 | | *unknown_block_hash, | 1040 | | RequestId(usize::MIN), | 1041 | | ) | 1042 | | ..=( | 1043 | | unknown_block_height, | 1044 | | *unknown_block_hash, | 1045 | | RequestId(usize::MAX), | 1046 | | ), | 1047 | | ) | 1048 | | .any(|(_, _, request_id)| { | 1049 | | self.requests[request_id.0].source_id == *source_id | 1050 | | }) | 1051 | | }) | 1052 | | .map(move |source_id| { | 1053 | | debug_assert!(self.sources.source_knows_non_finalized_block( | 1054 | | source_id, | 1055 | | unknown_block_height, | 1056 | | unknown_block_hash | 1057 | | )); | 1058 | | | 1059 | | DesiredRequest { | 1060 | | source_id, | 1061 | | request_params: RequestParams { | 1062 | | first_block_hash: *unknown_block_hash, | 1063 | | first_block_height: unknown_block_height, | 1064 | | num_blocks: NonZero::<u64>::new(if download_many { | 1065 | | unknown_block_height - self.sources.finalized_block_height() | 1066 | | } else { | 1067 | | 1 | 1068 | | }) | 1069 | | .unwrap(), | 1070 | | }, | 1071 | | } | 1072 | | }) | 1073 | | }, | 1074 | | ) | 1075 | 39 | } |
|
1076 | | } |
1077 | | |
1078 | | impl<TBl, TRq, TSrc> ops::Index<SourceId> for PendingBlocks<TBl, TRq, TSrc> { |
1079 | | type Output = TSrc; |
1080 | | |
1081 | | #[track_caller] |
1082 | 21 | fn index(&self, id: SourceId) -> &TSrc { |
1083 | 21 | &self.sources[id].user_data |
1084 | 21 | } Unexecuted instantiation: _RNvXININtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blockss0_0pppEINtB5_13PendingBlockspppEINtNtNtCs1p5UDGgVI4d_4core3ops5index5IndexNtNtB7_7sources8SourceIdE5indexBb_ Unexecuted instantiation: _RNvXs0_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCscoAnRPySggw_6author Unexecuted instantiation: _RNvXININtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blockss0_0pppEINtB5_13PendingBlockspppEINtNtNtCs1p5UDGgVI4d_4core3ops5index5IndexNtNtB7_7sources8SourceIdE5indexBb_ Unexecuted instantiation: _RNvXs0_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB2o_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCs7snhGEhbuap_18smoldot_light_wasm _RNvXs0_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCsjyNE3yDMkgA_14json_rpc_basic Line | Count | Source | 1082 | 2 | fn index(&self, id: SourceId) -> &TSrc { | 1083 | 2 | &self.sources[id].user_data | 1084 | 2 | } |
_RNvXs0_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index5IndexNtNtB7_7sources8SourceIdE5indexCs4VrkfB1pvQ3_25json_rpc_general_requests Line | Count | Source | 1082 | 19 | fn index(&self, id: SourceId) -> &TSrc { | 1083 | 19 | &self.sources[id].user_data | 1084 | 19 | } |
|
1085 | | } |
1086 | | |
1087 | | impl<TBl, TRq, TSrc> ops::IndexMut<SourceId> for PendingBlocks<TBl, TRq, TSrc> { |
1088 | | #[track_caller] |
1089 | 0 | fn index_mut(&mut self, id: SourceId) -> &mut TSrc { |
1090 | 0 | &mut self.sources[id].user_data |
1091 | 0 | } Unexecuted instantiation: _RNvXININtNtNtCsjlkOsLH0Zfj_7smoldot4sync9all_forks14pending_blockss1_0pppEINtB5_13PendingBlockspppEINtNtNtCs1p5UDGgVI4d_4core3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutBb_ Unexecuted instantiation: _RNvXs1_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCscoAnRPySggw_6author Unexecuted instantiation: _RNvXININtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blockss1_0pppEINtB5_13PendingBlockspppEINtNtNtCs1p5UDGgVI4d_4core3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutBb_ Unexecuted instantiation: _RNvXs1_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionuEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB2o_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCs7snhGEhbuap_18smoldot_light_wasm Unexecuted instantiation: _RNvXs1_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCsjyNE3yDMkgA_14json_rpc_basic Unexecuted instantiation: _RNvXs1_NtNtNtCsc1ywvx6YAnK_7smoldot4sync9all_forks14pending_blocksINtB5_13PendingBlocksINtB7_12PendingBlockINtNtCs1p5UDGgVI4d_4core6option6OptionNtNtCsfFWJyR6nd6r_17smoldot_full_node17consensus_service17NonFinalizedBlockEENtNtB9_3all20AllForksRequestExtraINtB7_6SourceNtB3A_19AllForksSourceExtraEEINtNtNtB1M_3ops5index8IndexMutNtNtB7_7sources8SourceIdE9index_mutCs4VrkfB1pvQ3_25json_rpc_general_requests |
1092 | | } |
1093 | | |
1094 | | /// See [`PendingBlocks::desired_requests`]. |
1095 | | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1096 | | pub struct DesiredRequest { |
1097 | | /// Source onto which to start this request. |
1098 | | pub source_id: SourceId, |
1099 | | /// Details of the request. |
1100 | | pub request_params: RequestParams, |
1101 | | } |
1102 | | |
1103 | | /// Information about a blocks request to be performed on a source. |
1104 | | /// |
1105 | | /// The source should return information about the block indicated with |
1106 | | /// [`RequestParams::first_block_height`] and [`RequestParams::first_block_hash`] and its |
1107 | | /// ancestors. In total, [`RequestParams::num_blocks`] should be provided by the source. |
1108 | | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1109 | | pub struct RequestParams { |
1110 | | /// Height of the first block to request. |
1111 | | pub first_block_height: u64, |
1112 | | |
1113 | | /// Hash of the first block to request. |
1114 | | pub first_block_hash: [u8; 32], |
1115 | | |
1116 | | /// Number of blocks the request should return. |
1117 | | /// |
1118 | | /// Note that this is only an indication, and the source is free to give fewer blocks |
1119 | | /// than requested. |
1120 | | pub num_blocks: NonZero<u64>, |
1121 | | } |