/__w/smoldot/smoldot/repo/lib/src/sync/all.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Substrate-lite |
2 | | // Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. |
3 | | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 |
4 | | |
5 | | // This program is free software: you can redistribute it and/or modify |
6 | | // it under the terms of the GNU General Public License as published by |
7 | | // the Free Software Foundation, either version 3 of the License, or |
8 | | // (at your option) any later version. |
9 | | |
10 | | // This program is distributed in the hope that it will be useful, |
11 | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | // GNU General Public License for more details. |
14 | | |
15 | | // You should have received a copy of the GNU General Public License |
16 | | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | |
18 | | //! All syncing strategies grouped together. |
19 | | //! |
20 | | //! This state machine combines GrandPa warp syncing and all forks syncing into one state machine. |
21 | | //! |
22 | | //! # Overview |
23 | | //! |
24 | | //! This state machine acts as a container of sources, blocks (verified or not), and requests. |
25 | | //! In order to initialize it, you need to pass, amongst other things, a |
26 | | //! [`chain_information::ChainInformation`] struct indicating the known state of the finality of |
27 | | //! the chain. |
28 | | //! |
29 | | //! A *request* represents a query for information from a source. Once the request has finished, |
30 | | //! call one of the methods of the [`AllSync`] in order to notify the state machine of the outcome. |
31 | | |
32 | | use crate::{ |
33 | | chain::{blocks_tree, chain_information}, |
34 | | executor::host, |
35 | | finality::decode, |
36 | | header, |
37 | | sync::{all_forks, warp_sync}, |
38 | | trie::Nibble, |
39 | | verify, |
40 | | }; |
41 | | |
42 | | use alloc::{borrow::Cow, vec::Vec}; |
43 | | use core::{ |
44 | | iter, |
45 | | marker::PhantomData, |
46 | | num::{NonZeroU32, NonZeroU64}, |
47 | | ops, |
48 | | time::Duration, |
49 | | }; |
50 | | |
51 | | pub use crate::executor::vm::ExecHint; |
52 | | pub use blocks_tree::{CommitVerifyError, JustificationVerifyError}; |
53 | | pub use warp_sync::{ |
54 | | BuildChainInformationError as WarpSyncBuildChainInformationError, |
55 | | BuildRuntimeError as WarpSyncBuildRuntimeError, ConfigCodeTrieNodeHint, VerifyFragmentError, |
56 | | WarpSyncFragment, |
57 | | }; |
58 | | |
59 | | use super::{all_forks::AllForksSync, warp_sync::RuntimeInformation}; |
60 | | |
61 | | /// Configuration for the [`AllSync`]. |
62 | | // TODO: review these fields |
63 | | #[derive(Debug)] |
64 | | pub struct Config { |
65 | | /// Information about the latest finalized block and its ancestors. |
66 | | pub chain_information: chain_information::ValidChainInformation, |
67 | | |
68 | | /// Number of bytes used when encoding/decoding the block number. Influences how various data |
69 | | /// structures should be parsed. |
70 | | pub block_number_bytes: usize, |
71 | | |
72 | | /// If `false`, blocks containing digest items with an unknown consensus engine will fail to |
73 | | /// verify. |
74 | | /// |
75 | | /// Note that blocks must always contain digest items that are relevant to the current |
76 | | /// consensus algorithm. This option controls what happens when blocks contain additional |
77 | | /// digest items that aren't recognized by the implementation. |
78 | | /// |
79 | | /// Passing `true` can lead to blocks being considered as valid when they shouldn't, as these |
80 | | /// additional digest items could have some logic attached to them that restricts which blocks |
81 | | /// are valid and which are not. |
82 | | /// |
83 | | /// However, since a recognized consensus engine must always be present, both `true` and |
84 | | /// `false` guarantee that the number of authorable blocks over the network is bounded. |
85 | | pub allow_unknown_consensus_engines: bool, |
86 | | |
87 | | /// Pre-allocated capacity for the number of block sources. |
88 | | pub sources_capacity: usize, |
89 | | |
90 | | /// Pre-allocated capacity for the number of blocks between the finalized block and the head |
91 | | /// of the chain. |
92 | | /// |
93 | | /// Should be set to the maximum number of block between two consecutive justifications. |
94 | | pub blocks_capacity: usize, |
95 | | |
96 | | /// Maximum number of blocks of unknown ancestry to keep in memory. |
97 | | /// |
98 | | /// See [`all_forks::Config::max_disjoint_headers`] for more information. |
99 | | pub max_disjoint_headers: usize, |
100 | | |
101 | | /// Maximum number of simultaneous pending requests made towards the same block. |
102 | | /// |
103 | | /// See [`all_forks::Config::max_requests_per_block`] for more information. |
104 | | pub max_requests_per_block: NonZeroU32, |
105 | | |
106 | | /// Number of blocks to download ahead of the best verified block. |
107 | | /// |
108 | | /// Whenever the latest best block is updated, the state machine will start block |
109 | | /// requests for the block `best_block_height + download_ahead_blocks` and all its |
110 | | /// ancestors. Considering that requesting blocks has some latency, downloading blocks ahead |
111 | | /// of time ensures that verification isn't blocked waiting for a request to be finished. |
112 | | /// |
113 | | /// The ideal value here depends on the speed of blocks verification speed and latency of |
114 | | /// block requests. |
115 | | pub download_ahead_blocks: NonZeroU32, |
116 | | |
117 | | /// If true, the body of a block is downloaded (if necessary) before a |
118 | | /// [`ProcessOne::VerifyBlock`] is generated. |
119 | | pub download_bodies: bool, |
120 | | |
121 | | /// If `true`, all the storage proofs and call proofs necessary in order to compute the chain |
122 | | /// information of the warp synced block will be downloaded during the warp syncing process. |
123 | | /// If `false`, the finality information of the warp synced block is inferred from the warp |
124 | | /// sync fragments instead. |
125 | | pub download_all_chain_information_storage_proofs: bool, |
126 | | |
127 | | /// Known valid Merkle value and storage value combination for the `:code` key. |
128 | | /// |
129 | | /// If provided, the warp syncing algorithm will first fetch the Merkle value of `:code`, and |
130 | | /// if it matches the Merkle value provided in the hint, use the storage value in the hint |
131 | | /// instead of downloading it. If the hint doesn't match, an extra round-trip will be needed, |
132 | | /// but if the hint matches it saves a big download. |
133 | | // TODO: provide only in non-full mode? |
134 | | pub code_trie_node_hint: Option<ConfigCodeTrieNodeHint>, |
135 | | } |
136 | | |
137 | | /// Identifier for a source in the [`AllSync`]. |
138 | | // |
139 | | // Implementation note: this is an index in `AllSync::sources`. |
140 | | #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] |
141 | | pub struct SourceId(usize); |
142 | | |
143 | | /// Identifier for a request in the [`AllSync`]. |
144 | | // |
145 | | // Implementation note: this is an index in `AllSync::requests`. |
146 | | #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] |
147 | | pub struct RequestId(usize); |
148 | | |
149 | | /// Status of the synchronization. |
150 | | #[derive(Debug)] |
151 | | pub enum Status<'a, TSrc> { |
152 | | /// Regular syncing mode. |
153 | | Sync, |
154 | | /// Warp syncing algorithm is downloading Grandpa warp sync fragments containing a finality |
155 | | /// proof. |
156 | | WarpSyncFragments { |
157 | | /// Source from which the fragments are currently being downloaded, if any. |
158 | | source: Option<(SourceId, &'a TSrc)>, |
159 | | /// Hash of the highest block that is proven to be finalized. |
160 | | /// |
161 | | /// This isn't necessarily the same block as returned by |
162 | | /// [`AllSync::as_chain_information`], as this function first has to download extra |
163 | | /// information compared to just the finalized block. |
164 | | finalized_block_hash: [u8; 32], |
165 | | /// Height of the block indicated by [`Status::WarpSyncFragments::finalized_block_hash`]. |
166 | | finalized_block_number: u64, |
167 | | }, |
168 | | /// Warp syncing algorithm has reached the head of the finalized chain and is downloading and |
169 | | /// building the chain information. |
170 | | WarpSyncChainInformation { |
171 | | /// Hash of the highest block that is proven to be finalized. |
172 | | /// |
173 | | /// This isn't necessarily the same block as returned by |
174 | | /// [`AllSync::as_chain_information`], as this function first has to download extra |
175 | | /// information compared to just the finalized block. |
176 | | finalized_block_hash: [u8; 32], |
177 | | /// Height of the block indicated by |
178 | | /// [`Status::WarpSyncChainInformation::finalized_block_hash`]. |
179 | | finalized_block_number: u64, |
180 | | }, |
181 | | } |
182 | | |
183 | | pub struct AllSync<TRq, TSrc, TBl> { |
184 | | warp_sync: Option<warp_sync::WarpSync<WarpSyncSourceExtra, WarpSyncRequestExtra>>, |
185 | | ready_to_transition: Option<warp_sync::RuntimeInformation>, |
186 | | // TODO: we store an `Option<TBl>` instead of `TBl` because we need to be able to extract block user datas when a warp sync is finished |
187 | | /// Always `Some`, except for temporary extractions. |
188 | | all_forks: |
189 | | Option<all_forks::AllForksSync<Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>>, |
190 | | shared: Shared<TRq, TSrc>, |
191 | | } |
192 | | |
193 | | impl<TRq, TSrc, TBl> AllSync<TRq, TSrc, TBl> { |
194 | | /// Initializes a new state machine. |
195 | 21 | pub fn new(config: Config) -> Self { |
196 | 21 | AllSync { |
197 | 21 | // TODO: notify API user if can't start warp sync? |
198 | 21 | warp_sync: warp_sync::start_warp_sync(warp_sync::Config { |
199 | 21 | start_chain_information: config.chain_information.clone(), |
200 | 21 | block_number_bytes: config.block_number_bytes, |
201 | 21 | sources_capacity: config.sources_capacity, |
202 | 21 | requests_capacity: config.sources_capacity, // TODO: ?! add as config? |
203 | 21 | download_all_chain_information_storage_proofs: config |
204 | 21 | .download_all_chain_information_storage_proofs, |
205 | 21 | code_trie_node_hint: config.code_trie_node_hint, |
206 | 21 | num_download_ahead_fragments: 128, // TODO: make configurable? |
207 | 21 | // TODO: make configurable? |
208 | 21 | warp_sync_minimum_gap: 32, |
209 | 21 | download_block_body: config.download_bodies, |
210 | 21 | }) |
211 | 21 | .ok(), |
212 | 21 | ready_to_transition: None, |
213 | 21 | all_forks: Some(AllForksSync::new(all_forks::Config { |
214 | 21 | chain_information: config.chain_information, |
215 | 21 | block_number_bytes: config.block_number_bytes, |
216 | 21 | sources_capacity: config.sources_capacity, |
217 | 21 | blocks_capacity: config.blocks_capacity, |
218 | 21 | download_bodies: config.download_bodies, |
219 | 21 | allow_unknown_consensus_engines: config.allow_unknown_consensus_engines, |
220 | 21 | max_disjoint_headers: config.max_disjoint_headers, |
221 | 21 | max_requests_per_block: config.max_requests_per_block, |
222 | 21 | })), |
223 | 21 | shared: Shared { |
224 | 21 | sources: slab::Slab::with_capacity(config.sources_capacity), |
225 | 21 | requests: slab::Slab::with_capacity(config.sources_capacity), |
226 | 21 | download_bodies: config.download_bodies, |
227 | 21 | sources_capacity: config.sources_capacity, |
228 | 21 | blocks_capacity: config.blocks_capacity, |
229 | 21 | max_disjoint_headers: config.max_disjoint_headers, |
230 | 21 | max_requests_per_block: config.max_requests_per_block, |
231 | 21 | block_number_bytes: config.block_number_bytes, |
232 | 21 | allow_unknown_consensus_engines: config.allow_unknown_consensus_engines, |
233 | 21 | }, |
234 | 21 | } |
235 | 21 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE3newB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE3newCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE3newB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE3newCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 195 | 2 | pub fn new(config: Config) -> Self { | 196 | 2 | AllSync { | 197 | 2 | // TODO: notify API user if can't start warp sync? | 198 | 2 | warp_sync: warp_sync::start_warp_sync(warp_sync::Config { | 199 | 2 | start_chain_information: config.chain_information.clone(), | 200 | 2 | block_number_bytes: config.block_number_bytes, | 201 | 2 | sources_capacity: config.sources_capacity, | 202 | 2 | requests_capacity: config.sources_capacity, // TODO: ?! add as config? | 203 | 2 | download_all_chain_information_storage_proofs: config | 204 | 2 | .download_all_chain_information_storage_proofs, | 205 | 2 | code_trie_node_hint: config.code_trie_node_hint, | 206 | 2 | num_download_ahead_fragments: 128, // TODO: make configurable? | 207 | 2 | // TODO: make configurable? | 208 | 2 | warp_sync_minimum_gap: 32, | 209 | 2 | download_block_body: config.download_bodies, | 210 | 2 | }) | 211 | 2 | .ok(), | 212 | 2 | ready_to_transition: None, | 213 | 2 | all_forks: Some(AllForksSync::new(all_forks::Config { | 214 | 2 | chain_information: config.chain_information, | 215 | 2 | block_number_bytes: config.block_number_bytes, | 216 | 2 | sources_capacity: config.sources_capacity, | 217 | 2 | blocks_capacity: config.blocks_capacity, | 218 | 2 | download_bodies: config.download_bodies, | 219 | 2 | allow_unknown_consensus_engines: config.allow_unknown_consensus_engines, | 220 | 2 | max_disjoint_headers: config.max_disjoint_headers, | 221 | 2 | max_requests_per_block: config.max_requests_per_block, | 222 | 2 | })), | 223 | 2 | shared: Shared { | 224 | 2 | sources: slab::Slab::with_capacity(config.sources_capacity), | 225 | 2 | requests: slab::Slab::with_capacity(config.sources_capacity), | 226 | 2 | download_bodies: config.download_bodies, | 227 | 2 | sources_capacity: config.sources_capacity, | 228 | 2 | blocks_capacity: config.blocks_capacity, | 229 | 2 | max_disjoint_headers: config.max_disjoint_headers, | 230 | 2 | max_requests_per_block: config.max_requests_per_block, | 231 | 2 | block_number_bytes: config.block_number_bytes, | 232 | 2 | allow_unknown_consensus_engines: config.allow_unknown_consensus_engines, | 233 | 2 | }, | 234 | 2 | } | 235 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE3newCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE3newCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 195 | 19 | pub fn new(config: Config) -> Self { | 196 | 19 | AllSync { | 197 | 19 | // TODO: notify API user if can't start warp sync? | 198 | 19 | warp_sync: warp_sync::start_warp_sync(warp_sync::Config { | 199 | 19 | start_chain_information: config.chain_information.clone(), | 200 | 19 | block_number_bytes: config.block_number_bytes, | 201 | 19 | sources_capacity: config.sources_capacity, | 202 | 19 | requests_capacity: config.sources_capacity, // TODO: ?! add as config? | 203 | 19 | download_all_chain_information_storage_proofs: config | 204 | 19 | .download_all_chain_information_storage_proofs, | 205 | 19 | code_trie_node_hint: config.code_trie_node_hint, | 206 | 19 | num_download_ahead_fragments: 128, // TODO: make configurable? | 207 | 19 | // TODO: make configurable? | 208 | 19 | warp_sync_minimum_gap: 32, | 209 | 19 | download_block_body: config.download_bodies, | 210 | 19 | }) | 211 | 19 | .ok(), | 212 | 19 | ready_to_transition: None, | 213 | 19 | all_forks: Some(AllForksSync::new(all_forks::Config { | 214 | 19 | chain_information: config.chain_information, | 215 | 19 | block_number_bytes: config.block_number_bytes, | 216 | 19 | sources_capacity: config.sources_capacity, | 217 | 19 | blocks_capacity: config.blocks_capacity, | 218 | 19 | download_bodies: config.download_bodies, | 219 | 19 | allow_unknown_consensus_engines: config.allow_unknown_consensus_engines, | 220 | 19 | max_disjoint_headers: config.max_disjoint_headers, | 221 | 19 | max_requests_per_block: config.max_requests_per_block, | 222 | 19 | })), | 223 | 19 | shared: Shared { | 224 | 19 | sources: slab::Slab::with_capacity(config.sources_capacity), | 225 | 19 | requests: slab::Slab::with_capacity(config.sources_capacity), | 226 | 19 | download_bodies: config.download_bodies, | 227 | 19 | sources_capacity: config.sources_capacity, | 228 | 19 | blocks_capacity: config.blocks_capacity, | 229 | 19 | max_disjoint_headers: config.max_disjoint_headers, | 230 | 19 | max_requests_per_block: config.max_requests_per_block, | 231 | 19 | block_number_bytes: config.block_number_bytes, | 232 | 19 | allow_unknown_consensus_engines: config.allow_unknown_consensus_engines, | 233 | 19 | }, | 234 | 19 | } | 235 | 19 | } |
|
236 | | |
237 | | /// Returns the value that was initially passed in [`Config::block_number_bytes`]. |
238 | 21 | pub fn block_number_bytes(&self) -> usize { |
239 | 21 | self.shared.block_number_bytes |
240 | 21 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE18block_number_bytesB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE18block_number_bytesCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE18block_number_bytesB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE18block_number_bytesCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 238 | 2 | pub fn block_number_bytes(&self) -> usize { | 239 | 2 | self.shared.block_number_bytes | 240 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE18block_number_bytesCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE18block_number_bytesCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 238 | 19 | pub fn block_number_bytes(&self) -> usize { | 239 | 19 | self.shared.block_number_bytes | 240 | 19 | } |
|
241 | | |
242 | | /// Builds a [`chain_information::ChainInformationRef`] struct corresponding to the current |
243 | | /// latest finalized block. Can later be used to reconstruct a chain. |
244 | 0 | pub fn as_chain_information(&self) -> chain_information::ValidChainInformationRef { |
245 | 0 | let Some(all_forks) = &self.all_forks else { |
246 | 0 | unreachable!() |
247 | | }; |
248 | | |
249 | 0 | all_forks.as_chain_information() |
250 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE20as_chain_informationB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE20as_chain_informationCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE20as_chain_informationB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20as_chain_informationCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20as_chain_informationCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20as_chain_informationCsibGXYHQB8Ea_25json_rpc_general_requests |
251 | | |
252 | | /// Returns the current status of the syncing. |
253 | 1 | pub fn status(&self) -> Status<TSrc> { |
254 | 1 | // TODO: |
255 | 1 | Status::Sync |
256 | 1 | /*match &self.inner { |
257 | 1 | AllSyncInner::AllForks(_) => Status::Sync, |
258 | 1 | AllSyncInner::WarpSync { inner, .. } => match inner.status() { |
259 | 1 | warp_sync::Status::Fragments { |
260 | 1 | source: None, |
261 | 1 | finalized_block_hash, |
262 | 1 | finalized_block_number, |
263 | 1 | } => Status::WarpSyncFragments { |
264 | 1 | source: None, |
265 | 1 | finalized_block_hash, |
266 | 1 | finalized_block_number, |
267 | 1 | }, |
268 | 1 | warp_sync::Status::Fragments { |
269 | 1 | source: Some((_, user_data)), |
270 | 1 | finalized_block_hash, |
271 | 1 | finalized_block_number, |
272 | 1 | } => Status::WarpSyncFragments { |
273 | 1 | source: Some((user_data.outer_source_id, &user_data.user_data)), |
274 | 1 | finalized_block_hash, |
275 | 1 | finalized_block_number, |
276 | 1 | }, |
277 | 1 | warp_sync::Status::ChainInformation { |
278 | 1 | finalized_block_hash, |
279 | 1 | finalized_block_number, |
280 | 1 | } => Status::WarpSyncChainInformation { |
281 | 1 | finalized_block_hash, |
282 | 1 | finalized_block_number, |
283 | 1 | }, |
284 | 1 | }, |
285 | 1 | AllSyncInner::Poisoned => unreachable!(), |
286 | 1 | }*/ |
287 | 1 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE6statusB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE6statusCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE6statusB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE6statusCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE6statusCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE6statusCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 253 | 1 | pub fn status(&self) -> Status<TSrc> { | 254 | 1 | // TODO: | 255 | 1 | Status::Sync | 256 | 1 | /*match &self.inner { | 257 | 1 | AllSyncInner::AllForks(_) => Status::Sync, | 258 | 1 | AllSyncInner::WarpSync { inner, .. } => match inner.status() { | 259 | 1 | warp_sync::Status::Fragments { | 260 | 1 | source: None, | 261 | 1 | finalized_block_hash, | 262 | 1 | finalized_block_number, | 263 | 1 | } => Status::WarpSyncFragments { | 264 | 1 | source: None, | 265 | 1 | finalized_block_hash, | 266 | 1 | finalized_block_number, | 267 | 1 | }, | 268 | 1 | warp_sync::Status::Fragments { | 269 | 1 | source: Some((_, user_data)), | 270 | 1 | finalized_block_hash, | 271 | 1 | finalized_block_number, | 272 | 1 | } => Status::WarpSyncFragments { | 273 | 1 | source: Some((user_data.outer_source_id, &user_data.user_data)), | 274 | 1 | finalized_block_hash, | 275 | 1 | finalized_block_number, | 276 | 1 | }, | 277 | 1 | warp_sync::Status::ChainInformation { | 278 | 1 | finalized_block_hash, | 279 | 1 | finalized_block_number, | 280 | 1 | } => Status::WarpSyncChainInformation { | 281 | 1 | finalized_block_hash, | 282 | 1 | finalized_block_number, | 283 | 1 | }, | 284 | 1 | }, | 285 | 1 | AllSyncInner::Poisoned => unreachable!(), | 286 | 1 | }*/ | 287 | 1 | } |
|
288 | | |
289 | | /// Returns the header of the finalized block. |
290 | 0 | pub fn finalized_block_header(&self) -> &[u8] { |
291 | 0 | let Some(all_forks) = &self.all_forks else { |
292 | 0 | unreachable!() |
293 | | }; |
294 | | |
295 | 0 | all_forks.finalized_block_header() |
296 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE22finalized_block_headerB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE22finalized_block_headerCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE22finalized_block_headerB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE22finalized_block_headerCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE22finalized_block_headerCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE22finalized_block_headerCsibGXYHQB8Ea_25json_rpc_general_requests |
297 | | |
298 | | /// Returns the height of the finalized block. |
299 | 0 | pub fn finalized_block_number(&self) -> u64 { |
300 | 0 | let Some(all_forks) = &self.all_forks else { |
301 | 0 | unreachable!() |
302 | | }; |
303 | | |
304 | 0 | all_forks.finalized_block_number() |
305 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE22finalized_block_numberB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE22finalized_block_numberCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE22finalized_block_numberB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE22finalized_block_numberCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE22finalized_block_numberCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE22finalized_block_numberCsibGXYHQB8Ea_25json_rpc_general_requests |
306 | | |
307 | | /// Returns the hash of the finalized block. |
308 | 0 | pub fn finalized_block_hash(&self) -> &[u8; 32] { |
309 | 0 | let Some(all_forks) = &self.all_forks else { |
310 | 0 | unreachable!() |
311 | | }; |
312 | | |
313 | 0 | all_forks.finalized_block_hash() |
314 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE20finalized_block_hashB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE20finalized_block_hashCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE20finalized_block_hashB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20finalized_block_hashCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20finalized_block_hashCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20finalized_block_hashCsibGXYHQB8Ea_25json_rpc_general_requests |
315 | | |
316 | | /// Returns the header of the best block. |
317 | | /// |
318 | | /// > **Note**: This value is provided only for informative purposes. Keep in mind that this |
319 | | /// > best block might be reverted in the future. |
320 | 0 | pub fn best_block_header(&self) -> &[u8] { |
321 | 0 | let Some(all_forks) = &self.all_forks else { |
322 | 0 | unreachable!() |
323 | | }; |
324 | | |
325 | 0 | all_forks.best_block_header() |
326 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE17best_block_headerB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE17best_block_headerB6_ |
327 | | |
328 | | /// Returns the number of the best block. |
329 | | /// |
330 | | /// > **Note**: This value is provided only for informative purposes. Keep in mind that this |
331 | | /// > best block might be reverted in the future. |
332 | 21 | pub fn best_block_number(&self) -> u64 { |
333 | 21 | let Some(all_forks) = &self.all_forks else { |
334 | 0 | unreachable!() |
335 | | }; |
336 | | |
337 | 21 | all_forks.best_block_number() |
338 | 21 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE17best_block_numberB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE17best_block_numberCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE17best_block_numberB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE17best_block_numberCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 332 | 2 | pub fn best_block_number(&self) -> u64 { | 333 | 2 | let Some(all_forks) = &self.all_forks else { | 334 | 0 | unreachable!() | 335 | | }; | 336 | | | 337 | 2 | all_forks.best_block_number() | 338 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE17best_block_numberCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE17best_block_numberCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 332 | 19 | pub fn best_block_number(&self) -> u64 { | 333 | 19 | let Some(all_forks) = &self.all_forks else { | 334 | 0 | unreachable!() | 335 | | }; | 336 | | | 337 | 19 | all_forks.best_block_number() | 338 | 19 | } |
|
339 | | |
340 | | /// Returns the hash of the best block. |
341 | | /// |
342 | | /// > **Note**: This value is provided only for informative purposes. Keep in mind that this |
343 | | /// > best block might be reverted in the future. |
344 | 21 | pub fn best_block_hash(&self) -> &[u8; 32] { |
345 | 21 | let Some(all_forks) = &self.all_forks else { |
346 | 0 | unreachable!() |
347 | | }; |
348 | | |
349 | 21 | all_forks.best_block_hash() |
350 | 21 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE15best_block_hashB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE15best_block_hashCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE15best_block_hashB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE15best_block_hashCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 344 | 2 | pub fn best_block_hash(&self) -> &[u8; 32] { | 345 | 2 | let Some(all_forks) = &self.all_forks else { | 346 | 0 | unreachable!() | 347 | | }; | 348 | | | 349 | 2 | all_forks.best_block_hash() | 350 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE15best_block_hashCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE15best_block_hashCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 344 | 19 | pub fn best_block_hash(&self) -> &[u8; 32] { | 345 | 19 | let Some(all_forks) = &self.all_forks else { | 346 | 0 | unreachable!() | 347 | | }; | 348 | | | 349 | 19 | all_forks.best_block_hash() | 350 | 19 | } |
|
351 | | |
352 | | /// Returns consensus information about the current best block of the chain. |
353 | 0 | pub fn best_block_consensus(&self) -> chain_information::ChainInformationConsensusRef { |
354 | 0 | todo!() // TODO: Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE20best_block_consensusB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE20best_block_consensusB6_ |
355 | | } |
356 | | |
357 | | /// Returns the header of all known non-finalized blocks in the chain without any specific |
358 | | /// order. |
359 | 0 | pub fn non_finalized_blocks_unordered(&self) -> impl Iterator<Item = header::HeaderRef> { |
360 | 0 | let Some(all_forks) = &self.all_forks else { |
361 | 0 | unreachable!() |
362 | | }; |
363 | | |
364 | 0 | all_forks.non_finalized_blocks_unordered() |
365 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE30non_finalized_blocks_unorderedB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE30non_finalized_blocks_unorderedCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE30non_finalized_blocks_unorderedB6_ |
366 | | |
367 | | /// Returns the header of all known non-finalized blocks in the chain. |
368 | | /// |
369 | | /// The returned items are guaranteed to be in an order in which the parents are found before |
370 | | /// their children. |
371 | 0 | pub fn non_finalized_blocks_ancestry_order(&self) -> impl Iterator<Item = header::HeaderRef> { |
372 | 0 | let Some(all_forks) = &self.all_forks else { |
373 | 0 | unreachable!() |
374 | | }; |
375 | | |
376 | 0 | all_forks.non_finalized_blocks_ancestry_order() |
377 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE35non_finalized_blocks_ancestry_orderB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE35non_finalized_blocks_ancestry_orderCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE35non_finalized_blocks_ancestry_orderB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE35non_finalized_blocks_ancestry_orderCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE35non_finalized_blocks_ancestry_orderCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE35non_finalized_blocks_ancestry_orderCsibGXYHQB8Ea_25json_rpc_general_requests |
378 | | |
379 | | /// Returns true if it is believed that we are near the head of the chain. |
380 | | /// |
381 | | /// The way this method is implemented is opaque and cannot be relied on. The return value |
382 | | /// should only ever be shown to the user and not used for any meaningful logic. |
383 | | // TODO: remove this function as it's too imprecise |
384 | 0 | pub fn is_near_head_of_chain_heuristic(&self) -> bool { |
385 | 0 | let Some(all_forks) = &self.all_forks else { |
386 | 0 | unreachable!() |
387 | | }; |
388 | | |
389 | 0 | let local_best_block = all_forks.best_block_number(); |
390 | 0 |
|
391 | 0 | // We return `false` if any source is more than 5 blocks ahead, and `true` otherwise. |
392 | 0 | !self.shared.sources.iter().any(|(_, src)| { |
393 | 0 | all_forks.source_best_block(src.all_forks).0 > local_best_block.saturating_add(5) |
394 | 0 | }) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE31is_near_head_of_chain_heuristic0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE31is_near_head_of_chain_heuristic0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE31is_near_head_of_chain_heuristic0B8_ |
395 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE31is_near_head_of_chain_heuristicB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE31is_near_head_of_chain_heuristicCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE31is_near_head_of_chain_heuristicB6_ |
396 | | |
397 | | /// Start the process of adding a new source to the sync state machine. |
398 | | /// |
399 | | /// Must be passed the best block number and hash of the source, as usually reported by the |
400 | | /// source itself. |
401 | | /// |
402 | | /// This function call doesn't modify anything but returns an object that allows actually |
403 | | /// inserting the source. |
404 | 21 | pub fn prepare_add_source( |
405 | 21 | &mut self, |
406 | 21 | best_block_number: u64, |
407 | 21 | best_block_hash: [u8; 32], |
408 | 21 | ) -> AddSource<TRq, TSrc, TBl> { |
409 | 21 | match self |
410 | 21 | .all_forks |
411 | 21 | .as_mut() |
412 | 21 | .unwrap_or_else(|| unreachable!()0 ) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE18prepare_add_source0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE18prepare_add_source0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE18prepare_add_source0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE18prepare_add_source0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE18prepare_add_source0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE18prepare_add_source0CsibGXYHQB8Ea_25json_rpc_general_requests |
413 | 21 | .prepare_add_source(best_block_number, best_block_hash) |
414 | | { |
415 | 0 | all_forks::AddSource::BestBlockAlreadyVerified(all_forks) => { |
416 | 0 | AddSource::BestBlockAlreadyVerified(AddSourceKnown { |
417 | 0 | all_forks, |
418 | 0 | slab_insertion: self.shared.sources.vacant_entry(), |
419 | 0 | warp_sync: &mut self.warp_sync, |
420 | 0 | marker: PhantomData, |
421 | 0 | }) |
422 | | } |
423 | 0 | all_forks::AddSource::BestBlockPendingVerification(all_forks) => { |
424 | 0 | AddSource::BestBlockPendingVerification(AddSourceKnown { |
425 | 0 | all_forks, |
426 | 0 | slab_insertion: self.shared.sources.vacant_entry(), |
427 | 0 | warp_sync: &mut self.warp_sync, |
428 | 0 | marker: PhantomData, |
429 | 0 | }) |
430 | | } |
431 | 21 | all_forks::AddSource::OldBestBlock(all_forks) => { |
432 | 21 | AddSource::OldBestBlock(AddSourceOldBlock { |
433 | 21 | all_forks, |
434 | 21 | slab_insertion: self.shared.sources.vacant_entry(), |
435 | 21 | warp_sync: &mut self.warp_sync, |
436 | 21 | marker: PhantomData, |
437 | 21 | }) |
438 | | } |
439 | 0 | all_forks::AddSource::UnknownBestBlock(all_forks) => { |
440 | 0 | AddSource::UnknownBestBlock(AddSourceUnknown { |
441 | 0 | all_forks, |
442 | 0 | slab_insertion: self.shared.sources.vacant_entry(), |
443 | 0 | warp_sync: &mut self.warp_sync, |
444 | 0 | marker: PhantomData, |
445 | 0 | }) |
446 | | } |
447 | | } |
448 | 21 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE18prepare_add_sourceB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE18prepare_add_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE18prepare_add_sourceB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE18prepare_add_sourceCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 404 | 2 | pub fn prepare_add_source( | 405 | 2 | &mut self, | 406 | 2 | best_block_number: u64, | 407 | 2 | best_block_hash: [u8; 32], | 408 | 2 | ) -> AddSource<TRq, TSrc, TBl> { | 409 | 2 | match self | 410 | 2 | .all_forks | 411 | 2 | .as_mut() | 412 | 2 | .unwrap_or_else(|| unreachable!()) | 413 | 2 | .prepare_add_source(best_block_number, best_block_hash) | 414 | | { | 415 | 0 | all_forks::AddSource::BestBlockAlreadyVerified(all_forks) => { | 416 | 0 | AddSource::BestBlockAlreadyVerified(AddSourceKnown { | 417 | 0 | all_forks, | 418 | 0 | slab_insertion: self.shared.sources.vacant_entry(), | 419 | 0 | warp_sync: &mut self.warp_sync, | 420 | 0 | marker: PhantomData, | 421 | 0 | }) | 422 | | } | 423 | 0 | all_forks::AddSource::BestBlockPendingVerification(all_forks) => { | 424 | 0 | AddSource::BestBlockPendingVerification(AddSourceKnown { | 425 | 0 | all_forks, | 426 | 0 | slab_insertion: self.shared.sources.vacant_entry(), | 427 | 0 | warp_sync: &mut self.warp_sync, | 428 | 0 | marker: PhantomData, | 429 | 0 | }) | 430 | | } | 431 | 2 | all_forks::AddSource::OldBestBlock(all_forks) => { | 432 | 2 | AddSource::OldBestBlock(AddSourceOldBlock { | 433 | 2 | all_forks, | 434 | 2 | slab_insertion: self.shared.sources.vacant_entry(), | 435 | 2 | warp_sync: &mut self.warp_sync, | 436 | 2 | marker: PhantomData, | 437 | 2 | }) | 438 | | } | 439 | 0 | all_forks::AddSource::UnknownBestBlock(all_forks) => { | 440 | 0 | AddSource::UnknownBestBlock(AddSourceUnknown { | 441 | 0 | all_forks, | 442 | 0 | slab_insertion: self.shared.sources.vacant_entry(), | 443 | 0 | warp_sync: &mut self.warp_sync, | 444 | 0 | marker: PhantomData, | 445 | 0 | }) | 446 | | } | 447 | | } | 448 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE18prepare_add_sourceCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE18prepare_add_sourceCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 404 | 19 | pub fn prepare_add_source( | 405 | 19 | &mut self, | 406 | 19 | best_block_number: u64, | 407 | 19 | best_block_hash: [u8; 32], | 408 | 19 | ) -> AddSource<TRq, TSrc, TBl> { | 409 | 19 | match self | 410 | 19 | .all_forks | 411 | 19 | .as_mut() | 412 | 19 | .unwrap_or_else(|| unreachable!()) | 413 | 19 | .prepare_add_source(best_block_number, best_block_hash) | 414 | | { | 415 | 0 | all_forks::AddSource::BestBlockAlreadyVerified(all_forks) => { | 416 | 0 | AddSource::BestBlockAlreadyVerified(AddSourceKnown { | 417 | 0 | all_forks, | 418 | 0 | slab_insertion: self.shared.sources.vacant_entry(), | 419 | 0 | warp_sync: &mut self.warp_sync, | 420 | 0 | marker: PhantomData, | 421 | 0 | }) | 422 | | } | 423 | 0 | all_forks::AddSource::BestBlockPendingVerification(all_forks) => { | 424 | 0 | AddSource::BestBlockPendingVerification(AddSourceKnown { | 425 | 0 | all_forks, | 426 | 0 | slab_insertion: self.shared.sources.vacant_entry(), | 427 | 0 | warp_sync: &mut self.warp_sync, | 428 | 0 | marker: PhantomData, | 429 | 0 | }) | 430 | | } | 431 | 19 | all_forks::AddSource::OldBestBlock(all_forks) => { | 432 | 19 | AddSource::OldBestBlock(AddSourceOldBlock { | 433 | 19 | all_forks, | 434 | 19 | slab_insertion: self.shared.sources.vacant_entry(), | 435 | 19 | warp_sync: &mut self.warp_sync, | 436 | 19 | marker: PhantomData, | 437 | 19 | }) | 438 | | } | 439 | 0 | all_forks::AddSource::UnknownBestBlock(all_forks) => { | 440 | 0 | AddSource::UnknownBestBlock(AddSourceUnknown { | 441 | 0 | all_forks, | 442 | 0 | slab_insertion: self.shared.sources.vacant_entry(), | 443 | 0 | warp_sync: &mut self.warp_sync, | 444 | 0 | marker: PhantomData, | 445 | 0 | }) | 446 | | } | 447 | | } | 448 | 19 | } |
|
449 | | |
450 | | /// Removes a source from the state machine. Returns the user data of this source, and all |
451 | | /// the requests that this source was expected to perform. |
452 | | /// |
453 | | /// # Panic |
454 | | /// |
455 | | /// Panics if the [`SourceId`] doesn't correspond to a valid source. |
456 | | /// |
457 | 0 | pub fn remove_source( |
458 | 0 | &mut self, |
459 | 0 | source_id: SourceId, |
460 | 0 | ) -> (TSrc, impl Iterator<Item = (RequestId, TRq)>) { |
461 | 0 | let source_info = self.shared.sources.remove(source_id.0); |
462 | | |
463 | 0 | let Some(all_forks) = &mut self.all_forks else { |
464 | 0 | unreachable!() |
465 | | }; |
466 | | |
467 | 0 | let _ = all_forks.remove_source(source_info.all_forks); |
468 | 0 | if let Some(warp_sync) = &mut self.warp_sync { |
469 | 0 | let _ = warp_sync.remove_source(source_info.warp_sync.unwrap()); |
470 | 0 | } |
471 | | |
472 | | // TODO: optimize |
473 | 0 | let request_ids = self |
474 | 0 | .shared |
475 | 0 | .requests |
476 | 0 | .iter() |
477 | 0 | .filter(|(_, rq)| rq.source_id == source_id) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE13remove_source0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE13remove_source0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE13remove_source0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE13remove_source0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE13remove_source0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE13remove_source0CsibGXYHQB8Ea_25json_rpc_general_requests |
478 | 0 | .map(|(id, _)| id) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE13remove_sources_0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE13remove_sources_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE13remove_sources_0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE13remove_sources_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE13remove_sources_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE13remove_sources_0CsibGXYHQB8Ea_25json_rpc_general_requests |
479 | 0 | .collect::<Vec<_>>(); |
480 | 0 |
|
481 | 0 | let mut requests = Vec::with_capacity(request_ids.len()); |
482 | 0 | for request_id in request_ids.into_iter().rev() { |
483 | 0 | let rq = self.shared.requests.remove(request_id); |
484 | 0 | requests.push((RequestId(request_id), rq.user_data)); |
485 | 0 | } |
486 | | |
487 | 0 | (source_info.user_data, requests.into_iter()) |
488 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE13remove_sourceB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE13remove_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE13remove_sourceB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE13remove_sourceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE13remove_sourceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE13remove_sourceCsibGXYHQB8Ea_25json_rpc_general_requests |
489 | | |
490 | | /// Returns the list of sources in this state machine. |
491 | 0 | pub fn sources(&'_ self) -> impl Iterator<Item = SourceId> + '_ { |
492 | 0 | let Some(all_forks) = &self.all_forks else { |
493 | 0 | unreachable!() |
494 | | }; |
495 | | |
496 | 0 | all_forks |
497 | 0 | .sources() |
498 | 0 | .map(move |id| all_forks[id].outer_source_id) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE7sources0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE7sources0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE7sources0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE7sources0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE7sources0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE7sources0CsibGXYHQB8Ea_25json_rpc_general_requests |
499 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE7sourcesB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE7sourcesCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE7sourcesB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE7sourcesCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE7sourcesCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE7sourcesCsibGXYHQB8Ea_25json_rpc_general_requests |
500 | | |
501 | | /// Returns the number of ongoing requests that concern this source. |
502 | | /// |
503 | | /// # Panic |
504 | | /// |
505 | | /// Panics if the [`SourceId`] is invalid. |
506 | | /// |
507 | 0 | pub fn source_num_ongoing_requests(&self, source_id: SourceId) -> usize { |
508 | | let Some(&SourceMapping { |
509 | 0 | num_requests: num_request, |
510 | | .. |
511 | 0 | }) = self.shared.sources.get(source_id.0) |
512 | | else { |
513 | 0 | panic!() |
514 | | }; |
515 | | |
516 | 0 | num_request |
517 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE27source_num_ongoing_requestsB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE27source_num_ongoing_requestsCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE27source_num_ongoing_requestsB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE27source_num_ongoing_requestsCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE27source_num_ongoing_requestsCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE27source_num_ongoing_requestsCsibGXYHQB8Ea_25json_rpc_general_requests |
518 | | |
519 | | /// Returns the current best block of the given source. |
520 | | /// |
521 | | /// This corresponds either the latest call to [`AllSync::block_announce`] where `is_best` was |
522 | | /// `true`, or to the parameter passed to [`AllSync::prepare_add_source`]. |
523 | | /// |
524 | | /// # Panic |
525 | | /// |
526 | | /// Panics if the [`SourceId`] is invalid. |
527 | | /// |
528 | 0 | pub fn source_best_block(&self, source_id: SourceId) -> (u64, &[u8; 32]) { |
529 | | let Some(&SourceMapping { |
530 | 0 | all_forks: inner_source_id, |
531 | | .. |
532 | 0 | }) = self.shared.sources.get(source_id.0) |
533 | | else { |
534 | 0 | panic!() |
535 | | }; |
536 | | |
537 | 0 | let Some(all_forks) = &self.all_forks else { |
538 | 0 | unreachable!() |
539 | | }; |
540 | | |
541 | 0 | all_forks.source_best_block(inner_source_id) |
542 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE17source_best_blockB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE17source_best_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE17source_best_blockB6_ |
543 | | |
544 | | /// Returns true if the source has earlier announced the block passed as parameter or one of |
545 | | /// its descendants. |
546 | | /// |
547 | | /// # Panic |
548 | | /// |
549 | | /// Panics if the [`SourceId`] is out of range. |
550 | | /// |
551 | | /// Panics if `height` is inferior or equal to the finalized block height. Finalized blocks |
552 | | /// are intentionally not tracked by this data structure, and panicking when asking for a |
553 | | /// potentially-finalized block prevents potentially confusing or erroneous situations. |
554 | | /// |
555 | 0 | pub fn source_knows_non_finalized_block( |
556 | 0 | &self, |
557 | 0 | source_id: SourceId, |
558 | 0 | height: u64, |
559 | 0 | hash: &[u8; 32], |
560 | 0 | ) -> bool { |
561 | | let Some(&SourceMapping { |
562 | 0 | all_forks: inner_source_id, |
563 | | .. |
564 | 0 | }) = self.shared.sources.get(source_id.0) |
565 | | else { |
566 | 0 | panic!() |
567 | | }; |
568 | | |
569 | 0 | let Some(all_forks) = &self.all_forks else { |
570 | 0 | unreachable!() |
571 | | }; |
572 | | |
573 | 0 | all_forks.source_knows_non_finalized_block(inner_source_id, height, hash) |
574 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE32source_knows_non_finalized_blockB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE32source_knows_non_finalized_blockB6_ |
575 | | |
576 | | /// Returns the list of sources for which [`AllSync::source_knows_non_finalized_block`] would |
577 | | /// return `true`. |
578 | | /// |
579 | | /// # Panic |
580 | | /// |
581 | | /// Panics if `height` is inferior or equal to the finalized block height. Finalized blocks |
582 | | /// are intentionally not tracked by this data structure, and panicking when asking for a |
583 | | /// potentially-finalized block prevents potentially confusing or erroneous situations. |
584 | | /// |
585 | 0 | pub fn knows_non_finalized_block( |
586 | 0 | &'_ self, |
587 | 0 | height: u64, |
588 | 0 | hash: &[u8; 32], |
589 | 0 | ) -> impl Iterator<Item = SourceId> + '_ { |
590 | 0 | let Some(all_forks) = &self.all_forks else { |
591 | 0 | unreachable!() |
592 | | }; |
593 | | |
594 | 0 | all_forks |
595 | 0 | .knows_non_finalized_block(height, hash) |
596 | 0 | .map(move |id| all_forks[id].outer_source_id) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE25knows_non_finalized_block0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE25knows_non_finalized_block0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE25knows_non_finalized_block0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE25knows_non_finalized_block0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE25knows_non_finalized_block0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE25knows_non_finalized_block0CsibGXYHQB8Ea_25json_rpc_general_requests |
597 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE25knows_non_finalized_blockB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE25knows_non_finalized_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE25knows_non_finalized_blockB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE25knows_non_finalized_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE25knows_non_finalized_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE25knows_non_finalized_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
598 | | |
599 | | /// Try register a new block that the source is aware of. |
600 | | /// |
601 | | /// Has no effect if `height` is inferior or equal to the finalized block height, or if the |
602 | | /// source was already known to know this block. |
603 | | /// |
604 | | /// The block does not need to be known by the data structure. |
605 | | /// |
606 | | /// This is automatically done for the blocks added through block announces or block requests.. |
607 | | /// |
608 | | /// # Panic |
609 | | /// |
610 | | /// Panics if the [`SourceId`] is out of range. |
611 | | /// |
612 | 0 | pub fn try_add_known_block_to_source( |
613 | 0 | &mut self, |
614 | 0 | source_id: SourceId, |
615 | 0 | height: u64, |
616 | 0 | hash: [u8; 32], |
617 | 0 | ) { |
618 | | let Some(&SourceMapping { |
619 | 0 | all_forks: inner_source_id, |
620 | | .. |
621 | 0 | }) = self.shared.sources.get(source_id.0) |
622 | | else { |
623 | 0 | panic!() |
624 | | }; |
625 | | |
626 | 0 | let Some(all_forks) = &mut self.all_forks else { |
627 | 0 | unreachable!() |
628 | | }; |
629 | | |
630 | 0 | all_forks.add_known_block_to_source(inner_source_id, height, hash); |
631 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE29try_add_known_block_to_sourceB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE29try_add_known_block_to_sourceB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE29try_add_known_block_to_sourceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE29try_add_known_block_to_sourceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE29try_add_known_block_to_sourceCsibGXYHQB8Ea_25json_rpc_general_requests |
632 | | |
633 | | /// Returns the details of a request to start towards a source. |
634 | | /// |
635 | | /// This method doesn't modify the state machine in any way. [`AllSync::add_request`] must be |
636 | | /// called in order for the request to actually be marked as started. |
637 | 43 | pub fn desired_requests( |
638 | 43 | &'_ self, |
639 | 43 | ) -> impl Iterator<Item = (SourceId, &'_ TSrc, DesiredRequest)> + '_ { |
640 | 43 | let Some(all_forks) = &self.all_forks else { |
641 | 0 | unreachable!() |
642 | | }; |
643 | | |
644 | 43 | let all_forks_requests = |
645 | 43 | all_forks |
646 | 43 | .desired_requests() |
647 | 43 | .map(move |(inner_source_id, _, rq_params)| { |
648 | 0 | ( |
649 | 0 | all_forks[inner_source_id].outer_source_id, |
650 | 0 | &self.shared.sources[all_forks[inner_source_id].outer_source_id.0] |
651 | 0 | .user_data, |
652 | 0 | all_forks_request_convert(rq_params, self.shared.download_bodies), |
653 | 0 | ) |
654 | 43 | }); Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE16desired_requests0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE16desired_requests0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE16desired_requests0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE16desired_requests0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE16desired_requests0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE16desired_requests0CsibGXYHQB8Ea_25json_rpc_general_requests |
655 | | |
656 | 43 | let warp_sync_requests = |
657 | 43 | if let Some(warp_sync) = &self.warp_sync { |
658 | 43 | either::Left(warp_sync.desired_requests().map( |
659 | 43 | move |(_, src_user_data, rq_detail)| {0 |
660 | 0 | let detail = match rq_detail { |
661 | 0 | warp_sync::DesiredRequest::WarpSyncRequest { block_hash } => { |
662 | 0 | DesiredRequest::WarpSync { |
663 | 0 | sync_start_block_hash: block_hash, |
664 | 0 | } |
665 | | } |
666 | | warp_sync::DesiredRequest::BlockBodyDownload { |
667 | 0 | block_hash, |
668 | 0 | block_number, |
669 | 0 | .. |
670 | 0 | } => DesiredRequest::BlocksRequest { |
671 | 0 | first_block_height: block_number, |
672 | 0 | first_block_hash: block_hash, |
673 | 0 | num_blocks: NonZeroU64::new(1).unwrap(), |
674 | 0 | request_headers: false, |
675 | 0 | request_bodies: true, |
676 | 0 | request_justification: false, |
677 | 0 | }, |
678 | | warp_sync::DesiredRequest::StorageGetMerkleProof { |
679 | 0 | block_hash, |
680 | 0 | state_trie_root, |
681 | 0 | keys, |
682 | 0 | } => DesiredRequest::StorageGetMerkleProof { |
683 | 0 | block_hash, |
684 | 0 | state_trie_root, |
685 | 0 | keys, |
686 | 0 | }, |
687 | | warp_sync::DesiredRequest::RuntimeCallMerkleProof { |
688 | 0 | block_hash, |
689 | 0 | function_name, |
690 | 0 | parameter_vectored, |
691 | 0 | } => DesiredRequest::RuntimeCallMerkleProof { |
692 | 0 | block_hash, |
693 | 0 | function_name, |
694 | 0 | parameter_vectored, |
695 | 0 | }, |
696 | | }; |
697 | | |
698 | 0 | ( |
699 | 0 | src_user_data.outer_source_id, |
700 | 0 | &self.shared.sources[src_user_data.outer_source_id.0].user_data, |
701 | 0 | detail, |
702 | 0 | ) |
703 | 43 | }, Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE16desired_requestss_0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE16desired_requestss_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE16desired_requestss_0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE16desired_requestss_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE16desired_requestss_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE16desired_requestss_0CsibGXYHQB8Ea_25json_rpc_general_requests |
704 | 43 | )) |
705 | | } else { |
706 | 0 | either::Right(iter::empty()) |
707 | | }; |
708 | | |
709 | | // We always prioritize warp sync requests over all fork requests. |
710 | | // The warp sync algorithm will only ever try to emit requests concerning sources that are |
711 | | // (or pretend to be) far ahead of the local node. Given a source that is (or pretends to |
712 | | // be) far ahead of the local node, it is more desirable to try to warp sync from it |
713 | | // rather than download blocks that are close. |
714 | 43 | warp_sync_requests.chain(all_forks_requests) |
715 | 43 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE16desired_requestsB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE16desired_requestsCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE16desired_requestsB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE16desired_requestsCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 637 | 4 | pub fn desired_requests( | 638 | 4 | &'_ self, | 639 | 4 | ) -> impl Iterator<Item = (SourceId, &'_ TSrc, DesiredRequest)> + '_ { | 640 | 4 | let Some(all_forks) = &self.all_forks else { | 641 | 0 | unreachable!() | 642 | | }; | 643 | | | 644 | 4 | let all_forks_requests = | 645 | 4 | all_forks | 646 | 4 | .desired_requests() | 647 | 4 | .map(move |(inner_source_id, _, rq_params)| { | 648 | | ( | 649 | | all_forks[inner_source_id].outer_source_id, | 650 | | &self.shared.sources[all_forks[inner_source_id].outer_source_id.0] | 651 | | .user_data, | 652 | | all_forks_request_convert(rq_params, self.shared.download_bodies), | 653 | | ) | 654 | 4 | }); | 655 | | | 656 | 4 | let warp_sync_requests = | 657 | 4 | if let Some(warp_sync) = &self.warp_sync { | 658 | 4 | either::Left(warp_sync.desired_requests().map( | 659 | 4 | move |(_, src_user_data, rq_detail)| { | 660 | | let detail = match rq_detail { | 661 | | warp_sync::DesiredRequest::WarpSyncRequest { block_hash } => { | 662 | | DesiredRequest::WarpSync { | 663 | | sync_start_block_hash: block_hash, | 664 | | } | 665 | | } | 666 | | warp_sync::DesiredRequest::BlockBodyDownload { | 667 | | block_hash, | 668 | | block_number, | 669 | | .. | 670 | | } => DesiredRequest::BlocksRequest { | 671 | | first_block_height: block_number, | 672 | | first_block_hash: block_hash, | 673 | | num_blocks: NonZeroU64::new(1).unwrap(), | 674 | | request_headers: false, | 675 | | request_bodies: true, | 676 | | request_justification: false, | 677 | | }, | 678 | | warp_sync::DesiredRequest::StorageGetMerkleProof { | 679 | | block_hash, | 680 | | state_trie_root, | 681 | | keys, | 682 | | } => DesiredRequest::StorageGetMerkleProof { | 683 | | block_hash, | 684 | | state_trie_root, | 685 | | keys, | 686 | | }, | 687 | | warp_sync::DesiredRequest::RuntimeCallMerkleProof { | 688 | | block_hash, | 689 | | function_name, | 690 | | parameter_vectored, | 691 | | } => DesiredRequest::RuntimeCallMerkleProof { | 692 | | block_hash, | 693 | | function_name, | 694 | | parameter_vectored, | 695 | | }, | 696 | | }; | 697 | | | 698 | | ( | 699 | | src_user_data.outer_source_id, | 700 | | &self.shared.sources[src_user_data.outer_source_id.0].user_data, | 701 | | detail, | 702 | | ) | 703 | 4 | }, | 704 | 4 | )) | 705 | | } else { | 706 | 0 | either::Right(iter::empty()) | 707 | | }; | 708 | | | 709 | | // We always prioritize warp sync requests over all fork requests. | 710 | | // The warp sync algorithm will only ever try to emit requests concerning sources that are | 711 | | // (or pretend to be) far ahead of the local node. Given a source that is (or pretends to | 712 | | // be) far ahead of the local node, it is more desirable to try to warp sync from it | 713 | | // rather than download blocks that are close. | 714 | 4 | warp_sync_requests.chain(all_forks_requests) | 715 | 4 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE16desired_requestsCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE16desired_requestsCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 637 | 39 | pub fn desired_requests( | 638 | 39 | &'_ self, | 639 | 39 | ) -> impl Iterator<Item = (SourceId, &'_ TSrc, DesiredRequest)> + '_ { | 640 | 39 | let Some(all_forks) = &self.all_forks else { | 641 | 0 | unreachable!() | 642 | | }; | 643 | | | 644 | 39 | let all_forks_requests = | 645 | 39 | all_forks | 646 | 39 | .desired_requests() | 647 | 39 | .map(move |(inner_source_id, _, rq_params)| { | 648 | | ( | 649 | | all_forks[inner_source_id].outer_source_id, | 650 | | &self.shared.sources[all_forks[inner_source_id].outer_source_id.0] | 651 | | .user_data, | 652 | | all_forks_request_convert(rq_params, self.shared.download_bodies), | 653 | | ) | 654 | 39 | }); | 655 | | | 656 | 39 | let warp_sync_requests = | 657 | 39 | if let Some(warp_sync) = &self.warp_sync { | 658 | 39 | either::Left(warp_sync.desired_requests().map( | 659 | 39 | move |(_, src_user_data, rq_detail)| { | 660 | | let detail = match rq_detail { | 661 | | warp_sync::DesiredRequest::WarpSyncRequest { block_hash } => { | 662 | | DesiredRequest::WarpSync { | 663 | | sync_start_block_hash: block_hash, | 664 | | } | 665 | | } | 666 | | warp_sync::DesiredRequest::BlockBodyDownload { | 667 | | block_hash, | 668 | | block_number, | 669 | | .. | 670 | | } => DesiredRequest::BlocksRequest { | 671 | | first_block_height: block_number, | 672 | | first_block_hash: block_hash, | 673 | | num_blocks: NonZeroU64::new(1).unwrap(), | 674 | | request_headers: false, | 675 | | request_bodies: true, | 676 | | request_justification: false, | 677 | | }, | 678 | | warp_sync::DesiredRequest::StorageGetMerkleProof { | 679 | | block_hash, | 680 | | state_trie_root, | 681 | | keys, | 682 | | } => DesiredRequest::StorageGetMerkleProof { | 683 | | block_hash, | 684 | | state_trie_root, | 685 | | keys, | 686 | | }, | 687 | | warp_sync::DesiredRequest::RuntimeCallMerkleProof { | 688 | | block_hash, | 689 | | function_name, | 690 | | parameter_vectored, | 691 | | } => DesiredRequest::RuntimeCallMerkleProof { | 692 | | block_hash, | 693 | | function_name, | 694 | | parameter_vectored, | 695 | | }, | 696 | | }; | 697 | | | 698 | | ( | 699 | | src_user_data.outer_source_id, | 700 | | &self.shared.sources[src_user_data.outer_source_id.0].user_data, | 701 | | detail, | 702 | | ) | 703 | 39 | }, | 704 | 39 | )) | 705 | | } else { | 706 | 0 | either::Right(iter::empty()) | 707 | | }; | 708 | | | 709 | | // We always prioritize warp sync requests over all fork requests. | 710 | | // The warp sync algorithm will only ever try to emit requests concerning sources that are | 711 | | // (or pretend to be) far ahead of the local node. Given a source that is (or pretends to | 712 | | // be) far ahead of the local node, it is more desirable to try to warp sync from it | 713 | | // rather than download blocks that are close. | 714 | 39 | warp_sync_requests.chain(all_forks_requests) | 715 | 39 | } |
|
716 | | |
717 | | /// Inserts a new request in the data structure. |
718 | | /// |
719 | | /// > **Note**: The request doesn't necessarily have to match a request returned by |
720 | | /// > [`AllSync::desired_requests`]. |
721 | | /// |
722 | | /// # Panic |
723 | | /// |
724 | | /// Panics if the [`SourceId`] is out of range. |
725 | | /// |
726 | 0 | pub fn add_request( |
727 | 0 | &mut self, |
728 | 0 | source_id: SourceId, |
729 | 0 | detail: RequestDetail, |
730 | 0 | user_data: TRq, |
731 | 0 | ) -> RequestId { |
732 | 0 | let Some(source_ids) = self.shared.sources.get_mut(source_id.0) else { |
733 | 0 | panic!() |
734 | | }; |
735 | | |
736 | 0 | let request_mapping_entry = self.shared.requests.vacant_entry(); |
737 | 0 | let outer_request_id = RequestId(request_mapping_entry.key()); |
738 | | |
739 | 0 | let all_forks_request_id = match detail { |
740 | | RequestDetail::BlocksRequest { |
741 | 0 | first_block_height, |
742 | 0 | first_block_hash, |
743 | 0 | num_blocks, |
744 | 0 | request_headers: true, |
745 | 0 | request_bodies, |
746 | | request_justification: true, |
747 | 0 | } if request_bodies || !self.shared.download_bodies => { |
748 | 0 | let Some(all_forks) = &mut self.all_forks else { |
749 | 0 | unreachable!() |
750 | | }; |
751 | | |
752 | 0 | Some(all_forks.add_request( |
753 | 0 | source_ids.all_forks, |
754 | 0 | all_forks::RequestParams { |
755 | 0 | first_block_hash, |
756 | 0 | first_block_height, |
757 | 0 | num_blocks, |
758 | 0 | }, |
759 | 0 | AllForksRequestExtra { outer_request_id }, |
760 | 0 | )) |
761 | | } |
762 | 0 | _ => None, |
763 | | }; |
764 | | |
765 | 0 | let warp_sync_request_id = match (&mut self.warp_sync, source_ids.warp_sync, detail) { |
766 | | ( |
767 | 0 | Some(warp_sync), |
768 | 0 | Some(inner_source_id), |
769 | 0 | RequestDetail::WarpSync { |
770 | 0 | sync_start_block_hash, |
771 | 0 | }, |
772 | 0 | ) => Some(warp_sync.add_request( |
773 | 0 | inner_source_id, |
774 | 0 | WarpSyncRequestExtra {}, |
775 | 0 | warp_sync::RequestDetail::WarpSyncRequest { |
776 | 0 | block_hash: sync_start_block_hash, |
777 | 0 | }, |
778 | 0 | )), |
779 | | ( |
780 | 0 | Some(warp_sync), |
781 | 0 | Some(inner_source_id), |
782 | 0 | RequestDetail::BlocksRequest { |
783 | 0 | first_block_height, |
784 | 0 | first_block_hash, |
785 | 0 | request_bodies: true, |
786 | 0 | .. |
787 | 0 | }, |
788 | 0 | ) => Some(warp_sync.add_request( |
789 | 0 | inner_source_id, |
790 | 0 | WarpSyncRequestExtra {}, |
791 | 0 | warp_sync::RequestDetail::BlockBodyDownload { |
792 | 0 | block_hash: first_block_hash, |
793 | 0 | block_number: first_block_height, |
794 | 0 | }, |
795 | 0 | )), |
796 | | ( |
797 | 0 | Some(warp_sync), |
798 | 0 | Some(inner_source_id), |
799 | 0 | RequestDetail::StorageGet { block_hash, keys }, |
800 | 0 | ) => Some(warp_sync.add_request( |
801 | 0 | inner_source_id, |
802 | 0 | WarpSyncRequestExtra {}, |
803 | 0 | warp_sync::RequestDetail::StorageGetMerkleProof { block_hash, keys }, |
804 | 0 | )), |
805 | | ( |
806 | 0 | Some(warp_sync), |
807 | 0 | Some(inner_source_id), |
808 | 0 | RequestDetail::RuntimeCallMerkleProof { |
809 | 0 | block_hash, |
810 | 0 | function_name, |
811 | 0 | parameter_vectored, |
812 | 0 | }, |
813 | 0 | ) => Some(warp_sync.add_request( |
814 | 0 | inner_source_id, |
815 | 0 | WarpSyncRequestExtra {}, |
816 | 0 | warp_sync::RequestDetail::RuntimeCallMerkleProof { |
817 | 0 | block_hash, |
818 | 0 | function_name, |
819 | 0 | parameter_vectored, |
820 | 0 | }, |
821 | 0 | )), |
822 | 0 | (None, None, _) | (Some(_), Some(_), _) => None, |
823 | | (Some(_), None, _) | (None, Some(_), _) => { |
824 | 0 | debug_assert!(false); |
825 | 0 | None |
826 | | } |
827 | | }; |
828 | | |
829 | 0 | source_ids.num_requests += 1; |
830 | 0 |
|
831 | 0 | request_mapping_entry.insert(RequestInfo { |
832 | 0 | all_forks: all_forks_request_id, |
833 | 0 | warp_sync: warp_sync_request_id, |
834 | 0 | source_id, |
835 | 0 | user_data, |
836 | 0 | }); |
837 | 0 |
|
838 | 0 | outer_request_id |
839 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE11add_requestB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE11add_requestCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE11add_requestB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE11add_requestCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE11add_requestCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE11add_requestCsibGXYHQB8Ea_25json_rpc_general_requests |
840 | | |
841 | | /// Removes the given request from the state machine. Returns the user data that was associated |
842 | | /// to it. |
843 | | /// |
844 | | /// > **Note**: The state machine might want to re-start the same request again. It is out of |
845 | | /// > the scope of this module to keep track of requests that don't succeed. |
846 | | /// |
847 | | /// # Panic |
848 | | /// |
849 | | /// Panics if the [`RequestId`] is invalid. |
850 | | /// |
851 | 0 | pub fn remove_request(&mut self, request_id: RequestId) -> TRq { |
852 | 0 | debug_assert!(self.shared.requests.contains(request_id.0)); |
853 | 0 | let request = self.shared.requests.remove(request_id.0); |
854 | 0 |
|
855 | 0 | self.shared.sources[request.source_id.0].num_requests -= 1; |
856 | | |
857 | 0 | if let Some(all_forks_request_id) = request.all_forks { |
858 | 0 | let Some(all_forks) = self.all_forks.as_mut() else { |
859 | 0 | unreachable!() |
860 | | }; |
861 | 0 | let (_, _) = all_forks.finish_request(all_forks_request_id); |
862 | 0 | } |
863 | | |
864 | 0 | if let Some(warp_sync_request_id) = request.warp_sync { |
865 | 0 | let Some(warp_sync) = &mut self.warp_sync else { |
866 | 0 | unreachable!() |
867 | | }; |
868 | 0 | warp_sync.remove_request(warp_sync_request_id); |
869 | 0 | } |
870 | | |
871 | 0 | request.user_data |
872 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE14remove_requestB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE14remove_requestCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE14remove_requestB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE14remove_requestCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE14remove_requestCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE14remove_requestCsibGXYHQB8Ea_25json_rpc_general_requests |
873 | | |
874 | | /// Returns a list of requests that are considered obsolete and can be removed using |
875 | | /// [`AllSync::blocks_request_response`] or similar. |
876 | | /// |
877 | | /// A request becomes obsolete if the state of the request blocks changes in such a way that |
878 | | /// they don't need to be requested anymore. The response to the request will be useless. |
879 | | /// |
880 | | /// > **Note**: It is in no way mandatory to actually call this function and cancel the |
881 | | /// > requests that are returned. |
882 | 0 | pub fn obsolete_requests(&'_ self) -> impl Iterator<Item = RequestId> + '_ { |
883 | | // TODO: not implemented properly |
884 | 0 | let Some(all_forks) = &self.all_forks else { |
885 | 0 | unreachable!() |
886 | | }; |
887 | | |
888 | 0 | all_forks |
889 | 0 | .obsolete_requests() |
890 | 0 | .map(move |(_, rq)| rq.outer_request_id) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE17obsolete_requests0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE17obsolete_requests0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE17obsolete_requests0B8_ |
891 | 0 | .chain( |
892 | 0 | self.shared |
893 | 0 | .requests |
894 | 0 | .iter() |
895 | 0 | .filter(|(_, rq)| rq.all_forks.is_none() && rq.warp_sync.is_none()) Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE17obsolete_requestss_0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE17obsolete_requestss_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE17obsolete_requestss_0B8_ |
896 | 0 | .map(|(id, _)| RequestId(id)), Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE17obsolete_requestss0_0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE17obsolete_requestss0_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE17obsolete_requestss0_0B8_ |
897 | 0 | ) |
898 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE17obsolete_requestsB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE17obsolete_requestsCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE17obsolete_requestsB6_ |
899 | | |
900 | | /// Returns the [`SourceId`] that is expected to fulfill the given request. |
901 | | /// |
902 | | /// # Panic |
903 | | /// |
904 | | /// Panics if the [`RequestId`] is invalid. |
905 | | /// |
906 | 0 | pub fn request_source_id(&self, request_id: RequestId) -> SourceId { |
907 | 0 | let Some(request) = self.shared.requests.get(request_id.0) else { |
908 | 0 | panic!() |
909 | | }; |
910 | | |
911 | 0 | request.source_id |
912 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE17request_source_idB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE17request_source_idCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE17request_source_idB6_ |
913 | | |
914 | | /// Process the next block in the queue of verification. |
915 | | /// |
916 | | /// This method takes ownership of the [`AllSync`] and starts a verification process. The |
917 | | /// [`AllSync`] is yielded back at the end of this process. |
918 | 21 | pub fn process_one(mut self) -> ProcessOne<TRq, TSrc, TBl> { |
919 | 21 | if let Some(warp_sync) = self.warp_sync.take() { |
920 | 21 | match warp_sync.process_one() { |
921 | 21 | warp_sync::ProcessOne::Idle(inner) => { |
922 | 21 | self.warp_sync = Some(inner); |
923 | 21 | } |
924 | 0 | warp_sync::ProcessOne::VerifyWarpSyncFragment(inner) => { |
925 | 0 | let Some(all_forks) = self.all_forks.take() else { |
926 | 0 | unreachable!() |
927 | | }; |
928 | 0 | return ProcessOne::VerifyWarpSyncFragment(WarpSyncFragmentVerify { |
929 | 0 | inner, |
930 | 0 | ready_to_transition: None, |
931 | 0 | all_forks, |
932 | 0 | shared: self.shared, |
933 | 0 | }); |
934 | | } |
935 | 0 | warp_sync::ProcessOne::BuildRuntime(inner) => { |
936 | 0 | let Some(all_forks) = self.all_forks.take() else { |
937 | 0 | unreachable!() |
938 | | }; |
939 | 0 | return ProcessOne::WarpSyncBuildRuntime(WarpSyncBuildRuntime { |
940 | 0 | inner, |
941 | 0 | ready_to_transition: None, |
942 | 0 | all_forks, |
943 | 0 | shared: self.shared, |
944 | 0 | }); |
945 | | } |
946 | 0 | warp_sync::ProcessOne::BuildChainInformation(inner) => { |
947 | 0 | let Some(all_forks) = self.all_forks.take() else { |
948 | 0 | unreachable!() |
949 | | }; |
950 | 0 | return ProcessOne::WarpSyncBuildChainInformation( |
951 | 0 | WarpSyncBuildChainInformation { |
952 | 0 | inner, |
953 | 0 | all_forks, |
954 | 0 | shared: self.shared, |
955 | 0 | }, |
956 | 0 | ); |
957 | | } |
958 | | } |
959 | 0 | } |
960 | | |
961 | | if let Some(RuntimeInformation { |
962 | 0 | finalized_runtime: finalized_block_runtime, |
963 | 0 | finalized_body, |
964 | 0 | finalized_storage_code, |
965 | 0 | finalized_storage_heap_pages, |
966 | 0 | finalized_storage_code_merkle_value, |
967 | 0 | finalized_storage_code_closest_ancestor_excluding, |
968 | 21 | }) = self.ready_to_transition.take() |
969 | | { |
970 | 0 | let (Some(all_forks), Some(warp_sync)) = |
971 | 0 | (self.all_forks.as_mut(), self.warp_sync.as_mut()) |
972 | | else { |
973 | 0 | unreachable!() |
974 | | }; |
975 | | |
976 | 0 | let mut new_all_forks = AllForksSync::new(all_forks::Config { |
977 | 0 | chain_information: warp_sync.as_chain_information().into(), |
978 | 0 | block_number_bytes: self.shared.block_number_bytes, |
979 | 0 | sources_capacity: self.shared.sources_capacity, |
980 | 0 | blocks_capacity: self.shared.blocks_capacity, |
981 | 0 | download_bodies: self.shared.download_bodies, |
982 | 0 | allow_unknown_consensus_engines: self.shared.allow_unknown_consensus_engines, |
983 | 0 | max_disjoint_headers: self.shared.max_disjoint_headers, |
984 | 0 | max_requests_per_block: self.shared.max_requests_per_block, |
985 | 0 | }); |
986 | | |
987 | 0 | for warp_sync_source_id in warp_sync.sources() { |
988 | 0 | let outer_source_id = warp_sync[warp_sync_source_id].outer_source_id; |
989 | 0 |
|
990 | 0 | let (best_block_number, &best_block_hash) = |
991 | 0 | all_forks.source_best_block(self.shared.sources[outer_source_id.0].all_forks); |
992 | | |
993 | 0 | let new_inner_source_id = |
994 | 0 | match new_all_forks.prepare_add_source(best_block_number, best_block_hash) { |
995 | 0 | all_forks::AddSource::BestBlockAlreadyVerified(b) |
996 | 0 | | all_forks::AddSource::BestBlockPendingVerification(b) => { |
997 | 0 | b.add_source(AllForksSourceExtra { outer_source_id }) |
998 | | } |
999 | 0 | all_forks::AddSource::OldBestBlock(b) => { |
1000 | 0 | b.add_source(AllForksSourceExtra { outer_source_id }) |
1001 | | } |
1002 | 0 | all_forks::AddSource::UnknownBestBlock(b) => { |
1003 | 0 | // If the best block of the source is unknown to the new state machine, |
1004 | 0 | // it necessarily means that this block's user data hasn't been |
1005 | 0 | // extracted from the old state machine yet. |
1006 | 0 | let block_user_data = all_forks[(best_block_number, &best_block_hash)] |
1007 | 0 | .take() |
1008 | 0 | .unwrap_or_else(|| unreachable!()); Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB4_7AllSyncpppE11process_one0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuE11process_one0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncpppE11process_one0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE11process_one0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE11process_one0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockE11process_one0CsibGXYHQB8Ea_25json_rpc_general_requests |
1009 | 0 | b.add_source_and_insert_block( |
1010 | 0 | AllForksSourceExtra { outer_source_id }, |
1011 | 0 | Some(block_user_data), |
1012 | 0 | ) |
1013 | | } |
1014 | | }; |
1015 | | |
1016 | 0 | new_all_forks.update_source_finality_state( |
1017 | 0 | new_inner_source_id, |
1018 | 0 | warp_sync.source_finality_state(warp_sync_source_id), |
1019 | 0 | ); |
1020 | 0 |
|
1021 | 0 | self.shared.sources[outer_source_id.0].all_forks = new_inner_source_id; |
1022 | | } |
1023 | | |
1024 | 0 | for (_, request) in self.shared.requests.iter_mut() { |
1025 | 0 | request.all_forks = None; |
1026 | 0 | } |
1027 | | |
1028 | 0 | self.all_forks = Some(new_all_forks); |
1029 | 0 |
|
1030 | 0 | return ProcessOne::WarpSyncFinished { |
1031 | 0 | sync: self, |
1032 | 0 | finalized_block_runtime, |
1033 | 0 | finalized_body, |
1034 | 0 | finalized_storage_code, |
1035 | 0 | finalized_storage_heap_pages, |
1036 | 0 | finalized_storage_code_merkle_value, |
1037 | 0 | finalized_storage_code_closest_ancestor_excluding, |
1038 | 0 | }; |
1039 | 21 | } |
1040 | | |
1041 | 21 | let Some(all_forks) = self.all_forks.take() else { |
1042 | 0 | unreachable!() |
1043 | | }; |
1044 | 21 | match all_forks.process_one() { |
1045 | 21 | all_forks::ProcessOne::AllSync { sync } => { |
1046 | 21 | self.all_forks = Some(sync); |
1047 | 21 | } |
1048 | 0 | all_forks::ProcessOne::BlockVerify(inner) => { |
1049 | 0 | return ProcessOne::VerifyBlock(BlockVerify { |
1050 | 0 | inner, |
1051 | 0 | warp_sync: self.warp_sync, |
1052 | 0 | ready_to_transition: self.ready_to_transition, |
1053 | 0 | shared: self.shared, |
1054 | 0 | }) |
1055 | | } |
1056 | 0 | all_forks::ProcessOne::FinalityProofVerify(inner) => { |
1057 | 0 | return ProcessOne::VerifyFinalityProof(FinalityProofVerify { |
1058 | 0 | inner, |
1059 | 0 | warp_sync: self.warp_sync, |
1060 | 0 | ready_to_transition: self.ready_to_transition, |
1061 | 0 | shared: self.shared, |
1062 | 0 | }) |
1063 | | } |
1064 | | } |
1065 | | |
1066 | 21 | ProcessOne::AllSync(self) |
1067 | 21 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE11process_oneB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE11process_oneCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE11process_oneB6_ _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE11process_oneCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 918 | 2 | pub fn process_one(mut self) -> ProcessOne<TRq, TSrc, TBl> { | 919 | 2 | if let Some(warp_sync) = self.warp_sync.take() { | 920 | 2 | match warp_sync.process_one() { | 921 | 2 | warp_sync::ProcessOne::Idle(inner) => { | 922 | 2 | self.warp_sync = Some(inner); | 923 | 2 | } | 924 | 0 | warp_sync::ProcessOne::VerifyWarpSyncFragment(inner) => { | 925 | 0 | let Some(all_forks) = self.all_forks.take() else { | 926 | 0 | unreachable!() | 927 | | }; | 928 | 0 | return ProcessOne::VerifyWarpSyncFragment(WarpSyncFragmentVerify { | 929 | 0 | inner, | 930 | 0 | ready_to_transition: None, | 931 | 0 | all_forks, | 932 | 0 | shared: self.shared, | 933 | 0 | }); | 934 | | } | 935 | 0 | warp_sync::ProcessOne::BuildRuntime(inner) => { | 936 | 0 | let Some(all_forks) = self.all_forks.take() else { | 937 | 0 | unreachable!() | 938 | | }; | 939 | 0 | return ProcessOne::WarpSyncBuildRuntime(WarpSyncBuildRuntime { | 940 | 0 | inner, | 941 | 0 | ready_to_transition: None, | 942 | 0 | all_forks, | 943 | 0 | shared: self.shared, | 944 | 0 | }); | 945 | | } | 946 | 0 | warp_sync::ProcessOne::BuildChainInformation(inner) => { | 947 | 0 | let Some(all_forks) = self.all_forks.take() else { | 948 | 0 | unreachable!() | 949 | | }; | 950 | 0 | return ProcessOne::WarpSyncBuildChainInformation( | 951 | 0 | WarpSyncBuildChainInformation { | 952 | 0 | inner, | 953 | 0 | all_forks, | 954 | 0 | shared: self.shared, | 955 | 0 | }, | 956 | 0 | ); | 957 | | } | 958 | | } | 959 | 0 | } | 960 | | | 961 | | if let Some(RuntimeInformation { | 962 | 0 | finalized_runtime: finalized_block_runtime, | 963 | 0 | finalized_body, | 964 | 0 | finalized_storage_code, | 965 | 0 | finalized_storage_heap_pages, | 966 | 0 | finalized_storage_code_merkle_value, | 967 | 0 | finalized_storage_code_closest_ancestor_excluding, | 968 | 2 | }) = self.ready_to_transition.take() | 969 | | { | 970 | 0 | let (Some(all_forks), Some(warp_sync)) = | 971 | 0 | (self.all_forks.as_mut(), self.warp_sync.as_mut()) | 972 | | else { | 973 | 0 | unreachable!() | 974 | | }; | 975 | | | 976 | 0 | let mut new_all_forks = AllForksSync::new(all_forks::Config { | 977 | 0 | chain_information: warp_sync.as_chain_information().into(), | 978 | 0 | block_number_bytes: self.shared.block_number_bytes, | 979 | 0 | sources_capacity: self.shared.sources_capacity, | 980 | 0 | blocks_capacity: self.shared.blocks_capacity, | 981 | 0 | download_bodies: self.shared.download_bodies, | 982 | 0 | allow_unknown_consensus_engines: self.shared.allow_unknown_consensus_engines, | 983 | 0 | max_disjoint_headers: self.shared.max_disjoint_headers, | 984 | 0 | max_requests_per_block: self.shared.max_requests_per_block, | 985 | 0 | }); | 986 | | | 987 | 0 | for warp_sync_source_id in warp_sync.sources() { | 988 | 0 | let outer_source_id = warp_sync[warp_sync_source_id].outer_source_id; | 989 | 0 |
| 990 | 0 | let (best_block_number, &best_block_hash) = | 991 | 0 | all_forks.source_best_block(self.shared.sources[outer_source_id.0].all_forks); | 992 | | | 993 | 0 | let new_inner_source_id = | 994 | 0 | match new_all_forks.prepare_add_source(best_block_number, best_block_hash) { | 995 | 0 | all_forks::AddSource::BestBlockAlreadyVerified(b) | 996 | 0 | | all_forks::AddSource::BestBlockPendingVerification(b) => { | 997 | 0 | b.add_source(AllForksSourceExtra { outer_source_id }) | 998 | | } | 999 | 0 | all_forks::AddSource::OldBestBlock(b) => { | 1000 | 0 | b.add_source(AllForksSourceExtra { outer_source_id }) | 1001 | | } | 1002 | 0 | all_forks::AddSource::UnknownBestBlock(b) => { | 1003 | 0 | // If the best block of the source is unknown to the new state machine, | 1004 | 0 | // it necessarily means that this block's user data hasn't been | 1005 | 0 | // extracted from the old state machine yet. | 1006 | 0 | let block_user_data = all_forks[(best_block_number, &best_block_hash)] | 1007 | 0 | .take() | 1008 | 0 | .unwrap_or_else(|| unreachable!()); | 1009 | 0 | b.add_source_and_insert_block( | 1010 | 0 | AllForksSourceExtra { outer_source_id }, | 1011 | 0 | Some(block_user_data), | 1012 | 0 | ) | 1013 | | } | 1014 | | }; | 1015 | | | 1016 | 0 | new_all_forks.update_source_finality_state( | 1017 | 0 | new_inner_source_id, | 1018 | 0 | warp_sync.source_finality_state(warp_sync_source_id), | 1019 | 0 | ); | 1020 | 0 |
| 1021 | 0 | self.shared.sources[outer_source_id.0].all_forks = new_inner_source_id; | 1022 | | } | 1023 | | | 1024 | 0 | for (_, request) in self.shared.requests.iter_mut() { | 1025 | 0 | request.all_forks = None; | 1026 | 0 | } | 1027 | | | 1028 | 0 | self.all_forks = Some(new_all_forks); | 1029 | 0 |
| 1030 | 0 | return ProcessOne::WarpSyncFinished { | 1031 | 0 | sync: self, | 1032 | 0 | finalized_block_runtime, | 1033 | 0 | finalized_body, | 1034 | 0 | finalized_storage_code, | 1035 | 0 | finalized_storage_heap_pages, | 1036 | 0 | finalized_storage_code_merkle_value, | 1037 | 0 | finalized_storage_code_closest_ancestor_excluding, | 1038 | 0 | }; | 1039 | 2 | } | 1040 | | | 1041 | 2 | let Some(all_forks) = self.all_forks.take() else { | 1042 | 0 | unreachable!() | 1043 | | }; | 1044 | 2 | match all_forks.process_one() { | 1045 | 2 | all_forks::ProcessOne::AllSync { sync } => { | 1046 | 2 | self.all_forks = Some(sync); | 1047 | 2 | } | 1048 | 0 | all_forks::ProcessOne::BlockVerify(inner) => { | 1049 | 0 | return ProcessOne::VerifyBlock(BlockVerify { | 1050 | 0 | inner, | 1051 | 0 | warp_sync: self.warp_sync, | 1052 | 0 | ready_to_transition: self.ready_to_transition, | 1053 | 0 | shared: self.shared, | 1054 | 0 | }) | 1055 | | } | 1056 | 0 | all_forks::ProcessOne::FinalityProofVerify(inner) => { | 1057 | 0 | return ProcessOne::VerifyFinalityProof(FinalityProofVerify { | 1058 | 0 | inner, | 1059 | 0 | warp_sync: self.warp_sync, | 1060 | 0 | ready_to_transition: self.ready_to_transition, | 1061 | 0 | shared: self.shared, | 1062 | 0 | }) | 1063 | | } | 1064 | | } | 1065 | | | 1066 | 2 | ProcessOne::AllSync(self) | 1067 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE11process_oneCscDgN54JpMGG_6author _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE11process_oneCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 918 | 19 | pub fn process_one(mut self) -> ProcessOne<TRq, TSrc, TBl> { | 919 | 19 | if let Some(warp_sync) = self.warp_sync.take() { | 920 | 19 | match warp_sync.process_one() { | 921 | 19 | warp_sync::ProcessOne::Idle(inner) => { | 922 | 19 | self.warp_sync = Some(inner); | 923 | 19 | } | 924 | 0 | warp_sync::ProcessOne::VerifyWarpSyncFragment(inner) => { | 925 | 0 | let Some(all_forks) = self.all_forks.take() else { | 926 | 0 | unreachable!() | 927 | | }; | 928 | 0 | return ProcessOne::VerifyWarpSyncFragment(WarpSyncFragmentVerify { | 929 | 0 | inner, | 930 | 0 | ready_to_transition: None, | 931 | 0 | all_forks, | 932 | 0 | shared: self.shared, | 933 | 0 | }); | 934 | | } | 935 | 0 | warp_sync::ProcessOne::BuildRuntime(inner) => { | 936 | 0 | let Some(all_forks) = self.all_forks.take() else { | 937 | 0 | unreachable!() | 938 | | }; | 939 | 0 | return ProcessOne::WarpSyncBuildRuntime(WarpSyncBuildRuntime { | 940 | 0 | inner, | 941 | 0 | ready_to_transition: None, | 942 | 0 | all_forks, | 943 | 0 | shared: self.shared, | 944 | 0 | }); | 945 | | } | 946 | 0 | warp_sync::ProcessOne::BuildChainInformation(inner) => { | 947 | 0 | let Some(all_forks) = self.all_forks.take() else { | 948 | 0 | unreachable!() | 949 | | }; | 950 | 0 | return ProcessOne::WarpSyncBuildChainInformation( | 951 | 0 | WarpSyncBuildChainInformation { | 952 | 0 | inner, | 953 | 0 | all_forks, | 954 | 0 | shared: self.shared, | 955 | 0 | }, | 956 | 0 | ); | 957 | | } | 958 | | } | 959 | 0 | } | 960 | | | 961 | | if let Some(RuntimeInformation { | 962 | 0 | finalized_runtime: finalized_block_runtime, | 963 | 0 | finalized_body, | 964 | 0 | finalized_storage_code, | 965 | 0 | finalized_storage_heap_pages, | 966 | 0 | finalized_storage_code_merkle_value, | 967 | 0 | finalized_storage_code_closest_ancestor_excluding, | 968 | 19 | }) = self.ready_to_transition.take() | 969 | | { | 970 | 0 | let (Some(all_forks), Some(warp_sync)) = | 971 | 0 | (self.all_forks.as_mut(), self.warp_sync.as_mut()) | 972 | | else { | 973 | 0 | unreachable!() | 974 | | }; | 975 | | | 976 | 0 | let mut new_all_forks = AllForksSync::new(all_forks::Config { | 977 | 0 | chain_information: warp_sync.as_chain_information().into(), | 978 | 0 | block_number_bytes: self.shared.block_number_bytes, | 979 | 0 | sources_capacity: self.shared.sources_capacity, | 980 | 0 | blocks_capacity: self.shared.blocks_capacity, | 981 | 0 | download_bodies: self.shared.download_bodies, | 982 | 0 | allow_unknown_consensus_engines: self.shared.allow_unknown_consensus_engines, | 983 | 0 | max_disjoint_headers: self.shared.max_disjoint_headers, | 984 | 0 | max_requests_per_block: self.shared.max_requests_per_block, | 985 | 0 | }); | 986 | | | 987 | 0 | for warp_sync_source_id in warp_sync.sources() { | 988 | 0 | let outer_source_id = warp_sync[warp_sync_source_id].outer_source_id; | 989 | 0 |
| 990 | 0 | let (best_block_number, &best_block_hash) = | 991 | 0 | all_forks.source_best_block(self.shared.sources[outer_source_id.0].all_forks); | 992 | | | 993 | 0 | let new_inner_source_id = | 994 | 0 | match new_all_forks.prepare_add_source(best_block_number, best_block_hash) { | 995 | 0 | all_forks::AddSource::BestBlockAlreadyVerified(b) | 996 | 0 | | all_forks::AddSource::BestBlockPendingVerification(b) => { | 997 | 0 | b.add_source(AllForksSourceExtra { outer_source_id }) | 998 | | } | 999 | 0 | all_forks::AddSource::OldBestBlock(b) => { | 1000 | 0 | b.add_source(AllForksSourceExtra { outer_source_id }) | 1001 | | } | 1002 | 0 | all_forks::AddSource::UnknownBestBlock(b) => { | 1003 | 0 | // If the best block of the source is unknown to the new state machine, | 1004 | 0 | // it necessarily means that this block's user data hasn't been | 1005 | 0 | // extracted from the old state machine yet. | 1006 | 0 | let block_user_data = all_forks[(best_block_number, &best_block_hash)] | 1007 | 0 | .take() | 1008 | 0 | .unwrap_or_else(|| unreachable!()); | 1009 | 0 | b.add_source_and_insert_block( | 1010 | 0 | AllForksSourceExtra { outer_source_id }, | 1011 | 0 | Some(block_user_data), | 1012 | 0 | ) | 1013 | | } | 1014 | | }; | 1015 | | | 1016 | 0 | new_all_forks.update_source_finality_state( | 1017 | 0 | new_inner_source_id, | 1018 | 0 | warp_sync.source_finality_state(warp_sync_source_id), | 1019 | 0 | ); | 1020 | 0 |
| 1021 | 0 | self.shared.sources[outer_source_id.0].all_forks = new_inner_source_id; | 1022 | | } | 1023 | | | 1024 | 0 | for (_, request) in self.shared.requests.iter_mut() { | 1025 | 0 | request.all_forks = None; | 1026 | 0 | } | 1027 | | | 1028 | 0 | self.all_forks = Some(new_all_forks); | 1029 | 0 |
| 1030 | 0 | return ProcessOne::WarpSyncFinished { | 1031 | 0 | sync: self, | 1032 | 0 | finalized_block_runtime, | 1033 | 0 | finalized_body, | 1034 | 0 | finalized_storage_code, | 1035 | 0 | finalized_storage_heap_pages, | 1036 | 0 | finalized_storage_code_merkle_value, | 1037 | 0 | finalized_storage_code_closest_ancestor_excluding, | 1038 | 0 | }; | 1039 | 19 | } | 1040 | | | 1041 | 19 | let Some(all_forks) = self.all_forks.take() else { | 1042 | 0 | unreachable!() | 1043 | | }; | 1044 | 19 | match all_forks.process_one() { | 1045 | 19 | all_forks::ProcessOne::AllSync { sync } => { | 1046 | 19 | self.all_forks = Some(sync); | 1047 | 19 | } | 1048 | 0 | all_forks::ProcessOne::BlockVerify(inner) => { | 1049 | 0 | return ProcessOne::VerifyBlock(BlockVerify { | 1050 | 0 | inner, | 1051 | 0 | warp_sync: self.warp_sync, | 1052 | 0 | ready_to_transition: self.ready_to_transition, | 1053 | 0 | shared: self.shared, | 1054 | 0 | }) | 1055 | | } | 1056 | 0 | all_forks::ProcessOne::FinalityProofVerify(inner) => { | 1057 | 0 | return ProcessOne::VerifyFinalityProof(FinalityProofVerify { | 1058 | 0 | inner, | 1059 | 0 | warp_sync: self.warp_sync, | 1060 | 0 | ready_to_transition: self.ready_to_transition, | 1061 | 0 | shared: self.shared, | 1062 | 0 | }) | 1063 | | } | 1064 | | } | 1065 | | | 1066 | 19 | ProcessOne::AllSync(self) | 1067 | 19 | } |
|
1068 | | |
1069 | | /// Injects a block announcement made by a source into the state machine. |
1070 | | /// |
1071 | | /// > **Note**: This information is normally reported by the source itself. In the case of a |
1072 | | /// > a networking peer, call this when the source sent a block announce. |
1073 | | /// |
1074 | | /// # Panic |
1075 | | /// |
1076 | | /// Panics if the [`SourceId`] is invalid. |
1077 | | /// |
1078 | 0 | pub fn block_announce( |
1079 | 0 | &mut self, |
1080 | 0 | source_id: SourceId, |
1081 | 0 | announced_scale_encoded_header: Vec<u8>, |
1082 | 0 | is_best: bool, |
1083 | 0 | ) -> BlockAnnounceOutcome<TRq, TSrc, TBl> { |
1084 | | let Some(&SourceMapping { |
1085 | 0 | all_forks: inner_source_id, |
1086 | | .. |
1087 | 0 | }) = self.shared.sources.get(source_id.0) |
1088 | | else { |
1089 | 0 | panic!() |
1090 | | }; |
1091 | | |
1092 | 0 | let Some(all_forks) = &mut self.all_forks else { |
1093 | 0 | unreachable!() |
1094 | | }; |
1095 | | |
1096 | 0 | match all_forks.block_announce(inner_source_id, announced_scale_encoded_header, is_best) { |
1097 | | all_forks::BlockAnnounceOutcome::TooOld { |
1098 | 0 | announce_block_height, |
1099 | 0 | finalized_block_height, |
1100 | 0 | } => BlockAnnounceOutcome::TooOld { |
1101 | 0 | announce_block_height, |
1102 | 0 | finalized_block_height, |
1103 | 0 | }, |
1104 | 0 | all_forks::BlockAnnounceOutcome::Unknown(inner) => { |
1105 | 0 | BlockAnnounceOutcome::Unknown(AnnouncedBlockUnknown { |
1106 | 0 | inner, |
1107 | 0 | marker: PhantomData, |
1108 | 0 | }) |
1109 | | } |
1110 | 0 | all_forks::BlockAnnounceOutcome::AlreadyPending(inner) => { |
1111 | 0 | BlockAnnounceOutcome::AlreadyPending(AnnouncedBlockKnown { |
1112 | 0 | inner, |
1113 | 0 | marker: PhantomData, |
1114 | 0 | }) |
1115 | | } |
1116 | 0 | all_forks::BlockAnnounceOutcome::AlreadyVerified(inner) => { |
1117 | 0 | BlockAnnounceOutcome::AlreadyVerified(AnnouncedBlockKnown { |
1118 | 0 | inner, |
1119 | 0 | marker: PhantomData, |
1120 | 0 | }) |
1121 | | } |
1122 | 0 | all_forks::BlockAnnounceOutcome::InvalidHeader(error) => { |
1123 | 0 | BlockAnnounceOutcome::InvalidHeader(error) |
1124 | | } |
1125 | | } |
1126 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE14block_announceB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE14block_announceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE14block_announceB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE14block_announceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE14block_announceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE14block_announceCsibGXYHQB8Ea_25json_rpc_general_requests |
1127 | | |
1128 | | /// Update the finalized block height of the given source. |
1129 | | /// |
1130 | | /// # Panic |
1131 | | /// |
1132 | | /// Panics if `source_id` is invalid. |
1133 | | /// |
1134 | 0 | pub fn update_source_finality_state( |
1135 | 0 | &mut self, |
1136 | 0 | source_id: SourceId, |
1137 | 0 | finalized_block_height: u64, |
1138 | 0 | ) { |
1139 | 0 | let source_id = self.shared.sources.get(source_id.0).unwrap(); |
1140 | 0 |
|
1141 | 0 | match (&mut self.warp_sync, source_id.warp_sync) { |
1142 | 0 | (Some(warp_sync), Some(inner_source_id)) => { |
1143 | 0 | warp_sync.set_source_finality_state(inner_source_id, finalized_block_height); |
1144 | 0 | } |
1145 | 0 | (None, None) => {} |
1146 | | _ => { |
1147 | | // Invalid internal state. |
1148 | 0 | debug_assert!(false); |
1149 | | } |
1150 | | } |
1151 | | |
1152 | 0 | let Some(all_forks) = &mut self.all_forks else { |
1153 | 0 | unreachable!() |
1154 | | }; |
1155 | 0 | all_forks.update_source_finality_state(source_id.all_forks, finalized_block_height); |
1156 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE28update_source_finality_stateB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE28update_source_finality_stateCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE28update_source_finality_stateB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE28update_source_finality_stateCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE28update_source_finality_stateCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE28update_source_finality_stateCsibGXYHQB8Ea_25json_rpc_general_requests |
1157 | | |
1158 | | /// Update the state machine with a Grandpa commit message received from the network. |
1159 | | /// |
1160 | | /// This function only inserts the commit message into the state machine, and does not |
1161 | | /// immediately verify it. |
1162 | 0 | pub fn grandpa_commit_message( |
1163 | 0 | &mut self, |
1164 | 0 | source_id: SourceId, |
1165 | 0 | scale_encoded_message: Vec<u8>, |
1166 | 0 | ) -> GrandpaCommitMessageOutcome { |
1167 | 0 | let source_id = self.shared.sources.get(source_id.0).unwrap(); |
1168 | 0 |
|
1169 | 0 | match (&mut self.warp_sync, source_id.warp_sync) { |
1170 | 0 | (Some(warp_sync), Some(inner_source_id)) => { |
1171 | 0 | let block_number = match decode::decode_grandpa_commit( |
1172 | 0 | &scale_encoded_message, |
1173 | 0 | warp_sync.block_number_bytes(), |
1174 | 0 | ) { |
1175 | 0 | Ok(msg) => msg.target_number, |
1176 | 0 | Err(_) => return GrandpaCommitMessageOutcome::Discarded, |
1177 | | }; |
1178 | | |
1179 | 0 | warp_sync.set_source_finality_state(inner_source_id, block_number); |
1180 | | } |
1181 | 0 | (None, None) => {} |
1182 | | _ => { |
1183 | | // Invalid internal state. |
1184 | 0 | debug_assert!(false); |
1185 | | } |
1186 | | } |
1187 | | |
1188 | 0 | let Some(all_forks) = &mut self.all_forks else { |
1189 | 0 | unreachable!() |
1190 | | }; |
1191 | 0 | match all_forks.grandpa_commit_message(source_id.all_forks, scale_encoded_message) { |
1192 | | all_forks::GrandpaCommitMessageOutcome::ParseError => { |
1193 | 0 | GrandpaCommitMessageOutcome::Discarded |
1194 | | } |
1195 | 0 | all_forks::GrandpaCommitMessageOutcome::Queued => GrandpaCommitMessageOutcome::Queued, |
1196 | | } |
1197 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE22grandpa_commit_messageB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE22grandpa_commit_messageCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE22grandpa_commit_messageB6_ |
1198 | | |
1199 | | /// Inject a response to a previously-emitted blocks request. |
1200 | | /// |
1201 | | /// The blocks should be provided in decreasing number, with `first_block_hash` as the highest |
1202 | | /// number. |
1203 | | /// |
1204 | | /// # Panic |
1205 | | /// |
1206 | | /// Panics if the [`RequestId`] doesn't correspond to any request, or corresponds to a request |
1207 | | /// of a different type. |
1208 | | /// |
1209 | | // TODO: refactor this function so that the user can know the state of each block |
1210 | 0 | pub fn blocks_request_response( |
1211 | 0 | &mut self, |
1212 | 0 | request_id: RequestId, |
1213 | 0 | blocks: impl Iterator<Item = BlockRequestSuccessBlock<TBl>>, |
1214 | 0 | ) -> (TRq, ResponseOutcome) { |
1215 | 0 | debug_assert!(self.shared.requests.contains(request_id.0)); |
1216 | 0 | let request = self.shared.requests.remove(request_id.0); |
1217 | 0 |
|
1218 | 0 | self.shared.sources[request.source_id.0].num_requests -= 1; |
1219 | 0 |
|
1220 | 0 | let mut blocks_iter = blocks.into_iter(); |
1221 | | |
1222 | 0 | let mut all_forks_blocks_append = if let Some(all_forks_request_id) = request.all_forks { |
1223 | 0 | let Some(all_forks) = self.all_forks.as_mut() else { |
1224 | 0 | unreachable!() |
1225 | | }; |
1226 | 0 | let (_, blocks_append) = all_forks.finish_request(all_forks_request_id); |
1227 | 0 | Some(blocks_append) |
1228 | | } else { |
1229 | 0 | None |
1230 | | }; |
1231 | | |
1232 | 0 | let mut is_first_block = true; |
1233 | | |
1234 | 0 | let outcome = loop { |
1235 | 0 | let block = match blocks_iter.next() { |
1236 | 0 | Some(v) => v, |
1237 | | None => { |
1238 | 0 | if let (true, Some(warp_sync_request_id)) = (is_first_block, request.warp_sync) |
1239 | 0 | { |
1240 | 0 | let Some(warp_sync) = self.warp_sync.as_mut() else { |
1241 | 0 | unreachable!() |
1242 | | }; |
1243 | | // TODO: report source misbehaviour |
1244 | 0 | warp_sync.remove_request(warp_sync_request_id); |
1245 | 0 | } |
1246 | 0 | break ResponseOutcome::Queued; |
1247 | | } |
1248 | | }; |
1249 | | |
1250 | 0 | if let (true, Some(warp_sync_request_id)) = (is_first_block, request.warp_sync) { |
1251 | 0 | let Some(warp_sync) = self.warp_sync.as_mut() else { |
1252 | 0 | unreachable!() |
1253 | | }; |
1254 | 0 | warp_sync.body_download_response( |
1255 | 0 | warp_sync_request_id, |
1256 | 0 | block.scale_encoded_extrinsics.clone(), // TODO: clone? |
1257 | 0 | ); |
1258 | 0 | } |
1259 | | |
1260 | 0 | if let Some(blocks_append) = all_forks_blocks_append { |
1261 | | // TODO: many of the errors don't properly translate here, needs some refactoring |
1262 | 0 | match blocks_append.add_block( |
1263 | 0 | block.scale_encoded_header, |
1264 | 0 | block.scale_encoded_extrinsics, |
1265 | 0 | block |
1266 | 0 | .scale_encoded_justifications |
1267 | 0 | .into_iter() |
1268 | 0 | .map(|j| (j.engine_id, j.justification)), Unexecuted instantiation: _RNCINvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_7AllSyncpppE23blocks_request_responsepE0B9_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE23blocks_request_responseINtNtNtNtCsaYZPK01V26L_4core4iter8adapters10filter_map9FilterMapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB2l_13block_request9BlockDataENCNCINvNtNtCsih6EgvAwZF2_13smoldot_light12sync_service10standalone22start_standalone_chainNtNtCsDDUKWWCHAU_18smoldot_light_wasm8platform11PlatformRefE0sn_0EE0B7o_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncpppE23blocks_request_responsepE0B9_ Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBY_4iter7sources4once4OnceINtB5_24BlockRequestSuccessBlockB2J_EEE0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBY_4iter8adapters3map3MapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtNtNtB9_7network5codec13block_request9BlockDataENCNCNvMs_B1x_NtB1x_14SyncBackground3run0sc_0EE0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBY_4iter7sources4once4OnceINtB5_24BlockRequestSuccessBlockB2J_EEE0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBY_4iter8adapters3map3MapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtNtNtB9_7network5codec13block_request9BlockDataENCNCNvMs_B1x_NtB1x_14SyncBackground3run0sc_0EE0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBY_4iter7sources4once4OnceINtB5_24BlockRequestSuccessBlockB2J_EEE0CsibGXYHQB8Ea_25json_rpc_general_requests Unexecuted instantiation: _RNCINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBY_4iter8adapters3map3MapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtNtNtB9_7network5codec13block_request9BlockDataENCNCNvMs_B1x_NtB1x_14SyncBackground3run0sc_0EE0CsibGXYHQB8Ea_25json_rpc_general_requests |
1269 | 0 | ) { |
1270 | 0 | Ok(all_forks::AddBlock::UnknownBlock(ba)) => { |
1271 | 0 | all_forks_blocks_append = Some(ba.insert(Some(block.user_data))) |
1272 | | } |
1273 | 0 | Ok(all_forks::AddBlock::AlreadyPending(ba)) => { |
1274 | 0 | // TODO: replacing the user data entirely is very opinionated, instead the API of the AllSync should be changed |
1275 | 0 | all_forks_blocks_append = Some(ba.replace(Some(block.user_data)).0) |
1276 | | } |
1277 | 0 | Ok(all_forks::AddBlock::AlreadyInChain(_)) if is_first_block => { |
1278 | 0 | break ResponseOutcome::AllAlreadyInChain; |
1279 | | } |
1280 | | Ok(all_forks::AddBlock::AlreadyInChain(_)) => { |
1281 | 0 | break ResponseOutcome::Queued; |
1282 | | } |
1283 | | Err(all_forks::AncestrySearchResponseError::NotFinalizedChain { |
1284 | 0 | discarded_unverified_block_headers, |
1285 | 0 | }) => { |
1286 | 0 | break ResponseOutcome::NotFinalizedChain { |
1287 | 0 | discarded_unverified_block_headers, |
1288 | 0 | }; |
1289 | | } |
1290 | | Err(_) => { |
1291 | 0 | break ResponseOutcome::Queued; |
1292 | | } |
1293 | | } |
1294 | 0 | } |
1295 | | |
1296 | 0 | is_first_block = false; |
1297 | | }; |
1298 | | |
1299 | 0 | (request.user_data, outcome) |
1300 | 0 | } Unexecuted instantiation: _RINvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB3_7AllSyncpppE23blocks_request_responsepEB7_ Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB7_6libp2p7peer_id6PeerIdNtNtNtNtB7_7network5codec15block_announces4RoleEuE23blocks_request_responseINtNtNtNtCsaYZPK01V26L_4core4iter8adapters10filter_map9FilterMapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtB2j_13block_request9BlockDataENCNCINvNtNtCsih6EgvAwZF2_13smoldot_light12sync_service10standalone22start_standalone_chainNtNtCsDDUKWWCHAU_18smoldot_light_wasm8platform11PlatformRefE0sn_0EEB7m_ Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncpppE23blocks_request_responsepEB7_ Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1v_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBW_4iter7sources4once4OnceINtB3_24BlockRequestSuccessBlockB2H_EEECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1v_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBW_4iter8adapters3map3MapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtNtNtB7_7network5codec13block_request9BlockDataENCNCNvMs_B1v_NtB1v_14SyncBackground3run0sc_0EECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1v_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBW_4iter7sources4once4OnceINtB3_24BlockRequestSuccessBlockB2H_EEECscDgN54JpMGG_6author Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1v_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBW_4iter8adapters3map3MapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtNtNtB7_7network5codec13block_request9BlockDataENCNCNvMs_B1v_NtB1v_14SyncBackground3run0sc_0EECscDgN54JpMGG_6author Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1v_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBW_4iter7sources4once4OnceINtB3_24BlockRequestSuccessBlockB2H_EEECsibGXYHQB8Ea_25json_rpc_general_requests Unexecuted instantiation: _RINvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB3_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1v_17NonFinalizedBlockE23blocks_request_responseINtNtNtNtBW_4iter8adapters3map3MapINtNtNtCsdZExvAaxgia_5alloc3vec9into_iter8IntoIterNtNtNtNtB7_7network5codec13block_request9BlockDataENCNCNvMs_B1v_NtB1v_14SyncBackground3run0sc_0EECsibGXYHQB8Ea_25json_rpc_general_requests |
1301 | | |
1302 | | /// Inject a response to a previously-emitted GrandPa warp sync request. |
1303 | | /// |
1304 | | /// # Panic |
1305 | | /// |
1306 | | /// Panics if the [`RequestId`] doesn't correspond to any request, or corresponds to a request |
1307 | | /// of a different type. |
1308 | | /// |
1309 | 0 | pub fn grandpa_warp_sync_response( |
1310 | 0 | &mut self, |
1311 | 0 | request_id: RequestId, |
1312 | 0 | fragments: Vec<WarpSyncFragment>, |
1313 | 0 | is_finished: bool, |
1314 | 0 | ) -> (TRq, ResponseOutcome) { |
1315 | 0 | debug_assert!(self.shared.requests.contains(request_id.0)); |
1316 | | |
1317 | 0 | let request = self.shared.requests.remove(request_id.0); |
1318 | 0 |
|
1319 | 0 | self.shared.sources[request.source_id.0].num_requests -= 1; |
1320 | | |
1321 | 0 | if let Some(warp_sync_request_id) = request.warp_sync { |
1322 | 0 | self.warp_sync.as_mut().unwrap().warp_sync_request_response( |
1323 | 0 | warp_sync_request_id, |
1324 | 0 | fragments, |
1325 | 0 | is_finished, |
1326 | 0 | ); |
1327 | 0 | } |
1328 | | |
1329 | | // TODO: type of request not always verified |
1330 | | |
1331 | | // TODO: don't always return Queued |
1332 | 0 | (request.user_data, ResponseOutcome::Queued) |
1333 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE26grandpa_warp_sync_responseB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE26grandpa_warp_sync_responseCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE26grandpa_warp_sync_responseB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE26grandpa_warp_sync_responseCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE26grandpa_warp_sync_responseCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE26grandpa_warp_sync_responseCsibGXYHQB8Ea_25json_rpc_general_requests |
1334 | | |
1335 | | /// Inject a response to a previously-emitted storage proof request. |
1336 | | /// |
1337 | | /// # Panic |
1338 | | /// |
1339 | | /// Panics if the [`RequestId`] doesn't correspond to any request, or corresponds to a request |
1340 | | /// of a different type. |
1341 | | /// |
1342 | 0 | pub fn storage_get_response( |
1343 | 0 | &mut self, |
1344 | 0 | request_id: RequestId, |
1345 | 0 | response: Vec<u8>, |
1346 | 0 | ) -> (TRq, ResponseOutcome) { |
1347 | 0 | debug_assert!(self.shared.requests.contains(request_id.0)); |
1348 | | |
1349 | 0 | let request = self.shared.requests.remove(request_id.0); |
1350 | 0 |
|
1351 | 0 | self.shared.sources[request.source_id.0].num_requests -= 1; |
1352 | | |
1353 | 0 | if let Some(warp_sync_request_id) = request.warp_sync { |
1354 | 0 | self.warp_sync |
1355 | 0 | .as_mut() |
1356 | 0 | .unwrap() |
1357 | 0 | .storage_get_response(warp_sync_request_id, response); |
1358 | 0 | } |
1359 | | |
1360 | | // TODO: type of request not always verified |
1361 | | |
1362 | | // TODO: don't always return Queued |
1363 | 0 | (request.user_data, ResponseOutcome::Queued) |
1364 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE20storage_get_responseB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE20storage_get_responseCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE20storage_get_responseB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20storage_get_responseCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20storage_get_responseCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE20storage_get_responseCsibGXYHQB8Ea_25json_rpc_general_requests |
1365 | | |
1366 | | /// Inject a response to a previously-emitted call proof request. |
1367 | | /// |
1368 | | /// On success, must contain the encoded Merkle proof. See the |
1369 | | /// [`trie`](crate::trie) module for a description of the format of Merkle proofs. |
1370 | | /// |
1371 | | /// # Panic |
1372 | | /// |
1373 | | /// Panics if the [`RequestId`] doesn't correspond to any request, or corresponds to a request |
1374 | | /// of a different type. |
1375 | | /// |
1376 | 0 | pub fn call_proof_response( |
1377 | 0 | &mut self, |
1378 | 0 | request_id: RequestId, |
1379 | 0 | response: Vec<u8>, |
1380 | 0 | ) -> (TRq, ResponseOutcome) { |
1381 | 0 | debug_assert!(self.shared.requests.contains(request_id.0)); |
1382 | | |
1383 | 0 | let request = self.shared.requests.remove(request_id.0); |
1384 | 0 |
|
1385 | 0 | self.shared.sources[request.source_id.0].num_requests -= 1; |
1386 | | |
1387 | 0 | if let Some(warp_sync_request_id) = request.warp_sync { |
1388 | 0 | self.warp_sync |
1389 | 0 | .as_mut() |
1390 | 0 | .unwrap() |
1391 | 0 | .runtime_call_merkle_proof_response(warp_sync_request_id, response); |
1392 | 0 | } |
1393 | | |
1394 | | // TODO: type of request not always verified |
1395 | | |
1396 | | // TODO: don't always return Queued |
1397 | 0 | (request.user_data, ResponseOutcome::Queued) |
1398 | 0 | } Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot4sync3allINtB2_7AllSyncpppE19call_proof_responseB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB6_6libp2p7peer_id6PeerIdNtNtNtNtB6_7network5codec15block_announces4RoleEuE19call_proof_responseCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncpppE19call_proof_responseB6_ Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE19call_proof_responseCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE19call_proof_responseCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot4sync3allINtB2_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1u_17NonFinalizedBlockE19call_proof_responseCsibGXYHQB8Ea_25json_rpc_general_requests |
1399 | | } |
1400 | | |
1401 | | impl<TRq, TSrc, TBl> ops::Index<SourceId> for AllSync<TRq, TSrc, TBl> { |
1402 | | type Output = TSrc; |
1403 | | |
1404 | | #[track_caller] |
1405 | 0 | fn index(&self, source_id: SourceId) -> &TSrc { |
1406 | 0 | let Some(SourceMapping { user_data, .. }) = self.shared.sources.get(source_id.0) else { |
1407 | 0 | panic!() |
1408 | | }; |
1409 | | |
1410 | 0 | user_data |
1411 | 0 | } Unexecuted instantiation: _RNvXININtNtCsN16ciHI6Qf_7smoldot4sync3alls_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexNtB5_8SourceIdE5indexB9_ Unexecuted instantiation: _RNvXs_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB8_6libp2p7peer_id6PeerIdNtNtNtNtB8_7network5codec15block_announces4RoleEuEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexNtB4_8SourceIdE5indexCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4sync3alls_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexNtB5_8SourceIdE5indexB9_ Unexecuted instantiation: _RNvXs_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockEINtNtNtBX_3ops5index5IndexNtB4_8SourceIdE5indexCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvXs_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockEINtNtNtBX_3ops5index5IndexNtB4_8SourceIdE5indexCscDgN54JpMGG_6author Unexecuted instantiation: _RNvXs_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB4_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1w_17NonFinalizedBlockEINtNtNtBX_3ops5index5IndexNtB4_8SourceIdE5indexCsibGXYHQB8Ea_25json_rpc_general_requests |
1412 | | } |
1413 | | |
1414 | | impl<TRq, TSrc, TBl> ops::IndexMut<SourceId> for AllSync<TRq, TSrc, TBl> { |
1415 | | #[track_caller] |
1416 | 0 | fn index_mut(&mut self, source_id: SourceId) -> &mut TSrc { |
1417 | 0 | let Some(SourceMapping { user_data, .. }) = self.shared.sources.get_mut(source_id.0) else { |
1418 | 0 | panic!() |
1419 | | }; |
1420 | | |
1421 | 0 | user_data |
1422 | 0 | } Unexecuted instantiation: _RNvXININtNtCsN16ciHI6Qf_7smoldot4sync3alls0_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutNtB5_8SourceIdE9index_mutB9_ Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4sync3alls0_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutNtB5_8SourceIdE9index_mutB9_ Unexecuted instantiation: _RNvXs0_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index8IndexMutNtB5_8SourceIdE9index_mutCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvXs0_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index8IndexMutNtB5_8SourceIdE9index_mutCscDgN54JpMGG_6author Unexecuted instantiation: _RNvXs0_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index8IndexMutNtB5_8SourceIdE9index_mutCsibGXYHQB8Ea_25json_rpc_general_requests |
1423 | | } |
1424 | | |
1425 | | impl<'a, TRq, TSrc, TBl> ops::Index<(u64, &'a [u8; 32])> for AllSync<TRq, TSrc, TBl> { |
1426 | | type Output = TBl; |
1427 | | |
1428 | | #[track_caller] |
1429 | 0 | fn index(&self, (block_height, block_hash): (u64, &'a [u8; 32])) -> &TBl { |
1430 | 0 | let Some(all_forks) = &self.all_forks else { |
1431 | 0 | unreachable!() |
1432 | | }; |
1433 | | |
1434 | 0 | all_forks[(block_height, block_hash)] |
1435 | 0 | .as_ref() |
1436 | 0 | .unwrap_or_else(|| unreachable!()) Unexecuted instantiation: _RNCNvXININtNtCsN16ciHI6Qf_7smoldot4sync3alls1_0pppEINtB7_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexTyRAhj20_EE5index0Bb_ Unexecuted instantiation: _RNCNvXININtNtCseuYC0Zibziv_7smoldot4sync3alls1_0pppEINtB7_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexTyRAhj20_EE5index0Bb_ Unexecuted instantiation: _RNCNvXs1_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockEINtNtNtB10_3ops5index5IndexTyRAhj20_EE5index0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvXs1_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockEINtNtNtB10_3ops5index5IndexTyRAhj20_EE5index0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvXs1_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockEINtNtNtB10_3ops5index5IndexTyRAhj20_EE5index0CsibGXYHQB8Ea_25json_rpc_general_requests |
1437 | 0 | } Unexecuted instantiation: _RNvXININtNtCsN16ciHI6Qf_7smoldot4sync3alls1_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexTyRAhj20_EE5indexB9_ Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4sync3alls1_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index5IndexTyRAhj20_EE5indexB9_ Unexecuted instantiation: _RNvXs1_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index5IndexTyRAhj20_EE5indexCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvXs1_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index5IndexTyRAhj20_EE5indexCscDgN54JpMGG_6author Unexecuted instantiation: _RNvXs1_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index5IndexTyRAhj20_EE5indexCsibGXYHQB8Ea_25json_rpc_general_requests |
1438 | | } |
1439 | | |
1440 | | impl<'a, TRq, TSrc, TBl> ops::IndexMut<(u64, &'a [u8; 32])> for AllSync<TRq, TSrc, TBl> { |
1441 | | #[track_caller] |
1442 | 0 | fn index_mut(&mut self, (block_height, block_hash): (u64, &'a [u8; 32])) -> &mut TBl { |
1443 | 0 | let Some(all_forks) = &mut self.all_forks else { |
1444 | 0 | unreachable!() |
1445 | | }; |
1446 | | |
1447 | 0 | all_forks[(block_height, block_hash)] |
1448 | 0 | .as_mut() |
1449 | 0 | .unwrap_or_else(|| unreachable!()) Unexecuted instantiation: _RNCNvXININtNtCsN16ciHI6Qf_7smoldot4sync3alls2_0pppEINtB7_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutTyRAhj20_EE9index_mut0Bb_ Unexecuted instantiation: _RNCNvXININtNtCseuYC0Zibziv_7smoldot4sync3alls2_0pppEINtB7_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutTyRAhj20_EE9index_mut0Bb_ Unexecuted instantiation: _RNCNvXs2_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockEINtNtNtB10_3ops5index8IndexMutTyRAhj20_EE9index_mut0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvXs2_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockEINtNtNtB10_3ops5index8IndexMutTyRAhj20_EE9index_mut0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvXs2_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockEINtNtNtB10_3ops5index8IndexMutTyRAhj20_EE9index_mut0CsibGXYHQB8Ea_25json_rpc_general_requests |
1450 | 0 | } Unexecuted instantiation: _RNvXININtNtCsN16ciHI6Qf_7smoldot4sync3alls2_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutTyRAhj20_EE9index_mutB9_ Unexecuted instantiation: _RNvXININtNtCseuYC0Zibziv_7smoldot4sync3alls2_0pppEINtB5_7AllSyncpppEINtNtNtCsaYZPK01V26L_4core3ops5index8IndexMutTyRAhj20_EE9index_mutB9_ Unexecuted instantiation: _RNvXs2_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index8IndexMutTyRAhj20_EE9index_mutCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvXs2_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index8IndexMutTyRAhj20_EE9index_mutCscDgN54JpMGG_6author Unexecuted instantiation: _RNvXs2_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_7AllSyncuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1x_17NonFinalizedBlockEINtNtNtBY_3ops5index8IndexMutTyRAhj20_EE9index_mutCsibGXYHQB8Ea_25json_rpc_general_requests |
1451 | | } |
1452 | | |
1453 | | /// Outcome of calling [`AllSync::prepare_add_source`]. |
1454 | | #[must_use] |
1455 | | pub enum AddSource<'a, TRq, TSrc, TBl> { |
1456 | | /// The best block of the source is older or equal to the local latest finalized block. This |
1457 | | /// block isn't tracked by the state machine. |
1458 | | OldBestBlock(AddSourceOldBlock<'a, TRq, TSrc, TBl>), |
1459 | | |
1460 | | /// The best block of the source has already been verified by this state machine. |
1461 | | BestBlockAlreadyVerified(AddSourceKnown<'a, TRq, TSrc, TBl>), |
1462 | | |
1463 | | /// The best block of the source is already known to this state machine but hasn't been |
1464 | | /// verified yet. |
1465 | | BestBlockPendingVerification(AddSourceKnown<'a, TRq, TSrc, TBl>), |
1466 | | |
1467 | | /// The best block of the source isn't in this state machine yet and needs to be inserted. |
1468 | | UnknownBestBlock(AddSourceUnknown<'a, TRq, TSrc, TBl>), |
1469 | | } |
1470 | | |
1471 | | impl<'a, TRq, TSrc, TBl> AddSource<'a, TRq, TSrc, TBl> { |
1472 | | /// Inserts the source, and the best block if it is unknown. |
1473 | | /// |
1474 | | /// The `best_block_user_data` is silently discarded if the block is already known or too old. |
1475 | 21 | pub fn add_source(self, source_user_data: TSrc, best_block_user_data: TBl) -> SourceId { |
1476 | 21 | match self { |
1477 | 0 | AddSource::BestBlockAlreadyVerified(b) => b.add_source(source_user_data), |
1478 | 0 | AddSource::BestBlockPendingVerification(b) => b.add_source(source_user_data), |
1479 | 21 | AddSource::OldBestBlock(b) => b.add_source(source_user_data), |
1480 | 0 | AddSource::UnknownBestBlock(b) => { |
1481 | 0 | b.add_source_and_insert_block(source_user_data, best_block_user_data) |
1482 | | } |
1483 | | } |
1484 | 21 | } Unexecuted instantiation: _RNvMs3_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_9AddSourcepppE10add_sourceB9_ Unexecuted instantiation: _RNvMs3_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_9AddSourceNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE10add_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs3_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_9AddSourcepppE10add_sourceB9_ _RNvMs3_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_9AddSourceuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockE10add_sourceCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1475 | 2 | pub fn add_source(self, source_user_data: TSrc, best_block_user_data: TBl) -> SourceId { | 1476 | 2 | match self { | 1477 | 0 | AddSource::BestBlockAlreadyVerified(b) => b.add_source(source_user_data), | 1478 | 0 | AddSource::BestBlockPendingVerification(b) => b.add_source(source_user_data), | 1479 | 2 | AddSource::OldBestBlock(b) => b.add_source(source_user_data), | 1480 | 0 | AddSource::UnknownBestBlock(b) => { | 1481 | 0 | b.add_source_and_insert_block(source_user_data, best_block_user_data) | 1482 | | } | 1483 | | } | 1484 | 2 | } |
Unexecuted instantiation: _RNvMs3_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_9AddSourceuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockE10add_sourceCscDgN54JpMGG_6author _RNvMs3_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_9AddSourceuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1z_17NonFinalizedBlockE10add_sourceCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1475 | 19 | pub fn add_source(self, source_user_data: TSrc, best_block_user_data: TBl) -> SourceId { | 1476 | 19 | match self { | 1477 | 0 | AddSource::BestBlockAlreadyVerified(b) => b.add_source(source_user_data), | 1478 | 0 | AddSource::BestBlockPendingVerification(b) => b.add_source(source_user_data), | 1479 | 19 | AddSource::OldBestBlock(b) => b.add_source(source_user_data), | 1480 | 0 | AddSource::UnknownBestBlock(b) => { | 1481 | 0 | b.add_source_and_insert_block(source_user_data, best_block_user_data) | 1482 | | } | 1483 | | } | 1484 | 19 | } |
|
1485 | | } |
1486 | | |
1487 | | /// See [`AddSource`] and [`AllSync::prepare_add_source`]. |
1488 | | #[must_use] |
1489 | | pub struct AddSourceOldBlock<'a, TRq, TSrc, TBl> { |
1490 | | slab_insertion: slab::VacantEntry<'a, SourceMapping<TSrc>>, |
1491 | | all_forks: |
1492 | | all_forks::AddSourceOldBlock<'a, Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
1493 | | warp_sync: &'a mut Option<warp_sync::WarpSync<WarpSyncSourceExtra, WarpSyncRequestExtra>>, |
1494 | | marker: PhantomData<TRq>, |
1495 | | } |
1496 | | |
1497 | | impl<'a, TRq, TSrc, TBl> AddSourceOldBlock<'a, TRq, TSrc, TBl> { |
1498 | | /// Inserts a new source in the state machine. |
1499 | | /// |
1500 | | /// Returns the newly-allocated identifier for that source. |
1501 | | /// |
1502 | | /// The `user_data` parameter is opaque and decided entirely by the user. It can later be |
1503 | | /// retrieved using the `Index` trait implementation of the [`AllSync`]. |
1504 | 21 | pub fn add_source(self, source_user_data: TSrc) -> SourceId { |
1505 | 21 | let outer_source_id = SourceId(self.slab_insertion.key()); |
1506 | 21 | |
1507 | 21 | let all_forks_source_id = self |
1508 | 21 | .all_forks |
1509 | 21 | .add_source(AllForksSourceExtra { outer_source_id }); |
1510 | | |
1511 | 21 | let warp_sync_source_id = if let Some(warp_sync) = self.warp_sync { |
1512 | 21 | Some(warp_sync.add_source(WarpSyncSourceExtra { outer_source_id })) |
1513 | | } else { |
1514 | 0 | None |
1515 | | }; |
1516 | | |
1517 | 21 | self.slab_insertion.insert(SourceMapping { |
1518 | 21 | warp_sync: warp_sync_source_id, |
1519 | 21 | all_forks: all_forks_source_id, |
1520 | 21 | user_data: source_user_data, |
1521 | 21 | num_requests: 0, |
1522 | 21 | }); |
1523 | 21 | |
1524 | 21 | outer_source_id |
1525 | 21 | } Unexecuted instantiation: _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_17AddSourceOldBlockpppE10add_sourceB9_ Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_17AddSourceOldBlockNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE10add_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_17AddSourceOldBlockpppE10add_sourceB9_ _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_17AddSourceOldBlockuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1I_17NonFinalizedBlockE10add_sourceCsiLzmwikkc22_14json_rpc_basic Line | Count | Source | 1504 | 2 | pub fn add_source(self, source_user_data: TSrc) -> SourceId { | 1505 | 2 | let outer_source_id = SourceId(self.slab_insertion.key()); | 1506 | 2 | | 1507 | 2 | let all_forks_source_id = self | 1508 | 2 | .all_forks | 1509 | 2 | .add_source(AllForksSourceExtra { outer_source_id }); | 1510 | | | 1511 | 2 | let warp_sync_source_id = if let Some(warp_sync) = self.warp_sync { | 1512 | 2 | Some(warp_sync.add_source(WarpSyncSourceExtra { outer_source_id })) | 1513 | | } else { | 1514 | 0 | None | 1515 | | }; | 1516 | | | 1517 | 2 | self.slab_insertion.insert(SourceMapping { | 1518 | 2 | warp_sync: warp_sync_source_id, | 1519 | 2 | all_forks: all_forks_source_id, | 1520 | 2 | user_data: source_user_data, | 1521 | 2 | num_requests: 0, | 1522 | 2 | }); | 1523 | 2 | | 1524 | 2 | outer_source_id | 1525 | 2 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_17AddSourceOldBlockuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1I_17NonFinalizedBlockE10add_sourceCscDgN54JpMGG_6author _RNvMs4_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_17AddSourceOldBlockuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1I_17NonFinalizedBlockE10add_sourceCsibGXYHQB8Ea_25json_rpc_general_requests Line | Count | Source | 1504 | 19 | pub fn add_source(self, source_user_data: TSrc) -> SourceId { | 1505 | 19 | let outer_source_id = SourceId(self.slab_insertion.key()); | 1506 | 19 | | 1507 | 19 | let all_forks_source_id = self | 1508 | 19 | .all_forks | 1509 | 19 | .add_source(AllForksSourceExtra { outer_source_id }); | 1510 | | | 1511 | 19 | let warp_sync_source_id = if let Some(warp_sync) = self.warp_sync { | 1512 | 19 | Some(warp_sync.add_source(WarpSyncSourceExtra { outer_source_id })) | 1513 | | } else { | 1514 | 0 | None | 1515 | | }; | 1516 | | | 1517 | 19 | self.slab_insertion.insert(SourceMapping { | 1518 | 19 | warp_sync: warp_sync_source_id, | 1519 | 19 | all_forks: all_forks_source_id, | 1520 | 19 | user_data: source_user_data, | 1521 | 19 | num_requests: 0, | 1522 | 19 | }); | 1523 | 19 | | 1524 | 19 | outer_source_id | 1525 | 19 | } |
|
1526 | | } |
1527 | | |
1528 | | /// See [`AddSource`] and [`AllSync::prepare_add_source`]. |
1529 | | #[must_use] |
1530 | | pub struct AddSourceKnown<'a, TRq, TSrc, TBl> { |
1531 | | slab_insertion: slab::VacantEntry<'a, SourceMapping<TSrc>>, |
1532 | | all_forks: |
1533 | | all_forks::AddSourceKnown<'a, Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
1534 | | warp_sync: &'a mut Option<warp_sync::WarpSync<WarpSyncSourceExtra, WarpSyncRequestExtra>>, |
1535 | | marker: PhantomData<TRq>, |
1536 | | } |
1537 | | |
1538 | | impl<'a, TRq, TSrc, TBl> AddSourceKnown<'a, TRq, TSrc, TBl> { |
1539 | | /// Gives access to the user data of the block. |
1540 | 0 | pub fn user_data_mut(&mut self) -> &mut TBl { |
1541 | 0 | self.all_forks |
1542 | 0 | .user_data_mut() |
1543 | 0 | .as_mut() |
1544 | 0 | .unwrap_or_else(|| unreachable!()) Unexecuted instantiation: _RNCNvMs5_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB7_14AddSourceKnownpppE13user_data_mut0Bb_ Unexecuted instantiation: _RNCNvMs5_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_14AddSourceKnownpppE13user_data_mut0Bb_ |
1545 | 0 | } Unexecuted instantiation: _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_14AddSourceKnownpppE13user_data_mutB9_ Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_14AddSourceKnownpppE13user_data_mutB9_ |
1546 | | |
1547 | | /// Inserts a new source in the state machine. |
1548 | | /// |
1549 | | /// Returns the newly-allocated identifier for that source. |
1550 | | /// |
1551 | | /// The `user_data` parameter is opaque and decided entirely by the user. It can later be |
1552 | | /// retrieved using the `Index` trait implementation of the [`AllForksSync`]. |
1553 | 0 | pub fn add_source(self, source_user_data: TSrc) -> SourceId { |
1554 | 0 | let outer_source_id = SourceId(self.slab_insertion.key()); |
1555 | 0 |
|
1556 | 0 | let all_forks_source_id = self |
1557 | 0 | .all_forks |
1558 | 0 | .add_source(AllForksSourceExtra { outer_source_id }); |
1559 | | |
1560 | 0 | let warp_sync_source_id = if let Some(warp_sync) = self.warp_sync { |
1561 | 0 | Some(warp_sync.add_source(WarpSyncSourceExtra { outer_source_id })) |
1562 | | } else { |
1563 | 0 | None |
1564 | | }; |
1565 | | |
1566 | 0 | self.slab_insertion.insert(SourceMapping { |
1567 | 0 | warp_sync: warp_sync_source_id, |
1568 | 0 | all_forks: all_forks_source_id, |
1569 | 0 | user_data: source_user_data, |
1570 | 0 | num_requests: 0, |
1571 | 0 | }); |
1572 | 0 |
|
1573 | 0 | outer_source_id |
1574 | 0 | } Unexecuted instantiation: _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_14AddSourceKnownpppE10add_sourceB9_ Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_14AddSourceKnownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE10add_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_14AddSourceKnownpppE10add_sourceB9_ Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_14AddSourceKnownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1F_17NonFinalizedBlockE10add_sourceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_14AddSourceKnownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1F_17NonFinalizedBlockE10add_sourceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs5_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_14AddSourceKnownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1F_17NonFinalizedBlockE10add_sourceCsibGXYHQB8Ea_25json_rpc_general_requests |
1575 | | } |
1576 | | |
1577 | | /// See [`AddSource`] and [`AllSync::prepare_add_source`]. |
1578 | | #[must_use] |
1579 | | pub struct AddSourceUnknown<'a, TRq, TSrc, TBl> { |
1580 | | slab_insertion: slab::VacantEntry<'a, SourceMapping<TSrc>>, |
1581 | | all_forks: |
1582 | | all_forks::AddSourceUnknown<'a, Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
1583 | | warp_sync: &'a mut Option<warp_sync::WarpSync<WarpSyncSourceExtra, WarpSyncRequestExtra>>, |
1584 | | marker: PhantomData<TRq>, |
1585 | | } |
1586 | | |
1587 | | impl<'a, TRq, TSrc, TBl> AddSourceUnknown<'a, TRq, TSrc, TBl> { |
1588 | | /// Inserts a new source in the state machine, plus the best block of that source. |
1589 | | /// |
1590 | | /// Returns the newly-allocated identifier for that source. |
1591 | | /// |
1592 | | /// The `source_user_data` parameter is opaque and decided entirely by the user. It can later |
1593 | | /// be retrieved using the `Index` trait implementation of the [`AllForksSync`]. |
1594 | | /// |
1595 | | /// The `best_block_user_data` parameter is opaque and decided entirely by the user and is |
1596 | | /// associated with the best block of the newly-added source. |
1597 | 0 | pub fn add_source_and_insert_block( |
1598 | 0 | self, |
1599 | 0 | source_user_data: TSrc, |
1600 | 0 | best_block_user_data: TBl, |
1601 | 0 | ) -> SourceId { |
1602 | 0 | let outer_source_id = SourceId(self.slab_insertion.key()); |
1603 | 0 |
|
1604 | 0 | let all_forks_source_id = self.all_forks.add_source_and_insert_block( |
1605 | 0 | AllForksSourceExtra { outer_source_id }, |
1606 | 0 | Some(best_block_user_data), |
1607 | 0 | ); |
1608 | | |
1609 | 0 | let warp_sync_source_id = if let Some(warp_sync) = self.warp_sync { |
1610 | 0 | Some(warp_sync.add_source(WarpSyncSourceExtra { outer_source_id })) |
1611 | | } else { |
1612 | 0 | None |
1613 | | }; |
1614 | | |
1615 | 0 | self.slab_insertion.insert(SourceMapping { |
1616 | 0 | warp_sync: warp_sync_source_id, |
1617 | 0 | all_forks: all_forks_source_id, |
1618 | 0 | user_data: source_user_data, |
1619 | 0 | num_requests: 0, |
1620 | 0 | }); |
1621 | 0 |
|
1622 | 0 | outer_source_id |
1623 | 0 | } Unexecuted instantiation: _RNvMs6_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_16AddSourceUnknownpppE27add_source_and_insert_blockB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_16AddSourceUnknownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE27add_source_and_insert_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_16AddSourceUnknownpppE27add_source_and_insert_blockB9_ Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_16AddSourceUnknownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1H_17NonFinalizedBlockE27add_source_and_insert_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_16AddSourceUnknownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1H_17NonFinalizedBlockE27add_source_and_insert_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs6_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_16AddSourceUnknownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1H_17NonFinalizedBlockE27add_source_and_insert_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
1624 | | } |
1625 | | |
1626 | | /// See [`AllSync::desired_requests`]. |
1627 | | #[derive(Debug, Clone, PartialEq, Eq)] |
1628 | | #[must_use] |
1629 | | pub enum DesiredRequest { |
1630 | | /// Requesting blocks from the source is requested. |
1631 | | /// |
1632 | | /// The blocks should be provided in decreasing number, with `first_block_hash` as the highest |
1633 | | /// number. |
1634 | | BlocksRequest { |
1635 | | /// Height of the first block to request. |
1636 | | first_block_height: u64, |
1637 | | /// Hash of the first block to request. |
1638 | | first_block_hash: [u8; 32], |
1639 | | /// Number of blocks the request should return. |
1640 | | /// |
1641 | | /// Note that this is only an indication, and the source is free to give fewer blocks |
1642 | | /// than requested. |
1643 | | /// |
1644 | | /// This might be equal to `u64::MAX` in case no upper bound is required. The API |
1645 | | /// user is responsible for clamping this value to a reasonable limit. |
1646 | | num_blocks: NonZeroU64, |
1647 | | /// `True` if headers should be included in the response. |
1648 | | request_headers: bool, |
1649 | | /// `True` if bodies should be included in the response. |
1650 | | request_bodies: bool, |
1651 | | /// `True` if the justification should be included in the response, if any. |
1652 | | request_justification: bool, |
1653 | | }, |
1654 | | |
1655 | | /// Sending a Grandpa warp sync request is requested. |
1656 | | WarpSync { |
1657 | | /// Hash of the known finalized block. Starting point of the request. |
1658 | | sync_start_block_hash: [u8; 32], |
1659 | | }, |
1660 | | |
1661 | | /// Sending a storage query is requested. |
1662 | | StorageGetMerkleProof { |
1663 | | /// Hash of the block whose storage is requested. |
1664 | | block_hash: [u8; 32], |
1665 | | /// Merkle value of the root of the storage trie of the block. |
1666 | | state_trie_root: [u8; 32], |
1667 | | /// Keys whose values is requested. |
1668 | | keys: Vec<Vec<u8>>, |
1669 | | }, |
1670 | | |
1671 | | /// Sending a call proof query is requested. |
1672 | | RuntimeCallMerkleProof { |
1673 | | /// Hash of the block whose call is made against. |
1674 | | block_hash: [u8; 32], |
1675 | | /// Name of the function to be called. |
1676 | | function_name: Cow<'static, str>, |
1677 | | /// Concatenated SCALE-encoded parameters to provide to the call. |
1678 | | parameter_vectored: Cow<'static, [u8]>, |
1679 | | }, |
1680 | | } |
1681 | | |
1682 | | /// See [`AllSync::desired_requests`]. |
1683 | | #[derive(Debug, Clone, PartialEq, Eq)] |
1684 | | #[must_use] |
1685 | | pub enum RequestDetail { |
1686 | | /// Requesting blocks from the source is requested. |
1687 | | BlocksRequest { |
1688 | | /// Height of the first block to request. |
1689 | | first_block_height: u64, |
1690 | | /// Hash of the first block to request. |
1691 | | first_block_hash: [u8; 32], |
1692 | | /// Number of blocks the request should return. |
1693 | | /// |
1694 | | /// Note that this is only an indication, and the source is free to give fewer blocks |
1695 | | /// than requested. |
1696 | | /// |
1697 | | /// This might be equal to `u64::MAX` in case no upper bound is required. The API |
1698 | | /// user is responsible for clamping this value to a reasonable limit. |
1699 | | num_blocks: NonZeroU64, |
1700 | | /// `True` if headers should be included in the response. |
1701 | | request_headers: bool, |
1702 | | /// `True` if bodies should be included in the response. |
1703 | | request_bodies: bool, |
1704 | | /// `True` if the justification should be included in the response, if any. |
1705 | | request_justification: bool, |
1706 | | }, |
1707 | | |
1708 | | /// Sending a Grandpa warp sync request is requested. |
1709 | | WarpSync { |
1710 | | /// Hash of the known finalized block. Starting point of the request. |
1711 | | sync_start_block_hash: [u8; 32], |
1712 | | }, |
1713 | | |
1714 | | /// Sending a storage query is requested. |
1715 | | StorageGet { |
1716 | | /// Hash of the block whose storage is requested. |
1717 | | block_hash: [u8; 32], |
1718 | | /// Keys whose values is requested. |
1719 | | keys: Vec<Vec<u8>>, |
1720 | | }, |
1721 | | |
1722 | | /// Sending a call proof query is requested. |
1723 | | RuntimeCallMerkleProof { |
1724 | | /// Hash of the block whose call is made against. |
1725 | | block_hash: [u8; 32], |
1726 | | /// Name of the function to be called. |
1727 | | function_name: Cow<'static, str>, |
1728 | | /// Concatenated SCALE-encoded parameters to provide to the call. |
1729 | | parameter_vectored: Cow<'static, [u8]>, |
1730 | | }, |
1731 | | } |
1732 | | |
1733 | | impl From<DesiredRequest> for RequestDetail { |
1734 | 0 | fn from(rq: DesiredRequest) -> RequestDetail { |
1735 | 0 | match rq { |
1736 | | DesiredRequest::BlocksRequest { |
1737 | 0 | first_block_height, |
1738 | 0 | first_block_hash, |
1739 | 0 | num_blocks, |
1740 | 0 | request_headers, |
1741 | 0 | request_bodies, |
1742 | 0 | request_justification, |
1743 | 0 | } => RequestDetail::BlocksRequest { |
1744 | 0 | first_block_height, |
1745 | 0 | first_block_hash, |
1746 | 0 | num_blocks, |
1747 | 0 | request_headers, |
1748 | 0 | request_bodies, |
1749 | 0 | request_justification, |
1750 | 0 | }, |
1751 | | DesiredRequest::WarpSync { |
1752 | 0 | sync_start_block_hash, |
1753 | 0 | } => RequestDetail::WarpSync { |
1754 | 0 | sync_start_block_hash, |
1755 | 0 | }, |
1756 | | DesiredRequest::StorageGetMerkleProof { |
1757 | 0 | block_hash, keys, .. |
1758 | 0 | } => RequestDetail::StorageGet { block_hash, keys }, |
1759 | | DesiredRequest::RuntimeCallMerkleProof { |
1760 | 0 | block_hash, |
1761 | 0 | function_name, |
1762 | 0 | parameter_vectored, |
1763 | 0 | } => RequestDetail::RuntimeCallMerkleProof { |
1764 | 0 | block_hash, |
1765 | 0 | function_name, |
1766 | 0 | parameter_vectored, |
1767 | 0 | }, |
1768 | | } |
1769 | 0 | } Unexecuted instantiation: _RNvXs7_NtNtCsN16ciHI6Qf_7smoldot4sync3allNtB5_13RequestDetailINtNtCsaYZPK01V26L_4core7convert4FromNtB5_14DesiredRequestE4from Unexecuted instantiation: _RNvXs7_NtNtCseuYC0Zibziv_7smoldot4sync3allNtB5_13RequestDetailINtNtCsaYZPK01V26L_4core7convert4FromNtB5_14DesiredRequestE4from |
1770 | | } |
1771 | | |
1772 | | pub struct BlockRequestSuccessBlock<TBl> { |
1773 | | pub scale_encoded_header: Vec<u8>, |
1774 | | pub scale_encoded_justifications: Vec<Justification>, |
1775 | | pub scale_encoded_extrinsics: Vec<Vec<u8>>, |
1776 | | pub user_data: TBl, |
1777 | | } |
1778 | | |
1779 | | /// See [`BlockRequestSuccessBlock::scale_encoded_justifications`]. |
1780 | | #[derive(Debug, Clone, PartialEq, Eq)] |
1781 | | pub struct Justification { |
1782 | | /// Short identifier of the consensus engine associated with that justification. |
1783 | | pub engine_id: [u8; 4], |
1784 | | /// Body of the justification. |
1785 | | pub justification: Vec<u8>, |
1786 | | } |
1787 | | |
1788 | | /// Outcome of calling [`AllSync::block_announce`]. |
1789 | | pub enum BlockAnnounceOutcome<'a, TRq, TSrc, TBl> { |
1790 | | /// Announced block is too old to be part of the finalized chain. |
1791 | | /// |
1792 | | /// It is assumed that all sources will eventually agree on the same finalized chain. Blocks |
1793 | | /// whose height is inferior to the height of the latest known finalized block should simply |
1794 | | /// be ignored. Whether or not this old block is indeed part of the finalized block isn't |
1795 | | /// verified, and it is assumed that the source is simply late. |
1796 | | /// |
1797 | | /// If the announced block was the source's best block, the state machine has been updated to |
1798 | | /// take this information into account. |
1799 | | TooOld { |
1800 | | /// Height of the announced block. |
1801 | | announce_block_height: u64, |
1802 | | /// Height of the currently finalized block. |
1803 | | finalized_block_height: u64, |
1804 | | }, |
1805 | | |
1806 | | /// Announced block has already been successfully verified and is part of the non-finalized |
1807 | | /// chain. |
1808 | | AlreadyVerified(AnnouncedBlockKnown<'a, TRq, TSrc, TBl>), |
1809 | | |
1810 | | /// Announced block is already known by the state machine but hasn't been verified yet. |
1811 | | AlreadyPending(AnnouncedBlockKnown<'a, TRq, TSrc, TBl>), |
1812 | | |
1813 | | /// Announced block isn't in the state machine. |
1814 | | Unknown(AnnouncedBlockUnknown<'a, TRq, TSrc, TBl>), |
1815 | | |
1816 | | /// Failed to decode announce header. |
1817 | | InvalidHeader(header::Error), |
1818 | | } |
1819 | | |
1820 | | /// See [`BlockAnnounceOutcome`] and [`AllSync::block_announce`]. |
1821 | | #[must_use] |
1822 | | pub struct AnnouncedBlockKnown<'a, TRq, TSrc, TBl> { |
1823 | | inner: |
1824 | | all_forks::AnnouncedBlockKnown<'a, Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
1825 | | marker: PhantomData<(TSrc, TRq)>, |
1826 | | } |
1827 | | |
1828 | | impl<'a, TRq, TSrc, TBl> AnnouncedBlockKnown<'a, TRq, TSrc, TBl> { |
1829 | | /// Returns the parent hash of the announced block. |
1830 | 0 | pub fn parent_hash(&self) -> &[u8; 32] { |
1831 | 0 | self.inner.parent_hash() |
1832 | 0 | } Unexecuted instantiation: _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE11parent_hashB9_ Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE11parent_hashCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE11parent_hashB9_ |
1833 | | |
1834 | | /// Returns the height of the announced block. |
1835 | 0 | pub fn height(&self) -> u64 { |
1836 | 0 | self.inner.height() |
1837 | 0 | } Unexecuted instantiation: _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE6heightB9_ Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE6heightCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE6heightB9_ |
1838 | | |
1839 | | /// Returns the hash of the announced block. |
1840 | 0 | pub fn hash(&self) -> &[u8; 32] { |
1841 | 0 | self.inner.hash() |
1842 | 0 | } Unexecuted instantiation: _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE4hashB9_ Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE4hashCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE4hashB9_ |
1843 | | |
1844 | | /// Gives access to the user data of the block. |
1845 | 0 | pub fn user_data_mut(&mut self) -> &mut TBl { |
1846 | 0 | self.inner |
1847 | 0 | .user_data_mut() |
1848 | 0 | .as_mut() |
1849 | 0 | .unwrap_or_else(|| unreachable!()) Unexecuted instantiation: _RNCNvMs8_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB7_19AnnouncedBlockKnownpppE13user_data_mut0Bb_ Unexecuted instantiation: _RNCNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19AnnouncedBlockKnownpppE13user_data_mut0Bb_ |
1850 | 0 | } Unexecuted instantiation: _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE13user_data_mutB9_ Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE13user_data_mutB9_ |
1851 | | |
1852 | | /// Updates the state machine to keep track of the fact that this source knows this block. |
1853 | | /// If the announced block is the source's best block, also updates this information. |
1854 | 0 | pub fn update_source_and_block(self) { |
1855 | 0 | self.inner.update_source_and_block() |
1856 | 0 | } Unexecuted instantiation: _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE23update_source_and_blockB9_ Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE23update_source_and_blockCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownpppE23update_source_and_blockB9_ Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE23update_source_and_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE23update_source_and_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs8_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19AnnouncedBlockKnownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE23update_source_and_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
1857 | | } |
1858 | | |
1859 | | /// See [`BlockAnnounceOutcome`] and [`AllForksSync::block_announce`]. |
1860 | | #[must_use] |
1861 | | pub struct AnnouncedBlockUnknown<'a, TRq, TSrc, TBl> { |
1862 | | inner: all_forks::AnnouncedBlockUnknown< |
1863 | | 'a, |
1864 | | Option<TBl>, |
1865 | | AllForksRequestExtra, |
1866 | | AllForksSourceExtra, |
1867 | | >, |
1868 | | marker: PhantomData<(TSrc, TRq)>, |
1869 | | } |
1870 | | |
1871 | | impl<'a, TRq, TSrc, TBl> AnnouncedBlockUnknown<'a, TRq, TSrc, TBl> { |
1872 | | /// Returns the parent hash of the announced block. |
1873 | 0 | pub fn parent_hash(&self) -> &[u8; 32] { |
1874 | 0 | self.inner.parent_hash() |
1875 | 0 | } Unexecuted instantiation: _RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE11parent_hashB9_ Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE11parent_hashCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE11parent_hashB9_ |
1876 | | |
1877 | | /// Returns the height of the announced block. |
1878 | 0 | pub fn height(&self) -> u64 { |
1879 | 0 | self.inner.height() |
1880 | 0 | } Unexecuted instantiation: _RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE6heightB9_ Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE6heightCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE6heightB9_ |
1881 | | |
1882 | | /// Returns the hash of the announced block. |
1883 | 0 | pub fn hash(&self) -> &[u8; 32] { |
1884 | 0 | self.inner.hash() |
1885 | 0 | } Unexecuted instantiation: _RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE4hashB9_ Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE4hashCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE4hashB9_ |
1886 | | |
1887 | | /// Inserts the block in the state machine and keeps track of the fact that this source knows |
1888 | | /// this block. |
1889 | | /// |
1890 | | /// If the announced block is the source's best block, also updates this information. |
1891 | 0 | pub fn insert_and_update_source(self, user_data: TBl) { |
1892 | 0 | self.inner.insert_and_update_source(Some(user_data)) |
1893 | 0 | } Unexecuted instantiation: _RNvMs9_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE24insert_and_update_sourceB9_ Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE24insert_and_update_sourceCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownpppE24insert_and_update_sourceB9_ Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE24insert_and_update_sourceCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE24insert_and_update_sourceCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMs9_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_21AnnouncedBlockUnknownuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE24insert_and_update_sourceCsibGXYHQB8Ea_25json_rpc_general_requests |
1894 | | } |
1895 | | |
1896 | | /// Response to a GrandPa warp sync request. |
1897 | | #[derive(Debug)] |
1898 | | pub struct WarpSyncResponseFragment<'a> { |
1899 | | /// Header of a block in the chain. |
1900 | | pub scale_encoded_header: &'a [u8], |
1901 | | |
1902 | | /// Justification that proves the finality of |
1903 | | /// [`WarpSyncResponseFragment::scale_encoded_header`]. |
1904 | | pub scale_encoded_justification: &'a [u8], |
1905 | | } |
1906 | | |
1907 | | /// Outcome of calling [`AllSync::process_one`]. |
1908 | | pub enum ProcessOne<TRq, TSrc, TBl> { |
1909 | | /// No block ready to be processed. |
1910 | | AllSync(AllSync<TRq, TSrc, TBl>), |
1911 | | |
1912 | | /// Building the runtime is necessary in order for the warp syncing to continue. |
1913 | | WarpSyncBuildRuntime(WarpSyncBuildRuntime<TRq, TSrc, TBl>), |
1914 | | |
1915 | | /// Building the chain information is necessary in order for the warp syncing to continue. |
1916 | | WarpSyncBuildChainInformation(WarpSyncBuildChainInformation<TRq, TSrc, TBl>), |
1917 | | |
1918 | | /// Response has made it possible to finish warp syncing. |
1919 | | WarpSyncFinished { |
1920 | | sync: AllSync<TRq, TSrc, TBl>, |
1921 | | |
1922 | | /// Runtime of the newly finalized block. |
1923 | | /// |
1924 | | /// > **Note**: Use methods such as [`AllSync::finalized_block_header`] to know which |
1925 | | /// > block this runtime corresponds to. |
1926 | | finalized_block_runtime: host::HostVmPrototype, |
1927 | | |
1928 | | /// SCALE-encoded extrinsics of the finalized block. The ordering is important. |
1929 | | /// |
1930 | | /// `Some` if and only if [`Config::download_bodies`] was `true`. |
1931 | | finalized_body: Option<Vec<Vec<u8>>>, |
1932 | | |
1933 | | /// Storage value at the `:code` key of the finalized block. |
1934 | | finalized_storage_code: Option<Vec<u8>>, |
1935 | | |
1936 | | /// Storage value at the `:heappages` key of the finalized block. |
1937 | | finalized_storage_heap_pages: Option<Vec<u8>>, |
1938 | | |
1939 | | /// Merkle value of the `:code` trie node of the finalized block. |
1940 | | finalized_storage_code_merkle_value: Option<Vec<u8>>, |
1941 | | |
1942 | | /// Closest ancestor of the `:code` trie node of the finalized block excluding `:code` |
1943 | | /// itself. |
1944 | | finalized_storage_code_closest_ancestor_excluding: Option<Vec<Nibble>>, |
1945 | | }, |
1946 | | |
1947 | | /// Ready to start verifying a block. |
1948 | | VerifyBlock(BlockVerify<TRq, TSrc, TBl>), |
1949 | | |
1950 | | /// Ready to start verifying a proof of finality. |
1951 | | VerifyFinalityProof(FinalityProofVerify<TRq, TSrc, TBl>), |
1952 | | |
1953 | | /// Ready to start verifying a warp sync fragment. |
1954 | | VerifyWarpSyncFragment(WarpSyncFragmentVerify<TRq, TSrc, TBl>), |
1955 | | } |
1956 | | |
1957 | | /// Outcome of injecting a response in the [`AllSync`]. |
1958 | | pub enum ResponseOutcome { |
1959 | | /// Request was no longer interesting for the state machine. |
1960 | | Outdated, |
1961 | | |
1962 | | /// Content of the response has been queued and will be processed later. |
1963 | | Queued, |
1964 | | |
1965 | | /// Source has given blocks that aren't part of the finalized chain. |
1966 | | /// |
1967 | | /// This doesn't necessarily mean that the source is malicious or uses a different chain. It |
1968 | | /// is possible for this to legitimately happen, for example if the finalized chain has been |
1969 | | /// updated while the ancestry search was in progress. |
1970 | | NotFinalizedChain { |
1971 | | /// List of block headers that were pending verification and that have now been discarded |
1972 | | /// since it has been found out that they don't belong to the finalized chain. |
1973 | | discarded_unverified_block_headers: Vec<Vec<u8>>, |
1974 | | }, |
1975 | | |
1976 | | /// All blocks in the ancestry search response were already in the list of verified blocks. |
1977 | | /// |
1978 | | /// This can happen if a block announce or different ancestry search response has been |
1979 | | /// processed in between the request and response. |
1980 | | AllAlreadyInChain, |
1981 | | } |
1982 | | |
1983 | | /// See [`AllSync::grandpa_commit_message`]. |
1984 | | #[derive(Debug, Clone, PartialEq, Eq)] |
1985 | | pub enum GrandpaCommitMessageOutcome { |
1986 | | /// Message has been silently discarded. |
1987 | | Discarded, |
1988 | | /// Message has been queued for later verification. |
1989 | | Queued, |
1990 | | } |
1991 | | |
1992 | | // TODO: doc |
1993 | | #[derive(Debug, Clone)] |
1994 | | pub struct Block<TBl> { |
1995 | | /// Header of the block. |
1996 | | pub header: Vec<u8>, |
1997 | | |
1998 | | /// Hash of the block. |
1999 | | pub block_hash: [u8; 32], |
2000 | | |
2001 | | /// User data associated to the block. |
2002 | | pub user_data: TBl, |
2003 | | } |
2004 | | |
2005 | | pub struct BlockVerify<TRq, TSrc, TBl> { |
2006 | | inner: all_forks::BlockVerify<Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
2007 | | warp_sync: Option<warp_sync::WarpSync<WarpSyncSourceExtra, WarpSyncRequestExtra>>, |
2008 | | ready_to_transition: Option<warp_sync::RuntimeInformation>, |
2009 | | shared: Shared<TRq, TSrc>, |
2010 | | } |
2011 | | |
2012 | | impl<TRq, TSrc, TBl> BlockVerify<TRq, TSrc, TBl> { |
2013 | | /// Returns the hash of the block to be verified. |
2014 | 0 | pub fn hash(&self) -> [u8; 32] { |
2015 | 0 | // TODO: return by ref |
2016 | 0 | *self.inner.hash() |
2017 | 0 | } Unexecuted instantiation: _RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_11BlockVerifypppE4hashB9_ Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE4hashCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifypppE4hashB9_ Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1C_17NonFinalizedBlockE4hashCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1C_17NonFinalizedBlockE4hashCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1C_17NonFinalizedBlockE4hashCsibGXYHQB8Ea_25json_rpc_general_requests |
2018 | | |
2019 | | /// Returns the list of SCALE-encoded extrinsics of the block to verify. |
2020 | | /// |
2021 | | /// This is `Some` if and only if [`Config::download_bodies`] is `true` |
2022 | 0 | pub fn scale_encoded_extrinsics( |
2023 | 0 | &'_ self, |
2024 | 0 | ) -> Option<impl ExactSizeIterator<Item = impl AsRef<[u8]> + Clone + '_> + Clone + '_> { |
2025 | 0 | self.inner.scale_encoded_extrinsics() |
2026 | 0 | } Unexecuted instantiation: _RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_11BlockVerifypppE24scale_encoded_extrinsicsB9_ Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifypppE24scale_encoded_extrinsicsB9_ |
2027 | | |
2028 | | /// Returns the SCALE-encoded header of the block about to be verified. |
2029 | 0 | pub fn scale_encoded_header(&self) -> &[u8] { |
2030 | 0 | self.inner.scale_encoded_header() |
2031 | 0 | } Unexecuted instantiation: _RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_11BlockVerifypppE20scale_encoded_headerB9_ Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifypppE20scale_encoded_headerB9_ |
2032 | | |
2033 | | /// Verify the header of the block. |
2034 | 0 | pub fn verify_header( |
2035 | 0 | self, |
2036 | 0 | now_from_unix_epoch: Duration, |
2037 | 0 | ) -> HeaderVerifyOutcome<TRq, TSrc, TBl> { |
2038 | 0 | let verified_block_hash = *self.inner.hash(); |
2039 | 0 |
|
2040 | 0 | match self.inner.verify_header(now_from_unix_epoch) { |
2041 | | all_forks::HeaderVerifyOutcome::Success { |
2042 | 0 | is_new_best, |
2043 | 0 | success, |
2044 | 0 | } => HeaderVerifyOutcome::Success { |
2045 | 0 | is_new_best, |
2046 | 0 | success: HeaderVerifySuccess { |
2047 | 0 | inner: success, |
2048 | 0 | warp_sync: self.warp_sync, |
2049 | 0 | ready_to_transition: self.ready_to_transition, |
2050 | 0 | shared: self.shared, |
2051 | 0 | verified_block_hash, |
2052 | 0 | }, |
2053 | 0 | }, |
2054 | 0 | all_forks::HeaderVerifyOutcome::Error { sync, error } => HeaderVerifyOutcome::Error { |
2055 | 0 | sync: AllSync { |
2056 | 0 | all_forks: Some(sync), |
2057 | 0 | warp_sync: self.warp_sync, |
2058 | 0 | ready_to_transition: self.ready_to_transition, |
2059 | 0 | shared: self.shared, |
2060 | 0 | }, |
2061 | 0 | error: match error { |
2062 | 0 | all_forks::HeaderVerifyError::VerificationFailed(error) => { |
2063 | 0 | HeaderVerifyError::VerificationFailed(error) |
2064 | | } |
2065 | | all_forks::HeaderVerifyError::UnknownConsensusEngine => { |
2066 | 0 | HeaderVerifyError::UnknownConsensusEngine |
2067 | | } |
2068 | | all_forks::HeaderVerifyError::ConsensusMismatch => { |
2069 | 0 | HeaderVerifyError::ConsensusMismatch |
2070 | | } |
2071 | | }, |
2072 | | }, |
2073 | | } |
2074 | 0 | } Unexecuted instantiation: _RNvMsa_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_11BlockVerifypppE13verify_headerB9_ Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE13verify_headerCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifypppE13verify_headerB9_ Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1C_17NonFinalizedBlockE13verify_headerCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1C_17NonFinalizedBlockE13verify_headerCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsa_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_11BlockVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1C_17NonFinalizedBlockE13verify_headerCsibGXYHQB8Ea_25json_rpc_general_requests |
2075 | | } |
2076 | | |
2077 | | /// Outcome of calling [`BlockVerify::verify_header`]. |
2078 | | pub enum HeaderVerifyOutcome<TRq, TSrc, TBl> { |
2079 | | /// Header has been successfully verified. |
2080 | | Success { |
2081 | | /// True if the newly-verified block is considered the new best block. |
2082 | | is_new_best: bool, |
2083 | | success: HeaderVerifySuccess<TRq, TSrc, TBl>, |
2084 | | }, |
2085 | | |
2086 | | /// Header verification failed. |
2087 | | Error { |
2088 | | /// State machine yielded back. Use to continue the processing. |
2089 | | sync: AllSync<TRq, TSrc, TBl>, |
2090 | | /// Error that happened. |
2091 | | error: HeaderVerifyError, |
2092 | | }, |
2093 | | } |
2094 | | |
2095 | | /// Error that can happen when verifying a block header. |
2096 | 0 | #[derive(Debug, derive_more::Display)] Unexecuted instantiation: _RNvXsY_NtNtCsN16ciHI6Qf_7smoldot4sync3allNtB5_17HeaderVerifyErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Unexecuted instantiation: _RNvXsY_NtNtCseuYC0Zibziv_7smoldot4sync3allNtB5_17HeaderVerifyErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
2097 | | pub enum HeaderVerifyError { |
2098 | | /// Block can't be verified as it uses an unknown consensus engine. |
2099 | | UnknownConsensusEngine, |
2100 | | /// Block uses a different consensus than the rest of the chain. |
2101 | | ConsensusMismatch, |
2102 | | /// The block verification has failed. The block is invalid and should be thrown away. |
2103 | | #[display(fmt = "{_0}")] |
2104 | | VerificationFailed(verify::header_only::Error), |
2105 | | } |
2106 | | |
2107 | | pub struct HeaderVerifySuccess<TRq, TSrc, TBl> { |
2108 | | inner: all_forks::HeaderVerifySuccess<Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
2109 | | warp_sync: Option<warp_sync::WarpSync<WarpSyncSourceExtra, WarpSyncRequestExtra>>, |
2110 | | ready_to_transition: Option<warp_sync::RuntimeInformation>, |
2111 | | shared: Shared<TRq, TSrc>, |
2112 | | verified_block_hash: [u8; 32], |
2113 | | } |
2114 | | |
2115 | | impl<TRq, TSrc, TBl> HeaderVerifySuccess<TRq, TSrc, TBl> { |
2116 | | /// Returns the height of the block that was verified. |
2117 | 0 | pub fn height(&self) -> u64 { |
2118 | 0 | self.inner.height() |
2119 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE6heightB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE6heightCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE6heightB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6heightCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6heightCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6heightCsibGXYHQB8Ea_25json_rpc_general_requests |
2120 | | |
2121 | | /// Returns the hash of the block that was verified. |
2122 | 0 | pub fn hash(&self) -> [u8; 32] { |
2123 | 0 | // TODO: return by ref |
2124 | 0 | *self.inner.hash() |
2125 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE4hashB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE4hashB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE4hashCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE4hashCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE4hashCsibGXYHQB8Ea_25json_rpc_general_requests |
2126 | | |
2127 | | /// Returns the list of SCALE-encoded extrinsics of the block to verify. |
2128 | | /// |
2129 | | /// This is `Some` if and only if [`Config::download_bodies`] is `true` |
2130 | 0 | pub fn scale_encoded_extrinsics( |
2131 | 0 | &'_ self, |
2132 | 0 | ) -> Option<impl ExactSizeIterator<Item = impl AsRef<[u8]> + Clone + '_> + Clone + '_> { |
2133 | 0 | self.inner.scale_encoded_extrinsics() |
2134 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE24scale_encoded_extrinsicsB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE24scale_encoded_extrinsicsB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE24scale_encoded_extrinsicsCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE24scale_encoded_extrinsicsCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE24scale_encoded_extrinsicsCsibGXYHQB8Ea_25json_rpc_general_requests |
2135 | | |
2136 | | /// Returns the hash of the parent of the block that was verified. |
2137 | 0 | pub fn parent_hash(&self) -> &[u8; 32] { |
2138 | 0 | self.inner.parent_hash() |
2139 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE11parent_hashB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE11parent_hashB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE11parent_hashCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE11parent_hashCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE11parent_hashCsibGXYHQB8Ea_25json_rpc_general_requests |
2140 | | |
2141 | | /// Returns the user data of the parent of the block to be verified, or `None` if the parent |
2142 | | /// is the finalized block. |
2143 | 0 | pub fn parent_user_data(&self) -> Option<&TBl> { |
2144 | 0 | self.inner |
2145 | 0 | .parent_user_data() |
2146 | 0 | .map(|ud| ud.as_ref().unwrap_or_else(|| unreachable!())) Unexecuted instantiation: _RNCNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB7_19HeaderVerifySuccesspppE16parent_user_data0Bb_ Unexecuted instantiation: _RNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19HeaderVerifySuccesspppE16parent_user_data0Bb_ Unexecuted instantiation: _RNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE16parent_user_data0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE16parent_user_data0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE16parent_user_data0CsibGXYHQB8Ea_25json_rpc_general_requests Unexecuted instantiation: _RNCNCNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB9_19HeaderVerifySuccesspppE16parent_user_data00Bd_ Unexecuted instantiation: _RNCNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB9_19HeaderVerifySuccesspppE16parent_user_data00Bd_ Unexecuted instantiation: _RNCNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB9_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1O_17NonFinalizedBlockE16parent_user_data00CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB9_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1O_17NonFinalizedBlockE16parent_user_data00CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNCNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB9_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1O_17NonFinalizedBlockE16parent_user_data00CsibGXYHQB8Ea_25json_rpc_general_requests |
2147 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE16parent_user_dataB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE16parent_user_dataB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE16parent_user_dataCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE16parent_user_dataCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE16parent_user_dataCsibGXYHQB8Ea_25json_rpc_general_requests |
2148 | | |
2149 | | /// Returns the SCALE-encoded header of the block that was verified. |
2150 | 0 | pub fn scale_encoded_header(&self) -> &[u8] { |
2151 | 0 | self.inner.scale_encoded_header() |
2152 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE20scale_encoded_headerB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE20scale_encoded_headerB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE20scale_encoded_headerCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE20scale_encoded_headerCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE20scale_encoded_headerCsibGXYHQB8Ea_25json_rpc_general_requests |
2153 | | |
2154 | | /// Returns the SCALE-encoded header of the parent of the block. |
2155 | 0 | pub fn parent_scale_encoded_header(&self) -> &[u8] { |
2156 | 0 | self.inner.parent_scale_encoded_header() |
2157 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE27parent_scale_encoded_headerB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE27parent_scale_encoded_headerB9_ |
2158 | | |
2159 | | /// Cancel the block verification. |
2160 | 0 | pub fn cancel(self) -> AllSync<TRq, TSrc, TBl> { |
2161 | 0 | let all_forks = self.inner.cancel(); |
2162 | 0 | AllSync { |
2163 | 0 | all_forks: Some(all_forks), |
2164 | 0 | warp_sync: self.warp_sync, |
2165 | 0 | ready_to_transition: self.ready_to_transition, |
2166 | 0 | shared: self.shared, |
2167 | 0 | } |
2168 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE6cancelB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE6cancelB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6cancelCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6cancelCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6cancelCsibGXYHQB8Ea_25json_rpc_general_requests |
2169 | | |
2170 | | /// Reject the block and mark it as bad. |
2171 | 0 | pub fn reject_bad_block(self) -> AllSync<TRq, TSrc, TBl> { |
2172 | 0 | let all_forks = self.inner.reject_bad_block(); |
2173 | 0 | AllSync { |
2174 | 0 | all_forks: Some(all_forks), |
2175 | 0 | warp_sync: self.warp_sync, |
2176 | 0 | ready_to_transition: self.ready_to_transition, |
2177 | 0 | shared: self.shared, |
2178 | 0 | } |
2179 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE16reject_bad_blockB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE16reject_bad_blockB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE16reject_bad_blockCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE16reject_bad_blockCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE16reject_bad_blockCsibGXYHQB8Ea_25json_rpc_general_requests |
2180 | | |
2181 | | /// Finish inserting the block header. |
2182 | 0 | pub fn finish(self, user_data: TBl) -> AllSync<TRq, TSrc, TBl> { |
2183 | 0 | let height = self.height(); |
2184 | 0 | let mut all_forks = self.inner.finish(); |
2185 | 0 | all_forks[(height, &self.verified_block_hash)] = Some(user_data); |
2186 | 0 | AllSync { |
2187 | 0 | all_forks: Some(all_forks), |
2188 | 0 | warp_sync: self.warp_sync, |
2189 | 0 | ready_to_transition: self.ready_to_transition, |
2190 | 0 | shared: self.shared, |
2191 | 0 | } |
2192 | 0 | } Unexecuted instantiation: _RNvMsb_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE6finishB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE6finishCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccesspppE6finishB9_ Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6finishCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6finishCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsb_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19HeaderVerifySuccessuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6finishCsibGXYHQB8Ea_25json_rpc_general_requests |
2193 | | } |
2194 | | |
2195 | | pub struct FinalityProofVerify<TRq, TSrc, TBl> { |
2196 | | inner: all_forks::FinalityProofVerify<Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
2197 | | warp_sync: Option<warp_sync::WarpSync<WarpSyncSourceExtra, WarpSyncRequestExtra>>, |
2198 | | ready_to_transition: Option<warp_sync::RuntimeInformation>, |
2199 | | shared: Shared<TRq, TSrc>, |
2200 | | } |
2201 | | |
2202 | | impl<TRq, TSrc, TBl> FinalityProofVerify<TRq, TSrc, TBl> { |
2203 | | /// Returns the source the justification was obtained from. |
2204 | 0 | pub fn sender(&self) -> (SourceId, &TSrc) { |
2205 | 0 | let sender = self.inner.sender().1; |
2206 | 0 | ( |
2207 | 0 | sender.outer_source_id, |
2208 | 0 | &self.shared.sources[sender.outer_source_id.0].user_data, |
2209 | 0 | ) |
2210 | 0 | } Unexecuted instantiation: _RNvMsc_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19FinalityProofVerifypppE6senderB9_ Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE6senderCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifypppE6senderB9_ Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6senderCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6senderCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE6senderCsibGXYHQB8Ea_25json_rpc_general_requests |
2211 | | |
2212 | | /// Perform the verification. |
2213 | | /// |
2214 | | /// A randomness seed must be provided and will be used during the verification. Note that the |
2215 | | /// verification is nonetheless deterministic. |
2216 | 0 | pub fn perform( |
2217 | 0 | mut self, |
2218 | 0 | randomness_seed: [u8; 32], |
2219 | 0 | ) -> (AllSync<TRq, TSrc, TBl>, FinalityProofVerifyOutcome<TBl>) { |
2220 | 0 | let (all_forks, outcome) = match self.inner.perform(randomness_seed) { |
2221 | | ( |
2222 | 0 | sync, |
2223 | 0 | all_forks::FinalityProofVerifyOutcome::NewFinalized { |
2224 | 0 | finalized_blocks_newest_to_oldest, |
2225 | 0 | pruned_blocks, |
2226 | 0 | updates_best_block, |
2227 | | }, |
2228 | | ) => { |
2229 | 0 | if let Some(warp_sync) = &mut self.warp_sync { |
2230 | 0 | warp_sync.set_chain_information(sync.as_chain_information()) |
2231 | 0 | } |
2232 | | |
2233 | 0 | ( |
2234 | 0 | sync, |
2235 | 0 | // TODO: weird conversions |
2236 | 0 | FinalityProofVerifyOutcome::NewFinalized { |
2237 | 0 | finalized_blocks_newest_to_oldest: finalized_blocks_newest_to_oldest |
2238 | 0 | .into_iter() |
2239 | 0 | .map(|b| Block { |
2240 | 0 | header: b.scale_encoded_header, |
2241 | 0 | block_hash: b.block_hash, |
2242 | 0 | user_data: b.user_data.unwrap(), |
2243 | 0 | }) Unexecuted instantiation: _RNCNvMsc_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB7_19FinalityProofVerifypppE7perform0Bb_ Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtBb_6libp2p7peer_id6PeerIdNtNtNtNtBb_7network5codec15block_announces4RoleEuE7perform0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifypppE7perform0Bb_ Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE7perform0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE7perform0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE7perform0CsibGXYHQB8Ea_25json_rpc_general_requests |
2244 | 0 | .collect(), |
2245 | 0 | pruned_blocks: pruned_blocks.into_iter().map(|b| b.block_hash).collect(), Unexecuted instantiation: _RNCNvMsc_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB7_19FinalityProofVerifypppE7performs_0Bb_ Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtBb_6libp2p7peer_id6PeerIdNtNtNtNtBb_7network5codec15block_announces4RoleEuE7performs_0CsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifypppE7performs_0Bb_ Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE7performs_0CsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE7performs_0CscDgN54JpMGG_6author Unexecuted instantiation: _RNCNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB7_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1M_17NonFinalizedBlockE7performs_0CsibGXYHQB8Ea_25json_rpc_general_requests |
2246 | 0 | updates_best_block, |
2247 | 0 | }, |
2248 | 0 | ) |
2249 | | } |
2250 | 0 | (sync, all_forks::FinalityProofVerifyOutcome::AlreadyFinalized) => { |
2251 | 0 | (sync, FinalityProofVerifyOutcome::AlreadyFinalized) |
2252 | | } |
2253 | 0 | (sync, all_forks::FinalityProofVerifyOutcome::GrandpaCommitPending) => { |
2254 | 0 | (sync, FinalityProofVerifyOutcome::GrandpaCommitPending) |
2255 | | } |
2256 | 0 | (sync, all_forks::FinalityProofVerifyOutcome::JustificationError(error)) => { |
2257 | 0 | (sync, FinalityProofVerifyOutcome::JustificationError(error)) |
2258 | | } |
2259 | 0 | (sync, all_forks::FinalityProofVerifyOutcome::GrandpaCommitError(error)) => { |
2260 | 0 | (sync, FinalityProofVerifyOutcome::GrandpaCommitError(error)) |
2261 | | } |
2262 | | }; |
2263 | | |
2264 | 0 | ( |
2265 | 0 | AllSync { |
2266 | 0 | all_forks: Some(all_forks), |
2267 | 0 | warp_sync: self.warp_sync, |
2268 | 0 | ready_to_transition: self.ready_to_transition, |
2269 | 0 | shared: self.shared, |
2270 | 0 | }, |
2271 | 0 | outcome, |
2272 | 0 | ) |
2273 | 0 | } Unexecuted instantiation: _RNvMsc_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_19FinalityProofVerifypppE7performB9_ Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE7performCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifypppE7performB9_ Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE7performCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE7performCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsc_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_19FinalityProofVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1K_17NonFinalizedBlockE7performCsibGXYHQB8Ea_25json_rpc_general_requests |
2274 | | } |
2275 | | |
2276 | | /// Information about the outcome of verifying a finality proof. |
2277 | | #[derive(Debug)] |
2278 | | pub enum FinalityProofVerifyOutcome<TBl> { |
2279 | | /// Proof verification successful. The block and all its ancestors is now finalized. |
2280 | | NewFinalized { |
2281 | | /// List of finalized blocks, in decreasing block number. |
2282 | | finalized_blocks_newest_to_oldest: Vec<Block<TBl>>, |
2283 | | /// List of hashes of blocks that are no longer descendant of the finalized block, in |
2284 | | /// an unspecified order. |
2285 | | pruned_blocks: Vec<[u8; 32]>, |
2286 | | /// If `true`, this operation modifies the best block of the non-finalized chain. |
2287 | | /// This can happen if the previous best block isn't a descendant of the now finalized |
2288 | | /// block. |
2289 | | updates_best_block: bool, |
2290 | | }, |
2291 | | /// Finality proof concerns block that was already finalized. |
2292 | | AlreadyFinalized, |
2293 | | /// GrandPa commit cannot be verified yet and has been stored for later. |
2294 | | GrandpaCommitPending, |
2295 | | /// Problem while verifying justification. |
2296 | | JustificationError(JustificationVerifyError), |
2297 | | /// Problem while verifying GrandPa commit. |
2298 | | GrandpaCommitError(CommitVerifyError), |
2299 | | } |
2300 | | |
2301 | | pub struct WarpSyncFragmentVerify<TRq, TSrc, TBl> { |
2302 | | inner: warp_sync::VerifyWarpSyncFragment<WarpSyncSourceExtra, WarpSyncRequestExtra>, |
2303 | | ready_to_transition: Option<warp_sync::RuntimeInformation>, |
2304 | | shared: Shared<TRq, TSrc>, |
2305 | | all_forks: all_forks::AllForksSync<Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
2306 | | } |
2307 | | |
2308 | | impl<TRq, TSrc, TBl> WarpSyncFragmentVerify<TRq, TSrc, TBl> { |
2309 | | /// Returns the identifier and user data of the source that has sent the fragment to be |
2310 | | /// verified. |
2311 | | /// |
2312 | | /// Returns `None` if the source has been removed since the fragments have been downloaded. |
2313 | 0 | pub fn proof_sender(&self) -> Option<(SourceId, &TSrc)> { |
2314 | 0 | let (_, ud) = self.inner.proof_sender()?; |
2315 | 0 | Some(( |
2316 | 0 | ud.outer_source_id, |
2317 | 0 | &self.shared.sources[ud.outer_source_id.0].user_data, |
2318 | 0 | )) |
2319 | 0 | } Unexecuted instantiation: _RNvMsd_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifypppE12proof_senderB9_ Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE12proof_senderCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifypppE12proof_senderB9_ Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1N_17NonFinalizedBlockE12proof_senderCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1N_17NonFinalizedBlockE12proof_senderCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1N_17NonFinalizedBlockE12proof_senderCsibGXYHQB8Ea_25json_rpc_general_requests |
2320 | | |
2321 | | /// Perform the verification. |
2322 | | /// |
2323 | | /// A randomness seed must be provided and will be used during the verification. Note that the |
2324 | | /// verification is nonetheless deterministic. |
2325 | | /// |
2326 | | /// On success, returns the block hash and height that have been verified as being part of |
2327 | | /// the chain. |
2328 | 0 | pub fn perform( |
2329 | 0 | self, |
2330 | 0 | randomness_seed: [u8; 32], |
2331 | 0 | ) -> ( |
2332 | 0 | AllSync<TRq, TSrc, TBl>, |
2333 | 0 | Result<([u8; 32], u64), VerifyFragmentError>, |
2334 | 0 | ) { |
2335 | 0 | let (warp_sync, result) = self.inner.verify(randomness_seed); |
2336 | 0 |
|
2337 | 0 | ( |
2338 | 0 | AllSync { |
2339 | 0 | warp_sync: Some(warp_sync), |
2340 | 0 | ready_to_transition: self.ready_to_transition, |
2341 | 0 | all_forks: Some(self.all_forks), |
2342 | 0 | shared: self.shared, |
2343 | 0 | }, |
2344 | 0 | result, |
2345 | 0 | ) |
2346 | 0 | } Unexecuted instantiation: _RNvMsd_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifypppE7performB9_ Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE7performCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifypppE7performB9_ Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1N_17NonFinalizedBlockE7performCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1N_17NonFinalizedBlockE7performCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsd_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_22WarpSyncFragmentVerifyuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1N_17NonFinalizedBlockE7performCsibGXYHQB8Ea_25json_rpc_general_requests |
2347 | | } |
2348 | | |
2349 | | /// Compiling a new runtime is necessary for the warp sync process. |
2350 | | #[must_use] |
2351 | | pub struct WarpSyncBuildRuntime<TRq, TSrc, TBl> { |
2352 | | inner: warp_sync::BuildRuntime<WarpSyncSourceExtra, WarpSyncRequestExtra>, |
2353 | | ready_to_transition: Option<warp_sync::RuntimeInformation>, |
2354 | | shared: Shared<TRq, TSrc>, |
2355 | | all_forks: all_forks::AllForksSync<Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
2356 | | } |
2357 | | |
2358 | | impl<TRq, TSrc, TBl> WarpSyncBuildRuntime<TRq, TSrc, TBl> { |
2359 | | /// Builds the runtime. |
2360 | | /// |
2361 | | /// Assuming that the warp syncing goes to completion, the provided parameters are used to |
2362 | | /// compile the runtime that will be yielded in |
2363 | | /// [`ProcessOne::WarpSyncFinished::finalized_block_runtime`]. |
2364 | 0 | pub fn build( |
2365 | 0 | self, |
2366 | 0 | exec_hint: ExecHint, |
2367 | 0 | allow_unresolved_imports: bool, |
2368 | 0 | ) -> ( |
2369 | 0 | AllSync<TRq, TSrc, TBl>, |
2370 | 0 | Result<(), WarpSyncBuildRuntimeError>, |
2371 | 0 | ) { |
2372 | 0 | let (warp_sync, outcome) = self.inner.build(exec_hint, allow_unresolved_imports); |
2373 | 0 |
|
2374 | 0 | ( |
2375 | 0 | AllSync { |
2376 | 0 | warp_sync: Some(warp_sync), |
2377 | 0 | ready_to_transition: self.ready_to_transition, |
2378 | 0 | all_forks: Some(self.all_forks), |
2379 | 0 | shared: self.shared, |
2380 | 0 | }, |
2381 | 0 | outcome, |
2382 | 0 | ) |
2383 | 0 | } Unexecuted instantiation: _RNvMse_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_20WarpSyncBuildRuntimepppE5buildB9_ Unexecuted instantiation: _RNvMse_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_20WarpSyncBuildRuntimeNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE5buildCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMse_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_20WarpSyncBuildRuntimepppE5buildB9_ Unexecuted instantiation: _RNvMse_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_20WarpSyncBuildRuntimeuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1L_17NonFinalizedBlockE5buildCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMse_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_20WarpSyncBuildRuntimeuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1L_17NonFinalizedBlockE5buildCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMse_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_20WarpSyncBuildRuntimeuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1L_17NonFinalizedBlockE5buildCsibGXYHQB8Ea_25json_rpc_general_requests |
2384 | | } |
2385 | | |
2386 | | /// Building the chain information is necessary for the warp sync process. |
2387 | | #[must_use] |
2388 | | pub struct WarpSyncBuildChainInformation<TRq, TSrc, TBl> { |
2389 | | inner: warp_sync::BuildChainInformation<WarpSyncSourceExtra, WarpSyncRequestExtra>, |
2390 | | shared: Shared<TRq, TSrc>, |
2391 | | all_forks: all_forks::AllForksSync<Option<TBl>, AllForksRequestExtra, AllForksSourceExtra>, |
2392 | | } |
2393 | | |
2394 | | impl<TRq, TSrc, TBl> WarpSyncBuildChainInformation<TRq, TSrc, TBl> { |
2395 | | /// Builds the chain information. |
2396 | 0 | pub fn build( |
2397 | 0 | self, |
2398 | 0 | ) -> ( |
2399 | 0 | AllSync<TRq, TSrc, TBl>, |
2400 | 0 | Result<(), WarpSyncBuildChainInformationError>, |
2401 | 0 | ) { |
2402 | 0 | let (warp_sync, outcome) = self.inner.build(); |
2403 | | |
2404 | 0 | let (ready_to_transition, outcome) = match outcome { |
2405 | 0 | Ok(info) => (Some(info), Ok(())), |
2406 | 0 | Err(err) => (None, Err(err)), |
2407 | | }; |
2408 | | |
2409 | 0 | ( |
2410 | 0 | AllSync { |
2411 | 0 | warp_sync: Some(warp_sync), |
2412 | 0 | ready_to_transition, |
2413 | 0 | all_forks: Some(self.all_forks), |
2414 | 0 | shared: self.shared, |
2415 | 0 | }, |
2416 | 0 | outcome, |
2417 | 0 | ) |
2418 | 0 | } Unexecuted instantiation: _RNvMsf_NtNtCsN16ciHI6Qf_7smoldot4sync3allINtB5_29WarpSyncBuildChainInformationpppE5buildB9_ Unexecuted instantiation: _RNvMsf_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_29WarpSyncBuildChainInformationNtNtCsbAmNCxs6rLz_12futures_util9abortable11AbortHandleTNtNtNtB9_6libp2p7peer_id6PeerIdNtNtNtNtB9_7network5codec15block_announces4RoleEuE5buildCsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvMsf_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_29WarpSyncBuildChainInformationpppE5buildB9_ Unexecuted instantiation: _RNvMsf_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_29WarpSyncBuildChainInformationuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1U_17NonFinalizedBlockE5buildCsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RNvMsf_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_29WarpSyncBuildChainInformationuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1U_17NonFinalizedBlockE5buildCscDgN54JpMGG_6author Unexecuted instantiation: _RNvMsf_NtNtCseuYC0Zibziv_7smoldot4sync3allINtB5_29WarpSyncBuildChainInformationuINtNtCsaYZPK01V26L_4core6option6OptionNtNtCsiUjFBJteJ7x_17smoldot_full_node17consensus_service17NetworkSourceInfoENtB1U_17NonFinalizedBlockE5buildCsibGXYHQB8Ea_25json_rpc_general_requests |
2419 | | } |
2420 | | |
2421 | | // TODO: are these structs useful? |
2422 | | struct AllForksSourceExtra { |
2423 | | outer_source_id: SourceId, |
2424 | | } |
2425 | | |
2426 | | struct AllForksRequestExtra { |
2427 | | outer_request_id: RequestId, |
2428 | | } |
2429 | | |
2430 | | struct WarpSyncSourceExtra { |
2431 | | outer_source_id: SourceId, |
2432 | | } |
2433 | | |
2434 | | // TODO: consider removing struct altogether |
2435 | | struct WarpSyncRequestExtra {} |
2436 | | |
2437 | | struct Shared<TRq, TSrc> { |
2438 | | sources: slab::Slab<SourceMapping<TSrc>>, |
2439 | | requests: slab::Slab<RequestInfo<TRq>>, |
2440 | | |
2441 | | /// See [`Config::download_bodies`]. |
2442 | | download_bodies: bool, |
2443 | | |
2444 | | /// Value passed through [`Config::sources_capacity`]. |
2445 | | sources_capacity: usize, |
2446 | | /// Value passed through [`Config::blocks_capacity`]. |
2447 | | blocks_capacity: usize, |
2448 | | /// Value passed through [`Config::max_disjoint_headers`]. |
2449 | | max_disjoint_headers: usize, |
2450 | | /// Value passed through [`Config::max_requests_per_block`]. |
2451 | | max_requests_per_block: NonZeroU32, |
2452 | | /// Value passed through [`Config::block_number_bytes`]. |
2453 | | block_number_bytes: usize, |
2454 | | /// Value passed through [`Config::allow_unknown_consensus_engines`]. |
2455 | | allow_unknown_consensus_engines: bool, |
2456 | | } |
2457 | | |
2458 | | #[derive(Debug, Clone, PartialEq, Eq)] |
2459 | | struct RequestInfo<TRq> { |
2460 | | warp_sync: Option<warp_sync::RequestId>, |
2461 | | all_forks: Option<all_forks::RequestId>, |
2462 | | source_id: SourceId, |
2463 | | user_data: TRq, |
2464 | | } |
2465 | | |
2466 | | #[derive(Debug, Clone, PartialEq, Eq)] |
2467 | | struct SourceMapping<TSrc> { |
2468 | | warp_sync: Option<warp_sync::SourceId>, |
2469 | | all_forks: all_forks::SourceId, |
2470 | | // TODO: all_forks also has a requests count tracker, deduplicate |
2471 | | num_requests: usize, |
2472 | | user_data: TSrc, |
2473 | | } |
2474 | | |
2475 | 0 | fn all_forks_request_convert( |
2476 | 0 | rq_params: all_forks::RequestParams, |
2477 | 0 | download_body: bool, |
2478 | 0 | ) -> DesiredRequest { |
2479 | 0 | DesiredRequest::BlocksRequest { |
2480 | 0 | first_block_hash: rq_params.first_block_hash, |
2481 | 0 | first_block_height: rq_params.first_block_height, |
2482 | 0 | num_blocks: rq_params.num_blocks, |
2483 | 0 | request_bodies: download_body, |
2484 | 0 | request_headers: true, |
2485 | 0 | request_justification: true, |
2486 | 0 | } |
2487 | 0 | } Unexecuted instantiation: _RNvNtNtCsN16ciHI6Qf_7smoldot4sync3all25all_forks_request_convert Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot4sync3all25all_forks_request_convert |