Coverage Report

Created: 2024-05-16 12:16

/__w/smoldot/smoldot/repo/lib/src/finality/decode.rs
Line
Count
Source (jump to first uncovered line)
1
// Smoldot
2
// Copyright (C) 2023  Pierre Krieger
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 crate::header;
19
20
use alloc::vec::Vec;
21
use core::fmt;
22
23
/// Attempt to decode the given SCALE-encoded justification.
24
1
pub fn decode_grandpa_justification(
25
1
    scale_encoded: &[u8],
26
1
    block_number_bytes: usize,
27
1
) -> Result<GrandpaJustificationRef, JustificationDecodeError> {
28
1
    match nom::combinator::complete(nom::combinator::all_consuming(grandpa_justification(
29
1
        block_number_bytes,
30
1
    )))(scale_encoded)
31
    {
32
1
        Ok((_, justification)) => Ok(justification),
33
0
        Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
34
0
            Err(JustificationDecodeError(err.code))
35
        }
36
0
        Err(_) => unreachable!(),
37
    }
38
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode28decode_grandpa_justification
Line
Count
Source
24
1
pub fn decode_grandpa_justification(
25
1
    scale_encoded: &[u8],
26
1
    block_number_bytes: usize,
27
1
) -> Result<GrandpaJustificationRef, JustificationDecodeError> {
28
1
    match nom::combinator::complete(nom::combinator::all_consuming(grandpa_justification(
29
1
        block_number_bytes,
30
1
    )))(scale_encoded)
31
    {
32
1
        Ok((_, justification)) => Ok(justification),
33
0
        Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
34
0
            Err(JustificationDecodeError(err.code))
35
        }
36
0
        Err(_) => unreachable!(),
37
    }
38
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode28decode_grandpa_justification
39
40
/// Attempt to decode the given SCALE-encoded justification.
41
///
42
/// Contrary to [`decode_grandpa_justification`], doesn't return an error if the slice is too long
43
/// but returns the remainder.
44
0
pub fn decode_partial_grandpa_justification(
45
0
    scale_encoded: &[u8],
46
0
    block_number_bytes: usize,
47
0
) -> Result<(GrandpaJustificationRef, &[u8]), JustificationDecodeError> {
48
0
    match nom::combinator::complete(grandpa_justification(block_number_bytes))(scale_encoded) {
49
0
        Ok((remainder, justification)) => Ok((justification, remainder)),
50
0
        Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
51
0
            Err(JustificationDecodeError(err.code))
52
        }
53
0
        Err(_) => unreachable!(),
54
    }
55
0
}
Unexecuted instantiation: _RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode36decode_partial_grandpa_justification
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode36decode_partial_grandpa_justification
56
57
/// Decoded justification.
58
// TODO: document and explain
59
#[derive(Debug)]
60
pub struct GrandpaJustificationRef<'a> {
61
    pub round: u64,
62
    pub target_hash: &'a [u8; 32],
63
    pub target_number: u64,
64
    pub precommits: PrecommitsRef<'a>,
65
    pub votes_ancestries: VotesAncestriesIter<'a>,
66
}
67
68
/// Decoded justification.
69
// TODO: document and explain
70
#[derive(Debug)]
71
pub struct GrandpaJustification {
72
    pub round: u64,
73
    pub target_hash: [u8; 32],
74
    pub target_number: u64,
75
    pub precommits: Vec<Precommit>,
76
    // TODO: pub votes_ancestries: Vec<Header>,
77
}
78
79
/// Attempt to decode the given SCALE-encoded Grandpa commit.
80
1
pub fn decode_grandpa_commit(
81
1
    scale_encoded: &[u8],
82
1
    block_number_bytes: usize,
83
1
) -> Result<CommitMessageRef, CommitDecodeError> {
84
1
    match nom::combinator::all_consuming(commit_message(block_number_bytes))(scale_encoded) {
85
1
        Ok((_, commit)) => Ok(commit),
86
0
        Err(err) => Err(CommitDecodeError(err)),
87
    }
88
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode21decode_grandpa_commit
Line
Count
Source
80
1
pub fn decode_grandpa_commit(
81
1
    scale_encoded: &[u8],
82
1
    block_number_bytes: usize,
83
1
) -> Result<CommitMessageRef, CommitDecodeError> {
84
1
    match nom::combinator::all_consuming(commit_message(block_number_bytes))(scale_encoded) {
85
1
        Ok((_, commit)) => Ok(commit),
86
0
        Err(err) => Err(CommitDecodeError(err)),
87
    }
88
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode21decode_grandpa_commit
89
90
/// Attempt to decode the given SCALE-encoded commit.
91
///
92
/// Contrary to [`decode_grandpa_commit`], doesn't return an error if the slice is too long, but
93
/// returns the remainder.
94
0
pub fn decode_partial_grandpa_commit(
95
0
    scale_encoded: &[u8],
96
0
    block_number_bytes: usize,
97
0
) -> Result<(CommitMessageRef, &[u8]), CommitDecodeError> {
98
0
    match commit_message(block_number_bytes)(scale_encoded) {
99
0
        Ok((remainder, commit)) => Ok((commit, remainder)),
100
0
        Err(err) => Err(CommitDecodeError(err)),
101
    }
102
0
}
Unexecuted instantiation: _RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode29decode_partial_grandpa_commit
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode29decode_partial_grandpa_commit
103
104
/// Error potentially returned by [`decode_grandpa_commit`].
105
0
#[derive(Debug, derive_more::Display)]
Unexecuted instantiation: _RNvXsc_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_17CommitDecodeErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt
Unexecuted instantiation: _RNvXsc_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_17CommitDecodeErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt
106
pub struct CommitDecodeError<'a>(nom::Err<nom::error::Error<&'a [u8]>>);
107
108
// TODO: document and explain
109
#[derive(Debug, Clone, PartialEq, Eq)]
110
pub struct CommitMessageRef<'a> {
111
    pub round_number: u64,
112
    pub set_id: u64,
113
    pub target_hash: &'a [u8; 32],
114
    pub target_number: u64,
115
    // TODO: don't use Vec
116
    pub precommits: Vec<UnsignedPrecommitRef<'a>>,
117
118
    /// List of Ed25519 signatures and public keys.
119
    // TODO: refactor
120
    // TODO: don't use Vec
121
    pub auth_data: Vec<(&'a [u8; 64], &'a [u8; 32])>,
122
}
123
124
#[derive(Debug, Clone, PartialEq, Eq)]
125
pub struct UnsignedPrecommitRef<'a> {
126
    pub target_hash: &'a [u8; 32],
127
    pub target_number: u64,
128
}
129
130
const PRECOMMIT_ENCODED_LEN: usize = 32 + 4 + 64 + 32;
131
132
impl<'a> From<&'a GrandpaJustification> for GrandpaJustificationRef<'a> {
133
0
    fn from(j: &'a GrandpaJustification) -> GrandpaJustificationRef<'a> {
134
0
        GrandpaJustificationRef {
135
0
            round: j.round,
136
0
            target_hash: &j.target_hash,
137
0
            target_number: j.target_number,
138
0
            precommits: PrecommitsRef {
139
0
                inner: PrecommitsRefInner::Decoded(&j.precommits),
140
0
            },
141
0
            // TODO:
142
0
            votes_ancestries: VotesAncestriesIter {
143
0
                slice: &[],
144
0
                num: 0,
145
0
                block_number_bytes: 4,
146
0
            },
147
0
        }
148
0
    }
Unexecuted instantiation: _RNvXNtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB2_23GrandpaJustificationRefINtNtCsaYZPK01V26L_4core7convert4FromRNtB2_20GrandpaJustificationE4from
Unexecuted instantiation: _RNvXNtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB2_23GrandpaJustificationRefINtNtCsaYZPK01V26L_4core7convert4FromRNtB2_20GrandpaJustificationE4from
149
}
150
151
impl<'a> From<GrandpaJustificationRef<'a>> for GrandpaJustification {
152
0
    fn from(j: GrandpaJustificationRef<'a>) -> GrandpaJustification {
153
0
        GrandpaJustification {
154
0
            round: j.round,
155
0
            target_hash: *j.target_hash,
156
0
            target_number: j.target_number,
157
0
            precommits: j.precommits.iter().map(Into::into).collect(),
158
0
        }
159
0
    }
Unexecuted instantiation: _RNvXs_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB4_20GrandpaJustificationINtNtCsaYZPK01V26L_4core7convert4FromNtB4_23GrandpaJustificationRefE4from
Unexecuted instantiation: _RNvXs_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB4_20GrandpaJustificationINtNtCsaYZPK01V26L_4core7convert4FromNtB4_23GrandpaJustificationRefE4from
160
}
161
162
#[derive(Copy, Clone)]
163
pub struct PrecommitsRef<'a> {
164
    inner: PrecommitsRefInner<'a>,
165
}
166
167
impl<'a> fmt::Debug for PrecommitsRef<'a> {
168
0
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
169
0
        f.debug_list().entries(self.iter()).finish()
170
0
    }
Unexecuted instantiation: _RNvXs0_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_13PrecommitsRefNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt
Unexecuted instantiation: _RNvXs0_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_13PrecommitsRefNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt
171
}
172
173
#[derive(Copy, Clone)]
174
enum PrecommitsRefInner<'a> {
175
    Undecoded {
176
        data: &'a [u8],
177
        block_number_bytes: usize,
178
    },
179
    Decoded(&'a [Precommit]),
180
}
181
182
impl<'a> PrecommitsRef<'a> {
183
0
    pub fn iter(&self) -> impl ExactSizeIterator<Item = PrecommitRef<'a>> + 'a {
184
0
        match self.inner {
185
            PrecommitsRefInner::Undecoded {
186
0
                data,
187
0
                block_number_bytes,
188
0
            } => {
189
0
                debug_assert_eq!(data.len() % PRECOMMIT_ENCODED_LEN, 0);
190
0
                PrecommitsRefIter {
191
0
                    inner: PrecommitsRefIterInner::Undecoded {
192
0
                        block_number_bytes,
193
0
                        remaining_len: data.len() / PRECOMMIT_ENCODED_LEN,
194
0
                        pointer: data,
195
0
                    },
196
0
                }
197
            }
198
0
            PrecommitsRefInner::Decoded(slice) => PrecommitsRefIter {
199
0
                inner: PrecommitsRefIterInner::Decoded(slice.iter()),
200
0
            },
201
        }
202
0
    }
Unexecuted instantiation: _RNvMs1_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_13PrecommitsRef4iter
Unexecuted instantiation: _RNvMs1_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_13PrecommitsRef4iter
203
}
204
205
pub struct PrecommitsRefIter<'a> {
206
    inner: PrecommitsRefIterInner<'a>,
207
}
208
209
enum PrecommitsRefIterInner<'a> {
210
    Decoded(core::slice::Iter<'a, Precommit>),
211
    Undecoded {
212
        block_number_bytes: usize,
213
        remaining_len: usize,
214
        pointer: &'a [u8],
215
    },
216
}
217
218
impl<'a> Iterator for PrecommitsRefIter<'a> {
219
    type Item = PrecommitRef<'a>;
220
221
0
    fn next(&mut self) -> Option<Self::Item> {
222
0
        match &mut self.inner {
223
0
            PrecommitsRefIterInner::Decoded(iter) => iter.next().map(Into::into),
224
            PrecommitsRefIterInner::Undecoded {
225
0
                block_number_bytes,
226
0
                pointer,
227
0
                remaining_len,
228
0
            } => {
229
0
                if *remaining_len == 0 {
230
0
                    return None;
231
0
                }
232
0
233
0
                let (new_pointer, precommit) = precommit(*block_number_bytes)(pointer).unwrap();
234
0
                *pointer = new_pointer;
235
0
                *remaining_len -= 1;
236
0
237
0
                Some(precommit)
238
            }
239
        }
240
0
    }
Unexecuted instantiation: _RNvXs2_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_17PrecommitsRefIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator4next
Unexecuted instantiation: _RNvXs2_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_17PrecommitsRefIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator4next
241
242
0
    fn size_hint(&self) -> (usize, Option<usize>) {
243
0
        match &self.inner {
244
0
            PrecommitsRefIterInner::Decoded(iter) => iter.size_hint(),
245
0
            PrecommitsRefIterInner::Undecoded { remaining_len, .. } => {
246
0
                (*remaining_len, Some(*remaining_len))
247
            }
248
        }
249
0
    }
Unexecuted instantiation: _RNvXs2_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_17PrecommitsRefIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator9size_hint
Unexecuted instantiation: _RNvXs2_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_17PrecommitsRefIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator9size_hint
250
}
251
252
impl<'a> ExactSizeIterator for PrecommitsRefIter<'a> {}
253
254
#[derive(Debug, Clone, PartialEq, Eq)]
255
pub struct PrecommitRef<'a> {
256
    /// Hash of the block concerned by the pre-commit.
257
    pub target_hash: &'a [u8; 32],
258
    /// Height of the block concerned by the pre-commit.
259
    pub target_number: u64,
260
261
    /// Ed25519 signature made with [`PrecommitRef::authority_public_key`].
262
    // TODO: document what is being signed
263
    pub signature: &'a [u8; 64],
264
265
    /// Authority that signed the precommit. Must be part of the authority set for the
266
    /// justification to be valid.
267
    pub authority_public_key: &'a [u8; 32],
268
}
269
270
impl<'a> PrecommitRef<'a> {
271
    /// Decodes a SCALE-encoded precommit.
272
    ///
273
    /// Returns the rest of the data alongside with the decoded struct.
274
0
    pub fn decode_partial(
275
0
        scale_encoded: &[u8],
276
0
        block_number_bytes: usize,
277
0
    ) -> Result<(PrecommitRef, &[u8]), JustificationDecodeError> {
278
0
        match precommit(block_number_bytes)(scale_encoded) {
279
0
            Ok((remainder, precommit)) => Ok((precommit, remainder)),
280
0
            Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
281
0
                Err(JustificationDecodeError(err.code))
282
            }
283
0
            Err(_) => unreachable!(),
284
        }
285
0
    }
Unexecuted instantiation: _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_12PrecommitRef14decode_partial
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_12PrecommitRef14decode_partial
286
}
287
288
#[derive(Debug, Clone, PartialEq, Eq)]
289
pub struct Precommit {
290
    /// Hash of the block concerned by the pre-commit.
291
    pub target_hash: [u8; 32],
292
    /// Height of the block concerned by the pre-commit.
293
    pub target_number: u64,
294
295
    /// Ed25519 signature made with [`PrecommitRef::authority_public_key`].
296
    // TODO: document what is being signed
297
    pub signature: [u8; 64],
298
299
    /// Authority that signed the precommit. Must be part of the authority set for the
300
    /// justification to be valid.
301
    pub authority_public_key: [u8; 32],
302
}
303
304
impl<'a> From<&'a Precommit> for PrecommitRef<'a> {
305
0
    fn from(pc: &'a Precommit) -> PrecommitRef<'a> {
306
0
        PrecommitRef {
307
0
            target_hash: &pc.target_hash,
308
0
            target_number: pc.target_number,
309
0
            signature: &pc.signature,
310
0
            authority_public_key: &pc.authority_public_key,
311
0
        }
312
0
    }
Unexecuted instantiation: _RNvXs5_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_12PrecommitRefINtNtCsaYZPK01V26L_4core7convert4FromRNtB5_9PrecommitE4from
Unexecuted instantiation: _RNvXs5_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_12PrecommitRefINtNtCsaYZPK01V26L_4core7convert4FromRNtB5_9PrecommitE4from
313
}
314
315
impl<'a> From<PrecommitRef<'a>> for Precommit {
316
0
    fn from(pc: PrecommitRef<'a>) -> Precommit {
317
0
        Precommit {
318
0
            target_hash: *pc.target_hash,
319
0
            target_number: pc.target_number,
320
0
            signature: *pc.signature,
321
0
            authority_public_key: *pc.authority_public_key,
322
0
        }
323
0
    }
Unexecuted instantiation: _RNvXs6_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_9PrecommitINtNtCsaYZPK01V26L_4core7convert4FromNtB5_12PrecommitRefE4from
Unexecuted instantiation: _RNvXs6_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_9PrecommitINtNtCsaYZPK01V26L_4core7convert4FromNtB5_12PrecommitRefE4from
324
}
325
326
/// Iterator towards the headers of the vote ancestries.
327
#[derive(Debug, Clone)]
328
pub struct VotesAncestriesIter<'a> {
329
    /// Encoded headers.
330
    slice: &'a [u8],
331
    /// Number of headers items remaining.
332
    num: usize,
333
    /// Number of bytes when encoding the block number.
334
    block_number_bytes: usize,
335
}
336
337
impl<'a> Iterator for VotesAncestriesIter<'a> {
338
    type Item = header::HeaderRef<'a>;
339
340
0
    fn next(&mut self) -> Option<Self::Item> {
341
0
        if self.num == 0 {
342
0
            return None;
343
0
        }
344
0
345
0
        // Validity is guaranteed when the `VotesAncestriesIter` is constructed.
346
0
        let (item, new_slice) =
347
0
            header::decode_partial(self.slice, self.block_number_bytes).unwrap();
348
0
        self.slice = new_slice;
349
0
        self.num -= 1;
350
0
351
0
        Some(item)
352
0
    }
Unexecuted instantiation: _RNvXs7_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_19VotesAncestriesIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator4next
Unexecuted instantiation: _RNvXs7_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_19VotesAncestriesIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator4next
353
354
0
    fn size_hint(&self) -> (usize, Option<usize>) {
355
0
        (self.num, Some(self.num))
356
0
    }
Unexecuted instantiation: _RNvXs7_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_19VotesAncestriesIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator9size_hint
Unexecuted instantiation: _RNvXs7_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_19VotesAncestriesIterNtNtNtNtCsaYZPK01V26L_4core4iter6traits8iterator8Iterator9size_hint
357
}
358
359
impl<'a> ExactSizeIterator for VotesAncestriesIter<'a> {}
360
361
/// Potential error when decoding a Grandpa justification.
362
0
#[derive(Debug, derive_more::Display)]
Unexecuted instantiation: _RNvXsE_NtNtCsN16ciHI6Qf_7smoldot8finality6decodeNtB5_24JustificationDecodeErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt
Unexecuted instantiation: _RNvXsE_NtNtCseuYC0Zibziv_7smoldot8finality6decodeNtB5_24JustificationDecodeErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt
363
#[display(fmt = "Justification parsing error: {_0:?}")]
364
pub struct JustificationDecodeError(nom::error::ErrorKind);
365
366
/// `Nom` combinator that parses a justification.
367
1
fn grandpa_justification<'a>(
368
1
    block_number_bytes: usize,
369
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], GrandpaJustificationRef> {
370
1
    nom::error::context(
371
1
        "grandpa_justification",
372
1
        nom::combinator::map(
373
1
            nom::sequence::tuple((
374
1
                nom::number::streaming::le_u64,
375
1
                nom::bytes::streaming::take(32u32),
376
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
377
1
                precommits(block_number_bytes),
378
1
                votes_ancestries(block_number_bytes),
379
1
            )),
380
1
            |(round, target_hash, target_number, precommits, votes_ancestries)| {
381
1
                GrandpaJustificationRef {
382
1
                    round,
383
1
                    target_hash: TryFrom::try_from(target_hash).unwrap(),
384
1
                    target_number,
385
1
                    precommits,
386
1
                    votes_ancestries,
387
1
                }
388
1
            },
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode21grandpa_justification0B7_
Line
Count
Source
380
1
            |(round, target_hash, target_number, precommits, votes_ancestries)| {
381
1
                GrandpaJustificationRef {
382
1
                    round,
383
1
                    target_hash: TryFrom::try_from(target_hash).unwrap(),
384
1
                    target_number,
385
1
                    precommits,
386
1
                    votes_ancestries,
387
1
                }
388
1
            },
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode21grandpa_justification0B7_
389
1
        ),
390
1
    )
391
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode21grandpa_justification
Line
Count
Source
367
1
fn grandpa_justification<'a>(
368
1
    block_number_bytes: usize,
369
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], GrandpaJustificationRef> {
370
1
    nom::error::context(
371
1
        "grandpa_justification",
372
1
        nom::combinator::map(
373
1
            nom::sequence::tuple((
374
1
                nom::number::streaming::le_u64,
375
1
                nom::bytes::streaming::take(32u32),
376
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
377
1
                precommits(block_number_bytes),
378
1
                votes_ancestries(block_number_bytes),
379
1
            )),
380
1
            |(round, target_hash, target_number, precommits, votes_ancestries)| {
381
                GrandpaJustificationRef {
382
                    round,
383
                    target_hash: TryFrom::try_from(target_hash).unwrap(),
384
                    target_number,
385
                    precommits,
386
                    votes_ancestries,
387
                }
388
1
            },
389
1
        ),
390
1
    )
391
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode21grandpa_justification
392
393
/// `Nom` combinator that parses a list of precommits.
394
1
fn precommits<'a>(
395
1
    block_number_bytes: usize,
396
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], PrecommitsRef> {
397
1
    nom::combinator::map(
398
1
        nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
399
1
            nom::combinator::recognize(nom::multi::fold_many_m_n(
400
1
                num_elems,
401
1
                num_elems,
402
1
                precommit(block_number_bytes),
403
1
                || {},
_RNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode10precommits00B9_
Line
Count
Source
403
1
                || {},
Unexecuted instantiation: _RNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode10precommits00B9_
404
5
                |(), _| (),
_RNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode10precommits0s_0B9_
Line
Count
Source
404
5
                |(), _| (),
Unexecuted instantiation: _RNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode10precommits0s_0B9_
405
1
            ))
406
1
        }),
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode10precommits0B7_
Line
Count
Source
398
1
        nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
399
1
            nom::combinator::recognize(nom::multi::fold_many_m_n(
400
1
                num_elems,
401
1
                num_elems,
402
1
                precommit(block_number_bytes),
403
1
                || {},
404
1
                |(), _| (),
405
1
            ))
406
1
        }),
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode10precommits0B7_
407
1
        move |data| PrecommitsRef {
408
1
            inner: PrecommitsRefInner::Undecoded {
409
1
                data,
410
1
                block_number_bytes,
411
1
            },
412
1
        },
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode10precommitss_0B7_
Line
Count
Source
407
1
        move |data| PrecommitsRef {
408
1
            inner: PrecommitsRefInner::Undecoded {
409
1
                data,
410
1
                block_number_bytes,
411
1
            },
412
1
        },
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode10precommitss_0B7_
413
1
    )
414
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode10precommits
Line
Count
Source
394
1
fn precommits<'a>(
395
1
    block_number_bytes: usize,
396
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], PrecommitsRef> {
397
1
    nom::combinator::map(
398
1
        nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
399
            nom::combinator::recognize(nom::multi::fold_many_m_n(
400
                num_elems,
401
                num_elems,
402
                precommit(block_number_bytes),
403
                || {},
404
                |(), _| (),
405
            ))
406
1
        }),
407
1
        move |data| PrecommitsRef {
408
            inner: PrecommitsRefInner::Undecoded {
409
                data,
410
                block_number_bytes,
411
            },
412
1
        },
413
1
    )
414
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode10precommits
415
416
/// `Nom` combinator that parses a single precommit.
417
1
fn precommit<'a>(
418
1
    block_number_bytes: usize,
419
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], PrecommitRef> {
420
1
    nom::error::context(
421
1
        "precommit",
422
1
        nom::combinator::map(
423
1
            nom::sequence::tuple((
424
1
                nom::bytes::streaming::take(32u32),
425
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
426
1
                nom::bytes::streaming::take(64u32),
427
1
                nom::bytes::streaming::take(32u32),
428
1
            )),
429
5
            |(target_hash, target_number, signature, authority_public_key)| PrecommitRef {
430
5
                target_hash: TryFrom::try_from(target_hash).unwrap(),
431
5
                target_number,
432
5
                signature: TryFrom::try_from(signature).unwrap(),
433
5
                authority_public_key: TryFrom::try_from(authority_public_key).unwrap(),
434
5
            },
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode9precommit0B7_
Line
Count
Source
429
5
            |(target_hash, target_number, signature, authority_public_key)| PrecommitRef {
430
5
                target_hash: TryFrom::try_from(target_hash).unwrap(),
431
5
                target_number,
432
5
                signature: TryFrom::try_from(signature).unwrap(),
433
5
                authority_public_key: TryFrom::try_from(authority_public_key).unwrap(),
434
5
            },
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode9precommit0B7_
435
1
        ),
436
1
    )
437
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode9precommit
Line
Count
Source
417
1
fn precommit<'a>(
418
1
    block_number_bytes: usize,
419
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], PrecommitRef> {
420
1
    nom::error::context(
421
1
        "precommit",
422
1
        nom::combinator::map(
423
1
            nom::sequence::tuple((
424
1
                nom::bytes::streaming::take(32u32),
425
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
426
1
                nom::bytes::streaming::take(64u32),
427
1
                nom::bytes::streaming::take(32u32),
428
1
            )),
429
1
            |(target_hash, target_number, signature, authority_public_key)| PrecommitRef {
430
                target_hash: TryFrom::try_from(target_hash).unwrap(),
431
                target_number,
432
                signature: TryFrom::try_from(signature).unwrap(),
433
                authority_public_key: TryFrom::try_from(authority_public_key).unwrap(),
434
1
            },
435
1
        ),
436
1
    )
437
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode9precommit
438
439
/// `Nom` combinator that parses a list of headers.
440
1
fn votes_ancestries<'a>(
441
1
    block_number_bytes: usize,
442
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], VotesAncestriesIter> {
443
1
    nom::error::context(
444
1
        "votes ancestries",
445
1
        nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
446
1
            nom::combinator::map(
447
1
                nom::combinator::recognize(nom::multi::fold_many_m_n(
448
1
                    num_elems,
449
1
                    num_elems,
450
1
                    move |s| {
451
0
                        header::decode_partial(s, block_number_bytes)
452
0
                            .map(|(a, b)| (b, a))
Unexecuted instantiation: _RNCNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries000Bb_
Unexecuted instantiation: _RNCNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries000Bb_
453
0
                            .map_err(|_| {
454
0
                                nom::Err::Failure(nom::error::make_error(
455
0
                                    s,
456
0
                                    nom::error::ErrorKind::Verify,
457
0
                                ))
458
0
                            })
Unexecuted instantiation: _RNCNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries00s_0Bb_
Unexecuted instantiation: _RNCNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries00s_0Bb_
459
1
                    },
Unexecuted instantiation: _RNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries00B9_
Unexecuted instantiation: _RNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries00B9_
460
1
                    || {},
_RNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries0s_0B9_
Line
Count
Source
460
1
                    || {},
Unexecuted instantiation: _RNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries0s_0B9_
461
1
                    |(), _| 
()0
,
Unexecuted instantiation: _RNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries0s0_0B9_
Unexecuted instantiation: _RNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries0s0_0B9_
462
1
                )),
463
1
                move |slice| VotesAncestriesIter {
464
1
                    slice,
465
1
                    num: num_elems,
466
1
                    block_number_bytes,
467
1
                },
_RNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries0s1_0B9_
Line
Count
Source
463
1
                move |slice| VotesAncestriesIter {
464
1
                    slice,
465
1
                    num: num_elems,
466
1
                    block_number_bytes,
467
1
                },
Unexecuted instantiation: _RNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries0s1_0B9_
468
1
            )
469
1
        }),
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries0B7_
Line
Count
Source
445
1
        nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
446
1
            nom::combinator::map(
447
1
                nom::combinator::recognize(nom::multi::fold_many_m_n(
448
1
                    num_elems,
449
1
                    num_elems,
450
1
                    move |s| {
451
                        header::decode_partial(s, block_number_bytes)
452
                            .map(|(a, b)| (b, a))
453
                            .map_err(|_| {
454
                                nom::Err::Failure(nom::error::make_error(
455
                                    s,
456
                                    nom::error::ErrorKind::Verify,
457
                                ))
458
                            })
459
1
                    },
460
1
                    || {},
461
1
                    |(), _| (),
462
1
                )),
463
1
                move |slice| VotesAncestriesIter {
464
                    slice,
465
                    num: num_elems,
466
                    block_number_bytes,
467
1
                },
468
1
            )
469
1
        }),
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries0B7_
470
1
    )
471
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode16votes_ancestries
Line
Count
Source
440
1
fn votes_ancestries<'a>(
441
1
    block_number_bytes: usize,
442
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], VotesAncestriesIter> {
443
1
    nom::error::context(
444
1
        "votes ancestries",
445
1
        nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
446
            nom::combinator::map(
447
                nom::combinator::recognize(nom::multi::fold_many_m_n(
448
                    num_elems,
449
                    num_elems,
450
                    move |s| {
451
                        header::decode_partial(s, block_number_bytes)
452
                            .map(|(a, b)| (b, a))
453
                            .map_err(|_| {
454
                                nom::Err::Failure(nom::error::make_error(
455
                                    s,
456
                                    nom::error::ErrorKind::Verify,
457
                                ))
458
                            })
459
                    },
460
                    || {},
461
                    |(), _| (),
462
                )),
463
                move |slice| VotesAncestriesIter {
464
                    slice,
465
                    num: num_elems,
466
                    block_number_bytes,
467
                },
468
            )
469
1
        }),
470
1
    )
471
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode16votes_ancestries
472
473
1
fn commit_message<'a>(
474
1
    block_number_bytes: usize,
475
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], CommitMessageRef> {
476
1
    nom::error::context(
477
1
        "commit_message",
478
1
        nom::combinator::map(
479
1
            nom::sequence::tuple((
480
1
                nom::number::streaming::le_u64,
481
1
                nom::number::streaming::le_u64,
482
1
                nom::bytes::streaming::take(32u32),
483
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
484
1
                nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
485
1
                    nom::multi::many_m_n(
486
1
                        num_elems,
487
1
                        num_elems,
488
1
                        unsigned_precommit(block_number_bytes),
489
1
                    )
490
1
                }),
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode14commit_message0B7_
Line
Count
Source
484
1
                nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
485
1
                    nom::multi::many_m_n(
486
1
                        num_elems,
487
1
                        num_elems,
488
1
                        unsigned_precommit(block_number_bytes),
489
1
                    )
490
1
                }),
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode14commit_message0B7_
491
1
                nom::combinator::flat_map(crate::util::nom_scale_compact_usize, |num_elems| {
492
1
                    nom::multi::many_m_n(
493
1
                        num_elems,
494
1
                        num_elems,
495
1
                        nom::combinator::map(
496
1
                            nom::sequence::tuple((
497
1
                                nom::bytes::streaming::take(64u32),
498
1
                                nom::bytes::streaming::take(32u32),
499
1
                            )),
500
7
                            |(sig, pubkey)| {
501
7
                                (
502
7
                                    <&[u8; 64]>::try_from(sig).unwrap(),
503
7
                                    <&[u8; 32]>::try_from(pubkey).unwrap(),
504
7
                                )
505
7
                            },
_RNCNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode14commit_messages_00B9_
Line
Count
Source
500
7
                            |(sig, pubkey)| {
501
7
                                (
502
7
                                    <&[u8; 64]>::try_from(sig).unwrap(),
503
7
                                    <&[u8; 32]>::try_from(pubkey).unwrap(),
504
7
                                )
505
7
                            },
Unexecuted instantiation: _RNCNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode14commit_messages_00B9_
506
1
                        ),
507
1
                    )
508
1
                }),
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode14commit_messages_0B7_
Line
Count
Source
491
1
                nom::combinator::flat_map(crate::util::nom_scale_compact_usize, |num_elems| {
492
1
                    nom::multi::many_m_n(
493
1
                        num_elems,
494
1
                        num_elems,
495
1
                        nom::combinator::map(
496
1
                            nom::sequence::tuple((
497
1
                                nom::bytes::streaming::take(64u32),
498
1
                                nom::bytes::streaming::take(32u32),
499
1
                            )),
500
1
                            |(sig, pubkey)| {
501
                                (
502
                                    <&[u8; 64]>::try_from(sig).unwrap(),
503
                                    <&[u8; 32]>::try_from(pubkey).unwrap(),
504
                                )
505
1
                            },
506
1
                        ),
507
1
                    )
508
1
                }),
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode14commit_messages_0B7_
509
1
            )),
510
1
            |(round_number, set_id, target_hash, target_number, precommits, auth_data)| {
511
1
                CommitMessageRef {
512
1
                    round_number,
513
1
                    set_id,
514
1
                    target_hash: <&[u8; 32]>::try_from(target_hash).unwrap(),
515
1
                    target_number,
516
1
                    precommits,
517
1
                    auth_data,
518
1
                }
519
1
            },
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode14commit_messages0_0B7_
Line
Count
Source
510
1
            |(round_number, set_id, target_hash, target_number, precommits, auth_data)| {
511
1
                CommitMessageRef {
512
1
                    round_number,
513
1
                    set_id,
514
1
                    target_hash: <&[u8; 32]>::try_from(target_hash).unwrap(),
515
1
                    target_number,
516
1
                    precommits,
517
1
                    auth_data,
518
1
                }
519
1
            },
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode14commit_messages0_0B7_
520
1
        ),
521
1
    )
522
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode14commit_message
Line
Count
Source
473
1
fn commit_message<'a>(
474
1
    block_number_bytes: usize,
475
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], CommitMessageRef> {
476
1
    nom::error::context(
477
1
        "commit_message",
478
1
        nom::combinator::map(
479
1
            nom::sequence::tuple((
480
1
                nom::number::streaming::le_u64,
481
1
                nom::number::streaming::le_u64,
482
1
                nom::bytes::streaming::take(32u32),
483
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
484
1
                nom::combinator::flat_map(crate::util::nom_scale_compact_usize, move |num_elems| {
485
                    nom::multi::many_m_n(
486
                        num_elems,
487
                        num_elems,
488
                        unsigned_precommit(block_number_bytes),
489
                    )
490
1
                }),
491
1
                nom::combinator::flat_map(crate::util::nom_scale_compact_usize, |num_elems| {
492
                    nom::multi::many_m_n(
493
                        num_elems,
494
                        num_elems,
495
                        nom::combinator::map(
496
                            nom::sequence::tuple((
497
                                nom::bytes::streaming::take(64u32),
498
                                nom::bytes::streaming::take(32u32),
499
                            )),
500
                            |(sig, pubkey)| {
501
                                (
502
                                    <&[u8; 64]>::try_from(sig).unwrap(),
503
                                    <&[u8; 32]>::try_from(pubkey).unwrap(),
504
                                )
505
                            },
506
                        ),
507
                    )
508
1
                }),
509
1
            )),
510
1
            |(round_number, set_id, target_hash, target_number, precommits, auth_data)| {
511
                CommitMessageRef {
512
                    round_number,
513
                    set_id,
514
                    target_hash: <&[u8; 32]>::try_from(target_hash).unwrap(),
515
                    target_number,
516
                    precommits,
517
                    auth_data,
518
                }
519
1
            },
520
1
        ),
521
1
    )
522
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode14commit_message
523
524
1
fn unsigned_precommit<'a>(
525
1
    block_number_bytes: usize,
526
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], UnsignedPrecommitRef> {
527
1
    nom::error::context(
528
1
        "unsigned_precommit",
529
1
        nom::combinator::map(
530
1
            nom::sequence::tuple((
531
1
                nom::bytes::streaming::take(32u32),
532
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
533
1
            )),
534
7
            |(target_hash, target_number)| UnsignedPrecommitRef {
535
7
                target_hash: <&[u8; 32]>::try_from(target_hash).unwrap(),
536
7
                target_number,
537
7
            },
_RNCNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode18unsigned_precommit0B7_
Line
Count
Source
534
7
            |(target_hash, target_number)| UnsignedPrecommitRef {
535
7
                target_hash: <&[u8; 32]>::try_from(target_hash).unwrap(),
536
7
                target_number,
537
7
            },
Unexecuted instantiation: _RNCNvNtNtCseuYC0Zibziv_7smoldot8finality6decode18unsigned_precommit0B7_
538
1
        ),
539
1
    )
540
1
}
_RNvNtNtCsN16ciHI6Qf_7smoldot8finality6decode18unsigned_precommit
Line
Count
Source
524
1
fn unsigned_precommit<'a>(
525
1
    block_number_bytes: usize,
526
1
) -> impl FnMut(&'a [u8]) -> nom::IResult<&[u8], UnsignedPrecommitRef> {
527
1
    nom::error::context(
528
1
        "unsigned_precommit",
529
1
        nom::combinator::map(
530
1
            nom::sequence::tuple((
531
1
                nom::bytes::streaming::take(32u32),
532
1
                crate::util::nom_varsize_number_decode_u64(block_number_bytes),
533
1
            )),
534
1
            |(target_hash, target_number)| UnsignedPrecommitRef {
535
                target_hash: <&[u8; 32]>::try_from(target_hash).unwrap(),
536
                target_number,
537
1
            },
538
1
        ),
539
1
    )
540
1
}
Unexecuted instantiation: _RNvNtNtCseuYC0Zibziv_7smoldot8finality6decode18unsigned_precommit
541
542
#[cfg(test)]
543
mod tests {
544
    #[test]
545
1
    fn basic_decode_justification() {
546
1
        super::decode_grandpa_justification(
547
1
            &[
548
1
                7, 181, 6, 0, 0, 0, 0, 0, 41, 241, 171, 236, 144, 172, 25, 157, 240, 109, 238, 59,
549
1
                160, 115, 76, 8, 195, 253, 109, 240, 108, 170, 63, 120, 149, 47, 143, 149, 22, 64,
550
1
                88, 210, 0, 158, 4, 0, 20, 41, 241, 171, 236, 144, 172, 25, 157, 240, 109, 238, 59,
551
1
                160, 115, 76, 8, 195, 253, 109, 240, 108, 170, 63, 120, 149, 47, 143, 149, 22, 64,
552
1
                88, 210, 0, 158, 4, 0, 13, 247, 129, 120, 204, 170, 120, 173, 41, 241, 213, 234,
553
1
                121, 111, 20, 38, 193, 94, 99, 139, 57, 30, 71, 209, 236, 222, 165, 123, 70, 139,
554
1
                71, 65, 36, 142, 39, 13, 94, 240, 44, 174, 150, 85, 149, 223, 166, 82, 210, 103,
555
1
                40, 129, 102, 26, 212, 116, 231, 209, 163, 107, 49, 82, 229, 197, 82, 8, 28, 21,
556
1
                28, 17, 203, 114, 51, 77, 38, 215, 7, 105, 227, 175, 123, 191, 243, 128, 26, 78,
557
1
                45, 202, 43, 9, 183, 204, 224, 175, 141, 216, 19, 7, 41, 241, 171, 236, 144, 172,
558
1
                25, 157, 240, 109, 238, 59, 160, 115, 76, 8, 195, 253, 109, 240, 108, 170, 63, 120,
559
1
                149, 47, 143, 149, 22, 64, 88, 210, 0, 158, 4, 0, 62, 37, 145, 44, 21, 192, 120,
560
1
                229, 236, 113, 122, 56, 193, 247, 45, 210, 184, 12, 62, 220, 253, 147, 70, 133, 85,
561
1
                18, 90, 167, 201, 118, 23, 107, 184, 187, 3, 104, 170, 132, 17, 18, 89, 77, 156,
562
1
                145, 242, 8, 185, 88, 74, 87, 21, 52, 247, 101, 57, 154, 163, 5, 130, 20, 15, 230,
563
1
                8, 3, 104, 13, 39, 130, 19, 249, 8, 101, 138, 73, 161, 2, 90, 127, 70, 108, 25,
564
1
                126, 143, 182, 250, 187, 94, 98, 34, 10, 123, 215, 95, 134, 12, 171, 41, 241, 171,
565
1
                236, 144, 172, 25, 157, 240, 109, 238, 59, 160, 115, 76, 8, 195, 253, 109, 240,
566
1
                108, 170, 63, 120, 149, 47, 143, 149, 22, 64, 88, 210, 0, 158, 4, 0, 125, 172, 79,
567
1
                71, 1, 38, 137, 128, 232, 95, 70, 104, 217, 95, 7, 58, 28, 114, 182, 216, 171, 56,
568
1
                231, 218, 199, 244, 220, 122, 6, 225, 5, 175, 172, 47, 198, 61, 84, 42, 75, 66, 62,
569
1
                90, 243, 18, 58, 36, 108, 235, 132, 103, 136, 38, 164, 164, 237, 164, 41, 225, 152,
570
1
                157, 146, 237, 24, 11, 142, 89, 54, 135, 0, 234, 137, 226, 191, 137, 34, 204, 158,
571
1
                75, 134, 214, 101, 29, 28, 104, 154, 13, 87, 129, 63, 151, 104, 219, 170, 222, 207,
572
1
                113, 41, 241, 171, 236, 144, 172, 25, 157, 240, 109, 238, 59, 160, 115, 76, 8, 195,
573
1
                253, 109, 240, 108, 170, 63, 120, 149, 47, 143, 149, 22, 64, 88, 210, 0, 158, 4, 0,
574
1
                68, 192, 211, 142, 239, 33, 55, 222, 165, 127, 203, 155, 217, 170, 61, 95, 206, 74,
575
1
                74, 19, 123, 60, 67, 142, 80, 18, 175, 40, 136, 156, 151, 224, 191, 157, 91, 187,
576
1
                39, 185, 249, 212, 158, 73, 197, 90, 54, 222, 13, 76, 181, 134, 69, 3, 165, 248,
577
1
                94, 196, 68, 186, 80, 218, 87, 162, 17, 11, 222, 166, 244, 167, 39, 211, 178, 57,
578
1
                146, 117, 214, 238, 136, 23, 136, 31, 16, 89, 116, 113, 220, 29, 39, 241, 68, 41,
579
1
                90, 214, 251, 147, 60, 122, 41, 241, 171, 236, 144, 172, 25, 157, 240, 109, 238,
580
1
                59, 160, 115, 76, 8, 195, 253, 109, 240, 108, 170, 63, 120, 149, 47, 143, 149, 22,
581
1
                64, 88, 210, 0, 158, 4, 0, 58, 187, 123, 135, 2, 157, 81, 197, 40, 200, 218, 52,
582
1
                253, 193, 119, 104, 190, 246, 221, 225, 175, 195, 177, 218, 209, 175, 83, 119, 98,
583
1
                175, 196, 48, 67, 76, 59, 223, 13, 202, 48, 1, 10, 99, 200, 201, 123, 29, 89, 131,
584
1
                120, 70, 162, 235, 11, 191, 96, 57, 83, 51, 217, 199, 35, 50, 174, 2, 247, 45, 175,
585
1
                46, 86, 14, 79, 15, 34, 251, 92, 187, 4, 173, 29, 127, 238, 133, 10, 171, 35, 143,
586
1
                208, 20, 193, 120, 118, 158, 126, 58, 155, 132, 0,
587
1
            ],
588
1
            4,
589
1
        )
590
1
        .unwrap();
591
1
    }
592
593
    #[test]
594
1
    fn basic_decode_commit() {
595
1
        let actual = super::decode_grandpa_commit(
596
1
            &[
597
1
                85, 14, 0, 0, 0, 0, 0, 0, 162, 13, 0, 0, 0, 0, 0, 0, 182, 68, 115, 35, 15, 201,
598
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
599
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 28, 182, 68, 115, 35, 15, 201,
600
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
601
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 182, 68, 115, 35, 15, 201,
602
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
603
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 182, 68, 115, 35, 15, 201,
604
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
605
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 182, 68, 115, 35, 15, 201,
606
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
607
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 182, 68, 115, 35, 15, 201,
608
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
609
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 182, 68, 115, 35, 15, 201,
610
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
611
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 182, 68, 115, 35, 15, 201,
612
1
                152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253, 4, 180, 158, 70, 161, 84,
613
1
                76, 118, 151, 68, 101, 104, 187, 82, 49, 231, 77, 0, 28, 189, 185, 216, 33, 163,
614
1
                12, 201, 104, 162, 255, 11, 241, 156, 90, 244, 205, 251, 44, 45, 139, 129, 117,
615
1
                178, 85, 129, 78, 58, 255, 76, 232, 199, 85, 236, 30, 227, 87, 50, 34, 22, 27, 241,
616
1
                6, 33, 137, 55, 5, 190, 36, 122, 61, 112, 51, 99, 34, 119, 46, 185, 156, 188, 133,
617
1
                140, 103, 33, 10, 45, 154, 173, 12, 30, 12, 25, 95, 195, 198, 235, 98, 29, 248, 44,
618
1
                121, 73, 203, 132, 51, 196, 138, 65, 42, 3, 49, 169, 182, 129, 146, 242, 193, 228,
619
1
                217, 26, 9, 233, 239, 30, 213, 103, 10, 33, 27, 44, 13, 178, 236, 216, 167, 190, 9,
620
1
                123, 151, 143, 1, 199, 58, 77, 121, 122, 215, 22, 19, 238, 190, 216, 8, 62, 6, 216,
621
1
                37, 197, 124, 141, 51, 196, 205, 205, 193, 24, 86, 246, 60, 16, 139, 66, 51, 93,
622
1
                168, 159, 147, 77, 90, 91, 8, 64, 14, 252, 119, 77, 211, 141, 23, 18, 115, 222, 3,
623
1
                2, 22, 42, 105, 85, 176, 71, 232, 230, 141, 12, 9, 124, 205, 194, 191, 90, 47, 202,
624
1
                233, 218, 161, 80, 55, 8, 134, 223, 202, 4, 137, 45, 10, 71, 90, 162, 252, 99, 19,
625
1
                252, 17, 175, 5, 75, 208, 81, 0, 96, 218, 5, 89, 250, 183, 161, 188, 227, 62, 107,
626
1
                34, 63, 155, 28, 176, 141, 174, 113, 162, 229, 148, 55, 39, 65, 36, 97, 159, 198,
627
1
                238, 222, 34, 76, 187, 40, 19, 109, 1, 67, 146, 40, 75, 194, 208, 80, 208, 221,
628
1
                175, 151, 239, 239, 127, 65, 39, 237, 145, 130, 36, 154, 135, 68, 105, 52, 102, 49,
629
1
                62, 137, 34, 187, 159, 55, 157, 88, 195, 49, 116, 72, 11, 37, 132, 176, 74, 69, 60,
630
1
                157, 67, 36, 156, 165, 71, 164, 86, 220, 240, 241, 13, 40, 125, 79, 147, 27, 56,
631
1
                254, 198, 231, 108, 187, 214, 187, 98, 229, 123, 116, 160, 126, 192, 98, 132, 247,
632
1
                206, 70, 228, 175, 152, 217, 252, 4, 109, 98, 24, 90, 117, 184, 11, 107, 32, 186,
633
1
                217, 155, 44, 253, 198, 120, 175, 170, 229, 66, 122, 141, 158, 75, 68, 108, 104,
634
1
                182, 223, 91, 126, 210, 38, 84, 143, 10, 142, 225, 77, 169, 12, 215, 222, 158, 85,
635
1
                4, 111, 196, 47, 56, 147, 93, 1, 202, 247, 137, 115, 30, 127, 94, 191, 31, 223,
636
1
                162, 16, 73, 219, 118, 52, 40, 255, 191, 183, 70, 132, 115, 91, 214, 191, 156, 189,
637
1
                203, 208, 152, 165, 115, 64, 123, 209, 153, 80, 44, 134, 143, 188, 140, 168, 162,
638
1
                134, 178, 192, 122, 10, 137, 41, 133, 127, 72, 223, 16, 65, 170, 114, 53, 173, 180,
639
1
                59, 208, 190, 54, 96, 123, 199, 137, 214, 115, 240, 73, 87, 253, 137, 81, 36, 66,
640
1
                175, 76, 40, 52, 216, 110, 234, 219, 158, 208, 142, 85, 168, 43, 164, 19, 154, 21,
641
1
                125, 174, 153, 165, 45, 54, 100, 36, 196, 46, 95, 64, 192, 178, 156, 16, 112, 5,
642
1
                237, 207, 113, 132, 125, 148, 34, 132, 105, 148, 216, 148, 182, 33, 74, 215, 161,
643
1
                252, 44, 24, 67, 77, 87, 6, 94, 109, 38, 64, 10, 195, 28, 194, 169, 175, 7, 98,
644
1
                210, 151, 4, 221, 136, 161, 204, 171, 251, 101, 63, 21, 245, 84, 189, 77, 59, 75,
645
1
                136, 44, 17, 217, 119, 206, 191, 191, 137, 127, 81, 55, 208, 225, 33, 209, 59, 83,
646
1
                121, 234, 160, 191, 38, 82, 1, 102, 178, 140, 58, 20, 131, 206, 37, 148, 106, 135,
647
1
                149, 74, 57, 27, 84, 215, 0, 47, 68, 1, 8, 139, 183, 125, 169, 4, 165, 168, 86,
648
1
                218, 178, 95, 157, 185, 64, 45, 211, 221, 151, 205, 240, 69, 133, 200, 15, 213,
649
1
                170, 162, 127, 93, 224, 36, 86, 116, 44, 42, 22, 255, 144, 193, 35, 175, 145, 62,
650
1
                184, 67, 143, 199, 253, 37, 115, 23, 154, 213, 141, 122, 105,
651
1
            ],
652
1
            4,
653
1
        )
654
1
        .unwrap();
655
1
656
1
        let expected = super::CommitMessageRef {
657
1
            round_number: 3669,
658
1
            set_id: 3490,
659
1
            target_hash: &[
660
1
                182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248, 98, 253,
661
1
                4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
662
1
            ],
663
1
            target_number: 5_105_457,
664
1
            precommits: vec![
665
1
                super::UnsignedPrecommitRef {
666
1
                    target_hash: &[
667
1
                        182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248,
668
1
                        98, 253, 4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
669
1
                    ],
670
1
                    target_number: 5_105_457,
671
1
                },
672
1
                super::UnsignedPrecommitRef {
673
1
                    target_hash: &[
674
1
                        182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248,
675
1
                        98, 253, 4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
676
1
                    ],
677
1
                    target_number: 5_105_457,
678
1
                },
679
1
                super::UnsignedPrecommitRef {
680
1
                    target_hash: &[
681
1
                        182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248,
682
1
                        98, 253, 4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
683
1
                    ],
684
1
                    target_number: 5_105_457,
685
1
                },
686
1
                super::UnsignedPrecommitRef {
687
1
                    target_hash: &[
688
1
                        182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248,
689
1
                        98, 253, 4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
690
1
                    ],
691
1
                    target_number: 5_105_457,
692
1
                },
693
1
                super::UnsignedPrecommitRef {
694
1
                    target_hash: &[
695
1
                        182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248,
696
1
                        98, 253, 4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
697
1
                    ],
698
1
                    target_number: 5_105_457,
699
1
                },
700
1
                super::UnsignedPrecommitRef {
701
1
                    target_hash: &[
702
1
                        182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248,
703
1
                        98, 253, 4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
704
1
                    ],
705
1
                    target_number: 5_105_457,
706
1
                },
707
1
                super::UnsignedPrecommitRef {
708
1
                    target_hash: &[
709
1
                        182, 68, 115, 35, 15, 201, 152, 195, 12, 181, 59, 244, 231, 124, 34, 248,
710
1
                        98, 253, 4, 180, 158, 70, 161, 84, 76, 118, 151, 68, 101, 104, 187, 82,
711
1
                    ],
712
1
                    target_number: 5_105_457,
713
1
                },
714
1
            ],
715
1
            auth_data: vec![
716
1
                (
717
1
                    &[
718
1
                        189, 185, 216, 33, 163, 12, 201, 104, 162, 255, 11, 241, 156, 90, 244, 205,
719
1
                        251, 44, 45, 139, 129, 117, 178, 85, 129, 78, 58, 255, 76, 232, 199, 85,
720
1
                        236, 30, 227, 87, 50, 34, 22, 27, 241, 6, 33, 137, 55, 5, 190, 36, 122, 61,
721
1
                        112, 51, 99, 34, 119, 46, 185, 156, 188, 133, 140, 103, 33, 10,
722
1
                    ],
723
1
                    &[
724
1
                        45, 154, 173, 12, 30, 12, 25, 95, 195, 198, 235, 98, 29, 248, 44, 121, 73,
725
1
                        203, 132, 51, 196, 138, 65, 42, 3, 49, 169, 182, 129, 146, 242, 193,
726
1
                    ],
727
1
                ),
728
1
                (
729
1
                    &[
730
1
                        228, 217, 26, 9, 233, 239, 30, 213, 103, 10, 33, 27, 44, 13, 178, 236, 216,
731
1
                        167, 190, 9, 123, 151, 143, 1, 199, 58, 77, 121, 122, 215, 22, 19, 238,
732
1
                        190, 216, 8, 62, 6, 216, 37, 197, 124, 141, 51, 196, 205, 205, 193, 24, 86,
733
1
                        246, 60, 16, 139, 66, 51, 93, 168, 159, 147, 77, 90, 91, 8,
734
1
                    ],
735
1
                    &[
736
1
                        64, 14, 252, 119, 77, 211, 141, 23, 18, 115, 222, 3, 2, 22, 42, 105, 85,
737
1
                        176, 71, 232, 230, 141, 12, 9, 124, 205, 194, 191, 90, 47, 202, 233,
738
1
                    ],
739
1
                ),
740
1
                (
741
1
                    &[
742
1
                        218, 161, 80, 55, 8, 134, 223, 202, 4, 137, 45, 10, 71, 90, 162, 252, 99,
743
1
                        19, 252, 17, 175, 5, 75, 208, 81, 0, 96, 218, 5, 89, 250, 183, 161, 188,
744
1
                        227, 62, 107, 34, 63, 155, 28, 176, 141, 174, 113, 162, 229, 148, 55, 39,
745
1
                        65, 36, 97, 159, 198, 238, 222, 34, 76, 187, 40, 19, 109, 1,
746
1
                    ],
747
1
                    &[
748
1
                        67, 146, 40, 75, 194, 208, 80, 208, 221, 175, 151, 239, 239, 127, 65, 39,
749
1
                        237, 145, 130, 36, 154, 135, 68, 105, 52, 102, 49, 62, 137, 34, 187, 159,
750
1
                    ],
751
1
                ),
752
1
                (
753
1
                    &[
754
1
                        55, 157, 88, 195, 49, 116, 72, 11, 37, 132, 176, 74, 69, 60, 157, 67, 36,
755
1
                        156, 165, 71, 164, 86, 220, 240, 241, 13, 40, 125, 79, 147, 27, 56, 254,
756
1
                        198, 231, 108, 187, 214, 187, 98, 229, 123, 116, 160, 126, 192, 98, 132,
757
1
                        247, 206, 70, 228, 175, 152, 217, 252, 4, 109, 98, 24, 90, 117, 184, 11,
758
1
                    ],
759
1
                    &[
760
1
                        107, 32, 186, 217, 155, 44, 253, 198, 120, 175, 170, 229, 66, 122, 141,
761
1
                        158, 75, 68, 108, 104, 182, 223, 91, 126, 210, 38, 84, 143, 10, 142, 225,
762
1
                        77,
763
1
                    ],
764
1
                ),
765
1
                (
766
1
                    &[
767
1
                        169, 12, 215, 222, 158, 85, 4, 111, 196, 47, 56, 147, 93, 1, 202, 247, 137,
768
1
                        115, 30, 127, 94, 191, 31, 223, 162, 16, 73, 219, 118, 52, 40, 255, 191,
769
1
                        183, 70, 132, 115, 91, 214, 191, 156, 189, 203, 208, 152, 165, 115, 64,
770
1
                        123, 209, 153, 80, 44, 134, 143, 188, 140, 168, 162, 134, 178, 192, 122,
771
1
                        10,
772
1
                    ],
773
1
                    &[
774
1
                        137, 41, 133, 127, 72, 223, 16, 65, 170, 114, 53, 173, 180, 59, 208, 190,
775
1
                        54, 96, 123, 199, 137, 214, 115, 240, 73, 87, 253, 137, 81, 36, 66, 175,
776
1
                    ],
777
1
                ),
778
1
                (
779
1
                    &[
780
1
                        76, 40, 52, 216, 110, 234, 219, 158, 208, 142, 85, 168, 43, 164, 19, 154,
781
1
                        21, 125, 174, 153, 165, 45, 54, 100, 36, 196, 46, 95, 64, 192, 178, 156,
782
1
                        16, 112, 5, 237, 207, 113, 132, 125, 148, 34, 132, 105, 148, 216, 148, 182,
783
1
                        33, 74, 215, 161, 252, 44, 24, 67, 77, 87, 6, 94, 109, 38, 64, 10,
784
1
                    ],
785
1
                    &[
786
1
                        195, 28, 194, 169, 175, 7, 98, 210, 151, 4, 221, 136, 161, 204, 171, 251,
787
1
                        101, 63, 21, 245, 84, 189, 77, 59, 75, 136, 44, 17, 217, 119, 206, 191,
788
1
                    ],
789
1
                ),
790
1
                (
791
1
                    &[
792
1
                        191, 137, 127, 81, 55, 208, 225, 33, 209, 59, 83, 121, 234, 160, 191, 38,
793
1
                        82, 1, 102, 178, 140, 58, 20, 131, 206, 37, 148, 106, 135, 149, 74, 57, 27,
794
1
                        84, 215, 0, 47, 68, 1, 8, 139, 183, 125, 169, 4, 165, 168, 86, 218, 178,
795
1
                        95, 157, 185, 64, 45, 211, 221, 151, 205, 240, 69, 133, 200, 15,
796
1
                    ],
797
1
                    &[
798
1
                        213, 170, 162, 127, 93, 224, 36, 86, 116, 44, 42, 22, 255, 144, 193, 35,
799
1
                        175, 145, 62, 184, 67, 143, 199, 253, 37, 115, 23, 154, 213, 141, 122, 105,
800
1
                    ],
801
1
                ),
802
1
            ],
803
1
        };
804
1
805
1
        assert_eq!(actual, expected);
806
1
    }
807
}