Skip to main content

platform_version/version/fee/storage/
mod.rs

1use bincode::{Decode, Encode};
2
3pub mod v1;
4
5#[derive(Clone, Debug, Encode, Decode, Default, PartialEq, Eq)]
6pub struct FeeStorageVersion {
7    pub storage_disk_usage_credit_per_byte: u64,
8    pub storage_processing_credit_per_byte: u64,
9    pub storage_load_credit_per_byte: u64,
10    pub non_storage_load_credit_per_byte: u64,
11    pub storage_seek_cost: u64,
12    /// Credits charged per byte written under a TTL'd `timeRange` index
13    /// subtree, billed to PROCESSING in place of the storage fee: the
14    /// bytes provably live at most one week (the `ttl` cap) plus a
15    /// bounded drainage lag, so charging them the perpetual-retention
16    /// storage price would overprice them by orders of magnitude. Zero
17    /// until protocol version 14 — the `ttl` grammar does not parse
18    /// before it, so no ephemeral-classified operation can exist.
19    pub ttl_ephemeral_disk_usage_credit_per_byte: u64,
20}
21
22#[cfg(test)]
23mod tests {
24    use super::FeeStorageVersion;
25
26    #[test]
27    // If this test failed, then a new field was added in FeeProcessingVersion. And the corresponding eq needs to be updated as well
28    fn test_fee_storage_version_equality() {
29        let version1 = FeeStorageVersion {
30            storage_disk_usage_credit_per_byte: 1,
31            storage_processing_credit_per_byte: 2,
32            storage_load_credit_per_byte: 3,
33            non_storage_load_credit_per_byte: 4,
34            storage_seek_cost: 5,
35            ttl_ephemeral_disk_usage_credit_per_byte: 6,
36        };
37
38        let version2 = FeeStorageVersion {
39            storage_disk_usage_credit_per_byte: 1,
40            storage_processing_credit_per_byte: 2,
41            storage_load_credit_per_byte: 3,
42            non_storage_load_credit_per_byte: 4,
43            storage_seek_cost: 5,
44            ttl_ephemeral_disk_usage_credit_per_byte: 6,
45        };
46
47        // This assertion will check if all fields are considered in the equality comparison
48        assert_eq!(version1, version2, "FeeStorageVersion equality test failed. If a field was added or removed, update the Eq implementation.");
49
50        // And the inequality direction: a difference in the newest field
51        // alone must be visible to Eq.
52        let version3 = FeeStorageVersion {
53            ttl_ephemeral_disk_usage_credit_per_byte: 7,
54            ..version2.clone()
55        };
56        assert_ne!(
57            version1, version3,
58            "FeeStorageVersion equality must distinguish ttl_ephemeral_disk_usage_credit_per_byte"
59        );
60    }
61}