tendermint/block/
size.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! Block size parameters

use serde::{Deserialize, Serialize};

use crate::serializers;

/// Block size parameters
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct Size {
    /// Maximum number of bytes in a block
    #[serde(with = "serializers::from_str")]
    pub max_bytes: u64,

    /// Maximum amount of gas which can be spent on a block
    #[serde(with = "serializers::from_str")]
    pub max_gas: i64,

    /// This parameter has no value anymore in Tendermint-core
    #[serde(with = "serializers::from_str", default = "Size::default_time_iota_ms")]
    pub time_iota_ms: i64,
}

impl Size {
    /// The default value for the `time_iota_ms` parameter.
    pub const fn default_time_iota_ms() -> i64 {
        1000
    }
}

mod v0_34 {
    use super::Size;
    use crate::error::Error;
    use tendermint_proto::v0_34::{
        abci::BlockParams as RawAbciSize, types::BlockParams as RawSize,
    };
    use tendermint_proto::Protobuf;

    impl Protobuf<RawSize> for Size {}

    impl TryFrom<RawSize> for Size {
        type Error = Error;

        fn try_from(value: RawSize) -> Result<Self, Self::Error> {
            Ok(Self {
                max_bytes: value
                    .max_bytes
                    .try_into()
                    .map_err(Error::integer_overflow)?,
                max_gas: value.max_gas,
                time_iota_ms: value.time_iota_ms,
            })
        }
    }

    impl From<Size> for RawSize {
        fn from(value: Size) -> Self {
            // Todo: make the struct more robust so this can become infallible.
            RawSize {
                max_bytes: value.max_bytes as i64,
                max_gas: value.max_gas,
                time_iota_ms: value.time_iota_ms,
            }
        }
    }

    impl Protobuf<RawAbciSize> for Size {}

    impl TryFrom<RawAbciSize> for Size {
        type Error = Error;

        fn try_from(value: RawAbciSize) -> Result<Self, Self::Error> {
            Ok(Self {
                max_bytes: value
                    .max_bytes
                    .try_into()
                    .map_err(Error::integer_overflow)?,
                max_gas: value.max_gas,
                time_iota_ms: Self::default_time_iota_ms(),
            })
        }
    }

    impl From<Size> for RawAbciSize {
        fn from(value: Size) -> Self {
            // Todo: make the struct more robust so this can become infallible.
            RawAbciSize {
                max_bytes: value.max_bytes as i64,
                max_gas: value.max_gas,
            }
        }
    }
}

mod v0_37 {
    use super::Size;
    use crate::error::Error;
    use tendermint_proto::v0_37::types::BlockParams as RawSize;
    use tendermint_proto::Protobuf;

    impl Protobuf<RawSize> for Size {}

    impl TryFrom<RawSize> for Size {
        type Error = Error;

        fn try_from(value: RawSize) -> Result<Self, Self::Error> {
            Ok(Self {
                max_bytes: value
                    .max_bytes
                    .try_into()
                    .map_err(Error::integer_overflow)?,
                max_gas: value.max_gas,
                time_iota_ms: Size::default_time_iota_ms(),
            })
        }
    }

    impl From<Size> for RawSize {
        fn from(value: Size) -> Self {
            // Todo: make the struct more robust so this can become infallible.
            RawSize {
                max_bytes: value.max_bytes as i64,
                max_gas: value.max_gas,
            }
        }
    }
}

mod v0_38 {
    use super::Size;
    use crate::error::Error;
    use tendermint_proto::v0_38::types::BlockParams as RawSize;
    use tendermint_proto::Protobuf;

    impl Protobuf<RawSize> for Size {}

    impl TryFrom<RawSize> for Size {
        type Error = Error;

        fn try_from(value: RawSize) -> Result<Self, Self::Error> {
            Ok(Self {
                max_bytes: value
                    .max_bytes
                    .try_into()
                    .map_err(Error::integer_overflow)?,
                max_gas: value.max_gas,
                time_iota_ms: Size::default_time_iota_ms(),
            })
        }
    }

    impl From<Size> for RawSize {
        fn from(value: Size) -> Self {
            // Todo: make the struct more robust so this can become infallible.
            RawSize {
                max_bytes: value.max_bytes as i64,
                max_gas: value.max_gas,
            }
        }
    }
}