/__w/smoldot/smoldot/repo/lib/src/chain_spec/light_sync_state.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Smoldot |
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 | | use super::{ParseError, ParseErrorInner}; |
19 | | use crate::header::BabeNextConfig; |
20 | | |
21 | | use alloc::{collections::BTreeMap, format, string::String, vec::Vec}; |
22 | | use serde::{Deserialize, Serialize}; |
23 | | |
24 | 9 | #[derive(Debug, Clone, Serialize, D5 eserialize)] _RINvXs_NvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_7___FieldB1t_11deserializeINtNtCscu7pqq74Vb8_10serde_json2de6MapKeyNtNtB2U_4read9SliceReadEEBe_ Line | Count | Source | 24 | 4 | #[derive(Debug, Clone, Serialize, Deserialize)] |
Unexecuted instantiation: _RINvXs0_NvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1w_7Visitor9visit_seqINtNtCscu7pqq74Vb8_10serde_json2de9SeqAccessNtNtB34_4read9SliceReadEEBf_ _RINvXs0_NvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1w_7Visitor9visit_mapINtNtCscu7pqq74Vb8_10serde_json2de9MapAccessNtNtB34_4read9SliceReadEEBf_ Line | Count | Source | 24 | 5 | #[derive(Debug, Clone, Serialize, D1 eserialize)] |
_RINvXNvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1t_7Visitor9visit_strNtNtCscu7pqq74Vb8_10serde_json5error5ErrorEBc_ Line | Count | Source | 24 | 4 | #[derive(Debug, Clone, Serialize, Deserialize)] |
Unexecuted instantiation: _RNvXs0_NvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_9___VisitorNtB1v_7Visitor9expecting Unexecuted instantiation: _RNvXNvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtB7_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB2_14___FieldVisitorNtB1s_7Visitor9expecting Unexecuted instantiation: _RINvXNvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1t_7Visitor9visit_u64pEBc_ Unexecuted instantiation: _RINvXNvXNvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1t_7Visitor11visit_bytespEBc_ Unexecuted instantiation: _RINvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1u_7Visitor9visit_strNtNtCscu7pqq74Vb8_10serde_json5error5ErrorECsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_mapINtNtCscu7pqq74Vb8_10serde_json2de9MapAccessNtNtB35_4read9SliceReadEECsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_seqINtNtCscu7pqq74Vb8_10serde_json2de9SeqAccessNtNtB35_4read9SliceReadEECsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RINvXs_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_7___FieldB1u_11deserializeINtNtCscu7pqq74Vb8_10serde_json2de6MapKeyNtNtB2V_4read9SliceReadEECsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RNvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB7_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB2_14___FieldVisitorNtB1t_7Visitor9expecting Unexecuted instantiation: _RNvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_9___VisitorNtB1w_7Visitor9expecting Unexecuted instantiation: _RINvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1u_7Visitor9visit_u64pEBc_ Unexecuted instantiation: _RINvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1u_7Visitor9visit_strpEBc_ Unexecuted instantiation: _RINvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1u_7Visitor11visit_bytespEBc_ Unexecuted instantiation: _RINvXs_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_7___FieldB1u_11deserializepEBe_ Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_seqpEBf_ Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_mappEBf_ Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_mapINtNtCscu7pqq74Vb8_10serde_json2de9MapAccessNtNtB35_4read9SliceReadEECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_seqINtNtCscu7pqq74Vb8_10serde_json2de9SeqAccessNtNtB35_4read9SliceReadEECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvXs_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_7___FieldB1u_11deserializeINtNtCscu7pqq74Vb8_10serde_json2de6MapKeyNtNtB2V_4read9SliceReadEECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1u_7Visitor9visit_strNtNtCscu7pqq74Vb8_10serde_json5error5ErrorECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_mapINtNtCscu7pqq74Vb8_10serde_json2de9MapAccessNtNtB35_4read9SliceReadEECscDgN54JpMGG_6author Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_seqINtNtCscu7pqq74Vb8_10serde_json2de9SeqAccessNtNtB35_4read9SliceReadEECscDgN54JpMGG_6author Unexecuted instantiation: _RINvXs_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_7___FieldB1u_11deserializeINtNtCscu7pqq74Vb8_10serde_json2de6MapKeyNtNtB2V_4read9SliceReadEECscDgN54JpMGG_6author Unexecuted instantiation: _RINvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1u_7Visitor9visit_strNtNtCscu7pqq74Vb8_10serde_json5error5ErrorECscDgN54JpMGG_6author Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_mapINtNtCscu7pqq74Vb8_10serde_json2de9MapAccessNtNtB35_4read9SliceReadEECsibGXYHQB8Ea_25json_rpc_general_requests Unexecuted instantiation: _RINvXs0_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBb_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB6_9___VisitorNtB1x_7Visitor9visit_seqINtNtCscu7pqq74Vb8_10serde_json2de9SeqAccessNtNtB35_4read9SliceReadEECsibGXYHQB8Ea_25json_rpc_general_requests Unexecuted instantiation: _RINvXs_NvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtBa_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB5_7___FieldB1u_11deserializeINtNtCscu7pqq74Vb8_10serde_json2de6MapKeyNtNtB2V_4read9SliceReadEECsibGXYHQB8Ea_25json_rpc_general_requests Unexecuted instantiation: _RINvXNvXNvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_states_1__NtB8_14LightSyncStateNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeNtB3_14___FieldVisitorNtB1u_7Visitor9visit_strNtNtCscu7pqq74Vb8_10serde_json5error5ErrorECsibGXYHQB8Ea_25json_rpc_general_requests |
25 | | #[serde(rename_all = "camelCase")] |
26 | | #[serde(deny_unknown_fields)] |
27 | | pub(super) struct LightSyncState { |
28 | | babe_epoch_changes: HexString, |
29 | | babe_finalized_block_weight: u32, |
30 | | finalized_block_header: HexString, |
31 | | grandpa_authority_set: HexString, |
32 | | } |
33 | | |
34 | | impl LightSyncState { |
35 | 2 | pub(super) fn decode( |
36 | 2 | &self, |
37 | 2 | block_number_bytes: usize, |
38 | 2 | ) -> Result<DecodedLightSyncState, ParseError> { |
39 | | // We don't use `all_consuming` in order to remain compatible in case new fields are added |
40 | | // in Substrate to these data structures. |
41 | | // This really should be solved by having a proper format for checkpoints, but |
42 | | // there isn't. |
43 | 2 | let grandpa_authority_set = match nom::Finish::finish(nom::combinator::complete( |
44 | 2 | authority_set::<nom::error::Error<&[u8]>>, |
45 | 2 | )( |
46 | 2 | &self.grandpa_authority_set.0[..] |
47 | 2 | )) { |
48 | 2 | Ok((_, v)) => v, |
49 | 0 | Err(_err) => return Err(ParseError(ParseErrorInner::Other)), |
50 | | }; |
51 | 2 | let babe_epoch_changes = match nom::Finish::finish(nom::combinator::complete( |
52 | 2 | epoch_changes::<nom::error::Error<&[u8]>>, |
53 | 2 | )(&self.babe_epoch_changes.0[..])) |
54 | | { |
55 | 2 | Ok((_, v)) => v, |
56 | 0 | Err(_err) => return Err(ParseError(ParseErrorInner::Other)), |
57 | | }; |
58 | | |
59 | | Ok(DecodedLightSyncState { |
60 | 2 | finalized_block_header: crate::header::decode( |
61 | 2 | &self.finalized_block_header.0[..], |
62 | 2 | block_number_bytes, |
63 | 2 | ) |
64 | 2 | .map_err(|_| ParseError(ParseErrorInner::Other)0 )?0 Unexecuted instantiation: _RNCNvMNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_stateNtB4_14LightSyncState6decode0B8_ Unexecuted instantiation: _RNCNvMNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB4_14LightSyncState6decode0B8_ |
65 | 2 | .into(), |
66 | 2 | grandpa_authority_set, |
67 | 2 | babe_epoch_changes, |
68 | | }) |
69 | 2 | } _RNvMNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_stateNtB2_14LightSyncState6decode Line | Count | Source | 35 | 2 | pub(super) fn decode( | 36 | 2 | &self, | 37 | 2 | block_number_bytes: usize, | 38 | 2 | ) -> Result<DecodedLightSyncState, ParseError> { | 39 | | // We don't use `all_consuming` in order to remain compatible in case new fields are added | 40 | | // in Substrate to these data structures. | 41 | | // This really should be solved by having a proper format for checkpoints, but | 42 | | // there isn't. | 43 | 2 | let grandpa_authority_set = match nom::Finish::finish(nom::combinator::complete( | 44 | 2 | authority_set::<nom::error::Error<&[u8]>>, | 45 | 2 | )( | 46 | 2 | &self.grandpa_authority_set.0[..] | 47 | 2 | )) { | 48 | 2 | Ok((_, v)) => v, | 49 | 0 | Err(_err) => return Err(ParseError(ParseErrorInner::Other)), | 50 | | }; | 51 | 2 | let babe_epoch_changes = match nom::Finish::finish(nom::combinator::complete( | 52 | 2 | epoch_changes::<nom::error::Error<&[u8]>>, | 53 | 2 | )(&self.babe_epoch_changes.0[..])) | 54 | | { | 55 | 2 | Ok((_, v)) => v, | 56 | 0 | Err(_err) => return Err(ParseError(ParseErrorInner::Other)), | 57 | | }; | 58 | | | 59 | | Ok(DecodedLightSyncState { | 60 | 2 | finalized_block_header: crate::header::decode( | 61 | 2 | &self.finalized_block_header.0[..], | 62 | 2 | block_number_bytes, | 63 | 2 | ) | 64 | 2 | .map_err(|_| ParseError(ParseErrorInner::Other))?0 | 65 | 2 | .into(), | 66 | 2 | grandpa_authority_set, | 67 | 2 | babe_epoch_changes, | 68 | | }) | 69 | 2 | } |
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB2_14LightSyncState6decode |
70 | | } |
71 | | |
72 | | #[derive(Debug)] |
73 | | pub(super) struct DecodedLightSyncState { |
74 | | pub(super) babe_epoch_changes: EpochChanges, |
75 | | pub(super) finalized_block_header: crate::header::Header, |
76 | | pub(super) grandpa_authority_set: AuthoritySet, |
77 | | } |
78 | | |
79 | | #[derive(Debug)] |
80 | | pub(super) struct EpochChanges { |
81 | | _inner: ForkTree<PersistedEpochHeader>, |
82 | | pub(super) epochs: BTreeMap<([u8; 32], u32), PersistedEpoch>, |
83 | | // TODO: Substrate has added the field below to the checkpoints format ; it is commented out |
84 | | // right now in order to maintain compatibility with checkpoints that were generated |
85 | | // a long time ago |
86 | | // gap: Option<GapEpochs>, |
87 | | } |
88 | | |
89 | 2 | fn epoch_changes<'a, E: nom::error::ParseError<&'a [u8]>>( |
90 | 2 | bytes: &'a [u8], |
91 | 2 | ) -> nom::IResult<&'a [u8], EpochChanges, E> { |
92 | 2 | nom::combinator::map( |
93 | 2 | nom::sequence::tuple(( |
94 | 2 | fork_tree(persisted_epoch_header), |
95 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { |
96 | 2 | nom::multi::many_m_n( |
97 | 2 | num_elems, |
98 | 2 | num_elems, |
99 | 2 | nom::sequence::tuple(( |
100 | 2 | nom::bytes::streaming::take(32u32), |
101 | 2 | nom::number::streaming::le_u32, |
102 | 2 | persisted_epoch, |
103 | 2 | )), |
104 | 2 | ) |
105 | 2 | }), _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 95 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 96 | 2 | nom::multi::many_m_n( | 97 | 2 | num_elems, | 98 | 2 | num_elems, | 99 | 2 | nom::sequence::tuple(( | 100 | 2 | nom::bytes::streaming::take(32u32), | 101 | 2 | nom::number::streaming::le_u32, | 102 | 2 | persisted_epoch, | 103 | 2 | )), | 104 | 2 | ) | 105 | 2 | }), |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
106 | 2 | )), |
107 | 2 | move |(inner, epochs)| EpochChanges { |
108 | 2 | _inner: inner, |
109 | 2 | epochs: epochs |
110 | 2 | .into_iter() |
111 | 2 | .map(|(h, n, e)| ((*<&[u8; 32]>::try_from(h).unwrap(), n), e)) _RNCNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_00Ba_ Line | Count | Source | 111 | 2 | .map(|(h, n, e)| ((*<&[u8; 32]>::try_from(h).unwrap(), n), e)) |
Unexecuted instantiation: _RNCNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_00Ba_ |
112 | 2 | .collect(), |
113 | 2 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ Line | Count | Source | 107 | 2 | move |(inner, epochs)| EpochChanges { | 108 | 2 | _inner: inner, | 109 | 2 | epochs: epochs | 110 | 2 | .into_iter() | 111 | 2 | .map(|(h, n, e)| ((*<&[u8; 32]>::try_from(h).unwrap(), n), e)) | 112 | 2 | .collect(), | 113 | 2 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ |
114 | 2 | )(bytes) |
115 | 2 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 89 | 2 | fn epoch_changes<'a, E: nom::error::ParseError<&'a [u8]>>( | 90 | 2 | bytes: &'a [u8], | 91 | 2 | ) -> nom::IResult<&'a [u8], EpochChanges, E> { | 92 | 2 | nom::combinator::map( | 93 | 2 | nom::sequence::tuple(( | 94 | 2 | fork_tree(persisted_epoch_header), | 95 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 96 | | nom::multi::many_m_n( | 97 | | num_elems, | 98 | | num_elems, | 99 | | nom::sequence::tuple(( | 100 | | nom::bytes::streaming::take(32u32), | 101 | | nom::number::streaming::le_u32, | 102 | | persisted_epoch, | 103 | | )), | 104 | | ) | 105 | 2 | }), | 106 | 2 | )), | 107 | 2 | move |(inner, epochs)| EpochChanges { | 108 | | _inner: inner, | 109 | | epochs: epochs | 110 | | .into_iter() | 111 | | .map(|(h, n, e)| ((*<&[u8; 32]>::try_from(h).unwrap(), n), e)) | 112 | | .collect(), | 113 | 2 | }, | 114 | 2 | )(bytes) | 115 | 2 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13epoch_changesINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
116 | | |
117 | | #[allow(unused)] |
118 | | #[derive(Debug)] |
119 | | pub(super) struct GapEpochs { |
120 | | current: ([u8; 32], u32, PersistedEpoch), |
121 | | next: Option<([u8; 32], u32, BabeEpoch)>, |
122 | | } |
123 | | |
124 | | #[allow(unused)] |
125 | 0 | fn gap_epochs<'a, E: nom::error::ParseError<&'a [u8]>>( |
126 | 0 | bytes: &'a [u8], |
127 | 0 | ) -> nom::IResult<&'a [u8], GapEpochs, E> { |
128 | 0 | nom::combinator::map( |
129 | 0 | nom::sequence::tuple(( |
130 | 0 | nom::sequence::tuple(( |
131 | 0 | nom::combinator::map(nom::bytes::streaming::take(32u32), |b| { |
132 | 0 | *<&[u8; 32]>::try_from(b).unwrap() |
133 | 0 | }), Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10gap_epochspE0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10gap_epochspE0B8_ |
134 | 0 | nom::number::streaming::le_u32, |
135 | 0 | persisted_epoch, |
136 | 0 | )), |
137 | 0 | crate::util::nom_option_decode(nom::sequence::tuple(( |
138 | 0 | nom::combinator::map(nom::bytes::streaming::take(32u32), |b| { |
139 | 0 | *<&[u8; 32]>::try_from(b).unwrap() |
140 | 0 | }), Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10gap_epochspEs_0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10gap_epochspEs_0B8_ |
141 | 0 | nom::number::streaming::le_u32, |
142 | 0 | babe_epoch, |
143 | 0 | ))), |
144 | 0 | )), |
145 | 0 | move |(current, next)| GapEpochs { current, next }, Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10gap_epochspEs0_0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10gap_epochspEs0_0B8_ |
146 | 0 | )(bytes) |
147 | 0 | } Unexecuted instantiation: _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10gap_epochspEB6_ Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10gap_epochspEB6_ |
148 | | |
149 | | #[derive(Debug)] |
150 | | #[allow(dead_code)] // Necessary to silence warnings about unused fields. |
151 | | pub(super) enum PersistedEpochHeader { |
152 | | Genesis(EpochHeader, EpochHeader), |
153 | | Regular(EpochHeader), |
154 | | } |
155 | | |
156 | 2 | fn persisted_epoch_header<'a, E: nom::error::ParseError<&'a [u8]>>( |
157 | 2 | bytes: &'a [u8], |
158 | 2 | ) -> nom::IResult<&'a [u8], PersistedEpochHeader, E> { |
159 | 2 | nom::branch::alt(( |
160 | 2 | nom::combinator::map( |
161 | 2 | nom::sequence::preceded( |
162 | 2 | nom::bytes::streaming::tag(&[0]), |
163 | 2 | nom::sequence::tuple((epoch_header, epoch_header)), |
164 | 2 | ), |
165 | 2 | |(a, b)| PersistedEpochHeader::Genesis(a, b), _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state22persisted_epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 165 | 2 | |(a, b)| PersistedEpochHeader::Genesis(a, b), |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state22persisted_epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
166 | 2 | ), |
167 | 2 | nom::combinator::map( |
168 | 2 | nom::sequence::preceded(nom::bytes::streaming::tag(&[1]), epoch_header), |
169 | 2 | PersistedEpochHeader::Regular, |
170 | 2 | ), |
171 | 2 | ))(bytes) |
172 | 2 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state22persisted_epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 156 | 2 | fn persisted_epoch_header<'a, E: nom::error::ParseError<&'a [u8]>>( | 157 | 2 | bytes: &'a [u8], | 158 | 2 | ) -> nom::IResult<&'a [u8], PersistedEpochHeader, E> { | 159 | 2 | nom::branch::alt(( | 160 | 2 | nom::combinator::map( | 161 | 2 | nom::sequence::preceded( | 162 | 2 | nom::bytes::streaming::tag(&[0]), | 163 | 2 | nom::sequence::tuple((epoch_header, epoch_header)), | 164 | 2 | ), | 165 | 2 | |(a, b)| PersistedEpochHeader::Genesis(a, b), | 166 | 2 | ), | 167 | 2 | nom::combinator::map( | 168 | 2 | nom::sequence::preceded(nom::bytes::streaming::tag(&[1]), epoch_header), | 169 | 2 | PersistedEpochHeader::Regular, | 170 | 2 | ), | 171 | 2 | ))(bytes) | 172 | 2 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state22persisted_epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
173 | | |
174 | | #[derive(Debug)] |
175 | | pub(super) struct EpochHeader { |
176 | | _start_slot: u64, |
177 | | _end_slot: u64, |
178 | | } |
179 | | |
180 | 4 | fn epoch_header<'a, E: nom::error::ParseError<&'a [u8]>>( |
181 | 4 | bytes: &'a [u8], |
182 | 4 | ) -> nom::IResult<&'a [u8], EpochHeader, E> { |
183 | 4 | nom::combinator::map( |
184 | 4 | nom::sequence::tuple(( |
185 | 4 | nom::number::streaming::le_u64, |
186 | 4 | nom::number::streaming::le_u64, |
187 | 4 | )), |
188 | 4 | move |(start_slot, end_slot)| EpochHeader { |
189 | 4 | _start_slot: start_slot, |
190 | 4 | _end_slot: end_slot, |
191 | 4 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state12epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 188 | 4 | move |(start_slot, end_slot)| EpochHeader { | 189 | 4 | _start_slot: start_slot, | 190 | 4 | _end_slot: end_slot, | 191 | 4 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state12epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
192 | 4 | )(bytes) |
193 | 4 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state12epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 180 | 4 | fn epoch_header<'a, E: nom::error::ParseError<&'a [u8]>>( | 181 | 4 | bytes: &'a [u8], | 182 | 4 | ) -> nom::IResult<&'a [u8], EpochHeader, E> { | 183 | 4 | nom::combinator::map( | 184 | 4 | nom::sequence::tuple(( | 185 | 4 | nom::number::streaming::le_u64, | 186 | 4 | nom::number::streaming::le_u64, | 187 | 4 | )), | 188 | 4 | move |(start_slot, end_slot)| EpochHeader { | 189 | | _start_slot: start_slot, | 190 | | _end_slot: end_slot, | 191 | 4 | }, | 192 | 4 | )(bytes) | 193 | 4 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state12epoch_headerINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
194 | | |
195 | | #[derive(Debug)] |
196 | | #[allow(dead_code)] // Necessary to silence warnings about unused fields. |
197 | | pub(super) enum PersistedEpoch { |
198 | | Genesis(BabeEpoch, BabeEpoch), |
199 | | Regular(BabeEpoch), |
200 | | } |
201 | | |
202 | 2 | fn persisted_epoch<'a, E: nom::error::ParseError<&'a [u8]>>( |
203 | 2 | bytes: &'a [u8], |
204 | 2 | ) -> nom::IResult<&'a [u8], PersistedEpoch, E> { |
205 | 2 | nom::branch::alt(( |
206 | 2 | nom::combinator::map( |
207 | 2 | nom::sequence::preceded( |
208 | 2 | nom::bytes::streaming::tag(&[0]), |
209 | 2 | nom::sequence::tuple((babe_epoch, babe_epoch)), |
210 | 2 | ), |
211 | 2 | |(a, b)| PersistedEpoch::Genesis(a, b), _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state15persisted_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 211 | 2 | |(a, b)| PersistedEpoch::Genesis(a, b), |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state15persisted_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
212 | 2 | ), |
213 | 2 | nom::combinator::map( |
214 | 2 | nom::sequence::preceded(nom::bytes::streaming::tag(&[1]), babe_epoch), |
215 | 2 | PersistedEpoch::Regular, |
216 | 2 | ), |
217 | 2 | ))(bytes) |
218 | 2 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state15persisted_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 202 | 2 | fn persisted_epoch<'a, E: nom::error::ParseError<&'a [u8]>>( | 203 | 2 | bytes: &'a [u8], | 204 | 2 | ) -> nom::IResult<&'a [u8], PersistedEpoch, E> { | 205 | 2 | nom::branch::alt(( | 206 | 2 | nom::combinator::map( | 207 | 2 | nom::sequence::preceded( | 208 | 2 | nom::bytes::streaming::tag(&[0]), | 209 | 2 | nom::sequence::tuple((babe_epoch, babe_epoch)), | 210 | 2 | ), | 211 | 2 | |(a, b)| PersistedEpoch::Genesis(a, b), | 212 | 2 | ), | 213 | 2 | nom::combinator::map( | 214 | 2 | nom::sequence::preceded(nom::bytes::streaming::tag(&[1]), babe_epoch), | 215 | 2 | PersistedEpoch::Regular, | 216 | 2 | ), | 217 | 2 | ))(bytes) | 218 | 2 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state15persisted_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
219 | | |
220 | | #[derive(Debug)] |
221 | | pub(super) struct BabeEpoch { |
222 | | pub(super) epoch_index: u64, |
223 | | pub(super) slot_number: u64, |
224 | | pub(super) duration: u64, |
225 | | pub(super) authorities: Vec<BabeAuthority>, |
226 | | pub(super) randomness: [u8; 32], |
227 | | pub(super) config: BabeNextConfig, |
228 | | } |
229 | | |
230 | 4 | fn babe_epoch<'a, E: nom::error::ParseError<&'a [u8]>>( |
231 | 4 | bytes: &'a [u8], |
232 | 4 | ) -> nom::IResult<&'a [u8], BabeEpoch, E> { |
233 | 4 | nom::combinator::map( |
234 | 4 | nom::sequence::tuple(( |
235 | 4 | nom::number::streaming::le_u64, |
236 | 4 | nom::number::streaming::le_u64, |
237 | 4 | nom::number::streaming::le_u64, |
238 | 4 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { |
239 | 4 | nom::multi::many_m_n(num_elems, num_elems, babe_authority) |
240 | 4 | }), _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 238 | 4 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 239 | 4 | nom::multi::many_m_n(num_elems, num_elems, babe_authority) | 240 | 4 | }), |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
241 | 4 | nom::bytes::streaming::take(32u32), |
242 | 4 | |b| { |
243 | 4 | BabeNextConfig::from_slice(b) |
244 | 4 | .map(|c| (&b[17..], c)) // TODO: hacky to use a constant _RNCNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_00Ba_ Line | Count | Source | 244 | 4 | .map(|c| (&b[17..], c)) // TODO: hacky to use a constant |
Unexecuted instantiation: _RNCNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_00Ba_ |
245 | 4 | .map_err(|_| { |
246 | 0 | nom::Err::Error(nom::error::make_error(b, nom::error::ErrorKind::MapOpt)) |
247 | 4 | }) Unexecuted instantiation: _RNCNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0s_0Ba_ Unexecuted instantiation: _RNCNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0s_0Ba_ |
248 | 4 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ Line | Count | Source | 242 | 4 | |b| { | 243 | 4 | BabeNextConfig::from_slice(b) | 244 | 4 | .map(|c| (&b[17..], c)) // TODO: hacky to use a constant | 245 | 4 | .map_err(|_| { | 246 | | nom::Err::Error(nom::error::make_error(b, nom::error::ErrorKind::MapOpt)) | 247 | 4 | }) | 248 | 4 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ |
249 | 4 | )), |
250 | 4 | move |(epoch_index, slot_number, duration, authorities, randomness, config)| BabeEpoch { |
251 | 4 | epoch_index, |
252 | 4 | slot_number, |
253 | 4 | duration, |
254 | 4 | authorities, |
255 | 4 | randomness: *<&[u8; 32]>::try_from(randomness).unwrap(), |
256 | 4 | config, |
257 | 4 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs0_0B8_ Line | Count | Source | 250 | 4 | move |(epoch_index, slot_number, duration, authorities, randomness, config)| BabeEpoch { | 251 | 4 | epoch_index, | 252 | 4 | slot_number, | 253 | 4 | duration, | 254 | 4 | authorities, | 255 | 4 | randomness: *<&[u8; 32]>::try_from(randomness).unwrap(), | 256 | 4 | config, | 257 | 4 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs0_0B8_ |
258 | 4 | )(bytes) |
259 | 4 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 230 | 4 | fn babe_epoch<'a, E: nom::error::ParseError<&'a [u8]>>( | 231 | 4 | bytes: &'a [u8], | 232 | 4 | ) -> nom::IResult<&'a [u8], BabeEpoch, E> { | 233 | 4 | nom::combinator::map( | 234 | 4 | nom::sequence::tuple(( | 235 | 4 | nom::number::streaming::le_u64, | 236 | 4 | nom::number::streaming::le_u64, | 237 | 4 | nom::number::streaming::le_u64, | 238 | 4 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 239 | | nom::multi::many_m_n(num_elems, num_elems, babe_authority) | 240 | 4 | }), | 241 | 4 | nom::bytes::streaming::take(32u32), | 242 | 4 | |b| { | 243 | | BabeNextConfig::from_slice(b) | 244 | | .map(|c| (&b[17..], c)) // TODO: hacky to use a constant | 245 | | .map_err(|_| { | 246 | | nom::Err::Error(nom::error::make_error(b, nom::error::ErrorKind::MapOpt)) | 247 | | }) | 248 | 4 | }, | 249 | 4 | )), | 250 | 4 | move |(epoch_index, slot_number, duration, authorities, randomness, config)| BabeEpoch { | 251 | | epoch_index, | 252 | | slot_number, | 253 | | duration, | 254 | | authorities, | 255 | | randomness: *<&[u8; 32]>::try_from(randomness).unwrap(), | 256 | | config, | 257 | 4 | }, | 258 | 4 | )(bytes) | 259 | 4 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10babe_epochINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
260 | | |
261 | | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
262 | | pub struct BabeAuthority { |
263 | | /// Sr25519 public key. |
264 | | pub public_key: [u8; 32], |
265 | | /// Arbitrary number indicating the weight of the authority. |
266 | | /// |
267 | | /// This value can only be compared to other weight values. |
268 | | // TODO: should be NonZeroU64; requires deep changes in decoding code though |
269 | | pub weight: u64, |
270 | | } |
271 | | |
272 | 4 | fn babe_authority<'a, E: nom::error::ParseError<&'a [u8]>>( |
273 | 4 | bytes: &'a [u8], |
274 | 4 | ) -> nom::IResult<&'a [u8], BabeAuthority, E> { |
275 | 4 | nom::combinator::map( |
276 | 4 | nom::sequence::tuple(( |
277 | 4 | nom::bytes::streaming::take(32u32), |
278 | 4 | nom::number::streaming::le_u64, |
279 | 4 | )), |
280 | 4 | move |(public_key, weight)| BabeAuthority { |
281 | 4 | public_key: *<&[u8; 32]>::try_from(public_key).unwrap(), |
282 | 4 | weight, |
283 | 4 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14babe_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 280 | 4 | move |(public_key, weight)| BabeAuthority { | 281 | 4 | public_key: *<&[u8; 32]>::try_from(public_key).unwrap(), | 282 | 4 | weight, | 283 | 4 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14babe_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
284 | 4 | )(bytes) |
285 | 4 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14babe_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 272 | 4 | fn babe_authority<'a, E: nom::error::ParseError<&'a [u8]>>( | 273 | 4 | bytes: &'a [u8], | 274 | 4 | ) -> nom::IResult<&'a [u8], BabeAuthority, E> { | 275 | 4 | nom::combinator::map( | 276 | 4 | nom::sequence::tuple(( | 277 | 4 | nom::bytes::streaming::take(32u32), | 278 | 4 | nom::number::streaming::le_u64, | 279 | 4 | )), | 280 | 4 | move |(public_key, weight)| BabeAuthority { | 281 | | public_key: *<&[u8; 32]>::try_from(public_key).unwrap(), | 282 | | weight, | 283 | 4 | }, | 284 | 4 | )(bytes) | 285 | 4 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14babe_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
286 | | |
287 | | #[derive(Debug)] |
288 | | pub(super) struct AuthoritySet { |
289 | | pub(super) current_authorities: Vec<GrandpaAuthority>, |
290 | | pub(super) set_id: u64, |
291 | | _pending_standard_changes: ForkTree<PendingChange>, |
292 | | _pending_forced_changes: Vec<PendingChange>, |
293 | | /// Note: this field didn't exist in Substrate before 2021-01-20. Light sync states that are |
294 | | /// older than that are missing it. |
295 | | _authority_set_changes: Vec<(u64, u32)>, |
296 | | } |
297 | | |
298 | 2 | fn authority_set<'a, E: nom::error::ParseError<&'a [u8]>>( |
299 | 2 | bytes: &'a [u8], |
300 | 2 | ) -> nom::IResult<&'a [u8], AuthoritySet, E> { |
301 | 2 | nom::combinator::map( |
302 | 2 | nom::sequence::tuple(( |
303 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { |
304 | 2 | nom::multi::many_m_n(num_elems, num_elems, grandpa_authority) |
305 | 2 | }), _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 303 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 304 | 2 | nom::multi::many_m_n(num_elems, num_elems, grandpa_authority) | 305 | 2 | }), |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
306 | 2 | nom::number::streaming::le_u64, |
307 | 2 | fork_tree(pending_change), |
308 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { |
309 | 2 | nom::multi::many_m_n(num_elems, num_elems, pending_change) |
310 | 2 | }), _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ Line | Count | Source | 308 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 309 | 2 | nom::multi::many_m_n(num_elems, num_elems, pending_change) | 310 | 2 | }), |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ |
311 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { |
312 | 2 | nom::multi::many_m_n( |
313 | 2 | num_elems, |
314 | 2 | num_elems, |
315 | 2 | nom::sequence::tuple(( |
316 | 2 | nom::number::streaming::le_u64, |
317 | 2 | nom::number::streaming::le_u32, |
318 | 2 | )), |
319 | 2 | ) |
320 | 2 | }), _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs0_0B8_ Line | Count | Source | 311 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 312 | 2 | nom::multi::many_m_n( | 313 | 2 | num_elems, | 314 | 2 | num_elems, | 315 | 2 | nom::sequence::tuple(( | 316 | 2 | nom::number::streaming::le_u64, | 317 | 2 | nom::number::streaming::le_u32, | 318 | 2 | )), | 319 | 2 | ) | 320 | 2 | }), |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs0_0B8_ |
321 | 2 | )), |
322 | 2 | move |( |
323 | | current_authorities, |
324 | | set_id, |
325 | | pending_standard_changes, |
326 | | pending_forced_changes, |
327 | | authority_set_changes, |
328 | 2 | )| AuthoritySet { |
329 | 2 | current_authorities, |
330 | 2 | set_id, |
331 | 2 | _pending_standard_changes: pending_standard_changes, |
332 | 2 | _pending_forced_changes: pending_forced_changes, |
333 | 2 | _authority_set_changes: authority_set_changes, |
334 | 2 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs1_0B8_ Line | Count | Source | 328 | 2 | )| AuthoritySet { | 329 | 2 | current_authorities, | 330 | 2 | set_id, | 331 | 2 | _pending_standard_changes: pending_standard_changes, | 332 | 2 | _pending_forced_changes: pending_forced_changes, | 333 | 2 | _authority_set_changes: authority_set_changes, | 334 | 2 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs1_0B8_ |
335 | 2 | )(bytes) |
336 | 2 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 298 | 2 | fn authority_set<'a, E: nom::error::ParseError<&'a [u8]>>( | 299 | 2 | bytes: &'a [u8], | 300 | 2 | ) -> nom::IResult<&'a [u8], AuthoritySet, E> { | 301 | 2 | nom::combinator::map( | 302 | 2 | nom::sequence::tuple(( | 303 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 304 | | nom::multi::many_m_n(num_elems, num_elems, grandpa_authority) | 305 | 2 | }), | 306 | 2 | nom::number::streaming::le_u64, | 307 | 2 | fork_tree(pending_change), | 308 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 309 | | nom::multi::many_m_n(num_elems, num_elems, pending_change) | 310 | 2 | }), | 311 | 2 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { | 312 | | nom::multi::many_m_n( | 313 | | num_elems, | 314 | | num_elems, | 315 | | nom::sequence::tuple(( | 316 | | nom::number::streaming::le_u64, | 317 | | nom::number::streaming::le_u32, | 318 | | )), | 319 | | ) | 320 | 2 | }), | 321 | 2 | )), | 322 | 2 | move |( | 323 | | current_authorities, | 324 | | set_id, | 325 | | pending_standard_changes, | 326 | | pending_forced_changes, | 327 | | authority_set_changes, | 328 | | )| AuthoritySet { | 329 | | current_authorities, | 330 | | set_id, | 331 | | _pending_standard_changes: pending_standard_changes, | 332 | | _pending_forced_changes: pending_forced_changes, | 333 | | _authority_set_changes: authority_set_changes, | 334 | 2 | }, | 335 | 2 | )(bytes) | 336 | 2 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state13authority_setINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
337 | | |
338 | | #[derive(Debug)] |
339 | | pub(super) struct PendingChange { |
340 | | _next_authorities: Vec<GrandpaAuthority>, |
341 | | _delay: u32, |
342 | | _canon_height: u32, |
343 | | _canon_hash: [u8; 32], |
344 | | _delay_kind: DelayKind, |
345 | | } |
346 | | |
347 | 0 | fn pending_change<'a, E: nom::error::ParseError<&'a [u8]>>( |
348 | 0 | bytes: &'a [u8], |
349 | 0 | ) -> nom::IResult<&'a [u8], PendingChange, E> { |
350 | 0 | nom::combinator::map( |
351 | 0 | nom::sequence::tuple(( |
352 | 0 | nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| { |
353 | 0 | nom::multi::many_m_n(num_elems, num_elems, grandpa_authority) |
354 | 0 | }), Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14pending_changeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14pending_changeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
355 | 0 | nom::number::streaming::le_u32, |
356 | 0 | nom::number::streaming::le_u32, |
357 | 0 | nom::bytes::streaming::take(32u32), |
358 | 0 | delay_kind, |
359 | 0 | )), |
360 | 0 | move |(next_authorities, delay, canon_height, canon_hash, delay_kind)| PendingChange { |
361 | 0 | _next_authorities: next_authorities, |
362 | 0 | _delay: delay, |
363 | 0 | _canon_height: canon_height, |
364 | 0 | _canon_hash: *<&[u8; 32]>::try_from(canon_hash).unwrap(), |
365 | 0 | _delay_kind: delay_kind, |
366 | 0 | }, Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14pending_changeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14pending_changeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ |
367 | 0 | )(bytes) |
368 | 0 | } Unexecuted instantiation: _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14pending_changeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14pending_changeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
369 | | |
370 | | #[derive(Debug)] |
371 | | pub(super) enum DelayKind { |
372 | | Finalized, |
373 | | Best { _median_last_finalized: u32 }, |
374 | | } |
375 | | |
376 | 0 | fn delay_kind<'a, E: nom::error::ParseError<&'a [u8]>>( |
377 | 0 | bytes: &'a [u8], |
378 | 0 | ) -> nom::IResult<&'a [u8], DelayKind, E> { |
379 | 0 | nom::branch::alt(( |
380 | 0 | nom::combinator::map(nom::bytes::streaming::tag(&[0]), |_| DelayKind::Finalized), Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10delay_kindINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10delay_kindINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
381 | 0 | nom::combinator::map( |
382 | 0 | nom::sequence::preceded( |
383 | 0 | nom::bytes::streaming::tag(&[1]), |
384 | 0 | nom::number::streaming::le_u32, |
385 | 0 | ), |
386 | 0 | |median_last_finalized| DelayKind::Best { |
387 | 0 | _median_last_finalized: median_last_finalized, |
388 | 0 | }, Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10delay_kindINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10delay_kindINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ |
389 | 0 | ), |
390 | 0 | ))(bytes) |
391 | 0 | } Unexecuted instantiation: _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state10delay_kindINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state10delay_kindINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
392 | | |
393 | | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
394 | | pub struct GrandpaAuthority { |
395 | | /// Ed25519 public key. |
396 | | pub public_key: [u8; 32], |
397 | | |
398 | | /// Arbitrary number indicating the weight of the authority. |
399 | | /// |
400 | | /// This value can only be compared to other weight values. |
401 | | // TODO: should be NonZeroU64; requires deep changes in decoding code though |
402 | | pub weight: u64, |
403 | | } |
404 | | |
405 | 2 | fn grandpa_authority<'a, E: nom::error::ParseError<&'a [u8]>>( |
406 | 2 | bytes: &'a [u8], |
407 | 2 | ) -> nom::IResult<&'a [u8], GrandpaAuthority, E> { |
408 | 2 | nom::combinator::map( |
409 | 2 | nom::sequence::tuple(( |
410 | 2 | nom::bytes::streaming::take(32u32), |
411 | 2 | nom::number::streaming::le_u64, |
412 | 2 | )), |
413 | 2 | move |(public_key, weight)| GrandpaAuthority { |
414 | 2 | public_key: *<&[u8; 32]>::try_from(public_key).unwrap(), |
415 | 2 | weight, |
416 | 2 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state17grandpa_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 413 | 2 | move |(public_key, weight)| GrandpaAuthority { | 414 | 2 | public_key: *<&[u8; 32]>::try_from(public_key).unwrap(), | 415 | 2 | weight, | 416 | 2 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state17grandpa_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
417 | 2 | )(bytes) |
418 | 2 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state17grandpa_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 405 | 2 | fn grandpa_authority<'a, E: nom::error::ParseError<&'a [u8]>>( | 406 | 2 | bytes: &'a [u8], | 407 | 2 | ) -> nom::IResult<&'a [u8], GrandpaAuthority, E> { | 408 | 2 | nom::combinator::map( | 409 | 2 | nom::sequence::tuple(( | 410 | 2 | nom::bytes::streaming::take(32u32), | 411 | 2 | nom::number::streaming::le_u64, | 412 | 2 | )), | 413 | 2 | move |(public_key, weight)| GrandpaAuthority { | 414 | | public_key: *<&[u8; 32]>::try_from(public_key).unwrap(), | 415 | | weight, | 416 | 2 | }, | 417 | 2 | )(bytes) | 418 | 2 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state17grandpa_authorityINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
419 | | |
420 | | #[derive(Debug)] |
421 | | pub(super) struct ForkTree<T> { |
422 | | _roots: Vec<ForkTreeNode<T>>, |
423 | | _best_finalized_number: Option<u32>, |
424 | | } |
425 | | |
426 | 4 | fn fork_tree<'a, T, E: nom::error::ParseError<&'a [u8]>>( |
427 | 4 | mut inner: impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], T, E>, |
428 | 4 | ) -> impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], ForkTree<T>, E> { |
429 | 4 | nom::combinator::map( |
430 | 4 | nom::sequence::tuple(( |
431 | 4 | // We do parsing manually due to borrow checking troubles regarding `inner`. |
432 | 4 | move |mut bytes| { |
433 | 4 | let (bytes_rest, num_roots) = match crate::util::nom_scale_compact_usize(bytes) { |
434 | 4 | Ok(d) => d, |
435 | 0 | Err(err) => return Err(err), |
436 | | }; |
437 | 4 | bytes = bytes_rest; |
438 | 4 | |
439 | 4 | let mut roots = Vec::with_capacity(num_roots); |
440 | 4 | for _ in 0..num_roots { |
441 | 2 | let (bytes_rest, child) = match fork_tree_node(&mut inner)(bytes) { |
442 | 2 | Ok(d) => d, |
443 | 0 | Err(err) => return Err(err), |
444 | | }; |
445 | 2 | bytes = bytes_rest; |
446 | 2 | roots.push(child); |
447 | | } |
448 | | |
449 | 4 | Ok((bytes, roots)) |
450 | 4 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_14pending_changeB1r_EE0B8_ Line | Count | Source | 432 | 2 | move |mut bytes| { | 433 | 2 | let (bytes_rest, num_roots) = match crate::util::nom_scale_compact_usize(bytes) { | 434 | 2 | Ok(d) => d, | 435 | 0 | Err(err) => return Err(err), | 436 | | }; | 437 | 2 | bytes = bytes_rest; | 438 | 2 | | 439 | 2 | let mut roots = Vec::with_capacity(num_roots); | 440 | 2 | for _ in 0..num_roots { | 441 | 0 | let (bytes_rest, child) = match fork_tree_node(&mut inner)(bytes) { | 442 | 0 | Ok(d) => d, | 443 | 0 | Err(err) => return Err(err), | 444 | | }; | 445 | 0 | bytes = bytes_rest; | 446 | 0 | roots.push(child); | 447 | | } | 448 | | | 449 | 2 | Ok((bytes, roots)) | 450 | 2 | }, |
_RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_22persisted_epoch_headerB1y_EE0B8_ Line | Count | Source | 432 | 2 | move |mut bytes| { | 433 | 2 | let (bytes_rest, num_roots) = match crate::util::nom_scale_compact_usize(bytes) { | 434 | 2 | Ok(d) => d, | 435 | 0 | Err(err) => return Err(err), | 436 | | }; | 437 | 2 | bytes = bytes_rest; | 438 | 2 | | 439 | 2 | let mut roots = Vec::with_capacity(num_roots); | 440 | 2 | for _ in 0..num_roots { | 441 | 2 | let (bytes_rest, child) = match fork_tree_node(&mut inner)(bytes) { | 442 | 2 | Ok(d) => d, | 443 | 0 | Err(err) => return Err(err), | 444 | | }; | 445 | 2 | bytes = bytes_rest; | 446 | 2 | roots.push(child); | 447 | | } | 448 | | | 449 | 2 | Ok((bytes, roots)) | 450 | 2 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_14pending_changeB1s_EE0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_22persisted_epoch_headerB1z_EE0B8_ |
451 | 4 | crate::util::nom_option_decode(nom::number::streaming::le_u32), |
452 | 4 | )), |
453 | 4 | |(roots, best_finalized_number)| ForkTree { |
454 | 4 | _roots: roots, |
455 | 4 | _best_finalized_number: best_finalized_number, |
456 | 4 | }, _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_14pending_changeB1r_EEs_0B8_ Line | Count | Source | 453 | 2 | |(roots, best_finalized_number)| ForkTree { | 454 | 2 | _roots: roots, | 455 | 2 | _best_finalized_number: best_finalized_number, | 456 | 2 | }, |
_RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_22persisted_epoch_headerB1y_EEs_0B8_ Line | Count | Source | 453 | 2 | |(roots, best_finalized_number)| ForkTree { | 454 | 2 | _roots: roots, | 455 | 2 | _best_finalized_number: best_finalized_number, | 456 | 2 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_14pending_changeB1s_EEs_0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state9fork_treeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB4_22persisted_epoch_headerB1z_EEs_0B8_ |
457 | 4 | ) |
458 | 4 | } _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state9fork_treeNtB2_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB2_22persisted_epoch_headerB1w_EEB6_ Line | Count | Source | 426 | 2 | fn fork_tree<'a, T, E: nom::error::ParseError<&'a [u8]>>( | 427 | 2 | mut inner: impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], T, E>, | 428 | 2 | ) -> impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], ForkTree<T>, E> { | 429 | 2 | nom::combinator::map( | 430 | 2 | nom::sequence::tuple(( | 431 | 2 | // We do parsing manually due to borrow checking troubles regarding `inner`. | 432 | 2 | move |mut bytes| { | 433 | | let (bytes_rest, num_roots) = match crate::util::nom_scale_compact_usize(bytes) { | 434 | | Ok(d) => d, | 435 | | Err(err) => return Err(err), | 436 | | }; | 437 | | bytes = bytes_rest; | 438 | | | 439 | | let mut roots = Vec::with_capacity(num_roots); | 440 | | for _ in 0..num_roots { | 441 | | let (bytes_rest, child) = match fork_tree_node(&mut inner)(bytes) { | 442 | | Ok(d) => d, | 443 | | Err(err) => return Err(err), | 444 | | }; | 445 | | bytes = bytes_rest; | 446 | | roots.push(child); | 447 | | } | 448 | | | 449 | | Ok((bytes, roots)) | 450 | 2 | }, | 451 | 2 | crate::util::nom_option_decode(nom::number::streaming::le_u32), | 452 | 2 | )), | 453 | 2 | |(roots, best_finalized_number)| ForkTree { | 454 | | _roots: roots, | 455 | | _best_finalized_number: best_finalized_number, | 456 | 2 | }, | 457 | 2 | ) | 458 | 2 | } |
_RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state9fork_treeNtB2_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB2_14pending_changeB1p_EEB6_ Line | Count | Source | 426 | 2 | fn fork_tree<'a, T, E: nom::error::ParseError<&'a [u8]>>( | 427 | 2 | mut inner: impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], T, E>, | 428 | 2 | ) -> impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], ForkTree<T>, E> { | 429 | 2 | nom::combinator::map( | 430 | 2 | nom::sequence::tuple(( | 431 | 2 | // We do parsing manually due to borrow checking troubles regarding `inner`. | 432 | 2 | move |mut bytes| { | 433 | | let (bytes_rest, num_roots) = match crate::util::nom_scale_compact_usize(bytes) { | 434 | | Ok(d) => d, | 435 | | Err(err) => return Err(err), | 436 | | }; | 437 | | bytes = bytes_rest; | 438 | | | 439 | | let mut roots = Vec::with_capacity(num_roots); | 440 | | for _ in 0..num_roots { | 441 | | let (bytes_rest, child) = match fork_tree_node(&mut inner)(bytes) { | 442 | | Ok(d) => d, | 443 | | Err(err) => return Err(err), | 444 | | }; | 445 | | bytes = bytes_rest; | 446 | | roots.push(child); | 447 | | } | 448 | | | 449 | | Ok((bytes, roots)) | 450 | 2 | }, | 451 | 2 | crate::util::nom_option_decode(nom::number::streaming::le_u32), | 452 | 2 | )), | 453 | 2 | |(roots, best_finalized_number)| ForkTree { | 454 | | _roots: roots, | 455 | | _best_finalized_number: best_finalized_number, | 456 | 2 | }, | 457 | 2 | ) | 458 | 2 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state9fork_treeNtB2_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB2_22persisted_epoch_headerB1x_EEB6_ Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state9fork_treeNtB2_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEINvB2_14pending_changeB1q_EEB6_ |
459 | | |
460 | | #[derive(Debug)] |
461 | | pub(super) struct ForkTreeNode<T> { |
462 | | _hash: [u8; 32], |
463 | | _number: u32, |
464 | | _data: T, |
465 | | _children: Vec<Self>, |
466 | | } |
467 | | |
468 | 2 | fn fork_tree_node<'a, 'p, T, E: nom::error::ParseError<&'a [u8]>>( |
469 | 2 | inner: &'p mut dyn FnMut(&'a [u8]) -> nom::IResult<&'a [u8], T, E>, |
470 | 2 | ) -> impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], ForkTreeNode<T>, E> + 'p { |
471 | 2 | nom::combinator::map( |
472 | 2 | nom::sequence::tuple(( |
473 | 2 | nom::bytes::streaming::take(32u32), |
474 | 2 | nom::number::streaming::le_u32, |
475 | 2 | // We do parsing manually due to borrow checking troubles regarding `inner`. |
476 | 2 | move |mut bytes| { |
477 | 2 | let (bytes_rest, data) = match inner(bytes) { |
478 | 2 | Ok(d) => d, |
479 | 0 | Err(err) => return Err(err), |
480 | | }; |
481 | 2 | bytes = bytes_rest; |
482 | | |
483 | 2 | let (bytes_rest, num_children) = match crate::util::nom_scale_compact_usize(bytes) { |
484 | 2 | Ok(d) => d, |
485 | 0 | Err(err) => return Err(err), |
486 | | }; |
487 | 2 | bytes = bytes_rest; |
488 | 2 | |
489 | 2 | let mut children = Vec::with_capacity(num_children); |
490 | 2 | for _ in 0..num_children { |
491 | 0 | let (bytes_rest, child) = match fork_tree_node(&mut *inner)(bytes) { |
492 | 0 | Ok(d) => d, |
493 | 0 | Err(err) => return Err(err), |
494 | | }; |
495 | 0 | bytes = bytes_rest; |
496 | 0 | children.push(child); |
497 | | } |
498 | | |
499 | 2 | Ok((bytes, (data, children))) |
500 | 2 | }, Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Line | Count | Source | 476 | 2 | move |mut bytes| { | 477 | 2 | let (bytes_rest, data) = match inner(bytes) { | 478 | 2 | Ok(d) => d, | 479 | 0 | Err(err) => return Err(err), | 480 | | }; | 481 | 2 | bytes = bytes_rest; | 482 | | | 483 | 2 | let (bytes_rest, num_children) = match crate::util::nom_scale_compact_usize(bytes) { | 484 | 2 | Ok(d) => d, | 485 | 0 | Err(err) => return Err(err), | 486 | | }; | 487 | 2 | bytes = bytes_rest; | 488 | 2 | | 489 | 2 | let mut children = Vec::with_capacity(num_children); | 490 | 2 | for _ in 0..num_children { | 491 | 0 | let (bytes_rest, child) = match fork_tree_node(&mut *inner)(bytes) { | 492 | 0 | Ok(d) => d, | 493 | 0 | Err(err) => return Err(err), | 494 | | }; | 495 | 0 | bytes = bytes_rest; | 496 | 0 | children.push(child); | 497 | | } | 498 | | | 499 | 2 | Ok((bytes, (data, children))) | 500 | 2 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEE0B8_ |
501 | 2 | )), |
502 | 2 | |(hash, number, (data, children))| ForkTreeNode { |
503 | 2 | _hash: *<&[u8; 32]>::try_from(hash).unwrap(), |
504 | 2 | _number: number, |
505 | 2 | _data: data, |
506 | 2 | _children: children, |
507 | 2 | }, Unexecuted instantiation: _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ _RNCINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ Line | Count | Source | 502 | 2 | |(hash, number, (data, children))| ForkTreeNode { | 503 | 2 | _hash: *<&[u8; 32]>::try_from(hash).unwrap(), | 504 | 2 | _number: number, | 505 | 2 | _data: data, | 506 | 2 | _children: children, | 507 | 2 | }, |
Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ Unexecuted instantiation: _RNCINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB4_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEs_0B8_ |
508 | 2 | ) |
509 | 2 | } Unexecuted instantiation: _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB2_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ _RINvNtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB2_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Line | Count | Source | 468 | 2 | fn fork_tree_node<'a, 'p, T, E: nom::error::ParseError<&'a [u8]>>( | 469 | 2 | inner: &'p mut dyn FnMut(&'a [u8]) -> nom::IResult<&'a [u8], T, E>, | 470 | 2 | ) -> impl FnMut(&'a [u8]) -> nom::IResult<&'a [u8], ForkTreeNode<T>, E> + 'p { | 471 | 2 | nom::combinator::map( | 472 | 2 | nom::sequence::tuple(( | 473 | 2 | nom::bytes::streaming::take(32u32), | 474 | 2 | nom::number::streaming::le_u32, | 475 | 2 | // We do parsing manually due to borrow checking troubles regarding `inner`. | 476 | 2 | move |mut bytes| { | 477 | | let (bytes_rest, data) = match inner(bytes) { | 478 | | Ok(d) => d, | 479 | | Err(err) => return Err(err), | 480 | | }; | 481 | | bytes = bytes_rest; | 482 | | | 483 | | let (bytes_rest, num_children) = match crate::util::nom_scale_compact_usize(bytes) { | 484 | | Ok(d) => d, | 485 | | Err(err) => return Err(err), | 486 | | }; | 487 | | bytes = bytes_rest; | 488 | | | 489 | | let mut children = Vec::with_capacity(num_children); | 490 | | for _ in 0..num_children { | 491 | | let (bytes_rest, child) = match fork_tree_node(&mut *inner)(bytes) { | 492 | | Ok(d) => d, | 493 | | Err(err) => return Err(err), | 494 | | }; | 495 | | bytes = bytes_rest; | 496 | | children.push(child); | 497 | | } | 498 | | | 499 | | Ok((bytes, (data, children))) | 500 | 2 | }, | 501 | 2 | )), | 502 | 2 | |(hash, number, (data, children))| ForkTreeNode { | 503 | | _hash: *<&[u8; 32]>::try_from(hash).unwrap(), | 504 | | _number: number, | 505 | | _data: data, | 506 | | _children: children, | 507 | 2 | }, | 508 | 2 | ) | 509 | 2 | } |
Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB2_13PendingChangeINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ Unexecuted instantiation: _RINvNtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_state14fork_tree_nodeNtB2_20PersistedEpochHeaderINtNtCs6ga8gEqbpRc_3nom5error5ErrorRShEEB6_ |
510 | | |
511 | | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
512 | | pub(super) struct HexString(pub(super) Vec<u8>); |
513 | | |
514 | | impl serde::Serialize for HexString { |
515 | 0 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
516 | 0 | where |
517 | 0 | S: serde::Serializer, |
518 | 0 | { |
519 | 0 | format!("0x{}", hex::encode(&self.0[..])).serialize(serializer) |
520 | 0 | } Unexecuted instantiation: _RINvXs_NtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_stateNtB5_9HexStringNtNtCsf0yC2YK6bpM_5serde3ser9Serialize9serializepEB9_ Unexecuted instantiation: _RINvXs_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB5_9HexStringNtNtCsf0yC2YK6bpM_5serde3ser9Serialize9serializeINtNtCscu7pqq74Vb8_10serde_json3ser18RawValueStrEmitterQINtNtCsdZExvAaxgia_5alloc3vec3VechENtB23_15PrettyFormatterEEB9_ Unexecuted instantiation: _RINvXs_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB5_9HexStringNtNtCsf0yC2YK6bpM_5serde3ser9Serialize9serializeQINtNtCscu7pqq74Vb8_10serde_json3ser10SerializerQINtNtCsdZExvAaxgia_5alloc3vec3VechENtB24_15PrettyFormatterEEB9_ |
521 | | } |
522 | | |
523 | | impl<'a> serde::Deserialize<'a> for HexString { |
524 | 3 | fn deserialize<D>(deserializer: D) -> Result<HexString, D::Error> |
525 | 3 | where |
526 | 3 | D: serde::Deserializer<'a>, |
527 | 3 | { |
528 | 3 | let string = String::deserialize(deserializer)?0 ; |
529 | | |
530 | 3 | if !string.starts_with("0x") { |
531 | 0 | return Err(serde::de::Error::custom( |
532 | 0 | "hexadecimal string doesn't start with 0x", |
533 | 0 | )); |
534 | 3 | } |
535 | | |
536 | 3 | let bytes = hex::decode(&string[2..]).map_err(serde::de::Error::custom)?0 ; |
537 | 3 | Ok(HexString(bytes)) |
538 | 3 | } Unexecuted instantiation: _RINvXs0_NtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeINtNvNtNtB1i_9___private2de13missing_field24MissingFieldDeserializerNtNtCscu7pqq74Vb8_10serde_json5error5ErrorEEBa_ _RINvXs0_NtNtCsN16ciHI6Qf_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeQINtNtCscu7pqq74Vb8_10serde_json2de12DeserializerNtNtB2b_4read9SliceReadEEBa_ Line | Count | Source | 524 | 3 | fn deserialize<D>(deserializer: D) -> Result<HexString, D::Error> | 525 | 3 | where | 526 | 3 | D: serde::Deserializer<'a>, | 527 | 3 | { | 528 | 3 | let string = String::deserialize(deserializer)?0 ; | 529 | | | 530 | 3 | if !string.starts_with("0x") { | 531 | 0 | return Err(serde::de::Error::custom( | 532 | 0 | "hexadecimal string doesn't start with 0x", | 533 | 0 | )); | 534 | 3 | } | 535 | | | 536 | 3 | let bytes = hex::decode(&string[2..]).map_err(serde::de::Error::custom)?0 ; | 537 | 3 | Ok(HexString(bytes)) | 538 | 3 | } |
Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeINtNvNtNtB1j_9___private2de13missing_field24MissingFieldDeserializerNtNtCscu7pqq74Vb8_10serde_json5error5ErrorEECsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeQINtNtCscu7pqq74Vb8_10serde_json2de12DeserializerNtNtB2c_4read9SliceReadEECsDDUKWWCHAU_18smoldot_light_wasm Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializepEBa_ Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeINtNvNtNtB1j_9___private2de13missing_field24MissingFieldDeserializerNtNtCscu7pqq74Vb8_10serde_json5error5ErrorEECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeQINtNtCscu7pqq74Vb8_10serde_json2de12DeserializerNtNtB2c_4read9SliceReadEECsiLzmwikkc22_14json_rpc_basic Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeINtNvNtNtB1j_9___private2de13missing_field24MissingFieldDeserializerNtNtCscu7pqq74Vb8_10serde_json5error5ErrorEECscDgN54JpMGG_6author Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeQINtNtCscu7pqq74Vb8_10serde_json2de12DeserializerNtNtB2c_4read9SliceReadEECscDgN54JpMGG_6author Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeINtNvNtNtB1j_9___private2de13missing_field24MissingFieldDeserializerNtNtCscu7pqq74Vb8_10serde_json5error5ErrorEECsibGXYHQB8Ea_25json_rpc_general_requests Unexecuted instantiation: _RINvXs0_NtNtCseuYC0Zibziv_7smoldot10chain_spec16light_sync_stateNtB6_9HexStringNtNtCsf0yC2YK6bpM_5serde2de11Deserialize11deserializeQINtNtCscu7pqq74Vb8_10serde_json2de12DeserializerNtNtB2c_4read9SliceReadEECsibGXYHQB8Ea_25json_rpc_general_requests |
539 | | } |