use crate::types::ProtocolVersion;
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
pub enum ProtocolFeature {
ImplicitAccountCreation,
RectifyInflation,
AccessKeyNonceRange,
FixApplyChunks,
LowerStorageCost,
DeleteActionRestriction,
AccountVersions,
TransactionSizeLimit,
FixStorageUsage,
CapMaxGasPrice,
CountRefundReceiptsInGasLimit,
MathExtension,
RestoreReceiptsAfterFixApplyChunks,
Wasmer2,
SimpleNightshade,
LowerDataReceiptAndEcrecoverBaseCost,
LowerRegularOpCost,
LowerRegularOpCost2,
LimitContractFunctionsNumber,
BlockHeaderV3,
AliasValidatorSelectionAlgorithm,
SynchronizeBlockChunkProduction,
CorrectStackLimit,
AccessKeyNonceForImplicitAccounts,
IncreaseDeploymentCost,
FunctionCallWeight,
LimitContractLocals,
ChunkNodesCache,
LowerStorageKeyLimit,
AltBn128,
ChunkOnlyProducers,
MaxKickoutPledge,
AccountIdInFunctionCallPermission,
ZeroBalanceAccount,
DelegateAction,
Ed25519Verify,
ComputeCosts,
FlatStorageReads,
PreparationV2,
UncVmRuntime,
BlockHeaderV4,
SimpleNightshadeV2,
#[cfg(feature = "protocol_feature_fix_staking_threshold")]
FixStakingThreshold,
#[cfg(feature = "protocol_feature_fix_contract_loading_cost")]
FixContractLoadingCost,
#[cfg(feature = "protocol_feature_reject_blocks_with_outdated_protocol_version")]
RejectBlocksWithOutdatedProtocolVersions,
RestrictTla,
TestnetFewerBlockProducers,
ChunkValidation,
EthAccounts,
}
impl ProtocolFeature {
pub const fn protocol_version(self) -> ProtocolVersion {
match self {
ProtocolFeature::ImplicitAccountCreation => 35,
ProtocolFeature::LowerStorageCost => 42,
ProtocolFeature::DeleteActionRestriction => 43,
ProtocolFeature::FixApplyChunks => 44,
ProtocolFeature::RectifyInflation | ProtocolFeature::AccessKeyNonceRange => 45,
ProtocolFeature::AccountVersions
| ProtocolFeature::TransactionSizeLimit
| ProtocolFeature::FixStorageUsage
| ProtocolFeature::CapMaxGasPrice
| ProtocolFeature::CountRefundReceiptsInGasLimit
| ProtocolFeature::MathExtension => 46,
ProtocolFeature::RestoreReceiptsAfterFixApplyChunks => 47,
ProtocolFeature::Wasmer2
| ProtocolFeature::LowerDataReceiptAndEcrecoverBaseCost
| ProtocolFeature::LowerRegularOpCost
| ProtocolFeature::SimpleNightshade => 48,
ProtocolFeature::LowerRegularOpCost2
| ProtocolFeature::LimitContractFunctionsNumber
| ProtocolFeature::BlockHeaderV3
| ProtocolFeature::AliasValidatorSelectionAlgorithm => 49,
ProtocolFeature::SynchronizeBlockChunkProduction
| ProtocolFeature::CorrectStackLimit => 50,
ProtocolFeature::AccessKeyNonceForImplicitAccounts => 51,
ProtocolFeature::IncreaseDeploymentCost
| ProtocolFeature::FunctionCallWeight
| ProtocolFeature::LimitContractLocals
| ProtocolFeature::ChunkNodesCache
| ProtocolFeature::LowerStorageKeyLimit => 53,
ProtocolFeature::AltBn128 => 55,
ProtocolFeature::ChunkOnlyProducers | ProtocolFeature::MaxKickoutPledge => 56,
ProtocolFeature::AccountIdInFunctionCallPermission => 57,
ProtocolFeature::Ed25519Verify
| ProtocolFeature::ZeroBalanceAccount
| ProtocolFeature::DelegateAction => 59,
ProtocolFeature::ComputeCosts | ProtocolFeature::FlatStorageReads => 61,
ProtocolFeature::PreparationV2 | ProtocolFeature::UncVmRuntime => 62,
ProtocolFeature::BlockHeaderV4 => 63,
ProtocolFeature::RestrictTla
| ProtocolFeature::TestnetFewerBlockProducers
| ProtocolFeature::SimpleNightshadeV2 => 64,
#[cfg(feature = "protocol_feature_fix_staking_threshold")]
ProtocolFeature::FixStakingThreshold => 126,
#[cfg(feature = "protocol_feature_fix_contract_loading_cost")]
ProtocolFeature::FixContractLoadingCost => 129,
#[cfg(feature = "protocol_feature_reject_blocks_with_outdated_protocol_version")]
ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions => 132,
ProtocolFeature::ChunkValidation => 137,
ProtocolFeature::EthAccounts => 138,
}
}
}
const STABLE_PROTOCOL_VERSION: ProtocolVersion = 64;
pub const PROTOCOL_VERSION: ProtocolVersion = if cfg!(feature = "nightly_protocol") {
139
} else {
STABLE_PROTOCOL_VERSION
};
pub const PEER_MIN_ALLOWED_PROTOCOL_VERSION: ProtocolVersion = STABLE_PROTOCOL_VERSION - 2;
#[macro_export]
macro_rules! checked_feature {
("stable", $feature:ident, $current_protocol_version:expr) => {{
$crate::version::ProtocolFeature::$feature.protocol_version() <= $current_protocol_version
}};
($feature_name:tt, $feature:ident, $current_protocol_version:expr) => {{
#[cfg(feature = $feature_name)]
let is_feature_enabled = $crate::version::ProtocolFeature::$feature.protocol_version()
<= $current_protocol_version;
#[cfg(not(feature = $feature_name))]
let is_feature_enabled = {
let _ = $current_protocol_version;
false
};
is_feature_enabled
}};
($feature_name:tt, $feature:ident, $current_protocol_version:expr, $feature_block:block) => {{
checked_feature!($feature_name, $feature, $current_protocol_version, $feature_block, {})
}};
($feature_name:tt, $feature:ident, $current_protocol_version:expr, $feature_block:block, $non_feature_block:block) => {{
#[cfg(feature = $feature_name)]
{
if checked_feature!($feature_name, $feature, $current_protocol_version) {
$feature_block
} else {
$non_feature_block
}
}
#[cfg(not(feature = $feature_name))]
{
let _ = $current_protocol_version;
$non_feature_block
}
}};
}