unc_primitives/
version.rs

1use crate::types::Balance;
2use once_cell::sync::Lazy;
3
4/// Data structure for semver version and github tag or commit.
5#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default)]
6pub struct Version {
7    pub version: String,
8    pub build: String,
9    #[serde(default)]
10    pub rustc_version: String,
11}
12
13use crate::upgrade_schedule::{get_protocol_version_internal, ProtocolUpgradeVotingSchedule};
14
15/// unc_primitives_core re-exports
16pub use unc_primitives_core::checked_feature;
17pub use unc_primitives_core::types::ProtocolVersion;
18pub use unc_primitives_core::version::ProtocolFeature;
19pub use unc_primitives_core::version::PEER_MIN_ALLOWED_PROTOCOL_VERSION;
20pub use unc_primitives_core::version::PROTOCOL_VERSION;
21
22/// Minimum gas price proposed in UIP 92 and the associated protocol version
23pub const MIN_GAS_PRICE_UIP_92: Balance = 1_000_000_000;
24pub const MIN_PROTOCOL_VERSION_UIP_92: ProtocolVersion = 31;
25
26/// Minimum gas price proposed in UIP 92 (fixed) and the associated protocol version
27pub const MIN_GAS_PRICE_UIP_92_FIX: Balance = 100_000_000;
28pub const MIN_PROTOCOL_VERSION_UIP_92_FIX: ProtocolVersion = 32;
29
30pub const CORRECT_RANDOM_VALUE_PROTOCOL_VERSION: ProtocolVersion = 33;
31
32/// The protocol version that enables reward on mainnet.
33pub const ENABLE_INFLATION_PROTOCOL_VERSION: ProtocolVersion = 36;
34
35/// Fix upgrade to use the latest voted protocol version instead of the current epoch protocol
36/// version when there is no new change in protocol version.
37pub const UPGRADABILITY_FIX_PROTOCOL_VERSION: ProtocolVersion = 37;
38
39/// Updates the way receipt ID, data ID and random seeds are constructed.
40pub const CREATE_HASH_PROTOCOL_VERSION: ProtocolVersion = 38;
41
42/// Fix the storage usage of the delete key action.
43pub const DELETE_KEY_STORAGE_USAGE_PROTOCOL_VERSION: ProtocolVersion = 40;
44
45pub const SHARD_CHUNK_HEADER_UPGRADE_VERSION: ProtocolVersion = 41;
46
47/// Updates the way receipt ID is constructed to use current block hash instead of last block hash
48pub const CREATE_RECEIPT_ID_SWITCH_TO_CURRENT_BLOCK_VERSION: ProtocolVersion = 42;
49
50/// The points in time after which the voting for the latest protocol version
51/// should start.
52///
53/// In non-release builds this is typically a date in the far past (meaning that
54/// nightly builds will vote for new protocols immediately).  On release builds
55/// it’s set according to the schedule for that protocol upgrade.  Release
56/// candidates usually have separate schedule to final releases.
57pub const PROTOCOL_UPGRADE_SCHEDULE: Lazy<ProtocolUpgradeVotingSchedule> = Lazy::new(|| {
58    // Update to according to schedule when making a release.
59    // Keep in mind that the protocol upgrade will happen 1-2 epochs (15h-30h)
60    // after the set date. Ideally that should be during working hours.
61    // e.g. ProtocolUpgradeVotingSchedule::from_env_or_str("2000-01-01 15:00:00").unwrap());
62
63    ProtocolUpgradeVotingSchedule::default()
64});
65
66/// Gives new clients an option to upgrade without announcing that they support
67/// the new version.  This gives non-validator nodes time to upgrade.  See
68/// <https://github.com/Utility/UEPs/issues/205>
69pub fn get_protocol_version(next_epoch_protocol_version: ProtocolVersion) -> ProtocolVersion {
70    get_protocol_version_internal(
71        next_epoch_protocol_version,
72        PROTOCOL_VERSION,
73        *PROTOCOL_UPGRADE_SCHEDULE,
74    )
75}