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
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//! Feature Management Program Interface
//!
//! This program provides a system-level mechanism for managing feature flags.
//! Activation is presence-based and append-only: a feature is active once its
//! name is added to the on-chain set, and names are never removed.
extern crate alloc;
use Vec;
use Pubkey;
declare_id!;
/// Storage account PDA seed for the features map
pub const STORAGE_ACCOUNT_SEED: & = b"features_storage";
/// Derive the storage account address
/// Maximum length for a feature name
pub const MAX_FEATURE_NAME_LENGTH: usize = 512;
/// Maximum number of features allowed in the system
pub const MAX_FEATURE_COUNT: usize = 10000;
/// Maximum number of names a single `Enable` instruction may carry.
///
/// Bounded by the ~64 KB transaction-size limit: 100 × 512-byte names
/// (`MAX_FEATURE_NAME_LENGTH`) plus borsh length prefixes ≈ 51.6 KB, well
/// inside the envelope with comfortable room for transaction headers,
/// signatures, and other instructions in the same tx. Raising the cap
/// requires re-validating the worst-case payload against the tx-size limit.
pub const MAX_NAMES_PER_BATCH: usize = 100;
/// Maximum total size of serialized features state (100 KB)
pub const MAX_FEATURES_STATE_SIZE: usize = 100 * 1024;
/// Validates a feature name
///
/// Feature names must:
/// - Not be empty
/// - Not exceed MAX_FEATURE_NAME_LENGTH
/// - Contain only alphanumeric characters, underscores, and hyphens
/// - Not start or end with whitespace
/// Create genesis storage data with initial authority
///
/// Creates the initial FeaturesState with the provided authority and serializes it
/// for use in genesis configuration.
///
/// # Arguments
/// * `authority` - The pubkey that will have authority over the feature management system
///
/// # Returns
/// A `Vec<u8>` containing the serialized FeaturesState