-
Notifications
You must be signed in to change notification settings - Fork 296
/
lib.rs
91 lines (82 loc) · 3.18 KB
/
lib.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
use strum_macros::{EnumCount, EnumIter};
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, EnumCount, EnumIter)]
pub enum CertificationVersion {
/// Initial version.
V0 = 0,
/// Added canister module hash and controller.
V1 = 1,
/// Added support for multiple canister controllers.
V2 = 2,
/// Added subnet to canister ID ranges routing tables.
V3 = 3,
/// Added optional `Request::cycles_payment` and `Response::cycles_refund`
/// fields that are not yet populated.
V4 = 4,
/// Added support for canister metadata custom sections.
V5 = 5,
/// Encoding of canister metadata custom sections.
V6 = 6,
/// Support for decoding of `StreamHeader::reject_signals`.
/// Support for `done` ingress history status.
V7 = 7,
/// Encoding of `StreamHeader::reject_signals`.
/// Producing `done` ingress history statuses.
V8 = 8,
/// Producing non-empty `StreamHeader::reject_signals`.
V9 = 9,
/// Dropped `SystemMetadata::id_counter`.
V10 = 10,
/// Producing `error_code` field in `request_status` subtree.
V11 = 11,
/// Added `/subnet/<own_subnet_id>/node` subtree, with node public keys.
V12 = 12,
/// Dropped `/canister/<canister_id>/controller`.
V13 = 13,
/// Define optional `Request::metadata` field.
V14 = 14,
/// Added subnet metrics in `subnet` subtree.
V15 = 15,
/// Added `/api_boundary_nodes` subtree with domain, ipv4_address and ipv6_address for each API boundary node.
V16 = 16,
}
#[derive(Debug, PartialEq, Eq)]
pub struct UnsupportedCertificationVersion(u32);
impl std::fmt::Display for UnsupportedCertificationVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use strum::IntoEnumIterator;
write!(
f,
"Certification version {} is not defined, known versions: {:?}",
self.0,
CertificationVersion::iter()
.map(|v| v as u32)
.collect::<Vec<_>>()
)
}
}
impl std::convert::TryFrom<u32> for CertificationVersion {
type Error = UnsupportedCertificationVersion;
fn try_from(n: u32) -> Result<Self, Self::Error> {
use strum::IntoEnumIterator;
CertificationVersion::iter()
.nth(n as usize)
.ok_or(UnsupportedCertificationVersion(n))
}
}
/// The Canonical State certification version that should be used for newly
/// computed states.
pub const CURRENT_CERTIFICATION_VERSION: CertificationVersion = CertificationVersion::V15;
/// Maximum supported certification version.
///
/// The replica will panic if requested to certify using a version higher than
/// this.
pub const MAX_SUPPORTED_CERTIFICATION_VERSION: CertificationVersion = CertificationVersion::V16;
/// Returns a list of all certification versions up to [MAX_SUPPORTED_CERTIFICATION_VERSION].
pub fn all_supported_versions() -> impl std::iter::Iterator<Item = CertificationVersion> {
use strum::IntoEnumIterator;
CertificationVersion::iter().take_while(|v| *v <= MAX_SUPPORTED_CERTIFICATION_VERSION)
}
#[test]
fn supported_version_ge_current() {
assert!(CURRENT_CERTIFICATION_VERSION <= MAX_SUPPORTED_CERTIFICATION_VERSION);
}