Skip to main content

ic_memory/
policy.rs

1use crate::{key::StableKey, slot::AllocationSlotDescriptor};
2
3///
4/// AllocationPolicy
5///
6/// Framework-supplied rules for whether a key may claim a slot.
7///
8/// Policy is intentionally separate from the durable ledger invariant. The
9/// ledger remembers `stable_key -> allocation_slot`; this trait lets an
10/// integration reject declarations that do not belong to its namespace or
11/// substrate-specific range before staging a generation.
12pub trait AllocationPolicy {
13    /// Policy error type.
14    type Error;
15
16    /// Validate a stable key against framework naming rules.
17    fn validate_key(&self, key: &StableKey) -> Result<(), Self::Error>;
18
19    /// Validate a stable-key to allocation-slot claim.
20    fn validate_slot(
21        &self,
22        key: &StableKey,
23        slot: &AllocationSlotDescriptor,
24    ) -> Result<(), Self::Error>;
25
26    /// Validate a reserved stable-key to allocation-slot claim.
27    fn validate_reserved_slot(
28        &self,
29        key: &StableKey,
30        slot: &AllocationSlotDescriptor,
31    ) -> Result<(), Self::Error>;
32}
33
34///
35/// NamespaceAuthority
36///
37/// Policy-owned stable-key namespace ownership.
38pub trait NamespaceAuthority {
39    /// Return true when this authority owns `key`.
40    fn owns(&self, key: &StableKey) -> bool;
41}
42
43///
44/// RangeAuthority
45///
46/// Optional substrate-specific range authority validation.
47pub trait RangeAuthority {
48    /// Range validation error type.
49    type Error;
50
51    /// Validate one allocation slot against the authority.
52    fn validate_slot(&self, slot: &AllocationSlotDescriptor) -> Result<(), Self::Error>;
53}