Coverage Report

Created: 2024-05-16 12:16

/__w/smoldot/smoldot/repo/lib/src/verify/inherents.rs
Line
Count
Source (jump to first uncovered line)
1
// Smoldot
2
// Copyright (C) 2019-2020  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
//! Inherents, together with transactions, form the body of a block.
19
//!
20
//! The body of a block consists of a list of what is called extrinsics. An extrinsic can be
21
//! either a transaction, when it was submitted by a user, or an inherent, which is what this
22
//! module is about.
23
//!
24
//! When a block is authored, one of the first steps is for the block author to generate the list
25
//! of inherents. This is done by calling a runtime function, passing as parameter an encoded
26
//! [`InherentData`].
27
//!
28
//! When a block is later verified, the inherents are verified by calling a runtime function and
29
//! passing as parameter an encoded [`InherentData`] as well.
30
31
/// Values of the inherents to pass to the runtime.
32
///
33
/// Historically, the inherent data included an Aura or Babe slot number, using the identifiers
34
/// `auraslot` or `babeslot`. The runtime-side verification of the slot number has been removed in
35
/// May 2021, and all the checks performed by the runtime are now performed by the client instead.
36
/// Older runtime versions still require the slot number. For this reason, verifying the inherents
37
/// (calling `BlockBuilder_check_inherents`) of blocks that are using older runtime versions will
38
/// lead to errors concerning the Aura or Babe modules that should simply be ignored. Authoring
39
/// blocks using older runtime versions is not supported anymore.
40
#[derive(Debug)]
41
pub struct InherentData {
42
    /// Number of milliseconds since the UNIX epoch when the block is generated, ignoring leap
43
    /// seconds.
44
    ///
45
    /// Its identifier passed to the runtime is: `timstap0`.
46
    pub timestamp: u64,
47
    // TODO: parachain-related inherents are missing
48
}
49
50
impl InherentData {
51
    /// Turns this list of inherents into a list that can be passed as parameter to the runtime.
52
1
    pub fn as_raw_list(
53
1
        &'_ self,
54
1
    ) -> impl ExactSizeIterator<Item = ([u8; 8], impl AsRef<[u8]> + Clone + '_)> + Clone + '_ {
55
1
        [(*b"timstap0", self.timestamp.to_le_bytes())].into_iter()
56
1
    }
_RNvMNtNtCsN16ciHI6Qf_7smoldot6verify9inherentsNtB2_12InherentData11as_raw_list
Line
Count
Source
52
1
    pub fn as_raw_list(
53
1
        &'_ self,
54
1
    ) -> impl ExactSizeIterator<Item = ([u8; 8], impl AsRef<[u8]> + Clone + '_)> + Clone + '_ {
55
1
        [(*b"timstap0", self.timestamp.to_le_bytes())].into_iter()
56
1
    }
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot6verify9inherentsNtB2_12InherentData11as_raw_list
57
58
    /// Turns this list of inherents into a list that can be passed as parameter to the runtime.
59
0
    pub fn into_raw_list(
60
0
        self,
61
0
    ) -> impl ExactSizeIterator<Item = ([u8; 8], impl AsRef<[u8]> + Clone)> + Clone {
62
0
        // TODO: DRY
63
0
        [(*b"timstap0", self.timestamp.to_le_bytes())].into_iter()
64
0
    }
Unexecuted instantiation: _RNvMNtNtCsN16ciHI6Qf_7smoldot6verify9inherentsNtB2_12InherentData13into_raw_list
Unexecuted instantiation: _RNvMNtNtCseuYC0Zibziv_7smoldot6verify9inherentsNtB2_12InherentData13into_raw_list
65
}